@@ -106,7 +106,7 @@ async def operational_impact_yearly():
106106 df_carbon_intensity ['carbon_intensity_g_per_watt_second' ] = df_carbon_intensity ['value' ] / (1000 * 3600 )
107107
108108 yearly_operational = (df_power ['power_watt' ].mean ()* df_carbon_intensity ["carbon_intensity_g_per_watt_second" ].mean ())* (3600 * 24 * 365 ) # in gCO2eq
109-
109+
110110 return round (yearly_operational / 1000.0 ) # in kgCO2eq
111111
112112
@@ -393,7 +393,7 @@ def get_metrics(start_time: float, end_time: float, verbose: bool, location: str
393393 },
394394 "electricity_carbon_intensity" : {
395395 "value" : boaviztapi_data ["verbose" ]["USAGE" ]["gwp_factor" ]["value" ],
396- "description" : "Carbon intensity of the elextricity mixed . Mix considered : {}" .format (location ),
396+ "description" : "Carbon intensity of the electricity mix . Mix considered : {}" .format (location ),
397397 "type" : "gauge" ,
398398 "unit" : "kg CO2eq / kWh" ,
399399 "long_unit" : "Kilograms CO2 equivalent per KiloWattHour"
@@ -413,7 +413,8 @@ def get_metrics(start_time: float, end_time: float, verbose: bool, location: str
413413 res ["emissions_calculation_data" ]["raw_data" ] = {
414414 "hardware_data" : hardware_data ,
415415 "resources_data" : "not implemented yet" ,
416- "boaviztapi_data" : boaviztapi_data
416+ "boaviztapi_data" : boaviztapi_data ,
417+ "power_data" : power_data
417418 }
418419 return res
419420
@@ -445,6 +446,20 @@ def get_power_data(start_time, end_time):
445446 "careful with this data. "
446447 return power_data
447448
449+ def get_timeseries_data (start_time , end_time ):
450+ with open (settings .power_file_path , 'r' ) as fd :
451+ # Get all items of the json list where start_time <= host.timestamp <= end_time
452+ data = json .load (fd )
453+ res = [e for e in data if start_time <= float (e ['host' ]['timestamp' ]) <= end_time ]
454+ power_data ['raw_data' ] = res
455+ power_data ['host_avg_consumption' ] = compute_average_consumption (res )
456+ if end_time - start_time <= 3600 :
457+ power_data [
458+ 'warning' ] = "The time window is lower than one hour, but the energy consumption estimate is in " \
459+ "Watt.Hour. So this is an extrapolation of the power usage profile on one hour. Be " \
460+ "careful with this data. "
461+ return power_data
462+
448463
449464def compute_average_consumption (power_data ):
450465 # Host energy consumption
0 commit comments