mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-01-31 04:31:01 -05:00
"Changed first_harvest" to "days_to_first_harvest"
This commit is contained in:
@@ -221,7 +221,7 @@ class Crop < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def update_harvest_medians
|
||||
update(median_first_harvest: Planting.where(crop: self).median(:first_harvest))
|
||||
update(median_days_to_first_harvest: Planting.where(crop: self).median(:days_to_first_harvest))
|
||||
update(median_last_harvest: Planting.where(crop: self).median(:last_harvest))
|
||||
end
|
||||
|
||||
|
||||
@@ -115,16 +115,15 @@ class Planting < ActiveRecord::Base
|
||||
|
||||
def update_harvest_days
|
||||
harvests_with_dates = harvests.where.not(harvested_at: nil)
|
||||
first_harvest = nil
|
||||
days_to_first_harvest = nil
|
||||
last_harvest = nil
|
||||
if planted_at.present? && harvests_with_dates.size.positive?
|
||||
# how long ago was this planted
|
||||
first_harvest = (harvests_with_dates.order(harvested_at: :asc).limit(1).first.harvested_at - planted_at).to_i
|
||||
days_to_first_harvest = (harvests_with_dates.order(harvested_at: :asc).first.harvested_at - planted_at).to_i
|
||||
if finished?
|
||||
last_harvest = (harvests_with_dates.order(harvested_at: :desc).limit(1).first.harvested_at - planted_at).to_i
|
||||
last_harvest = (harvests_with_dates.order(harvested_at: :desc).first.harvested_at - planted_at).to_i
|
||||
end
|
||||
end
|
||||
update(first_harvest: first_harvest, last_harvest: last_harvest)
|
||||
update(days_to_first_harvest: days_to_first_harvest, last_harvest: last_harvest)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
Median Lifespan
|
||||
%b= crop.median_lifespan
|
||||
days
|
||||
- unless crop.median_first_harvest.nil?
|
||||
- unless crop.median_days_to_first_harvest.nil?
|
||||
%p
|
||||
First harvest expected
|
||||
%b= crop.median_first_harvest
|
||||
%b= crop.median_days_to_first_harvest
|
||||
days after planting
|
||||
|
||||
- if crop.annual? && crop.median_last_harvest.present?
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
%b= crop.median_lifespan
|
||||
days
|
||||
|
||||
- unless crop.median_first_harvest.nil?
|
||||
- unless crop.median_days_to_first_harvest.nil?
|
||||
%p
|
||||
First harvest expected
|
||||
%b= crop.median_first_harvest
|
||||
%b= crop.median_days_to_first_harvest
|
||||
days after planting
|
||||
|
||||
- if crop.perennial == false && crop.median_last_harvest.present?
|
||||
|
||||
@@ -56,9 +56,9 @@
|
||||
- if @planting.lifespan.present?
|
||||
%dt Actual Lifespan:
|
||||
%dd #{@planting.lifespan} days
|
||||
- if @planting.first_harvest.present?
|
||||
- if @planting.days_to_first_harvest.present?
|
||||
%dt First Harvest:
|
||||
%dd #{@planting.first_harvest} days after planting
|
||||
%dd #{@planting.days_to_first_harvest} days after planting
|
||||
- if @planting.last_harvest.present?
|
||||
%dt Last Harvest:
|
||||
%dd #{@planting.last_harvest} days after planting
|
||||
|
||||
@@ -6,12 +6,12 @@ class AllThePredictions < ActiveRecord::Migration
|
||||
add_column :plantings, :lifespan, :integer
|
||||
|
||||
# how old was planting at first harvest
|
||||
add_column :plantings, :first_harvest, :integer
|
||||
add_column :plantings, :days_to_first_harvest, :integer
|
||||
add_column :plantings, :last_harvest, :integer
|
||||
|
||||
# Keep the median values for the crop
|
||||
add_column :crops, :median_lifespan, :integer
|
||||
add_column :crops, :median_first_harvest, :integer
|
||||
add_column :crops, :median_days_to_first_harvest, :integer
|
||||
add_column :crops, :median_last_harvest, :integer
|
||||
|
||||
create_table :median_functions do |t|
|
||||
|
||||
@@ -196,7 +196,7 @@ ActiveRecord::Schema.define(version: 20171105011017) do
|
||||
t.text "rejection_notes"
|
||||
t.boolean "perennial", default: false
|
||||
t.integer "median_lifespan"
|
||||
t.integer "median_first_harvest"
|
||||
t.integer "median_days_to_first_harvest"
|
||||
t.integer "median_last_harvest"
|
||||
end
|
||||
|
||||
@@ -431,7 +431,7 @@ ActiveRecord::Schema.define(version: 20171105011017) do
|
||||
t.date "finished_at"
|
||||
t.integer "days_before_maturity"
|
||||
t.integer "lifespan"
|
||||
t.integer "first_harvest"
|
||||
t.integer "days_to_first_harvest"
|
||||
t.integer "last_harvest"
|
||||
end
|
||||
|
||||
|
||||
@@ -82,9 +82,9 @@ describe Planting do
|
||||
describe 'planting first harvest preductions' do
|
||||
context 'no data' do
|
||||
let(:planting) { FactoryBot.create :planting }
|
||||
it { expect(planting.crop.median_first_harvest).to eq(nil) }
|
||||
it { expect(planting.crop.median_days_to_first_harvest).to eq(nil) }
|
||||
it { expect(planting.crop.median_last_harvest).to eq(nil) }
|
||||
it { expect(planting.first_harvest).to eq(nil) }
|
||||
it { expect(planting.days_to_first_harvest).to eq(nil) }
|
||||
it { expect(planting.last_harvest).to eq(nil) }
|
||||
it { expect(planting.expected_lifespan).to eq(nil) }
|
||||
end
|
||||
@@ -106,7 +106,7 @@ describe Planting do
|
||||
planting.crop.update_lifespan_medians
|
||||
planting.crop.update_harvest_medians
|
||||
end
|
||||
it { expect(planting.crop.median_first_harvest).to eq(20) }
|
||||
it { expect(planting.crop.median_days_to_first_harvest).to eq(20) }
|
||||
end
|
||||
describe 'planting has no harvests' do
|
||||
before do
|
||||
@@ -114,7 +114,7 @@ describe Planting do
|
||||
planting.crop.update_harvest_medians
|
||||
end
|
||||
let(:planting) { FactoryBot.create :planting }
|
||||
it { expect(planting.first_harvest).to eq(nil) }
|
||||
it { expect(planting.days_to_first_harvest).to eq(nil) }
|
||||
it { expect(planting.last_harvest).to eq(nil) }
|
||||
end
|
||||
describe 'planting has first harvest' do
|
||||
@@ -124,9 +124,9 @@ describe Planting do
|
||||
planting.update_harvest_days
|
||||
planting.crop.update_harvest_medians
|
||||
end
|
||||
it { expect(planting.first_harvest).to eq(90) }
|
||||
it { expect(planting.days_to_first_harvest).to eq(90) }
|
||||
it { expect(planting.last_harvest).to eq(nil) }
|
||||
it { expect(planting.crop.median_first_harvest).to eq(90) }
|
||||
it { expect(planting.crop.median_days_to_first_harvest).to eq(90) }
|
||||
it { expect(planting.crop.median_last_harvest).to eq(nil) }
|
||||
end
|
||||
describe 'planting has last harvest' do
|
||||
@@ -137,9 +137,9 @@ describe Planting do
|
||||
planting.update_harvest_days
|
||||
planting.crop.update_harvest_medians
|
||||
end
|
||||
it { expect(planting.first_harvest).to eq(10) }
|
||||
it { expect(planting.days_to_first_harvest).to eq(10) }
|
||||
it { expect(planting.last_harvest).to eq(90) }
|
||||
it { expect(planting.crop.median_first_harvest).to eq(10) }
|
||||
it { expect(planting.crop.median_days_to_first_harvest).to eq(10) }
|
||||
it { expect(planting.crop.median_last_harvest).to eq(90) }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user