Got restrictive to work
Browse files- .gitignore +1 -0
- app.py +43 -17
.gitignore
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
/app_with_api.py
|
| 2 |
/app_with_rte.py
|
|
|
|
| 3 |
/venv
|
|
|
|
| 1 |
/app_with_api.py
|
| 2 |
/app_with_rte.py
|
| 3 |
+
/app_notrestrictive.py
|
| 4 |
/venv
|
app.py
CHANGED
|
@@ -186,33 +186,32 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
|
|
| 186 |
|
| 187 |
sorted_df = sorted_df.copy().reset_index(drop=True)
|
| 188 |
|
| 189 |
-
cruas_2 = sorted_df.copy()[(sorted_df.copy()["name"] == "
|
| 190 |
-
print(cruas_2[['updated_date', 'end_date', 'available_capacity']])
|
| 191 |
|
| 192 |
# Filter to get identifiers
|
| 193 |
filtered_id_df = sorted_df.copy()
|
| 194 |
-
|
| 195 |
# I commented this out
|
| 196 |
filtered_id_df = filtered_id_df.drop_duplicates(subset='identifier', keep='last')
|
| 197 |
|
| 198 |
-
cruas_2 = filtered_id_df.copy()[(filtered_id_df.copy()["name"] == "
|
| 199 |
-
print(cruas_2[['updated_date', 'end_date', 'available_capacity']])
|
| 200 |
-
# --------------------------- !!!!!!!!!!!!!!!!!!!!!!! HERE IS POTENTIAL ERROR!!!!!!!!!!!!!!!!!!!!!!! --------------------------- #
|
| 201 |
|
| 202 |
filtered_id_df = filtered_id_df.copy().reset_index(drop=True)
|
| 203 |
|
| 204 |
# This filter should take all the dates with unavs that include days with unavs in the range of the start and end date
|
| 205 |
|
| 206 |
-
# --------------------------- !!!!!!!!!!!!!!!!!!!!!!! HERE IS POTENTIAL ERROR!!!!!!!!!!!!!!!!!!!!!!! --------------------------- #
|
| 207 |
|
| 208 |
# This filter might take out the most recent identifiers (Message ID) that change the dates of unavailability of a plant.
|
| 209 |
# This means that the actual unavailability is something else
|
| 210 |
# filtered_df = filtered_id_df.copy()[(filtered_id_df.copy()['start_date'] <= end_date_str) & (filtered_id_df.copy()['end_date'] >= start_date_str)]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
filtered_df = filtered_id_df.copy()
|
| 212 |
|
| 213 |
-
|
| 214 |
-
# --------------------------- !!!!!!!!!!!!!!!!!!!!!!! HERE IS POTENTIAL ERROR!!!!!!!!!!!!!!!!!!!!!!! --------------------------- #
|
| 215 |
-
|
| 216 |
# Update available_capacity where the condition is True
|
| 217 |
|
| 218 |
# Standardize datetime in dataframe
|
|
@@ -282,8 +281,6 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
|
|
| 282 |
filtered_values.append(item)
|
| 283 |
results_filtered[key] = filtered_values
|
| 284 |
|
| 285 |
-
# Need to eventually do a filter that takes the most restrictive updated identifier instead of the most recent when there
|
| 286 |
-
# is an overlap
|
| 287 |
|
| 288 |
sorted_results = results_filtered
|
| 289 |
# --------------------- SECOND DATA CLEANING ------------------------ #
|
|
@@ -308,7 +305,7 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
|
|
| 308 |
results_plants = {plant_name: {date: {"available_capacity": power, "updated_date": pd.to_datetime("1970-01-01", utc=True)} for date in dates_of_interest}
|
| 309 |
for plant_name, power in plants_metadata.items()}
|
| 310 |
|
| 311 |
-
|
| 312 |
for plant, unavailabilities in results_sorted.items():
|
| 313 |
# Get the full power of a given plant according to the sorted results
|
| 314 |
original_power = plants_metadata[plant]
|
|
@@ -336,7 +333,29 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
|
|
| 336 |
|
| 337 |
if start_date_unav <= day <= end_date_unav:
|
| 338 |
# Check if the day is already updated with a later update_date
|
|
|
|
| 339 |
if day in results_current_plant and updated_date_unav <= results_current_plant[day]["updated_date"]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
continue # Skip to the next loop if there is already information for a later update_date
|
| 341 |
|
| 342 |
# Calculate the % of the day that the plant is under maintenance
|
|
@@ -357,8 +376,15 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
|
|
| 357 |
power_of_day = percentage_of_day * power_unavailability + (1 - percentage_of_day) * original_power
|
| 358 |
|
| 359 |
# Update the available_capacity for the day only if it's not already updated with a later update_date
|
| 360 |
-
if day not in results_current_plant
|
| 361 |
results_current_plant[day] = {"available_capacity": power_of_day, "updated_date": updated_date_unav}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
|
| 363 |
|
| 364 |
output_results = {}
|
|
@@ -381,12 +407,12 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
|
|
| 381 |
# -------------------------------------------------
|
| 382 |
|
| 383 |
|
| 384 |
-
@st.cache_data
|
| 385 |
def get_mongodb_data(start_date, end_date, past_date):
|
| 386 |
database_data = mongo_unavs_call(start_date, end_date, past_date)
|
| 387 |
return database_data
|
| 388 |
|
| 389 |
-
@st.cache_data
|
| 390 |
def get_nucmonitor_data(start_date, end_date, past_date):
|
| 391 |
mongo = get_mongodb_data(start_date, end_date, past_date)
|
| 392 |
response_nucmonitor = nuc_monitor(start_date, end_date, past_date, mongo)
|
|
@@ -396,7 +422,7 @@ def get_nucmonitor_data(start_date, end_date, past_date):
|
|
| 396 |
df = pd.read_json(response_nucmonitor)
|
| 397 |
return df
|
| 398 |
|
| 399 |
-
@st.cache_data
|
| 400 |
def get_photodate_data(start_date, end_date, past_date):
|
| 401 |
mongo = get_mongodb_data(start_date, end_date, past_date)
|
| 402 |
response_nucmonitor = nuc_monitor(start_date, end_date, past_date, mongo)
|
|
|
|
| 186 |
|
| 187 |
sorted_df = sorted_df.copy().reset_index(drop=True)
|
| 188 |
|
| 189 |
+
# cruas_2 = sorted_df.copy()[(sorted_df.copy()["name"] == "ST ALBAN 2") & (sorted_df.copy()["end_date"] >= start_date_str)]
|
| 190 |
+
# print(cruas_2[['updated_date', 'end_date', 'available_capacity']])
|
| 191 |
|
| 192 |
# Filter to get identifiers
|
| 193 |
filtered_id_df = sorted_df.copy()
|
| 194 |
+
|
| 195 |
# I commented this out
|
| 196 |
filtered_id_df = filtered_id_df.drop_duplicates(subset='identifier', keep='last')
|
| 197 |
|
| 198 |
+
# cruas_2 = filtered_id_df.copy()[(filtered_id_df.copy()["name"] == "ST ALBAN 2") & (filtered_id_df.copy()["end_date"] >= start_date_str)]
|
| 199 |
+
# print(cruas_2[['updated_date', 'end_date', 'available_capacity']])
|
|
|
|
| 200 |
|
| 201 |
filtered_id_df = filtered_id_df.copy().reset_index(drop=True)
|
| 202 |
|
| 203 |
# This filter should take all the dates with unavs that include days with unavs in the range of the start and end date
|
| 204 |
|
|
|
|
| 205 |
|
| 206 |
# This filter might take out the most recent identifiers (Message ID) that change the dates of unavailability of a plant.
|
| 207 |
# This means that the actual unavailability is something else
|
| 208 |
# filtered_df = filtered_id_df.copy()[(filtered_id_df.copy()['start_date'] <= end_date_str) & (filtered_id_df.copy()['end_date'] >= start_date_str)]
|
| 209 |
+
|
| 210 |
+
# Need to eventually do a filter that takes the most restrictive updated identifier instead of the most recent when there
|
| 211 |
+
# is an overlap
|
| 212 |
+
|
| 213 |
filtered_df = filtered_id_df.copy()
|
| 214 |
|
|
|
|
|
|
|
|
|
|
| 215 |
# Update available_capacity where the condition is True
|
| 216 |
|
| 217 |
# Standardize datetime in dataframe
|
|
|
|
| 281 |
filtered_values.append(item)
|
| 282 |
results_filtered[key] = filtered_values
|
| 283 |
|
|
|
|
|
|
|
| 284 |
|
| 285 |
sorted_results = results_filtered
|
| 286 |
# --------------------- SECOND DATA CLEANING ------------------------ #
|
|
|
|
| 305 |
results_plants = {plant_name: {date: {"available_capacity": power, "updated_date": pd.to_datetime("1970-01-01", utc=True)} for date in dates_of_interest}
|
| 306 |
for plant_name, power in plants_metadata.items()}
|
| 307 |
|
| 308 |
+
print(results_sorted)
|
| 309 |
for plant, unavailabilities in results_sorted.items():
|
| 310 |
# Get the full power of a given plant according to the sorted results
|
| 311 |
original_power = plants_metadata[plant]
|
|
|
|
| 333 |
|
| 334 |
if start_date_unav <= day <= end_date_unav:
|
| 335 |
# Check if the day is already updated with a later update_date
|
| 336 |
+
|
| 337 |
if day in results_current_plant and updated_date_unav <= results_current_plant[day]["updated_date"]:
|
| 338 |
+
# Here is likely where we can do the filter for worst case scenario
|
| 339 |
+
# --------------------------- !!!!!!CREATE NEW FILTER THAT KEEPS ONLY MOST RESTRICTIVE OVERLAP!!!!!! --------------------------- #
|
| 340 |
+
# if power_unavailability < results_current_plant[day]['available_capacity']:
|
| 341 |
+
|
| 342 |
+
# # Calculate the % of the day that the plant is under maintenance
|
| 343 |
+
# if start_date_unav == day and day == end_date_unav:
|
| 344 |
+
# # The unavailability starts and ends on the same day
|
| 345 |
+
# percentage_of_day = (end_hour * 60 + end_minute - start_hour * 60 - start_minute) / (24 * 60)
|
| 346 |
+
# elif start_date_unav == day:
|
| 347 |
+
# # The unavailability starts on the current day but ends on a later day
|
| 348 |
+
# percentage_of_day = (24 * 60 - (start_hour * 60 + start_minute)) / (24 * 60)
|
| 349 |
+
# elif day == end_date_unav:
|
| 350 |
+
# # The unavailability starts on a previous day and ends on the current day
|
| 351 |
+
# percentage_of_day = (end_hour * 60 + end_minute) / (24 * 60)
|
| 352 |
+
# else:
|
| 353 |
+
# # The unavailability covers the entire day
|
| 354 |
+
# percentage_of_day = 1
|
| 355 |
+
|
| 356 |
+
# --------------------------- !!!!!!CREATE NEW FILTER THAT KEEPS ONLY MOST RESTRICTIVE OVERLAP!!!!!! --------------------------- #
|
| 357 |
+
# else:
|
| 358 |
+
|
| 359 |
continue # Skip to the next loop if there is already information for a later update_date
|
| 360 |
|
| 361 |
# Calculate the % of the day that the plant is under maintenance
|
|
|
|
| 376 |
power_of_day = percentage_of_day * power_unavailability + (1 - percentage_of_day) * original_power
|
| 377 |
|
| 378 |
# Update the available_capacity for the day only if it's not already updated with a later update_date
|
| 379 |
+
if (day not in results_current_plant):
|
| 380 |
results_current_plant[day] = {"available_capacity": power_of_day, "updated_date": updated_date_unav}
|
| 381 |
+
|
| 382 |
+
elif (day in results_current_plant) and (updated_date_unav > results_current_plant[day]["updated_date"]) and (power_of_day < results_current_plant[day]['available_capacity']):
|
| 383 |
+
results_current_plant[day] = {"available_capacity": power_of_day, "updated_date": updated_date_unav}
|
| 384 |
+
|
| 385 |
+
else:
|
| 386 |
+
continue
|
| 387 |
+
|
| 388 |
|
| 389 |
|
| 390 |
output_results = {}
|
|
|
|
| 407 |
# -------------------------------------------------
|
| 408 |
|
| 409 |
|
| 410 |
+
# @st.cache_data
|
| 411 |
def get_mongodb_data(start_date, end_date, past_date):
|
| 412 |
database_data = mongo_unavs_call(start_date, end_date, past_date)
|
| 413 |
return database_data
|
| 414 |
|
| 415 |
+
# @st.cache_data
|
| 416 |
def get_nucmonitor_data(start_date, end_date, past_date):
|
| 417 |
mongo = get_mongodb_data(start_date, end_date, past_date)
|
| 418 |
response_nucmonitor = nuc_monitor(start_date, end_date, past_date, mongo)
|
|
|
|
| 422 |
df = pd.read_json(response_nucmonitor)
|
| 423 |
return df
|
| 424 |
|
| 425 |
+
# @st.cache_data
|
| 426 |
def get_photodate_data(start_date, end_date, past_date):
|
| 427 |
mongo = get_mongodb_data(start_date, end_date, past_date)
|
| 428 |
response_nucmonitor = nuc_monitor(start_date, end_date, past_date, mongo)
|