Commit b1e5b04d by ivan Lan

Add Aqi::Forecast

parent afebacf0
class CreateCityForecasts < ActiveRecord::Migration[5.0] class CreateCityForecasts < ActiveRecord::Migration[5.0]
def up def up
create_table :city_forecasts do |t| create_table :city_forecasts do |t|
t.date :date t.datetime :datetime
t.integer :temp_low t.integer :temp_low
t.integer :temp_high t.integer :temp_high
t.string :weather_text t.string :weather_text
......
class CreateAqiForecasts < ActiveRecord::Migration[5.0]
def up
create_table :aqi_forecasts do |t|
t.datetime :datetime
t.string :prompt
t.text :list
t.timestamps
end
add_index :aqi_forecasts, :datetime
end
def down
drop_table :aqi_forecasts
end
end
...@@ -2,7 +2,7 @@ module WeatherModel ...@@ -2,7 +2,7 @@ module WeatherModel
module SourceSchema module SourceSchema
def self.sorts def self.sorts
[:Forecast, :AutoStation] [:Forecast, :AutoStation, :Aqi]
end end
Dir['./lib/weather-model/source_schemas/*.rb'].each { |file| Dir['./lib/weather-model/source_schemas/*.rb'].each { |file|
......
module WeatherModel
module SourceSchema
Forecast =
{
sort: 'Aqi',
table_name: :aqi_forecasts,
schema: {
datetime: :datetime,
prompt: :string,
list: :text
},
options: {
index: %i[datetime],
expire: 2 * 24 * 60 * 60,
unique: nil,
belongs_to: nil,
has_many: nil,
json_columns: :list
},
factory_name: :aqi_forecast,
factory: {
datetime: Time.parse('2011-11-11 11:11'),
prompt: '',
list: [
{
"period"=>"今天夜间(20时—06时)",
"aqi"=>"35-55",
"level"=>"优到良",
"pripoll"=>"PM10"
}, {
"period"=>"明天上午(06时—12时)",
"aqi"=>"35-55",
"level"=>"优到良",
"pripoll"=>"PM10"
}, {
"period"=>"明天下午(12时—20时)",
"aqi"=>"45-65",
"level"=>"优到良",
"pripoll"=>"O3"
}, {
"period"=>"明天夜间(20时—06时)",
"aqi"=>"35-55",
"level"=>"优到良",
"pripoll"=>"PM10"
}, {
"period"=>"后天白天(06时—20时)",
"aqi"=>"55-75",
"level"=>"良",
"pripoll"=>"O3"
}
]
}
}
end
end
\ No newline at end of file
...@@ -5,7 +5,7 @@ module WeatherModel ...@@ -5,7 +5,7 @@ module WeatherModel
sort: 'Forecast', sort: 'Forecast',
table_name: :city_forecasts, table_name: :city_forecasts,
schema: { schema: {
date: :date, datetime: :datetime,
cityname: :string, cityname: :string,
temp_high: :string, temp_high: :string,
temp_low: :string, temp_low: :string,
...@@ -24,7 +24,7 @@ module WeatherModel ...@@ -24,7 +24,7 @@ module WeatherModel
}, },
factory_name: :city_forecast, factory_name: :city_forecast,
factory: { factory: {
date: Time.parse('2017-05-16'), datetime: Time.parse('2017-05-16 16:00'),
cityname: '上海', cityname: '上海',
temp_high: '100', temp_high: '100',
temp_low: '0', temp_low: '0',
......
...@@ -41,7 +41,7 @@ RSpec.describe WeatherModel do ...@@ -41,7 +41,7 @@ RSpec.describe WeatherModel do
@expire = 1 @expire = 1
Forecast::CityForecast::Ohm.expire @expire Forecast::CityForecast::Ohm.expire @expire
mysql_obj = Forecast::CityForecast.create({ mysql_obj = Forecast::CityForecast.create({
date: '2017-05-16', datetime: '2017-05-16',
cityname: 'shanghai', cityname: 'shanghai',
temp_high: '100', temp_high: '100',
temp_low: '0', temp_low: '0',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment