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

New metric to get cumulative power from time 0 in TimeSeriesPower metric #164

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
27 changes: 26 additions & 1 deletion cymetric/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,29 @@ def inventory_quantity_per_gwe(expinv,power):
inv.Quantity = inv.Quantity/inv.Value
inv=inv.drop(['Value'],axis=1)
return inv


# Cumulative power from time 0 to time t in TimeSeriesPower metric
_cumpdeps = ['TimeSeriesPower']

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

@metric(name='CumulativeTimeSeriesPower', depends=_cumpdeps, schema=_cumpschema)
def cumulative_timeseriespower(power):
"""Cumulative Timeseriespower metric returns the TimeSeriesPower metric with a cumulative sum
of the power generated by each SimId from time 0 to time t.
"""
power = pd.DataFrame(data={'SimId': power.SimId,
'AgentId': power.AgentId,
'Time': power.Time,
'Value': power.Value},
columns=['SimId','AgentID','Time', 'Value'])
power_index = ['SimId','Time']
power = power.groupby(power_index).sum()
df1 = power.reset_index()
df1['Value'] = df1['Value'].cumsum()
return df1
23 changes: 23 additions & 0 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,29 @@ def test_inventory_quantity_per_gwe():
obs = metrics.inventory_quantity_per_gwe.func(inv, tsp)
assert_frame_equal(exp, obs)


def test_cumulative_timeseriespower():
#exp is the expected output metrics
exp = pd.DataFrame(np.array([
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 300),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 3, 700)
], dtype=ensure_dt_bytes([
('SimId', 'O'), ('Time', '<i8'), ('Value', '<f8')]))
)


#tsp is the TimeSeriesPower metrics
tsp = pd.DataFrame(np.array([
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 2, 100),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 2, 200),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 3, 300),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 3, 100),
], dtype=ensure_dt_bytes([
('SimId', 'O'), ('AgentId', '<i8'), ('Time', '<i8'),
('Value', '<f8')]))
)
obs = metrics.cumulative_timeseriespower.func(tsp)
assert_frame_equal(exp, obs)

if __name__ == "__main__":
nose.runmodule()
Expand Down