Skip to content

Commit

Permalink
working timeseries
Browse files Browse the repository at this point in the history
  • Loading branch information
bam241 committed Aug 5, 2019
1 parent 5ba8b3c commit 79989af
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions cymetric/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 79989af

Please sign in to comment.