text
stringlengths 0
828
|
---|
temperature = forcast_day.temperature
|
if forecast_temp_min > temperature:
|
forecast_temp_min = temperature
|
if forecast_temp_max < temperature:
|
forecast_temp_max = temperature
|
if forcast_day.valid_time.hour == 12:
|
forecast = copy.deepcopy(forcast_day)
|
total_precipitation = total_precipitation + \
|
forcast_day._total_precipitation
|
if forecast is None:
|
# We passed 12 noon, set to current
|
forecast = forecasts_day[0]
|
forecast._temperature_max = forecast_temp_max
|
forecast._temperature_min = forecast_temp_min
|
forecast._total_precipitation = total_precipitation
|
forecast._mean_precipitation = total_precipitation/24
|
forecasts.append(forecast)
|
day_nr = day_nr + 1
|
return forecasts"
|
382,"def _get_all_forecast_from_api(api_result: dict) -> OrderedDict:
|
""""""Converts results fråm API to SmhiForeCast list""""""
|
# Total time in hours since last forecast
|
total_hours_last_forecast = 1.0
|
# Last forecast time
|
last_time = None
|
# Need the ordered dict to get
|
# the days in order in next stage
|
forecasts_ordered = OrderedDict()
|
# Get the parameters
|
for forecast in api_result['timeSeries']:
|
valid_time = datetime.strptime(
|
forecast['validTime'], ""%Y-%m-%dT%H:%M:%SZ"")
|
for param in forecast['parameters']:
|
if param['name'] == 't':
|
temperature = float(param['values'][0]) # Celcisus
|
elif param['name'] == 'r':
|
humidity = int(param['values'][0]) # Percent
|
elif param['name'] == 'msl':
|
pressure = int(param['values'][0]) # hPa
|
elif param['name'] == 'tstm':
|
thunder = int(param['values'][0]) # Percent
|
elif param['name'] == 'tcc_mean':
|
octa = int(param['values'][0]) # Cloudiness in octas
|
if 0 <= octa <= 8: # Between 0 -> 8
|
cloudiness = round(100*octa/8) # Convert octas to percent
|
else:
|
cloudiness = 100 # If not determined use 100%
|
elif param['name'] == 'Wsymb2':
|
symbol = int(param['values'][0]) # category
|
elif param['name'] == 'pcat':
|
precipitation = int(param['values'][0]) # percipitation
|
elif param['name'] == 'pmean':
|
mean_precipitation = float(
|
param['values'][0]) # mean_percipitation
|
elif param['name'] == 'ws':
|
wind_speed = float(param['values'][0]) # wind speed
|
elif param['name'] == 'wd':
|
wind_direction = int(param['values'][0]) # wind direction
|
elif param['name'] == 'vis':
|
horizontal_visibility = float(param['values'][0]) # Visibility
|
elif param['name'] == 'gust':
|
wind_gust = float(param['values'][0]) # wind gust speed
|
roundedTemp = int(round(temperature))
|
if last_time is not None:
|
total_hours_last_forecast = (valid_time - last_time).seconds/60/60
|
# Total precipitation, have to calculate with the nr of
|
# hours since last forecast to get correct total value
|
tp = round(mean_precipitation*total_hours_last_forecast, 2)
|
forecast = \
|
SmhiForecast(roundedTemp, roundedTemp, roundedTemp,
|
humidity, pressure, thunder, cloudiness,
|
precipitation, wind_direction, wind_speed,
|
horizontal_visibility, wind_gust,
|
round(mean_precipitation, 1), tp, symbol,
|
valid_time)
|
if valid_time.day not in forecasts_ordered:
|
# add a new list
|
forecasts_ordered[valid_time.day] = []
|
forecasts_ordered[valid_time.day].append(forecast)
|
last_time = valid_time
|
return forecasts_ordered"
|
383,"def get_forecast_api(self, longitude: str, latitude: str) -> {}:
|
""""""gets data from API""""""
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.