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 metrics to return Transaction table with quantity in units of kg/GWe #161

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions cymetric/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,47 @@ def inventory_quantity_per_gwe(expinv,power):
inv.Quantity = inv.Quantity/inv.Value
inv=inv.drop(['Value'],axis=1)
return inv
louishartono marked this conversation as resolved.
Show resolved Hide resolved

# Quantity per GigaWattElectric in TransactionQuantity [kg/GWe]
louishartono marked this conversation as resolved.
Show resolved Hide resolved
_tranactsdeps = ['TransactionQuantity','TimeSeriesPower']

_tranactsschema = [
('SimId', ts.UUID),
('TransactionId', ts.INT),
('ResourceId', ts.INT),
('ObjId', ts.INT),
('Time', ts.INT),
('SenderId', ts.INT),
('ReceiverId', ts.INT),
('Commodity', ts.STRING),
('Units', ts.STRING),
('Quantity', ts.DOUBLE)
]


@metric(name='TransactionQuantityPerGWe', depends=_tranactsdeps, schema=_tranactsschema)
louishartono marked this conversation as resolved.
Show resolved Hide resolved
def transaction_quantity_per_gwe(tranacts, power):
"""Transaction Quantity per GWe metric returns the transaction quantity table with quantity
in units of kg/GWe, calculated by dividing the original quantity by the electricity generated
at the corresponding simulation and the specific time in TimeSeriesPower metric.
louishartono marked this conversation as resolved.
Show resolved Hide resolved
"""
power = power.groupby(['SimId','Time']).sum()
louishartono marked this conversation as resolved.
Show resolved Hide resolved
df1 = power.reset_index()
tranacts = pd.DataFrame(data={'SimId': tranacts.SimId,
'TransactionId': tranacts.TransactionId,
'ResourceId': tranacts.ResourceId,
'ObjId': tranacts.ObjId,
'Time': tranacts.TimeCreated,
'SenderId': tranacts.SenderId,
'ReceiverId': tranacts.ReceiverId,
'Commodity': tranacts.Commodity,
'Units': tranacts.Units,
'Quantity': tranacts.Quantity},
columns=['SimId','TransactionId','ResourceId','ObjId','Time',
'SenderId','ReceiverId','Commodity','Units','Quantity'])
louishartono marked this conversation as resolved.
Show resolved Hide resolved
tranacts['Units'] = "kg/GWe"
louishartono marked this conversation as resolved.
Show resolved Hide resolved
tranacts=pd.merge(tranacts,df1, on=['SimId','Time'],how='left')
louishartono marked this conversation as resolved.
Show resolved Hide resolved
tranacts.Quantity = tranacts.Quantity/tranacts.Value
return tranacts[['SimId','TransactionId','ResourceId','ObjId','Time',
'SenderId','ReceiverId','Commodity','Units','Quantity']]
louishartono marked this conversation as resolved.
Show resolved Hide resolved

35 changes: 35 additions & 0 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,41 @@ def test_inventory_quantity_per_gwe():
obs = metrics.inventory_quantity_per_gwe.func(inv, tsp)
assert_frame_equal(exp, obs)
louishartono marked this conversation as resolved.
Show resolved Hide resolved


louishartono marked this conversation as resolved.
Show resolved Hide resolved
def test_transaction_quantity_per_gwe():
#exp is the expected output metrics
louishartono marked this conversation as resolved.
Show resolved Hide resolved
exp = pd.DataFrame(np.array([
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 7, 3, 3, 10, 20, 'LWR Fuel', 'kg/GWe', 0.82),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 8, 4, 3, 20, 30, 'FR Fuel', 'kg/GWe', 0.61),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 3, 9, 5, 12, 30, 40, 'Spent Fuel', 'kg/GWe', 0.09),
Copy link
Member

Choose a reason for hiding this comment

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

lines over 80 chars

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't it be confusing if I separate this line?

Copy link
Member

Choose a reason for hiding this comment

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

no, PEP8 recommandation are line should be shorter than 80 chars to improve readability,

I might seem unintuitive, but this way readers don't have to scroll horizontally

], dtype=ensure_dt_bytes([
('SimId', 'O'), ('TransactionId', '<i8'), ('ResourceId', '<i8'),
('ObjId', '<i8'), ('Time', '<i8'), ('SenderId', '<i8'),
('ReceiverId', '<i8'), ('Commodity', 'O'), ('Units', 'O'),
('Quantity', '<f8')]))
louishartono marked this conversation as resolved.
Show resolved Hide resolved
)
#tsp is the TimeSeriesPower metrics
louishartono marked this conversation as resolved.
Show resolved Hide resolved
tsp = pd.DataFrame(np.array([
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 3, 225),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 3, 275),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 12, 100),
], dtype=ensure_dt_bytes([
('SimId', 'O'), ('AgentId', '<i8'), ('Time', '<i8'),
('Value', '<f8')]))
louishartono marked this conversation as resolved.
Show resolved Hide resolved
)
#tranacts is the TransactionQuantity metrics
louishartono marked this conversation as resolved.
Show resolved Hide resolved
tranacts = pd.DataFrame(np.array([
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 7, 3, 3, 10, 20, 'LWR Fuel', 'kg', 410),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 8, 4, 3, 20, 30, 'FR Fuel', 'kg', 305),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 3, 9, 5, 12, 30, 40, 'Spent Fuel', 'kg', 9),
], dtype=ensure_dt_bytes([
('SimId', 'O'), ('TransactionId', '<i8'), ('ResourceId', '<i8'),
('ObjId', '<i8'), ('TimeCreated', '<i8'), ('SenderId', '<i8'),
('ReceiverId', '<i8'), ('Commodity', 'O'), ('Units', 'O'),
('Quantity', '<f8')]))
louishartono marked this conversation as resolved.
Show resolved Hide resolved
)
obs = metrics.transaction_quantity_per_gwe.func(tranacts, tsp)
assert_frame_equal(exp, obs)

if __name__ == "__main__":
louishartono marked this conversation as resolved.
Show resolved Hide resolved
nose.runmodule()
Expand Down