Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
weather-model
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
weather-model
Commits
3e58dcdb
Commit
3e58dcdb
authored
May 20, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test to all source data
parent
139ef81e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
3 deletions
+64
-3
3_create_aqi_forecasts.rb
db/migrate/3_create_aqi_forecasts.rb
+0
-1
4_create_realtime_aqi.rb
db/migrate/4_create_realtime_aqi.rb
+20
-0
aqi.rb
lib/weather-model/source_schemas/aqi.rb
+33
-0
auto_station.rb
lib/weather-model/source_schemas/auto_station.rb
+2
-2
weather-model_spec.rb
spec/weather-model_spec.rb
+9
-0
No files found.
db/migrate/3_create_aqi_forecasts.rb
View file @
3e58dcdb
...
@@ -15,4 +15,3 @@ class CreateAqiForecasts < ActiveRecord::Migration[5.0]
...
@@ -15,4 +15,3 @@ class CreateAqiForecasts < ActiveRecord::Migration[5.0]
drop_table
:aqi_forecasts
drop_table
:aqi_forecasts
end
end
end
end
db/migrate/4_create_realtime_aqi.rb
0 → 100644
View file @
3e58dcdb
class
CreateRealtimeAqi
<
ActiveRecord
::
Migration
[
5.0
]
def
up
create_table
:realtime_aqi
do
|
t
|
t
.
datetime
:datetime
t
.
integer
:aqi
t
.
string
:level
t
.
string
:pripoll
t
.
string
:content
t
.
string
:measure
t
.
timestamps
end
add_index
:realtime_aqi
,
:datetime
end
def
down
drop_table
:realtime_aqi
end
end
lib/weather-model/source_schemas/aqi.rb
View file @
3e58dcdb
...
@@ -51,5 +51,38 @@ module WeatherModel
...
@@ -51,5 +51,38 @@ module WeatherModel
]
]
}
}
}
}
RealtimeAqi
=
{
sort:
'Aqi'
,
table_name: :realtime_aqi
,
schema:
{
datetime: :datetime
,
aqi: :string
,
level: :string
,
pripoll: :string
,
content: :string
,
measure: :string
,
},
options:
{
index:
%i[datetime]
,
expire:
3
*
24
*
60
*
60
,
unique:
nil
,
belongs_to:
nil
,
has_many:
nil
,
json_column: :msg
},
factory_name: :realtime_aqi
,
factory:
{
datetime:
Time
.
parse
(
'2011-11-11 11:11'
),
aqi:
'54'
,
level:
'良'
,
pripoll:
'PM10'
,
msg:
{
content:
'空气质量可接受,但某些污染物可能对极少数异常敏感人群健康有较弱影响。'
,
measure:
'建议措施极少数异常敏感人群应减少户外活动。'
}
}
}
end
end
end
end
lib/weather-model/source_schemas/auto_station.rb
View file @
3e58dcdb
module
WeatherModel
module
WeatherModel
module
SourceSchema
module
SourceSchema
TenMins
=
AutoStation
TenMins
=
{
{
sort:
'AutoStation'
,
sort:
'AutoStation'
,
table_name: :auto_station
s
_ten_mins
,
table_name: :auto_station_ten_mins
,
schema:
{
schema:
{
datetime: :datetime
,
datetime: :datetime
,
sitenumber: :string
,
sitenumber: :string
,
...
...
spec/weather-model_spec.rb
View file @
3e58dcdb
...
@@ -84,6 +84,15 @@ RSpec.describe WeatherModel do
...
@@ -84,6 +84,15 @@ RSpec.describe WeatherModel do
expect
(
Aqi
::
AqiForecast
::
Ohm
.
all
.
first
.
list
.
class
).
to
eq
(
Array
),
'Ohm json_column 正常'
expect
(
Aqi
::
AqiForecast
::
Ohm
.
all
.
first
.
list
.
class
).
to
eq
(
Array
),
'Ohm json_column 正常'
end
end
it
'Test all source data'
do
[
Forecast
::
CityForecast
,
AutoStation
::
AutoStationTenMins
,
Aqi
::
AqiForecast
,
Aqi
::
RealtimeAqi
].
each
{
|
source
|
source
.
all
;
source
.
const_get
(
'Ohm'
).
all
}
end
after
do
after
do
ActiveRecord
::
Migration
[
5.0
].
subclasses
.
each
do
|
migrate
|
ActiveRecord
::
Migration
[
5.0
].
subclasses
.
each
do
|
migrate
|
migrate
.
migrate
(
:down
)
migrate
.
migrate
(
:down
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment