dmarr commited on
Commit
29f59f7
·
1 Parent(s): 91bd6f0
Files changed (1) hide show
  1. app.py +4 -16
app.py CHANGED
@@ -115,15 +115,15 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
115
  "ST LAURENT 2": 915.0, "TRICASTIN 1": 915.0, "TRICASTIN 2": 915.0, "TRICASTIN 3": 915.0,
116
  "TRICASTIN 4": 915.0, "FESSENHEIM 1": 880.0, "FESSENHEIM 2": 880.0}
117
 
118
-
119
  # --------------------- INITIAL DATA CLEANING FOR MONGO DATA ------------------------ #
120
 
121
  # # Create a DataFrame
122
  # mongo_data = mongo_unavs_call(usr_start_date, usr_end_date, past_date)
123
  # mongo_data = get_mongodb_data(usr_start_date, usr_end_date, past_date)
124
-
125
  mongo_df = pd.DataFrame(mongo_db_data)
126
 
 
127
  # Unpack the dictionaries into separate columns
128
  mongo_df_unpacked = pd.json_normalize(mongo_df['generation_unavailabilities'])
129
 
@@ -132,7 +132,6 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
132
 
133
  # Drop the original column
134
  mongo_df_result.drop(columns=['generation_unavailabilities'], inplace=True)
135
- mongo_df_columns = mongo_df_result.columns
136
 
137
  mongo_df_result['start_date'] = mongo_df_result['values'].apply(lambda x: x[0]['start_date'])
138
  mongo_df_result['end_date'] = mongo_df_result['values'].apply(lambda x: x[0]['end_date'])
@@ -164,7 +163,7 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
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)]
@@ -199,22 +198,11 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
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
@@ -293,7 +281,7 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
293
  sorted_results[key] = sorted(value, key=lambda x: x['updated_date'])
294
 
295
  results_sorted = sorted_results
296
-
297
  dates_of_interest = [start_date] # We are creating a list of dates ranging from user specified start and end dates
298
  date_plus_one = start_date
299
 
 
115
  "ST LAURENT 2": 915.0, "TRICASTIN 1": 915.0, "TRICASTIN 2": 915.0, "TRICASTIN 3": 915.0,
116
  "TRICASTIN 4": 915.0, "FESSENHEIM 1": 880.0, "FESSENHEIM 2": 880.0}
117
 
 
118
  # --------------------- INITIAL DATA CLEANING FOR MONGO DATA ------------------------ #
119
 
120
  # # Create a DataFrame
121
  # mongo_data = mongo_unavs_call(usr_start_date, usr_end_date, past_date)
122
  # mongo_data = get_mongodb_data(usr_start_date, usr_end_date, past_date)
123
+ # print(mongo_db_data)
124
  mongo_df = pd.DataFrame(mongo_db_data)
125
 
126
+ # print(mongo_df)
127
  # Unpack the dictionaries into separate columns
128
  mongo_df_unpacked = pd.json_normalize(mongo_df['generation_unavailabilities'])
129
 
 
132
 
133
  # Drop the original column
134
  mongo_df_result.drop(columns=['generation_unavailabilities'], inplace=True)
 
135
 
136
  mongo_df_result['start_date'] = mongo_df_result['values'].apply(lambda x: x[0]['start_date'])
137
  mongo_df_result['end_date'] = mongo_df_result['values'].apply(lambda x: x[0]['end_date'])
 
163
 
164
  # nuclear_unav = mongo_unavs.copy()[(mongo_unavs.copy()["production_type"] == "NUCLEAR") & (mongo_unavs.copy()["updated_date"] <= past_date_str)]
165
  nuclear_unav = mongo_unavs.copy()[(mongo_unavs.copy()["production_type"] == "NUCLEAR") & (mongo_unavs.copy()["updated_date"] <= past_date_str)
166
+ & (mongo_unavs.copy()["status"] != "DISMISSED")]
167
 
168
  # if photo_date == True:
169
  # nuclear_unav = merged_df.copy()[(merged_df.copy()["production_type"] == "NUCLEAR") & (merged_df.copy()["updated_date"] <= past_date_str)]
 
198
  # This means that the actual unavailability is something else
199
  # filtered_df = filtered_id_df.copy()[(filtered_id_df.copy()['start_date'] <= end_date_str) & (filtered_id_df.copy()['end_date'] >= start_date_str)]
200
  filtered_df = filtered_id_df.copy()
 
 
 
201
 
 
202
 
203
  # --------------------------- !!!!!!!!!!!!!!!!!!!!!!! HERE IS POTENTIAL ERROR!!!!!!!!!!!!!!!!!!!!!!! --------------------------- #
204
 
 
 
 
 
 
 
205
  # Update available_capacity where the condition is True
 
206
 
207
  # Standardize datetime in dataframe
208
  filtered_df2 = filtered_df.copy() # This code will just standardize datetime stuff
 
281
  sorted_results[key] = sorted(value, key=lambda x: x['updated_date'])
282
 
283
  results_sorted = sorted_results
284
+
285
  dates_of_interest = [start_date] # We are creating a list of dates ranging from user specified start and end dates
286
  date_plus_one = start_date
287