Ciroc0 commited on
Commit
fb67cdb
·
verified ·
1 Parent(s): e3511ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -119,13 +119,18 @@ def fetch_actuals_for_period(start_date, end_date):
119
  timestamps = pd.to_datetime(data['hourly']['time'])
120
  timestamps = timestamps.tz_localize('Europe/Copenhagen', ambiguous='infer')
121
 
122
- return pd.DataFrame({
123
  'timestamp': timestamps,
124
  'actual_temp': data['hourly']['temperature_2m'],
125
  'actual_wind': data['hourly']['windspeed_10m'],
126
  'actual_pressure': data['hourly']['pressure_msl'],
127
  'actual_humidity': data['hourly']['relativehumidity_2m']
128
  })
 
 
 
 
 
129
  except Exception as e:
130
  print(f"❌ Fejl: {e}")
131
  return None
@@ -317,6 +322,9 @@ def backfill_historical_data():
317
  return "❌ Ingen data"
318
 
319
  final_df = pd.concat(all_data, ignore_index=True)
 
 
 
320
  # Drop duplicates baseret på timestamp (target tid)
321
  final_df = final_df.drop_duplicates(subset=['timestamp'], keep='first')
322
 
@@ -355,6 +363,10 @@ def update_daily():
355
  if len(merged) == 0:
356
  return "❌ Ingen match"
357
 
 
 
 
 
358
  merged['hour'] = merged['reference_time'].dt.hour
359
  merged['day_of_year'] = merged['reference_time'].dt.dayofyear
360
  merged['month'] = merged['reference_time'].dt.month
 
119
  timestamps = pd.to_datetime(data['hourly']['time'])
120
  timestamps = timestamps.tz_localize('Europe/Copenhagen', ambiguous='infer')
121
 
122
+ actuals_df = pd.DataFrame({
123
  'timestamp': timestamps,
124
  'actual_temp': data['hourly']['temperature_2m'],
125
  'actual_wind': data['hourly']['windspeed_10m'],
126
  'actual_pressure': data['hourly']['pressure_msl'],
127
  'actual_humidity': data['hourly']['relativehumidity_2m']
128
  })
129
+
130
+ # Filtrer fremtidige timer væk: behold kun observationer op til nuværende time
131
+ current_hour = now_cph().replace(minute=0, second=0, microsecond=0)
132
+ actuals_df = actuals_df[actuals_df['timestamp'] <= current_hour]
133
+ return actuals_df
134
  except Exception as e:
135
  print(f"❌ Fejl: {e}")
136
  return None
 
322
  return "❌ Ingen data"
323
 
324
  final_df = pd.concat(all_data, ignore_index=True)
325
+ # Fjern fremtidige tider: behold kun rækker hvor timestamp er mindre eller lig med nuværende time
326
+ current_hour = now_cph().replace(minute=0, second=0, microsecond=0)
327
+ final_df = final_df[final_df['timestamp'] <= current_hour]
328
  # Drop duplicates baseret på timestamp (target tid)
329
  final_df = final_df.drop_duplicates(subset=['timestamp'], keep='first')
330
 
 
363
  if len(merged) == 0:
364
  return "❌ Ingen match"
365
 
366
+ # Fjern fremtidige tider: behold kun rækker hvor timestamp er mindre eller lig med nuværende time
367
+ current_hour = now_cph().replace(minute=0, second=0, microsecond=0)
368
+ merged = merged[merged['timestamp'] <= current_hour]
369
+
370
  merged['hour'] = merged['reference_time'].dt.hour
371
  merged['day_of_year'] = merged['reference_time'].dt.dayofyear
372
  merged['month'] = merged['reference_time'].dt.month