File size: 14,915 Bytes
1d31989
 
 
 
 
 
 
 
 
 
 
1d3c9ee
1d31989
 
 
 
 
f4930a4
 
 
1d31989
 
 
 
1d3c9ee
 
 
 
f4930a4
 
 
 
 
 
 
 
1d3c9ee
 
 
 
 
 
 
1d31989
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f4930a4
 
1d31989
 
 
 
 
 
 
 
 
 
f4930a4
1d31989
f4930a4
 
1d31989
f4930a4
1d31989
 
 
f4930a4
1d31989
 
 
 
f4930a4
1d31989
f4930a4
 
 
1d31989
 
f4930a4
 
 
 
1d31989
 
 
f4930a4
1d31989
f4930a4
 
 
 
1d31989
f4930a4
1d31989
f4930a4
 
1d31989
 
 
f4930a4
1d31989
f4930a4
 
1d31989
 
 
 
 
 
 
 
 
 
f4930a4
1d31989
f4930a4
 
 
 
1d31989
f4930a4
 
 
 
1d31989
 
 
f4930a4
1d31989
f4930a4
 
 
 
 
1d31989
 
f4930a4
 
1d31989
 
 
f4930a4
 
 
 
 
 
 
 
 
 
 
 
1d31989
 
 
 
 
 
f4930a4
 
 
 
 
 
 
 
 
1d31989
f4930a4
 
 
 
 
 
 
 
 
1d31989
 
f4930a4
1d31989
 
 
 
 
f4930a4
1d31989
 
 
 
f4930a4
1d31989
 
 
 
 
f4930a4
1d31989
 
f4930a4
1d31989
 
 
 
 
f4930a4
1d31989
 
 
 
f4930a4
1d31989
 
 
 
 
f4930a4
1d31989
 
f4930a4
1d31989
 
 
 
 
f4930a4
1d31989
e2ebde2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d31989
 
 
 
1d3c9ee
1d31989
 
 
 
 
 
 
 
 
 
 
 
 
1d3c9ee
1d31989
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Users\\elikl\\Documents\\Uni\\yr3\\ML for industry\\utrecht-pollution-prediction\\.venv\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "from src.predict import get_data_and_predictions\n",
    "from src.data_api_calls import get_combined_data\n",
    "from src.past_data_api_calls import get_past_combined_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Data is already up to date.\n",
      "Data is already up to date.\n",
      "Number of rows with missing values dropped: 7\n",
      "Data is already up to date.\n",
      "Number of rows with missing values dropped: 7\n"
     ]
    }
   ],
   "source": [
    "week_data, predictions_O3, predictions_NO2 = get_data_and_predictions()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>NO2</th>\n",
       "      <th>O3</th>\n",
       "      <th>wind_speed</th>\n",
       "      <th>mean_temp</th>\n",
       "      <th>global_radiation</th>\n",
       "      <th>percipitation</th>\n",
       "      <th>pressure</th>\n",
       "      <th>minimum_visibility</th>\n",
       "      <th>humidity</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2024-10-17</td>\n",
       "      <td>22.804605</td>\n",
       "      <td>22.769160</td>\n",
       "      <td>51</td>\n",
       "      <td>169</td>\n",
       "      <td>43</td>\n",
       "      <td>6</td>\n",
       "      <td>10100</td>\n",
       "      <td>371</td>\n",
       "      <td>86</td>\n",
       "      <td>Thursday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2024-10-18</td>\n",
       "      <td>23.268500</td>\n",
       "      <td>23.307332</td>\n",
       "      <td>21</td>\n",
       "      <td>155</td>\n",
       "      <td>42</td>\n",
       "      <td>39</td>\n",
       "      <td>10140</td>\n",
       "      <td>45</td>\n",
       "      <td>97</td>\n",
       "      <td>Friday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2024-10-19</td>\n",
       "      <td>23.910064</td>\n",
       "      <td>23.171714</td>\n",
       "      <td>41</td>\n",
       "      <td>147</td>\n",
       "      <td>43</td>\n",
       "      <td>16</td>\n",
       "      <td>10141</td>\n",
       "      <td>228</td>\n",
       "      <td>89</td>\n",
       "      <td>Saturday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2024-10-20</td>\n",
       "      <td>22.573238</td>\n",
       "      <td>23.537845</td>\n",
       "      <td>81</td>\n",
       "      <td>155</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>10160</td>\n",
       "      <td>415</td>\n",
       "      <td>83</td>\n",
       "      <td>Sunday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2024-10-21</td>\n",
       "      <td>21.145700</td>\n",
       "      <td>24.020696</td>\n",
       "      <td>58</td>\n",
       "      <td>144</td>\n",
       "      <td>27</td>\n",
       "      <td>43</td>\n",
       "      <td>10206</td>\n",
       "      <td>220</td>\n",
       "      <td>92</td>\n",
       "      <td>Monday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2024-10-22</td>\n",
       "      <td>21.776580</td>\n",
       "      <td>23.335886</td>\n",
       "      <td>53</td>\n",
       "      <td>114</td>\n",
       "      <td>57</td>\n",
       "      <td>49</td>\n",
       "      <td>10269</td>\n",
       "      <td>226</td>\n",
       "      <td>92</td>\n",
       "      <td>Tuesday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2024-10-23</td>\n",
       "      <td>21.974794</td>\n",
       "      <td>22.214689</td>\n",
       "      <td>36</td>\n",
       "      <td>112</td>\n",
       "      <td>12</td>\n",
       "      <td>0</td>\n",
       "      <td>10328</td>\n",
       "      <td>65</td>\n",
       "      <td>97</td>\n",
       "      <td>Wednesday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2024-10-24</td>\n",
       "      <td>25.512568</td>\n",
       "      <td>20.913710</td>\n",
       "      <td>56</td>\n",
       "      <td>104</td>\n",
       "      <td>62</td>\n",
       "      <td>0</td>\n",
       "      <td>10247</td>\n",
       "      <td>130</td>\n",
       "      <td>94</td>\n",
       "      <td>Thursday</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        date        NO2         O3  wind_speed  mean_temp  global_radiation  \\\n",
       "0 2024-10-17  22.804605  22.769160          51        169                43   \n",
       "1 2024-10-18  23.268500  23.307332          21        155                42   \n",
       "2 2024-10-19  23.910064  23.171714          41        147                43   \n",
       "3 2024-10-20  22.573238  23.537845          81        155                 0   \n",
       "4 2024-10-21  21.145700  24.020696          58        144                27   \n",
       "5 2024-10-22  21.776580  23.335886          53        114                57   \n",
       "6 2024-10-23  21.974794  22.214689          36        112                12   \n",
       "7 2024-10-24  25.512568  20.913710          56        104                62   \n",
       "\n",
       "   percipitation  pressure  minimum_visibility  humidity    weekday  \n",
       "0              6     10100                 371        86   Thursday  \n",
       "1             39     10140                  45        97     Friday  \n",
       "2             16     10141                 228        89   Saturday  \n",
       "3              5     10160                 415        83     Sunday  \n",
       "4             43     10206                 220        92     Monday  \n",
       "5             49     10269                 226        92    Tuesday  \n",
       "6              0     10328                  65        97  Wednesday  \n",
       "7              0     10247                 130        94   Thursday  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "week_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[10.33808859, 16.00098432, 19.64377496]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predictions_O3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[25.68519992, 25.76030745, 31.21057679]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predictions_NO2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from src.data_api_calls import get_combined_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'<' not supported between instances of 'Timestamp' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[2], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mget_combined_data\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m2024-10-10\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mc:\\Users\\elikl\\Documents\\Uni\\yr3\\ML for industry\\utrecht-pollution-prediction\\src\\data_api_calls.py:136\u001b[0m, in \u001b[0;36mget_combined_data\u001b[1;34m(input_date)\u001b[0m\n\u001b[0;32m    133\u001b[0m     start_date \u001b[38;5;241m=\u001b[39m end_date \u001b[38;5;241m-\u001b[39m timedelta(\u001b[38;5;241m7\u001b[39m)\n\u001b[0;32m    135\u001b[0m update_weather_data(start_date, end_date)\n\u001b[1;32m--> 136\u001b[0m \u001b[43mupdate_pollution_data\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstart_date\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mend_date\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    138\u001b[0m weather_df \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mread_csv(WEATHER_DATA_FILE)\n\u001b[0;32m    140\u001b[0m weather_df\u001b[38;5;241m.\u001b[39minsert(\u001b[38;5;241m1\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNO2\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m)\n",
      "File \u001b[1;32mc:\\Users\\elikl\\Documents\\Uni\\yr3\\ML for industry\\utrecht-pollution-prediction\\src\\data_api_calls.py:123\u001b[0m, in \u001b[0;36mupdate_pollution_data\u001b[1;34m(start_date, end_date)\u001b[0m\n\u001b[0;32m    121\u001b[0m updated_data \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mconcat([existing_data, new_data], ignore_index\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m    122\u001b[0m updated_data\u001b[38;5;241m.\u001b[39mdrop_duplicates(subset\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdate\u001b[39m\u001b[38;5;124m\"\u001b[39m, keep\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlast\u001b[39m\u001b[38;5;124m\"\u001b[39m, inplace\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[1;32m--> 123\u001b[0m updated_data \u001b[38;5;241m=\u001b[39m \u001b[43mupdated_data\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msort_values\u001b[49m\u001b[43m(\u001b[49m\u001b[43mby\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mdate\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m    124\u001b[0m updated_data\u001b[38;5;241m.\u001b[39mto_csv(POLLUTION_DATA_FILE, index\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m)\n",
      "File \u001b[1;32mc:\\Users\\elikl\\Documents\\Uni\\yr3\\ML for industry\\utrecht-pollution-prediction\\.venv\\Lib\\site-packages\\pandas\\core\\frame.py:7200\u001b[0m, in \u001b[0;36mDataFrame.sort_values\u001b[1;34m(self, by, axis, ascending, inplace, kind, na_position, ignore_index, key)\u001b[0m\n\u001b[0;32m   7197\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(ascending, (\u001b[38;5;28mtuple\u001b[39m, \u001b[38;5;28mlist\u001b[39m)):\n\u001b[0;32m   7198\u001b[0m         ascending \u001b[38;5;241m=\u001b[39m ascending[\u001b[38;5;241m0\u001b[39m]\n\u001b[1;32m-> 7200\u001b[0m     indexer \u001b[38;5;241m=\u001b[39m \u001b[43mnargsort\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   7201\u001b[0m \u001b[43m        \u001b[49m\u001b[43mk\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkind\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mkind\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mascending\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mascending\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mna_position\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mna_position\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkey\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mkey\u001b[49m\n\u001b[0;32m   7202\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m   7203\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m   7204\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m inplace:\n",
      "File \u001b[1;32mc:\\Users\\elikl\\Documents\\Uni\\yr3\\ML for industry\\utrecht-pollution-prediction\\.venv\\Lib\\site-packages\\pandas\\core\\sorting.py:439\u001b[0m, in \u001b[0;36mnargsort\u001b[1;34m(items, kind, ascending, na_position, key, mask)\u001b[0m\n\u001b[0;32m    437\u001b[0m     non_nans \u001b[38;5;241m=\u001b[39m non_nans[::\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m]\n\u001b[0;32m    438\u001b[0m     non_nan_idx \u001b[38;5;241m=\u001b[39m non_nan_idx[::\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m]\n\u001b[1;32m--> 439\u001b[0m indexer \u001b[38;5;241m=\u001b[39m non_nan_idx[\u001b[43mnon_nans\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43margsort\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkind\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mkind\u001b[49m\u001b[43m)\u001b[49m]\n\u001b[0;32m    440\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m ascending:\n\u001b[0;32m    441\u001b[0m     indexer \u001b[38;5;241m=\u001b[39m indexer[::\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m]\n",
      "\u001b[1;31mTypeError\u001b[0m: '<' not supported between instances of 'Timestamp' and 'str'"
     ]
    }
   ],
   "source": [
    "get_combined_data(\"2024-10-10\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}