morelists 0.1.0__tar.gz → 0.1.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: morelists
3
- Version: 0.1.0
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,215 @@
1
+ import time
2
+
3
+ class GameList():
4
+ def __init__(self, list = {}, expirationList = {}, flippedList = {}, freeze = False, deltaTime = 0):
5
+ self.list = list
6
+ self.expirationList = expirationList
7
+ self.flippedList = flippedList
8
+
9
+ self.addValue = 0
10
+ self.subtractValue = 0
11
+ self.multiplyValue = 1
12
+ self.divideValue = 1
13
+ self.sum = 0
14
+
15
+ self.freeze = freeze
16
+
17
+ self.history = [(0, {}, {}, {}, 0.0)]
18
+
19
+ self.deltaTime = deltaTime
20
+
21
+
22
+ def add(self, item, expires = -1):
23
+ perf_counter = time.time()
24
+ if expires != -1:
25
+ expires += perf_counter
26
+ self.list[expires] = {"name":item.get("name", ""), "type":item.get("type", "add"), "value":item.get("value", 0)}
27
+ if self.list[expires]["type"] not in ["add", "subtract", "multiply", "divide"]:
28
+ self.list[expires]["type"] = "add"
29
+
30
+ if expires != -1:
31
+ self.expirationList[expires] = self.list[expires]
32
+ self.flippedList[str(self.list[expires])] = expires
33
+
34
+ if item["type"] == "add":
35
+ self.addValue += item["value"]
36
+ elif item["type"] == "subtract":
37
+ self.subtractValue += item["value"]
38
+ elif item["type"] == "multiply":
39
+ self.multiplyValue += (item["value"] - 1)
40
+ elif item["type"] == "divide":
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))
44
+
45
+ def unsafeAdd(self, item, expires = -1):
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
53
+
54
+ if item["type"] == "add":
55
+ self.addValue += item["value"]
56
+ elif item["type"] == "subtract":
57
+ self.subtractValue += item["value"]
58
+ elif item["type"] == "multiply":
59
+ self.multiplyValue += (item["value"] - 1)
60
+ elif item["type"] == "divide":
61
+ self.divideValue += (item["value"] - 1)
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
+
83
+
84
+ def update(self):
85
+ try:
86
+ expiration = min(self.expirationList.keys())
87
+ while expiration < time.time():
88
+ if self.list[expiration]["type"] == "add":
89
+ self.addValue -= self.list[expiration]["value"]
90
+ elif self.list[expiration]["type"] == "subtract":
91
+ self.subtractValue -= self.list[expiration]["value"]
92
+ elif self.list[expiration]["type"] == "multiply":
93
+ self.multiplyValue -= (self.list[expiration]["value"] - 1)
94
+ else:
95
+ self.divideValue -= (self.list[expiration]["value"] - 1)
96
+
97
+ del self.flippedList[str(self.list[expiration])]
98
+ del self.list[expiration]
99
+
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())
102
+ except ValueError:
103
+ pass
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
+
128
+ def pop(self, name):
129
+ perf_counter = time.time()
130
+ pops = [value for value in self.list.values() if value["name"] == name]
131
+ pops.sort(key=lambda a: a["expires"])
132
+ if pops:
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])]]
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))
138
+
139
+ def popAny(self, name):
140
+ perf_counter = time.time()
141
+ pops = [value for value in self.list.values() if value["name"] == name]
142
+ if pops:
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])]]
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))
148
+
149
+ def popAll(self, name):
150
+ perf_counter = time.time()
151
+ pops = [value for value in self.list.values() if value["name"] == name]
152
+ if pops:
153
+ for x in range(len(pops)):
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])]]
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))
159
+
160
+ def remove(self, item):
161
+ perf_counter = time.time()
162
+ if self.flippedList.get(str(item), None):
163
+ del self.list[self.flippedList[str(item)]]
164
+ if self.flippedList[str(item)] in self.expirationList: del self.expirationList[self.flippedList[str(item)]]
165
+ del self.flippedList[str(item)]
166
+
167
+ if item["type"] == "add":
168
+ self.addValue -= item["value"]
169
+ elif item["type"] == "subtract":
170
+ self.subtractValue -= item["value"]
171
+ elif item["type"] == "multiply":
172
+ self.multiplyValue -= (item["value"] - 1)
173
+ else:
174
+ self.divideValue -= (item["value"] - 1)
175
+
176
+ object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, (self.addValue - self.subtractValue) * self.multiplyValue / self.divideValue))
177
+
178
+ def unsafeRemove(self, item):
179
+ perf_counter = time.time()
180
+ if item in self.list.values():
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)])]
183
+ del self.flippedList[str(item)]
184
+
185
+ if item["type"] == "add":
186
+ self.addValue -= item["value"]
187
+ elif item["type"] == "subtract":
188
+ self.subtractValue -= item["value"]
189
+ elif item["type"] == "multiply":
190
+ self.multiplyValue -= (item["value"] - 1)
191
+ else:
192
+ self.divideValue -= (item["value"] - 1)
193
+
194
+ object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, (self.addValue - self.subtractValue) * self.multiplyValue / self.divideValue))
195
+
196
+ def __getattribute__(self, name):
197
+ if name == "sum":
198
+ if not object.__getattribute__(self, "freeze"):
199
+ self.update()
200
+ return (object.__getattribute__(self, "addValue") -
201
+ object.__getattribute__(self, "subtractValue")) * \
202
+ object.__getattribute__(self, "multiplyValue") / \
203
+ object.__getattribute__(self, "divideValue")
204
+ elif name == "history":
205
+ if not object.__getattribute__(self, "freeze"):
206
+ self.update()
207
+
208
+
209
+ return object.__getattribute__(self, name)
210
+
211
+
212
+
213
+
214
+
215
+
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: morelists
3
- Version: 0.1.0
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "morelists"
7
- version = "0.1.0"
7
+ version = "0.1.1"
8
8
  description = "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."
9
9
  authors = [{name = "Emanuel Odén Hesselroth", email = "emanuelodenhesselroth@gmail.com"}]
10
10
  license = {text = "MIT"}
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="morelists",
5
- version="0.1.0",
5
+ version="0.1.1",
6
6
  packages=find_packages(),
7
7
  install_requires=[],
8
8
  description="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.",
@@ -1,127 +0,0 @@
1
- import time
2
-
3
- class GameList():
4
- def __init__(self):
5
- self.list = {}
6
- self.flippedList = {}
7
-
8
- self.addValue = 0
9
- self.subtractValue = 0
10
- self.multiplyValue = 1
11
- self.divideValue = 1
12
- self.sum = 0
13
-
14
- def add(self, item, expires = -1):
15
- expires += time.time()
16
- self.list[expires] = {"name":item.get("name", ""), "type":item.get("type", "add"), "value":item.get("value", 0)}
17
- if self.list[expires]["type"] not in ["add", "subtract", "multiply", "divide"]:
18
- self.list[expires]["type"] = "add"
19
- self.flippedList[str(self.list[expires])] = expires
20
-
21
- if item["type"] == "add":
22
- self.addValue += item["value"]
23
- elif item["type"] == "subtract":
24
- self.subtractValue += item["value"]
25
- elif item["type"] == "multiply":
26
- self.multiplyValue += (item["value"] - 1)
27
- elif item["type"] == "divide":
28
- self.divideValue += (item["value"] - 1)
29
-
30
- def unsafeAdd(self, item, expires = -1):
31
- expiration = expires + time.time()
32
- self.list[expiration] = item
33
- self.flippedList[str(item)] = expiration
34
-
35
- if item["type"] == "add":
36
- self.addValue += item["value"]
37
- elif item["type"] == "subtract":
38
- self.subtractValue += item["value"]
39
- elif item["type"] == "multiply":
40
- self.multiplyValue += (item["value"] - 1)
41
- elif item["type"] == "divide":
42
- self.divideValue += (item["value"] - 1)
43
-
44
-
45
- def update(self):
46
- try:
47
- expiration = min(self.list.keys())
48
- while expiration < time.time():
49
- if self.list[expiration]["type"] == "add":
50
- self.addValue -= self.list[expiration]["value"]
51
- elif self.list[expiration]["type"] == "subtract":
52
- self.subtractValue -= self.list[expiration]["value"]
53
- elif self.list[expiration]["type"] == "multiply":
54
- self.multiplyValue -= (self.list[expiration]["value"] - 1)
55
- else:
56
- self.divideValue -= (self.list[expiration]["value"] - 1)
57
- del self.list[expiration]
58
-
59
- expiration = min(self.list.keys())
60
- except ValueError:
61
- pass
62
-
63
- def pop(self, name):
64
- pops = [value for value in self.list.values() if value["name"] == name]
65
- pops.sort(key=lambda a: a["expires"])
66
- if pops:
67
- del self.list[self.flippedList[str(pops[0])]]
68
- del self.flippedList[str(pops[0])]
69
-
70
- def popAny(self, name):
71
- pops = [value for value in self.list.values() if value["name"] == name]
72
- if pops:
73
- del self.list[self.flippedList[str(pops[0])]]
74
- del self.flippedList[str(pops[0])]
75
-
76
- def popAll(self, name):
77
- pops = [value for value in self.list.values() if value["name"] == name]
78
- if pops:
79
- for x in range(len(pops)):
80
- del self.list[self.flippedList[str(pops[x])]]
81
- del self.flippedList[str(pops[x])]
82
-
83
- def remove(self, item):
84
- if self.flippedList.get(str(item), None):
85
- del self.list[self.flippedList[str(item)]]
86
- del self.flippedList[str(item)]
87
-
88
- if item["type"] == "add":
89
- self.addValue -= item["value"]
90
- elif item["type"] == "subtract":
91
- self.subtractValue -= item["value"]
92
- elif item["type"] == "multiply":
93
- self.multiplyValue -= (item["value"] - 1)
94
- else:
95
- self.divideValue -= (item["value"] - 1)
96
-
97
- def unsafeRemove(self, item):
98
- if item in self.list.values():
99
- del self.list[dict(self.flippedList[str(item)])]
100
- del self.flippedList[str(item)]
101
-
102
- if item["type"] == "add":
103
- self.addValue -= item["value"]
104
- elif item["type"] == "subtract":
105
- self.subtractValue -= item["value"]
106
- elif item["type"] == "multiply":
107
- self.multiplyValue -= (item["value"] - 1)
108
- else:
109
- self.divideValue -= (item["value"] - 1)
110
-
111
- def __getattribute__(self, name):
112
- if name == "sum":
113
- self.update()
114
- return (object.__getattribute__(self, "addValue") -
115
- object.__getattribute__(self, "subtractValue")) * \
116
- object.__getattribute__(self, "multiplyValue") / \
117
- object.__getattribute__(self, "divideValue")
118
- return object.__getattribute__(self, name)
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
File without changes
File without changes
File without changes