diff options
| author | Sam Chudnick <sam@chudnick.com> | 2023-06-03 14:02:59 -0400 |
|---|---|---|
| committer | Sam Chudnick <sam@chudnick.com> | 2023-06-03 14:02:59 -0400 |
| commit | c023b5704d49679989ddae60851b82f051f4ac2f (patch) | |
| tree | b3e1bad64b29ae27049c6c339d38eaae1e21df03 | |
| parent | cb3212d8c076bad4e9c20b63123aba6fcb9e25f4 (diff) | |
Appended N/A when no data is available
| -rw-r--r-- | library.py | 60 |
1 files changed, 38 insertions, 22 deletions
| @@ -146,8 +146,8 @@ def get_temperature(raw_data): | |||
| 146 | ret = [] | 146 | ret = [] |
| 147 | 147 | ||
| 148 | for val in raw_values: | 148 | for val in raw_values: |
| 149 | val_celc = val["value"] | 149 | val_celc = round(val["value"]) |
| 150 | val_fahr = celcius_to_fahrenheit(val_celc) | 150 | val_fahr = round(celcius_to_fahrenheit(val_celc)) |
| 151 | time_str, duration_str = val["validTime"].split('/') | 151 | time_str, duration_str = val["validTime"].split('/') |
| 152 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") | 152 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") |
| 153 | duration = parse_duration(duration_str) | 153 | duration = parse_duration(duration_str) |
| @@ -162,8 +162,8 @@ def get_apparent_temperature(raw_data): | |||
| 162 | 162 | ||
| 163 | 163 | ||
| 164 | for val in raw_values: | 164 | for val in raw_values: |
| 165 | val_celc = val["value"] | 165 | val_celc = round(val["value"]) |
| 166 | val_fahr = celcius_to_fahrenheit(val_celc) | 166 | val_fahr = round(celcius_to_fahrenheit(val_celc)) |
| 167 | time_str, duration_str = val["validTime"].split('/') | 167 | time_str, duration_str = val["validTime"].split('/') |
| 168 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") | 168 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") |
| 169 | duration = parse_duration(duration_str) | 169 | duration = parse_duration(duration_str) |
| @@ -180,7 +180,7 @@ def get_humidity(raw_data): | |||
| 180 | time_str, duration_str = val["validTime"].split('/') | 180 | time_str, duration_str = val["validTime"].split('/') |
| 181 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") | 181 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") |
| 182 | duration = parse_duration(duration_str) | 182 | duration = parse_duration(duration_str) |
| 183 | ret.append({"time":time,"duration":duration,"value":val["value"]}) | 183 | ret.append({"time":time,"duration":duration,"value":round(val["value"])}) |
| 184 | 184 | ||
| 185 | return normalize(ret) | 185 | return normalize(ret) |
| 186 | 186 | ||
| @@ -190,8 +190,8 @@ def get_wind_chill(raw_data): | |||
| 190 | ret = [] | 190 | ret = [] |
| 191 | 191 | ||
| 192 | for val in raw_values: | 192 | for val in raw_values: |
| 193 | val_celc = val["value"] | 193 | val_celc = round(val["value"]) |
| 194 | val_fahr = celcius_to_fahrenheit(val_celc) | 194 | val_fahr = round(celcius_to_fahrenheit(val_celc)) |
| 195 | time_str, duration_str = val["validTime"].split('/') | 195 | time_str, duration_str = val["validTime"].split('/') |
| 196 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") | 196 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") |
| 197 | duration = parse_duration(duration_str) | 197 | duration = parse_duration(duration_str) |
| @@ -208,7 +208,7 @@ def get_wind_speed(raw_data): | |||
| 208 | time_str, duration_str = val["validTime"].split('/') | 208 | time_str, duration_str = val["validTime"].split('/') |
| 209 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") | 209 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") |
| 210 | duration = parse_duration(duration_str) | 210 | duration = parse_duration(duration_str) |
| 211 | ret.append({"time":time,"duration":duration,"value":val["value"]}) | 211 | ret.append({"time":time,"duration":duration,"value":round(val["value"])}) |
| 212 | 212 | ||
| 213 | return normalize(ret) | 213 | return normalize(ret) |
| 214 | 214 | ||
| @@ -221,7 +221,7 @@ def get_wind_gust(raw_data): | |||
| 221 | time_str, duration_str = val["validTime"].split('/') | 221 | time_str, duration_str = val["validTime"].split('/') |
| 222 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") | 222 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") |
| 223 | duration = parse_duration(duration_str) | 223 | duration = parse_duration(duration_str) |
| 224 | ret.append({"time":time,"duration":duration,"value":val["value"]}) | 224 | ret.append({"time":time,"duration":duration,"value":round(val["value"])}) |
| 225 | 225 | ||
| 226 | return normalize(ret) | 226 | return normalize(ret) |
| 227 | 227 | ||
| @@ -234,7 +234,7 @@ def get_precip_chance(raw_data): | |||
| 234 | time_str, duration_str = val["validTime"].split('/') | 234 | time_str, duration_str = val["validTime"].split('/') |
| 235 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") | 235 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") |
| 236 | duration = parse_duration(duration_str) | 236 | duration = parse_duration(duration_str) |
| 237 | ret.append({"time":time,"duration":duration,"value":val["value"]}) | 237 | ret.append({"time":time,"duration":duration,"value":round(val["value"])}) |
| 238 | 238 | ||
| 239 | return normalize(ret) | 239 | return normalize(ret) |
| 240 | 240 | ||
| @@ -247,7 +247,7 @@ def get_precip_amount(raw_data): | |||
| 247 | time_str, duration_str = val["validTime"].split('/') | 247 | time_str, duration_str = val["validTime"].split('/') |
| 248 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") | 248 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") |
| 249 | duration = parse_duration(duration_str) | 249 | duration = parse_duration(duration_str) |
| 250 | ret.append({"time":time,"duration":duration,"value":val["value"]}) | 250 | ret.append({"time":time,"duration":duration,"value":round(val["value"])}) |
| 251 | 251 | ||
| 252 | return normalize(ret) | 252 | return normalize(ret) |
| 253 | 253 | ||
| @@ -260,7 +260,7 @@ def get_snowfall_amount(raw_data): | |||
| 260 | time_str, duration_str = val["validTime"].split('/') | 260 | time_str, duration_str = val["validTime"].split('/') |
| 261 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") | 261 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") |
| 262 | duration = parse_duration(duration_str) | 262 | duration = parse_duration(duration_str) |
| 263 | ret.append({"time":time,"duration":duration,"value":val["value"]}) | 263 | ret.append({"time":time,"duration":duration,"value":round(val["value"])}) |
| 264 | 264 | ||
| 265 | return normalize(ret) | 265 | return normalize(ret) |
| 266 | 266 | ||
| @@ -273,7 +273,7 @@ def get_snow_level(raw_data): | |||
| 273 | time_str, duration_str = val["validTime"].split('/') | 273 | time_str, duration_str = val["validTime"].split('/') |
| 274 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") | 274 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") |
| 275 | duration = parse_duration(duration_str) | 275 | duration = parse_duration(duration_str) |
| 276 | ret.append({"time":time,"duration":duration,"value":val["value"]}) | 276 | ret.append({"time":time,"duration":duration,"value":round(val["value"])}) |
| 277 | 277 | ||
| 278 | return normalize(ret) | 278 | return normalize(ret) |
| 279 | 279 | ||
| @@ -286,7 +286,7 @@ def get_visibility(raw_data): | |||
| 286 | time_str, duration_str = val["validTime"].split('/') | 286 | time_str, duration_str = val["validTime"].split('/') |
| 287 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") | 287 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") |
| 288 | duration = parse_duration(duration_str) | 288 | duration = parse_duration(duration_str) |
| 289 | ret.append({"time":time,"duration":duration,"value":val["value"]}) | 289 | ret.append({"time":time,"duration":duration,"value":round(val["value"])}) |
| 290 | 290 | ||
| 291 | return normalize(ret) | 291 | return normalize(ret) |
| 292 | 292 | ||
| @@ -317,8 +317,8 @@ def get_dewpoint(raw_data): | |||
| 317 | ret = [] | 317 | ret = [] |
| 318 | 318 | ||
| 319 | for val in raw_values: | 319 | for val in raw_values: |
| 320 | val_celc = val["value"] | 320 | val_celc = round(val["value"]) |
| 321 | val_fahr = celcius_to_fahrenheit(val_celc) | 321 | val_fahr = round(celcius_to_fahrenheit(val_celc)) |
| 322 | time_str, duration_str = val["validTime"].split('/') | 322 | time_str, duration_str = val["validTime"].split('/') |
| 323 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") | 323 | time = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S%z") |
| 324 | duration = parse_duration(duration_str) | 324 | duration = parse_duration(duration_str) |
| @@ -329,21 +329,37 @@ def get_dewpoint(raw_data): | |||
| 329 | 329 | ||
| 330 | def get_hourly_data(raw_data, end_time): | 330 | def get_hourly_data(raw_data, end_time): |
| 331 | temps = get_temperature(raw_data) | 331 | temps = get_temperature(raw_data) |
| 332 | humidity = get_humidity(raw_data) | ||
| 332 | precip_chance = get_precip_chance(raw_data) | 333 | precip_chance = get_precip_chance(raw_data) |
| 333 | precip_amount = get_precip_amount(raw_data) | 334 | precip_amount = get_precip_amount(raw_data) |
| 334 | humidity = get_humidity(raw_data) | ||
| 335 | wind_speed = get_wind_speed(raw_data) | 335 | wind_speed = get_wind_speed(raw_data) |
| 336 | wind_direction = get_wind_direction(raw_data) | 336 | wind_direction = get_wind_direction(raw_data) |
| 337 | 337 | ||
| 338 | ret = [] | 338 | ret = [] |
| 339 | i = 0 | 339 | i = 0 |
| 340 | while i < len(temps) and temps[i]["time"] < end_time: | 340 | while i < len(temps) and temps[i]["time"] < end_time: |
| 341 | |||
| 342 | if i >= len(temps): | ||
| 343 | temps.append({"value":"N/A"}) | ||
| 344 | if i >= len(humidity): | ||
| 345 | humidity.append({"value":"N/A"}) | ||
| 346 | if i >= len(precip_chance): | ||
| 347 | precip_chance.append({"value":"N/A"}) | ||
| 348 | if i >= len(precip_amount): | ||
| 349 | precip_amount.append({"value":"N/A"}) | ||
| 350 | if i >= len(wind_speed): | ||
| 351 | wind_speed.append({"value":"N/A"}) | ||
| 352 | if i >= len(wind_direction): | ||
| 353 | wind_direction.append({"value":"N/A"}) | ||
| 354 | |||
| 355 | |||
| 356 | |||
| 341 | val_dict = { "time": temps[i]["time"], | 357 | val_dict = { "time": temps[i]["time"], |
| 342 | "temp": int(temps[i]["value_fahr"]), | 358 | "temp": temps[i]["value_fahr"], |
| 343 | "humidity": int(humidity[i]["value"]), | 359 | "humidity": humidity[i]["value"], |
| 344 | "precip_chance": int(precip_chance[i]["value"]), | 360 | "precip_chance": precip_chance[i]["value"], |
| 345 | "precip_amount": int(precip_amount[i]["value"]), | 361 | "precip_amount": precip_amount[i]["value"], |
| 346 | "wind_speed": int(wind_speed[i]["value"]), | 362 | "wind_speed": wind_speed[i]["value"], |
| 347 | "wind_direction": wind_direction[i]["value"] } | 363 | "wind_direction": wind_direction[i]["value"] } |
| 348 | ret.append(val_dict) | 364 | ret.append(val_dict) |
| 349 | i+=1 | 365 | i+=1 |
