dmarr commited on
Commit
03b3284
·
1 Parent(s): 5acc1b8

Updated with suggestions from JC

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -398,10 +398,27 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
398
  # print(results_plants)
399
  # Convert datetime key to string to store in mongodb
400
  output_results = {plant: {str(date): power for date, power in plant_data.items()} for plant, plant_data in output_results.items()}
401
- # output_results = pd.DataFrame(output_results)
402
- # print(output_results)
403
 
404
  # -------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
405
 
406
  json_data = json.dumps(output_results)
407
  # print(json_data)
 
398
  # print(results_plants)
399
  # Convert datetime key to string to store in mongodb
400
  output_results = {plant: {str(date): power for date, power in plant_data.items()} for plant, plant_data in output_results.items()}
401
+ output_results = pd.DataFrame(output_results)
402
+ print(output_results)
403
 
404
  # -------------------------------------------------
405
+ # Calculate the average of each column excluding the last row
406
+ averages = output_results.iloc[:-1, :].mean()
407
+
408
+ # Replace the last row with the calculated averages
409
+ output_results.iloc[-1, :] = averages
410
+
411
+ output_results = output_results.to_dict()
412
+
413
+ def turn_total_row_to_avg(data):
414
+ # Replace the last key of each dictionary with 'Averages'
415
+ for key, value in data.items():
416
+ last_key = list(value.keys())[-1]
417
+ value['Averages'] = value.pop(last_key)
418
+
419
+ turn_total_row_to_avg(output_results)
420
+
421
+ # print(output_results)
422
 
423
  json_data = json.dumps(output_results)
424
  # print(json_data)