Campfireman commited on
Commit
9e5f3ef
1 Parent(s): b67094f

Update functions.py

Browse files
Files changed (1) hide show
  1. functions.py +86 -0
functions.py CHANGED
@@ -101,3 +101,89 @@ def get_model(project, model_name, evaluation_metric, sort_metrics_by):
101
 
102
  return model
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
  return model
103
 
104
+
105
+
106
+ def get_weather_json(date, WEATHER_API_KEY):
107
+ return requests.get(f'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/helsinki/{date}?unitGroup=metric&include=days&key={WEATHER_API_KEY}&contentType=json').json()
108
+
109
+
110
+ def get_weather_data(date):
111
+ WEATHER_API_KEY = os.getenv('WEATHER_API_KEY')
112
+ json = get_weather_json(date, WEATHER_API_KEY)
113
+ data = json['days'][0]
114
+
115
+ return [
116
+ json['address'].capitalize(),
117
+ data['datetime'],
118
+ data['tempmax'],
119
+ data['tempmin'],
120
+ data['temp'],
121
+ data['feelslikemax'],
122
+ data['feelslikemin'],
123
+ data['feelslike'],
124
+ data['dew'],
125
+ data['humidity'],
126
+ data['precip'],
127
+ data['precipprob'],
128
+ data['precipcover'],
129
+ data['snow'],
130
+ data['snowdepth'],
131
+ data['windgust'],
132
+ data['windspeed'],
133
+ data['winddir'],
134
+ data['pressure'],
135
+ data['cloudcover'],
136
+ data['visibility'],
137
+ data['solarradiation'],
138
+ data['solarenergy'],
139
+ data['uvindex'],
140
+ data['conditions']
141
+ ]
142
+
143
+
144
+ def get_weather_df(data):
145
+ col_names = [
146
+ 'city',
147
+ 'date',
148
+ 'tempmax',
149
+ 'tempmin',
150
+ 'temp',
151
+ 'feelslikemax',
152
+ 'feelslikemin',
153
+ 'feelslike',
154
+ 'dew',
155
+ 'humidity',
156
+ 'precip',
157
+ 'precipprob',
158
+ 'precipcover',
159
+ 'snow',
160
+ 'snowdepth',
161
+ 'windgust',
162
+ 'windspeed',
163
+ 'winddir',
164
+ 'pressure',
165
+ 'cloudcover',
166
+ 'visibility',
167
+ 'solarradiation',
168
+ 'solarenergy',
169
+ 'uvindex',
170
+ 'conditions'
171
+ ]
172
+
173
+ new_data = pd.DataFrame(
174
+ data,
175
+ columns=col_names
176
+ )
177
+ new_data.date = new_data.date.apply(timestamp_2_time1)
178
+
179
+ return new_data
180
+
181
+ def timestamp_2_time1(x):
182
+ dt_obj = datetime.strptime(str(x), '%Y-%m-%d')
183
+ dt_obj = dt_obj.timestamp() * 1000
184
+ return int(dt_obj)
185
+
186
+ def timestamp_2_time(x):
187
+ dt_obj = datetime.strptime(str(x), '%m/%d/%Y')
188
+ dt_obj = dt_obj.timestamp() * 1000
189
+ return int(dt_obj)