From 0da27e2e219753f7887f42170c400a18060156e4 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 20 Jun 2019 08:36:32 -0500 Subject: [PATCH 01/11] adding Metadat in RootMetric --- cymetric/root_metrics.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cymetric/root_metrics.py b/cymetric/root_metrics.py index d3e78be2..69a8a53b 100644 --- a/cymetric/root_metrics.py +++ b/cymetric/root_metrics.py @@ -102,3 +102,4 @@ def root_metric(obj=None, name=None, schema=None, *args, **kwargs): time_series_power = root_metric(name='TimeSeriesPower') time_series_enrichmentfeed = root_metric(name='TimeSeriesEnrichmentFeed') time_series_enrichmentswu = root_metric(name='TimeSeriesEnrichmentSWU') +metadata = root_metric(name='Metadata') From 15a9aa03f661af3298b50a0d2633e2cce3317080 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 20 Jun 2019 08:36:46 -0500 Subject: [PATCH 02/11] start usage Metric implementation --- cymetric/metrics.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/cymetric/metrics.py b/cymetric/metrics.py index aa62dcab..d88c7ca2 100644 --- a/cymetric/metrics.py +++ b/cymetric/metrics.py @@ -408,6 +408,49 @@ def annual_electricity_generated_by_agent(elec): del _egdeps, _egschema +# Usage +_egdeps = [ + ('Metadata', ('SimId', 'AgentId', 'keyword', 'Type'), 'Value'), + ('TimeList', ('SimId'), 'TimeStep'), + ('AgentEntry', ('SimId', 'AgentId', 'Prototype'), 'EnterTime'), + ('AgentEntry', ('SimId', 'AgentId', 'Prototype'), 'LifeTime'), + ] + +_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(series): + """ + """ + metadata = series[0].reset_index() + time = series[1].reset_index() + agent_in = series[2].reset_index() + + decommission = metadata[ metadata['Type'] == "decommission" ] + deployment = metadata[ metadata['Type'] == "deployment" ] + timestep = metadata[ metadata['Type'] == "timestep" ] + throughput = metadata[ metadata['Type'] == "throughput" ] + + # Deployement + # Filter Prototype + deployment_agent = agent_in[agent_in['AgentId'].isin(deployment['AgentId'])] + deploy_usage = pd.DataFrame(data={'SimId': deployemnt_agent.SimId, + 'AgentId': deployemnt_agent.AgentId, + 'Time': deployemnt_agent.Enter + + metadata = metadata.groupby(el_index).sum() + rtn = metadata.reset_index() + return rtn + +del _egdeps, _egschema + + # # Not a metric, not a root metric metrics # From fe9e98470a7f74e38561414c09c5c108496184eb Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Tue, 2 Jul 2019 12:59:39 -0500 Subject: [PATCH 03/11] some progress on metadata --- cymetric/metrics.py | 9 ++------- cymetric/tools.py | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/cymetric/metrics.py b/cymetric/metrics.py index d88c7ca2..3202d2fc 100644 --- a/cymetric/metrics.py +++ b/cymetric/metrics.py @@ -400,7 +400,7 @@ 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() @@ -409,12 +409,7 @@ def annual_electricity_generated_by_agent(elec): del _egdeps, _egschema # Usage -_egdeps = [ - ('Metadata', ('SimId', 'AgentId', 'keyword', 'Type'), 'Value'), - ('TimeList', ('SimId'), 'TimeStep'), - ('AgentEntry', ('SimId', 'AgentId', 'Prototype'), 'EnterTime'), - ('AgentEntry', ('SimId', 'AgentId', 'Prototype'), 'LifeTime'), - ] +_egdeps = ['Metadata', 'TimeList', 'AgentEntry'] _egschema = [ ('SimId', ts.UUID), diff --git a/cymetric/tools.py b/cymetric/tools.py index baa8af07..a74cc330 100644 --- a/cymetric/tools.py +++ b/cymetric/tools.py @@ -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 From d7f4fe3526314f5f58e79c8d2b47b59314be66d9 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Sun, 4 Aug 2019 12:55:33 -0500 Subject: [PATCH 04/11] udpate --- cymetric/root_metrics.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cymetric/root_metrics.py b/cymetric/root_metrics.py index 69a8a53b..3fc9db06 100644 --- a/cymetric/root_metrics.py +++ b/cymetric/root_metrics.py @@ -100,6 +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') From 95fbd75b11526d75a6d84a6a54a26c4782f1cbac Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Sun, 4 Aug 2019 14:01:53 -0500 Subject: [PATCH 05/11] decom to timestep working --- cymetric/metrics.py | 61 +++++++++++++++++++++++++++++++--------- cymetric/root_metrics.py | 4 +-- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/cymetric/metrics.py b/cymetric/metrics.py index 3202d2fc..02377056 100644 --- a/cymetric/metrics.py +++ b/cymetric/metrics.py @@ -420,27 +420,62 @@ def annual_electricity_generated_by_agent(elec): ] @metric(name='Usage', depends=_egdeps, schema=_egschema) -def usage_by_agent(series): +def usage_by_agent(metadata, time, agents_entry): """ """ - metadata = series[0].reset_index() - time = series[1].reset_index() - agent_in = series[2].reset_index() - decommission = metadata[ metadata['Type'] == "decommission" ] deployment = metadata[ metadata['Type'] == "deployment" ] + decom = metadata[ metadata['Type'] == "decommission" ] timestep = metadata[ metadata['Type'] == "timestep" ] throughput = metadata[ metadata['Type'] == "throughput" ] + # Deployement - # Filter Prototype - deployment_agent = agent_in[agent_in['AgentId'].isin(deployment['AgentId'])] - deploy_usage = pd.DataFrame(data={'SimId': deployemnt_agent.SimId, - 'AgentId': deployemnt_agent.AgentId, - 'Time': deployemnt_agent.Enter - - metadata = metadata.groupby(el_index).sum() - rtn = metadata.reset_index() + 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']) + + + # Decommision + decom_agent = agents_entry[agents_entry['AgentId'].isin(decom['AgentId'])] + 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']) + + # TimeStep + timestep_agent = agents_entry[agents_entry['AgentId'].isin(timestep['AgentId'])] + 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([deployment_use, decom_use, timestep_use], ignore_index=True) + return rtn del _egdeps, _egschema diff --git a/cymetric/root_metrics.py b/cymetric/root_metrics.py index 3fc9db06..a9589b1c 100644 --- a/cymetric/root_metrics.py +++ b/cymetric/root_metrics.py @@ -100,8 +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_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') From fc2f0b19f62b0b6669a6a3934c3f74ad4a844b19 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Mon, 5 Aug 2019 12:36:32 -0500 Subject: [PATCH 06/11] 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 From 15735f275b20afb03b31da22cf69b47dd38ba357 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Mon, 5 Aug 2019 12:41:43 -0500 Subject: [PATCH 07/11] celaring trailing space --- cymetric/metrics.py | 48 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/cymetric/metrics.py b/cymetric/metrics.py index f7d1cc00..2380f093 100644 --- a/cymetric/metrics.py +++ b/cymetric/metrics.py @@ -433,26 +433,26 @@ def usage_by_agent(metadata, time, agents_entry, power, SWU, throughput_ts): # 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)}, + + + 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() - + 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)}, + 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) @@ -460,13 +460,13 @@ def usage_by_agent(metadata, time, agents_entry, power, SWU, throughput_ts): 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']) + 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']): @@ -476,8 +476,8 @@ def usage_by_agent(metadata, time, agents_entry, power, SWU, throughput_ts): 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) - + 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']) @@ -487,7 +487,7 @@ def get_throughput_timeseries(throughput_df, throughput_meta): 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) From 8d5f7c602beccb8085cacf5c00a535305a58828d Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 12 Sep 2019 12:12:50 -0500 Subject: [PATCH 08/11] working external metadata --- cymetric/metadata.py | 100 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 cymetric/metadata.py diff --git a/cymetric/metadata.py b/cymetric/metadata.py new file mode 100644 index 00000000..04bfc5e1 --- /dev/null +++ b/cymetric/metadata.py @@ -0,0 +1,100 @@ +import warnings +import pandas as pd +import numpy as np + + +try: + from pyne import data + import pyne.enrichment as enr + from pyne import nucname + HAVE_PYNE = True +except ImportError: + HAVE_PYNE = False + + +from cymetric.tools import format_nucs, reduce, merge, add_missing_time_step + +def get_usage(evaler): + + metadata = evaler.eval("Metadata") + agents_entry = evaler.eval('AgentEntry') + deployment = metadata[ metadata['Type'] == "deployment" ] + decom = metadata[ metadata['Type'] == "decommission" ] + timestep = metadata[ metadata['Type'] == "timestep" ] + throughput_meta = metadata[ metadata['Type'] == "throughput" ] + + worklabel = metadata[ metadata['Keyword'] == "WORKLABEL" ] + + # 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) + + worklabel.drop(columns=['AgentId'], inplace=True) + worklabel.drop_duplicates(inplace=True) + worktimeseries = [] + for index, row in worklabel.iterrows(): + if (row['AgentId'] in throughput_meta['AgentId']): + work_name = "TimeSeries" + row['Value'] + timeseries = myEval.eval(work_name) + if timeseries is not None: + worktimeseries.append(timeseries[timeseries['AgentId'] == row['AgentId'] ]) + + 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() + + for work in worktimeseries: + rtn = pd.concat([rtn, get_throughput_timeseries(work, throughput_meta)], ignore_index=True) + + + return rtn From f575283f008c94fdc334924a643c80b0ae624177 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 12 Sep 2019 12:13:29 -0500 Subject: [PATCH 09/11] comment out throughput --- cymetric/metrics.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cymetric/metrics.py b/cymetric/metrics.py index 2380f093..6b3d4346 100644 --- a/cymetric/metrics.py +++ b/cymetric/metrics.py @@ -478,19 +478,19 @@ def usage_by_agent(metadata, time, agents_entry, power, SWU, throughput_ts): 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): - 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) +# 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 From 88f96e88e03cbf4e784af3811033f5e691a75ff7 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 12 Sep 2019 12:20:43 -0500 Subject: [PATCH 10/11] working version --- cymetric/metadata.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cymetric/metadata.py b/cymetric/metadata.py index 04bfc5e1..e5814745 100644 --- a/cymetric/metadata.py +++ b/cymetric/metadata.py @@ -73,13 +73,12 @@ def get_usage(evaler): timestep_use = pd.DataFrame(time_step_data, columns=['SimId', 'AgentId', 'Time', 'Keyword', 'Value']) rtn = pd.concat([rtn, timestep_use], ignore_index=True) - worklabel.drop(columns=['AgentId'], inplace=True) worklabel.drop_duplicates(inplace=True) worktimeseries = [] for index, row in worklabel.iterrows(): if (row['AgentId'] in throughput_meta['AgentId']): work_name = "TimeSeries" + row['Value'] - timeseries = myEval.eval(work_name) + timeseries = evaler.eval(work_name) if timeseries is not None: worktimeseries.append(timeseries[timeseries['AgentId'] == row['AgentId'] ]) @@ -89,7 +88,7 @@ def get_throughput_timeseries(throughput_df, throughput_meta): _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 + return _tmp[['SimId', 'AgentId', 'Time', 'Keyword', 'Value']] else: return pd.DataFrame() From 5eecfa271aa89092fc6b34517be55079bee96f66 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 12 Sep 2019 14:10:55 -0500 Subject: [PATCH 11/11] removing useless metrics --- cymetric/metrics.py | 76 --------------------------------------------- 1 file changed, 76 deletions(-) diff --git a/cymetric/metrics.py b/cymetric/metrics.py index 2380f093..bbb8f673 100644 --- a/cymetric/metrics.py +++ b/cymetric/metrics.py @@ -419,82 +419,6 @@ def annual_electricity_generated_by_agent(elec): ('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): - 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