Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata #153

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
92 changes: 91 additions & 1 deletion cymetric/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,104 @@ def annual_electricity_generated_by_agent(elec):
'AgentId': elec.AgentId,
'Year': elec.Time.apply(lambda x: x//12),
'Energy': elec.Value.apply(lambda x: x/12)},
columns=['SimId', 'AgentId', 'Year', 'Energy'])
columns=['SimId', 'AgentId', 'Year', 'Energy'])
el_index = ['SimId', 'AgentId', 'Year']
elec = elec.groupby(el_index).sum()
rtn = elec.reset_index()
return rtn

del _egdeps, _egschema

# Usage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More documentation required for these new sections. i don't really know what they mean

_egdeps = ['Metadata', 'TimeList', 'AgentEntry', 'TimeSeriesPower', 'TimeSeriesEnrichmentSWU', 'TimeSeriesThroughput']

_egschema = [
('SimId', ts.UUID),
('AgentId', ts.INT),
('Time', ts.INT),
('Keyword', ts.STRING),
('Value', ts.DOUBLE)
]

@metric(name='Usage', depends=_egdeps, schema=_egschema)
def usage_by_agent(metadata, time, agents_entry, power, SWU, throughput_ts):
"""
"""

deployment = metadata[ metadata['Type'] == "deployment" ]
decom = metadata[ metadata['Type'] == "decommission" ]
timestep = metadata[ metadata['Type'] == "timestep" ]
throughput_meta = metadata[ metadata['Type'] == "throughput" ]


# Deployement
dep_agent = agents_entry[agents_entry['AgentId'].isin(deployment['AgentId'])]
_tmp = pd.merge(deployment[['SimId', 'AgentId','Keyword', 'Value']], dep_agent, on=['SimId', 'AgentId'])


deployment_use = pd.DataFrame(data={'SimId': _tmp.SimId,
'AgentId': _tmp.AgentId,
'Time': _tmp.EnterTime,
'Keyword': _tmp.Keyword,
'Value':_tmp.Value.astype(float)},
columns=['SimId', 'AgentId', 'Time', 'Keyword', 'Value'])
rtn = deployment_use.copy()

# Decommision
decom_agent = agents_entry[agents_entry['AgentId'].isin(decom['AgentId'])]
decom_agent = decom_agent.reset_index(drop=True)
decom_agent['ExitTime'] = decom_agent['EnterTime'] + decom_agent['Lifetime']
_tmp = pd.merge(decom[['SimId', 'AgentId','Keyword', 'Value']], decom_agent, on=['SimId', 'AgentId'])
decom_use = pd.DataFrame(data={'SimId': _tmp.SimId,
'AgentId': _tmp.AgentId,
'Time': _tmp.ExitTime,
'Keyword': _tmp.Keyword,
'Value':_tmp.Value.astype(float)},
columns=['SimId', 'AgentId', 'Time', 'Keyword', 'Value'])
rtn = pd.concat([rtn, decom_use], ignore_index=True)

# TimeStep
timestep_agent = agents_entry[agents_entry['AgentId'].isin(timestep['AgentId'])]
timestep_agent = timestep_agent.reset_index(drop=True)
timestep_agent['ExitTime'] = timestep_agent['EnterTime'] + timestep_agent['Lifetime']
timestep_tmp = pd.DataFrame(data={'SimId': _tmp.SimId,
'AgentId': _tmp.AgentId,
'EnterTime': _tmp.EnterTime,
'ExitTime': _tmp.ExitTime ,
'Keyword': _tmp.Keyword,
'Value':_tmp.Value.astype(float)},
columns=['SimId', 'AgentId', 'EnterTime', 'ExitTime', 'Keyword', 'Value'])
time_step_data = []
for index, row in timestep_tmp.iterrows():
for i in range(row['EnterTime'], row['ExitTime']):
time_step_data.append( (row['SimId'],
row['AgentId'],
i,
row['Keyword'],
row['Value']))
timestep_use = pd.DataFrame(time_step_data, columns=['SimId', 'AgentId', 'Time', 'Keyword', 'Value'])
rtn = pd.concat([rtn, timestep_use], ignore_index=True)

# def get_throughput_timeseries(throughput_df, throughput_meta):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete these commented functions?

# if throughput_df is not None:
# _tmp = pd.merge(throughput_meta[['SimId', 'AgentId','Keyword', 'Value']], throughput_df, on=['SimId', 'AgentId'])
# _tmp['Value_y'] = _tmp.Value_x.astype(float)*_tmp.Value_y
# _tmp.drop(columns=['Value_x'], inplace=True)
# _tmp.rename(columns={"Value_y": "Value"}, inplace=True)
# return _tmp
# else:
# return pd.DataFrame()
#
# rtn = pd.concat([rtn, get_throughput_timeseries(power, throughput_meta)], ignore_index=True)
# rtn = pd.concat([rtn, get_throughput_timeseries(SWU, throughput_meta)], ignore_index=True)
# rtn = pd.concat([rtn, get_throughput_timeseries(throughput_ts, throughput_meta)], ignore_index=True)


return rtn

del _egdeps, _egschema


#
# Not a metric, not a root metric metrics
#
Expand Down
3 changes: 3 additions & 0 deletions cymetric/root_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,8 @@ def root_metric(obj=None, name=None, schema=None, *args, **kwargs):

#toolkit-enabled tables
time_series_power = root_metric(name='TimeSeriesPower')
time_series_deployedisnt = root_metric(name='TimeSeriesDeployedInst')
time_series_throughput = root_metric(name='TimeSeriesThroughput')
time_series_enrichmentfeed = root_metric(name='TimeSeriesEnrichmentFeed')
time_series_enrichmentswu = root_metric(name='TimeSeriesEnrichmentSWU')
metadata = root_metric(name='Metadata')
4 changes: 2 additions & 2 deletions cymetric/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def add_missing_time_step(df, ref_time):

def merge(df, base_col, add_df, add_col):
"""
Merge some additionnal columns fram an additionnal Pandas Data Frame
onother one and then remove the second base column (keeping SimID
Merge some additionnal columns from an additionnal Pandas Data Frame
another one and then remove the second base column (keeping SimID
information).

Parameters
Expand Down