-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log weather periodically via OpenWeatherAPI - proof of concept/WIP #1307
Closed
CloCkWeRX
wants to merge
15
commits into
Growstuff:dev
from
CloCkWeRX:the_rain_in_spain_falls_mainly_where_the_weatherapi_says_it_does
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7ec699e
Add open-weather client
CloCkWeRX a7ca8f1
Add a rake task to log weather for plantings
CloCkWeRX a466c2e
Add a weather_log structure
CloCkWeRX d29899f
Add activerecord models for weather structure
CloCkWeRX 3cfc8e7
Record weather logs
CloCkWeRX 4bb3819
Shift to application config, and sleep between API calls but not DB w…
CloCkWeRX d1337b3
Put a hard limit on the number of plantings we'll look up weather for…
CloCkWeRX 235d3fa
Rubocop
CloCkWeRX f12f15f
Rubocop
CloCkWeRX 64721e2
Rubocop
CloCkWeRX e19c8f4
Ask for postgres 9.4 and above.
CloCkWeRX 8c40f10
Fix accidental killing off of .ruby-version
CloCkWeRX f393bc2
Fix accidental commit to Gemfile
CloCkWeRX 2fd929d
Undo changes to db config
CloCkWeRX 2dfabdb
Encourage code I didn't change to stop being complained about
CloCkWeRX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Defines a JSON data type as weather_log | ||
# See http://edgeguides.rubyonrails.org/active_record_postgresql.html#json for how to query it | ||
# See http://openweathermap.org/current for documentation | ||
|
||
# Example call: http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=df8abc00e3162fbd98bc48063cc6c4b5 | ||
# { | ||
# "coord":{ | ||
# "lon":-0.13, | ||
# "lat":51.51 | ||
# }, | ||
# "weather":[ | ||
# { | ||
# "id":800, | ||
# "main":"Clear", | ||
# "description":"clear sky", | ||
# "icon":"01d" | ||
# } | ||
# ], | ||
# "base":"stations", | ||
# "main":{ | ||
# "temp":281.83, | ||
# "pressure":1025, | ||
# "humidity":61, | ||
# "temp_min":280.15, | ||
# "temp_max":283.15 | ||
# }, | ||
# "visibility":10000, | ||
# "wind":{ | ||
# "speed":5.7, | ||
# "deg":300 | ||
# }, | ||
# "clouds":{ | ||
# "all":0 | ||
# }, | ||
# "dt":1491808800, | ||
# "sys":{ | ||
# "type":1, | ||
# "id":5091, | ||
# "message":0.0097, | ||
# "country":"GB", | ||
# "sunrise":1491801287, | ||
# "sunset":1491850179 | ||
# }, | ||
# "id":2643743, | ||
# "name":"London", | ||
# "cod":200 | ||
# } | ||
class PlantingWeatherLog < ActiveRecord::Base | ||
belongs_to :planting | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class PlantingWeatherLog < ActiveRecord::Migration | ||
def change | ||
create_table :planting_weather_logs do |t| | ||
t.integer :planting_id | ||
t.timestamps | ||
t.json 'weather_data' | ||
end | ||
|
||
add_index :planting_weather_logs, :planting_id | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be per garden? Or even per location? The basil and the tomatoes are next to each other so have the same weather afaik
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went for planting so you can answer things like "Why did my leeks grow better last year than this year? Oh, 27 days of 40 degree temperature in a row on last year's planting" more easily
IE its simpler to do
SELECT AVG(temp) FROM planting_weather_log WHERE planting_id = ?
and only have data recorded for the duration of the planting; than it is to doSELECT AVG(temp) FROM garden_weather_log JOIN gardens JOIN plantings WHERE garden_weather_log.created_at BETWEEN planting.start and planting.end GROUP BY planting_id
x lots.
Plantings also have a start and end date usually (planting.active); while a Garden is forever; and at least one per user; even if they never do anything with the site.
I suspect we'd run out of the free tier of API usage if we did that for everyone's gardens.
For dealing with plantings in the same garden/location/etc; we can probably cache the API requests at a city/geocoded location level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about a weather log for a timestamp+location, then a planting links to that? Then the weather for a member's 100+ plantings isn't duplicated.