dmarr commited on
Commit
91bd6f0
·
1 Parent(s): 0f41898

Updated filters

Browse files
Files changed (1) hide show
  1. app.py +34 -11
app.py CHANGED
@@ -44,8 +44,8 @@ def mongo_unavs_call(user_input_start_date, user_input_end_date, user_input_past
44
  {
45
  "$match": {
46
  "results.generation_unavailabilities.production_type": "NUCLEAR",
47
- "results.generation_unavailabilities.start_date": {"$lte": end_date},
48
- "results.generation_unavailabilities.end_date": {"$gte": start_date},
49
  "results.generation_unavailabilities.updated_date": {"$lte": end_date}
50
  }
51
  },
@@ -162,7 +162,9 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
162
  past_date_str = str(past_date)
163
  current_datetime_str = current_datetime.strftime("%Y-%m-%d")
164
 
165
- nuclear_unav = mongo_unavs.copy()[(mongo_unavs.copy()["production_type"] == "NUCLEAR") & (mongo_unavs.copy()["updated_date"] <= past_date_str)]
 
 
166
 
167
  # if photo_date == True:
168
  # nuclear_unav = merged_df.copy()[(merged_df.copy()["production_type"] == "NUCLEAR") & (merged_df.copy()["updated_date"] <= past_date_str)]
@@ -182,19 +184,37 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
182
 
183
  # Filter to get identifiers
184
  filtered_id_df = sorted_df.copy()
 
 
185
  filtered_id_df.drop_duplicates(subset='identifier', keep='last', inplace=True)
 
 
186
  filtered_id_df = filtered_id_df.copy().reset_index(drop=True)
187
 
188
  # This filter should take all the dates with unavs that include days with unavs in the range of the start and end date
189
 
190
- filtered_df = filtered_id_df.copy()[(filtered_id_df.copy()['start_date'] <= end_date_str) & (filtered_id_df.copy()['end_date'] >= start_date_str)]
191
- # Create a boolean mask to identify rows where status is "Dismissed"
192
- mask = filtered_df["status"] == "DISMISSED"
193
- print(filtered_df["status"])
194
- print(filtered_df[mask])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
  # Update available_capacity where the condition is True
197
- filtered_df.loc[mask, "available_capacity"] = filtered_df.loc[mask, "installed_capacity"]
198
 
199
  # Standardize datetime in dataframe
200
  filtered_df2 = filtered_df.copy() # This code will just standardize datetime stuff
@@ -280,16 +300,19 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
280
  while date_plus_one < end_date:
281
  date_plus_one = date_plus_one + datetime.timedelta(days=1)
282
  dates_of_interest.append(date_plus_one)
283
-
284
  # This is to standardize the datetimes. Without this, the datetime calculations for each power plant will not work
 
 
285
  results_plants = {plant_name: {date: {"available_capacity": power, "updated_date": pd.to_datetime("1970-01-01", utc=True)} for date in dates_of_interest}
286
  for plant_name, power in plants_metadata.items()}
287
 
288
 
289
  for plant, unavailabilities in results_sorted.items():
290
-
291
  original_power = plants_metadata[plant]
292
  # Get all the unavailabilities scheduled for the plant.
 
293
  results_current_plant = results_plants[plant]
294
 
295
  for unavailability in unavailabilities:
 
44
  {
45
  "$match": {
46
  "results.generation_unavailabilities.production_type": "NUCLEAR",
47
+ # "results.generation_unavailabilities.start_date": {"$lte": end_date},
48
+ # "results.generation_unavailabilities.end_date": {"$gte": start_date},
49
  "results.generation_unavailabilities.updated_date": {"$lte": end_date}
50
  }
51
  },
 
162
  past_date_str = str(past_date)
163
  current_datetime_str = current_datetime.strftime("%Y-%m-%d")
164
 
165
+ # nuclear_unav = mongo_unavs.copy()[(mongo_unavs.copy()["production_type"] == "NUCLEAR") & (mongo_unavs.copy()["updated_date"] <= past_date_str)]
166
+ nuclear_unav = mongo_unavs.copy()[(mongo_unavs.copy()["production_type"] == "NUCLEAR") & (mongo_unavs.copy()["updated_date"] <= past_date_str)
167
+ & (mongo_unavs.copy()["status"] != "DISMISSED")]
168
 
169
  # if photo_date == True:
170
  # nuclear_unav = merged_df.copy()[(merged_df.copy()["production_type"] == "NUCLEAR") & (merged_df.copy()["updated_date"] <= past_date_str)]
 
184
 
185
  # Filter to get identifiers
186
  filtered_id_df = sorted_df.copy()
187
+ # --------------------------- !!!!!!!!!!!!!!!!!!!!!!! HERE IS POTENTIAL ERROR!!!!!!!!!!!!!!!!!!!!!!! --------------------------- #
188
+ # I commented this out
189
  filtered_id_df.drop_duplicates(subset='identifier', keep='last', inplace=True)
190
+ # --------------------------- !!!!!!!!!!!!!!!!!!!!!!! HERE IS POTENTIAL ERROR!!!!!!!!!!!!!!!!!!!!!!! --------------------------- #
191
+
192
  filtered_id_df = filtered_id_df.copy().reset_index(drop=True)
193
 
194
  # This filter should take all the dates with unavs that include days with unavs in the range of the start and end date
195
 
196
+ # --------------------------- !!!!!!!!!!!!!!!!!!!!!!! HERE IS POTENTIAL ERROR!!!!!!!!!!!!!!!!!!!!!!! --------------------------- #
197
+
198
+ # This filter might take out the most recent identifiers (Message ID) that change the dates of unavailability of a plant.
199
+ # This means that the actual unavailability is something else
200
+ # filtered_df = filtered_id_df.copy()[(filtered_id_df.copy()['start_date'] <= end_date_str) & (filtered_id_df.copy()['end_date'] >= start_date_str)]
201
+ filtered_df = filtered_id_df.copy()
202
+ # 2022-11 a 2023-03
203
+ print("filtered_df\n", filtered_df)
204
+ filtered_df_chooz = filtered_df[filtered_df["name"] == "CHOOZ 2"]
205
+
206
+ print(filtered_df_chooz[["name", "message_id", "creation_date", "updated_date", "status", "available_capacity"]])
207
+
208
+ # --------------------------- !!!!!!!!!!!!!!!!!!!!!!! HERE IS POTENTIAL ERROR!!!!!!!!!!!!!!!!!!!!!!! --------------------------- #
209
+
210
+ # # Create a boolean mask to identify rows where status is "Dismissed"
211
+ # mask_dismissed = filtered_df["status"] == "DISMISSED"
212
+
213
+ # print(filtered_df["status"])
214
+ # print(filtered_df[mask])
215
 
216
  # Update available_capacity where the condition is True
217
+ # filtered_df.loc[mask_dismissed, "available_capacity"] = filtered_df.loc[mask_dismissed, "installed_capacity"]
218
 
219
  # Standardize datetime in dataframe
220
  filtered_df2 = filtered_df.copy() # This code will just standardize datetime stuff
 
300
  while date_plus_one < end_date:
301
  date_plus_one = date_plus_one + datetime.timedelta(days=1)
302
  dates_of_interest.append(date_plus_one)
303
+
304
  # This is to standardize the datetimes. Without this, the datetime calculations for each power plant will not work
305
+ # This is just getting the plant metadata and giving it updated_date????? With an amount of items based on the length of the
306
+ # date range????
307
  results_plants = {plant_name: {date: {"available_capacity": power, "updated_date": pd.to_datetime("1970-01-01", utc=True)} for date in dates_of_interest}
308
  for plant_name, power in plants_metadata.items()}
309
 
310
 
311
  for plant, unavailabilities in results_sorted.items():
312
+ # Get the full power of a given plant according to the sorted results
313
  original_power = plants_metadata[plant]
314
  # Get all the unavailabilities scheduled for the plant.
315
+ # This is actually apparently just getting the metadata though???
316
  results_current_plant = results_plants[plant]
317
 
318
  for unavailability in unavailabilities: