-
Notifications
You must be signed in to change notification settings - Fork 3
/
bigData.py
132 lines (99 loc) · 3.98 KB
/
bigData.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import copy
import numpy as np
import database as d
#bigdata makes SHALLOW COPIES of all lists passed to it.
class bigdata(object):
def __init__(self, unit):
self.unit = unit
self.locality = unit.getLocality()
self.sales = []
self.failSales = []
self.price = []
self.oPrice = []
self.crafted = []
self.customers = []
self.planted = []
self.harvested = []
self.DMC = []
self.stock = []
self.output = []
self.transports = []
self.failTransports = []
def getData(self, dayNum):
values_dict = {}
for key in ("sales", "price", "customers", "planted", "crafted", "harvested"):
try:
values_dict[key] = getattr(self, key)[dayNum]
except (KeyError, IndexError):
values_dict[key] = None
return values_dict
#i = materialIndex
def getMonth(self, i):
dayNum = self.getDayNum()
days = []
lastThirty= ((dayNum - 29, dayNum) if dayNum > 29 else (0, 29))
for key in ( "price", "crafted", "sales", "failSales", "transports", "failTransports", "stock", "output"):
today = []
for j in range(*lastThirty):
try:
product = getattr(self, key)[j][i]
except (KeyError, IndexError):
product = 0
today.append(product)
days.append(today)
return days
def getDayNum(self):
return self.locality.getDayNum()
def getRecentSales(self, days):
return self.sales[-days:]
def getRecentFailSales(self, days):
return self.failSales[-days:]
def getAvgSales(self, i):
if len(self.sales) > 0:
return sum([self.sales[day][i] for day in range(len(self.sales))]) / len(self.sales)
else:
return 0
def getAvgFailSales(self, i):
if len(self.failSales) > 0:
return sum([self.failSales[day][i] for day in range(len(self.failSales))]) / len(self.failSales)
else:
return 0
def getAvgTransports(self, i):
if len(self.transports) > 0:
return sum([self.transports[day][i] for day in range(len(self.transports))]) / len(self.transports)
else:
return 0
def getAvgFailTransports(self, i):
if len(self.failTransports) > 0:
return sum([self.failTransports[day][i] for day in range(len(self.failTransports))]) / len(self.failTransports)
else:
return 0
#works as long as all 4 arrays are the same length. Otherwise need weighted avg
def getAvgDemand(self, i):
return (self.getAvgSales(i) + self.getAvgFailSales(i) + self.getAvgTransports(i) + self.getAvgFailTransports(i))
def updateSales(self, sales):
self.sales.append(copy.copy(sales))
def updateFailSales(self, failSales):
self.failSales.append(copy.copy(failSales))
def updatePrice(self, price):
self.price.append(copy.copy(price))
def updateOptimalPrice(self, oPrice):
self.oPrice.append(copy.copy(oPrice))
def updateCrafted(self, crafted):
self.crafted.append(copy.copy(crafted))
def updateCustomers(self, customers):
self.customers.append(copy.copy(customers))
def updatePlanted(self, planted):
self.planted.append(copy.copy(planted))
def updateHarvested(self, harvested):
self.harvested.append(copy.copy(harvested))
def updateDMC(self, DMC):
self.DMC.append(copy.copy(DMC))
def updateStock(self, stock):
self.stock.append(copy.copy(stock))
def updateOutput(self, output):
self.output.append(copy.copy(output))
def updateTransports(self, transports):
self.transports.append(copy.copy(transports))
def updateFailTransports(self, failTransports):
self.failTransports.append(copy.copy(failTransports))