Skip to content

Commit b3f88d3

Browse files
committed
chore: added power data to raw data
1 parent 2f5b629 commit b3f88d3

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

boagent/api/api.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

449464
def compute_average_consumption(power_data):
450465
# Host energy consumption

boagent/api/database.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ def get_max(table_name):
197197

198198
def add_from_scaphandre(session):
199199
last_timestamp = get_most_recent_timestamp(session)
200-
last_timestamp = last_timestamp + timedelta(seconds=5) if last_timestamp != None else datetime.now() - timedelta(
201-
hours=24)
200+
last_timestamp = last_timestamp + timedelta(seconds=5) if last_timestamp != None else datetime.now() - timedelta(hours=24)
202201
df = scaphandre_to_csv(start_date=last_timestamp, stop_date=datetime.utcnow())
203202
if df.empty:
204203
return

0 commit comments

Comments
 (0)