-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput.py
More file actions
61 lines (47 loc) · 1.45 KB
/
output.py
File metadata and controls
61 lines (47 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Output settings.
Author: Liming Xu
Email: lx249@cam.ac.uk
"""
import pandas as pd
import numpy as np
# The columns names and their dtypes.
column_dtypes = [
("timestep", int),
("node_idx", int),
("tier", int),
("power", int),
("is_bankrupt", bool),
("stock", int),
("cash", float),
("order_from", int),
("buy_amount", int),
("receive_amount", int),
("purchase_value", float),
("sale_value", float),
("cash_from", int), # Sender of payment
("pay_amount", float), # Amount of payment
("unfilled", int), # Unfilled orders
("issued", int), # Issued orders
("b_loan", float), # Loan from bank financing
("receivable", float),
("payable", float),
("debt", float)
]
columns = list(zip(*column_dtypes))[0]
class Writer(object):
def __init__(self, sim_id, column_dtypes=column_dtypes):
self.output_file = f"output_data/output__sim_{sim_id}.csv"
self.output = pd.DataFrame(np.empty(0, dtype=np.dtype(column_dtypes)))
def append(self, data_at_t):
"""
Append data into the output dataframe.
Parameters
---------
`data_at_t`: dict
the output data at a time step.
"""
incoming_output = pd.DataFrame.from_dict(data_at_t)
self.output = pd.concat([self.output, incoming_output], ignore_index=True)
def write(self):
self.output.to_csv(self.output_file, index=False)