From 79989af8880092e8fd5b37132362d3d8d792a23a Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Mon, 5 Aug 2019 12:36:32 -0500 Subject: [PATCH] working timeseries --- cymetric/metrics.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/cymetric/metrics.py b/cymetric/metrics.py index 02377056..f7d1cc00 100644 --- a/cymetric/metrics.py +++ b/cymetric/metrics.py @@ -409,7 +409,7 @@ def annual_electricity_generated_by_agent(elec): del _egdeps, _egschema # Usage -_egdeps = ['Metadata', 'TimeList', 'AgentEntry'] +_egdeps = ['Metadata', 'TimeList', 'AgentEntry', 'TimeSeriesPower', 'TimeSeriesEnrichmentSWU', 'TimeSeriesThroughput'] _egschema = [ ('SimId', ts.UUID), @@ -420,14 +420,14 @@ def annual_electricity_generated_by_agent(elec): ] @metric(name='Usage', depends=_egdeps, schema=_egschema) -def usage_by_agent(metadata, time, agents_entry): +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 = metadata[ metadata['Type'] == "throughput" ] + throughput_meta = metadata[ metadata['Type'] == "throughput" ] # Deployement @@ -441,10 +441,11 @@ def usage_by_agent(metadata, time, agents_entry): '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, @@ -453,9 +454,11 @@ def usage_by_agent(metadata, time, agents_entry): '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, @@ -473,9 +476,23 @@ def usage_by_agent(metadata, time, agents_entry): row['Keyword'], row['Value'])) timestep_use = pd.DataFrame(time_step_data, columns=['SimId', 'AgentId', 'Time', 'Keyword', 'Value']) - - rtn = pd.concat([deployment_use, decom_use, timestep_use], ignore_index=True) + rtn = pd.concat([rtn, timestep_use], ignore_index=True) + def get_throughput_timeseries(throughput_df, throughput_meta): + 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