morelists 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- morelists/__init__.py +102 -14
- {morelists-0.1.0.dist-info → morelists-0.1.1.dist-info}/METADATA +3 -2
- morelists-0.1.1.dist-info/RECORD +6 -0
- {morelists-0.1.0.dist-info → morelists-0.1.1.dist-info}/WHEEL +1 -1
- morelists-0.1.0.dist-info/RECORD +0 -6
- {morelists-0.1.0.dist-info → morelists-0.1.1.dist-info/licenses}/LICENSE +0 -0
- {morelists-0.1.0.dist-info → morelists-0.1.1.dist-info}/top_level.txt +0 -0
morelists/__init__.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
import time
|
2
2
|
|
3
3
|
class GameList():
|
4
|
-
def __init__(self):
|
5
|
-
self.list =
|
6
|
-
self.
|
4
|
+
def __init__(self, list = {}, expirationList = {}, flippedList = {}, freeze = False, deltaTime = 0):
|
5
|
+
self.list = list
|
6
|
+
self.expirationList = expirationList
|
7
|
+
self.flippedList = flippedList
|
7
8
|
|
8
9
|
self.addValue = 0
|
9
10
|
self.subtractValue = 0
|
@@ -11,11 +12,23 @@ class GameList():
|
|
11
12
|
self.divideValue = 1
|
12
13
|
self.sum = 0
|
13
14
|
|
15
|
+
self.freeze = freeze
|
16
|
+
|
17
|
+
self.history = [(0, {}, {}, {}, 0.0)]
|
18
|
+
|
19
|
+
self.deltaTime = deltaTime
|
20
|
+
|
21
|
+
|
14
22
|
def add(self, item, expires = -1):
|
15
|
-
|
23
|
+
perf_counter = time.time()
|
24
|
+
if expires != -1:
|
25
|
+
expires += perf_counter
|
16
26
|
self.list[expires] = {"name":item.get("name", ""), "type":item.get("type", "add"), "value":item.get("value", 0)}
|
17
27
|
if self.list[expires]["type"] not in ["add", "subtract", "multiply", "divide"]:
|
18
28
|
self.list[expires]["type"] = "add"
|
29
|
+
|
30
|
+
if expires != -1:
|
31
|
+
self.expirationList[expires] = self.list[expires]
|
19
32
|
self.flippedList[str(self.list[expires])] = expires
|
20
33
|
|
21
34
|
if item["type"] == "add":
|
@@ -25,12 +38,18 @@ class GameList():
|
|
25
38
|
elif item["type"] == "multiply":
|
26
39
|
self.multiplyValue += (item["value"] - 1)
|
27
40
|
elif item["type"] == "divide":
|
28
|
-
self.divideValue += (item["value"] - 1)
|
41
|
+
self.divideValue += (item["value"] - 1)
|
42
|
+
|
43
|
+
object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, (self.addValue - self.subtractValue) * self.multiplyValue / self.divideValue))
|
29
44
|
|
30
45
|
def unsafeAdd(self, item, expires = -1):
|
31
|
-
|
32
|
-
|
33
|
-
|
46
|
+
perf_counter = time.time()
|
47
|
+
if expires != -1:
|
48
|
+
expires += perf_counter
|
49
|
+
self.list[expires] = item
|
50
|
+
if expires != -1:
|
51
|
+
self.expirationList[expires] = self.list[expires]
|
52
|
+
self.flippedList[str(item)] = expires
|
34
53
|
|
35
54
|
if item["type"] == "add":
|
36
55
|
self.addValue += item["value"]
|
@@ -41,10 +60,30 @@ class GameList():
|
|
41
60
|
elif item["type"] == "divide":
|
42
61
|
self.divideValue += (item["value"] - 1)
|
43
62
|
|
63
|
+
object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, (self.addValue - self.subtractValue) * self.multiplyValue / self.divideValue))
|
64
|
+
|
65
|
+
|
66
|
+
def calculateSum(self):
|
67
|
+
self.addValue = 0
|
68
|
+
self.subtractValue = 0
|
69
|
+
self.multiplyValue = 1
|
70
|
+
self.divideValue = 1
|
71
|
+
for item in self.list.values():
|
72
|
+
if item["type"] == "add":
|
73
|
+
self.addValue += item["value"]
|
74
|
+
elif item["type"] == "subtract":
|
75
|
+
self.subtractValue += item["value"]
|
76
|
+
elif item["type"] == "multiply":
|
77
|
+
self.multiplyValue += (item["value"] - 1)
|
78
|
+
elif item["type"] == "divide":
|
79
|
+
self.divideValue += (item["value"] - 1)
|
80
|
+
return (self.addValue - self.subtractValue) * self.multiplyValue / self.divideValue
|
81
|
+
|
82
|
+
|
44
83
|
|
45
84
|
def update(self):
|
46
85
|
try:
|
47
|
-
expiration = min(self.
|
86
|
+
expiration = min(self.expirationList.keys())
|
48
87
|
while expiration < time.time():
|
49
88
|
if self.list[expiration]["type"] == "add":
|
50
89
|
self.addValue -= self.list[expiration]["value"]
|
@@ -54,35 +93,75 @@ class GameList():
|
|
54
93
|
self.multiplyValue -= (self.list[expiration]["value"] - 1)
|
55
94
|
else:
|
56
95
|
self.divideValue -= (self.list[expiration]["value"] - 1)
|
96
|
+
|
97
|
+
del self.flippedList[str(self.list[expiration])]
|
57
98
|
del self.list[expiration]
|
58
99
|
|
59
|
-
expiration
|
100
|
+
object.__getattribute__(self, "history").append((expiration, self.list, self.expirationList, self.flippedList, (self.addValue - self.subtractValue) * self.multiplyValue / self.divideValue))
|
101
|
+
expiration = min(self.expirationList.keys())
|
60
102
|
except ValueError:
|
61
103
|
pass
|
62
104
|
|
105
|
+
def pause(self):
|
106
|
+
self.freeze = True
|
107
|
+
|
108
|
+
def resume(self):
|
109
|
+
self.freeze = False
|
110
|
+
|
111
|
+
def updateToPresent(self):
|
112
|
+
pass
|
113
|
+
|
114
|
+
def restoreState(self, t) -> "GameList":
|
115
|
+
self.update()
|
116
|
+
lastItem = None
|
117
|
+
for item in self.history:
|
118
|
+
if item[0] < t:
|
119
|
+
lastItem = item
|
120
|
+
|
121
|
+
if lastItem == None:
|
122
|
+
return GameList()
|
123
|
+
else:
|
124
|
+
return GameList(lastItem[1], lastItem[2], False, time.time() - lastItem[0])
|
125
|
+
|
126
|
+
|
127
|
+
|
63
128
|
def pop(self, name):
|
129
|
+
perf_counter = time.time()
|
64
130
|
pops = [value for value in self.list.values() if value["name"] == name]
|
65
131
|
pops.sort(key=lambda a: a["expires"])
|
66
132
|
if pops:
|
67
133
|
del self.list[self.flippedList[str(pops[0])]]
|
134
|
+
if self.flippedList[str(pops[0])] in self.expirationList: del self.expirationList[self.flippedList[str(pops[0])]]
|
68
135
|
del self.flippedList[str(pops[0])]
|
136
|
+
self.calculateSum()
|
137
|
+
object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, (self.addValue - self.subtractValue) * self.multiplyValue / self.divideValue))
|
69
138
|
|
70
139
|
def popAny(self, name):
|
140
|
+
perf_counter = time.time()
|
71
141
|
pops = [value for value in self.list.values() if value["name"] == name]
|
72
142
|
if pops:
|
73
143
|
del self.list[self.flippedList[str(pops[0])]]
|
144
|
+
if self.flippedList[str(pops[0])] in self.expirationList: del self.expirationList[self.flippedList[str(pops[0])]]
|
74
145
|
del self.flippedList[str(pops[0])]
|
146
|
+
self.calculateSum()
|
147
|
+
object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, (self.addValue - self.subtractValue) * self.multiplyValue / self.divideValue))
|
75
148
|
|
76
149
|
def popAll(self, name):
|
150
|
+
perf_counter = time.time()
|
77
151
|
pops = [value for value in self.list.values() if value["name"] == name]
|
78
152
|
if pops:
|
79
153
|
for x in range(len(pops)):
|
80
154
|
del self.list[self.flippedList[str(pops[x])]]
|
155
|
+
if self.flippedList[str(pops[x])] in self.expirationList: del self.expirationList[self.flippedList[str(pops[x])]]
|
81
156
|
del self.flippedList[str(pops[x])]
|
157
|
+
self.calculateSum()
|
158
|
+
object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, (self.addValue - self.subtractValue) * self.multiplyValue / self.divideValue))
|
82
159
|
|
83
160
|
def remove(self, item):
|
161
|
+
perf_counter = time.time()
|
84
162
|
if self.flippedList.get(str(item), None):
|
85
163
|
del self.list[self.flippedList[str(item)]]
|
164
|
+
if self.flippedList[str(item)] in self.expirationList: del self.expirationList[self.flippedList[str(item)]]
|
86
165
|
del self.flippedList[str(item)]
|
87
166
|
|
88
167
|
if item["type"] == "add":
|
@@ -94,9 +173,13 @@ class GameList():
|
|
94
173
|
else:
|
95
174
|
self.divideValue -= (item["value"] - 1)
|
96
175
|
|
176
|
+
object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, (self.addValue - self.subtractValue) * self.multiplyValue / self.divideValue))
|
177
|
+
|
97
178
|
def unsafeRemove(self, item):
|
179
|
+
perf_counter = time.time()
|
98
180
|
if item in self.list.values():
|
99
181
|
del self.list[dict(self.flippedList[str(item)])]
|
182
|
+
if dict(self.flippedList[str(item)]) in self.expirationList: del self.expirationList[dict(self.flippedList[str(item)])]
|
100
183
|
del self.flippedList[str(item)]
|
101
184
|
|
102
185
|
if item["type"] == "add":
|
@@ -108,18 +191,23 @@ class GameList():
|
|
108
191
|
else:
|
109
192
|
self.divideValue -= (item["value"] - 1)
|
110
193
|
|
194
|
+
object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, (self.addValue - self.subtractValue) * self.multiplyValue / self.divideValue))
|
195
|
+
|
111
196
|
def __getattribute__(self, name):
|
112
197
|
if name == "sum":
|
113
|
-
|
198
|
+
if not object.__getattribute__(self, "freeze"):
|
199
|
+
self.update()
|
114
200
|
return (object.__getattribute__(self, "addValue") -
|
115
201
|
object.__getattribute__(self, "subtractValue")) * \
|
116
202
|
object.__getattribute__(self, "multiplyValue") / \
|
117
203
|
object.__getattribute__(self, "divideValue")
|
118
|
-
|
119
|
-
|
120
|
-
|
204
|
+
elif name == "history":
|
205
|
+
if not object.__getattribute__(self, "freeze"):
|
206
|
+
self.update()
|
121
207
|
|
122
208
|
|
209
|
+
return object.__getattribute__(self, name)
|
210
|
+
|
123
211
|
|
124
212
|
|
125
213
|
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: morelists
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.1
|
4
4
|
Summary: A small and easy list you can add together like a math equation and has a expiration date for items. Mostly useful for games with stats from multiple sources. More lists will come soon.
|
5
5
|
Home-page: https://github.com/EmanuelNorsk/enlist
|
6
6
|
Author: Emanuel Odén Hesselroth
|
@@ -13,3 +13,4 @@ Requires-Python: >=3.6
|
|
13
13
|
License-File: LICENSE
|
14
14
|
Dynamic: author
|
15
15
|
Dynamic: home-page
|
16
|
+
Dynamic: license-file
|
@@ -0,0 +1,6 @@
|
|
1
|
+
morelists/__init__.py,sha256=2ADwt9v-X0M-agPoRLKfELfbIAzxxcjtSvyL_ltJIeo,9344
|
2
|
+
morelists-0.1.1.dist-info/licenses/LICENSE,sha256=-ASFHlrne1rk8zV57Qj01X2JB-D67ZHPMv1PtQhrbN8,32
|
3
|
+
morelists-0.1.1.dist-info/METADATA,sha256=2AmxOSbe5kT0sziBKdoebqVI9DCtjqAx4i6A2gSGt8Q,681
|
4
|
+
morelists-0.1.1.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
|
5
|
+
morelists-0.1.1.dist-info/top_level.txt,sha256=Zd7NosYzor-RcH_aD86FXJa3fQzWunYA4_FQS3Yodqo,10
|
6
|
+
morelists-0.1.1.dist-info/RECORD,,
|
morelists-0.1.0.dist-info/RECORD
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
morelists/__init__.py,sha256=MCofk70SKqV9lkk01iBpyYAIFl29vB09RXX4WnOM0UA,4718
|
2
|
-
morelists-0.1.0.dist-info/LICENSE,sha256=-ASFHlrne1rk8zV57Qj01X2JB-D67ZHPMv1PtQhrbN8,32
|
3
|
-
morelists-0.1.0.dist-info/METADATA,sha256=jq8smAfeCnSeI0uDBOOBJt-44Xa4oI-AY2GWO-H517Q,658
|
4
|
-
morelists-0.1.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
5
|
-
morelists-0.1.0.dist-info/top_level.txt,sha256=Zd7NosYzor-RcH_aD86FXJa3fQzWunYA4_FQS3Yodqo,10
|
6
|
-
morelists-0.1.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|