Skip to content

Commit

Permalink
chore: added power data to raw data
Browse files Browse the repository at this point in the history
  • Loading branch information
bpetit committed Apr 9, 2023
1 parent 2f5b629 commit b3f88d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 18 additions & 3 deletions boagent/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async def operational_impact_yearly():
df_carbon_intensity['carbon_intensity_g_per_watt_second'] = df_carbon_intensity['value'] / (1000 * 3600)

yearly_operational = (df_power['power_watt'].mean()*df_carbon_intensity["carbon_intensity_g_per_watt_second"].mean())*(3600*24*365) # in gCO2eq

return round(yearly_operational/1000.0) # in kgCO2eq


Expand Down Expand Up @@ -393,7 +393,7 @@ def get_metrics(start_time: float, end_time: float, verbose: bool, location: str
},
"electricity_carbon_intensity": {
"value": boaviztapi_data["verbose"]["USAGE"]["gwp_factor"]["value"],
"description": "Carbon intensity of the elextricity mixed. Mix considered : {}".format(location),
"description": "Carbon intensity of the electricity mix. Mix considered : {}".format(location),
"type": "gauge",
"unit": "kg CO2eq / kWh",
"long_unit": "Kilograms CO2 equivalent per KiloWattHour"
Expand All @@ -413,7 +413,8 @@ def get_metrics(start_time: float, end_time: float, verbose: bool, location: str
res["emissions_calculation_data"]["raw_data"] = {
"hardware_data": hardware_data,
"resources_data": "not implemented yet",
"boaviztapi_data": boaviztapi_data
"boaviztapi_data": boaviztapi_data,
"power_data": power_data
}
return res

Expand Down Expand Up @@ -445,6 +446,20 @@ def get_power_data(start_time, end_time):
"careful with this data. "
return power_data

def get_timeseries_data(start_time, end_time):
with open(settings.power_file_path, 'r') as fd:
# Get all items of the json list where start_time <= host.timestamp <= end_time
data = json.load(fd)
res = [e for e in data if start_time <= float(e['host']['timestamp']) <= end_time]
power_data['raw_data'] = res
power_data['host_avg_consumption'] = compute_average_consumption(res)
if end_time - start_time <= 3600:
power_data[
'warning'] = "The time window is lower than one hour, but the energy consumption estimate is in " \
"Watt.Hour. So this is an extrapolation of the power usage profile on one hour. Be " \
"careful with this data. "
return power_data


def compute_average_consumption(power_data):
# Host energy consumption
Expand Down
3 changes: 1 addition & 2 deletions boagent/api/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ def get_max(table_name):

def add_from_scaphandre(session):
last_timestamp = get_most_recent_timestamp(session)
last_timestamp = last_timestamp + timedelta(seconds=5) if last_timestamp != None else datetime.now() - timedelta(
hours=24)
last_timestamp = last_timestamp + timedelta(seconds=5) if last_timestamp != None else datetime.now() - timedelta(hours=24)
df = scaphandre_to_csv(start_date=last_timestamp, stop_date=datetime.utcnow())
if df.empty:
return
Expand Down

0 comments on commit b3f88d3

Please sign in to comment.