morelists 0.1.1__tar.gz → 0.1.3__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
1
  Metadata-Version: 2.4
2
2
  Name: morelists
3
- Version: 0.1.1
3
+ Version: 0.1.3
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
@@ -0,0 +1,414 @@
1
+ import time
2
+ import json
3
+
4
+ class GameList():
5
+ def __init__(self, list = None, expirationList = None, flippedList = None, freeze = False, deltaTime = 0):
6
+ """
7
+ Creates a new GameList
8
+
9
+ Useful when you want to add, subtract, multiply, and divide items
10
+ inside a list to calculate strength of effect or other things.
11
+ Comes with a built-in expiration date for easy use.
12
+
13
+ Perfect for game engine with changing stats like adding buffs and debuffs.
14
+
15
+ Should not receive any arguments without experienced knowledge of the library.
16
+
17
+ Keyword arguments:
18
+ list -- the starting list (default None)
19
+ expirationList -- the starting list tracking expiration dates (default None)
20
+ flippedList -- inverted list, used for faster lookup (default None)
21
+ freeze -- preserve the list and stops the built-in expiration date deletor (default False)
22
+ deltaTime -- tells the list how much behind it is in time. Used in updateToPresent() (default 0)
23
+ """
24
+ self.list: dict = list if list != None else {}
25
+ self.expirationList: dict = expirationList if expirationList != None else {}
26
+ self.flippedList: dict = flippedList if flippedList != None else {}
27
+
28
+ self.addValue = 0
29
+ self.subtractValue = 0
30
+ self.multiplyValue = 1
31
+ self.divideValue = 1
32
+ self.sum = 0
33
+
34
+ self.freeze = freeze
35
+
36
+ self.history = [(0, {}, {}, {}, 0.0)]
37
+
38
+ self.deltaTime = deltaTime
39
+
40
+
41
+ def safeSum(self):
42
+ """
43
+ Returns the sum in a safe matter.
44
+
45
+ Dont use this, please access the sum by using .sum
46
+ """
47
+ try:
48
+ return (self.addValue - self.subtractValue) * self.multiplyValue / self.divideValue
49
+ except ZeroDivisionError:
50
+ print("[WARNING]: GameList can't sum the list because of a ZeroDivisionError. Defaulted the sum value to be 0.")
51
+ return 0
52
+
53
+
54
+ def add(self, item, expires = -1):
55
+ """
56
+ Adds a item to the list.
57
+
58
+ Keyword arguments:
59
+ item -- item you wish to add. Format: {"name":"nameHere", "type":"add/subtract/multiply/divide", "value":float}
60
+ expires -- in seconds on how long until it expires and gets deleted. Set it to -1 to allow it to exist forever (default -1)
61
+ """
62
+ immortal = True if expires == -1 else False
63
+ perf_counter = time.time()
64
+ expires += perf_counter
65
+ self.list[expires] = {"name":item.get("name", ""), "type":item.get("type", "add"), "value":item.get("value", 0)}
66
+
67
+
68
+ if self.list[expires]["type"] not in ["add", "subtract", "multiply", "divide"]:
69
+ print(f"[WARNING]: GameList only supports add/subtract/multiply/divide types. Your input type: {self.list[expires]["type"]}. Defaulting to add type.")
70
+ self.list[expires]["type"] = "add"
71
+
72
+ if not "value" in item:
73
+ defaultValue = 0 if self.list[expires]["type"] in ["add", "subtract"] else 1
74
+ self.list[expires]["value"] = defaultValue
75
+ print(f"[WARNING]: GameList uses the key 'value' to store the value of each item. You seem to have not given it a value. Defaulted to {defaultValue}.")
76
+
77
+ if self.list[expires]["name"] == "":
78
+ print(f'[WARNING]: GameList uses the key \'name\' to track items. You seem to have not given it a value. This will make it hard to track and pop at a later time (before its expiration date). Defaulted to "".')
79
+
80
+ if not immortal:
81
+ self.expirationList[expires] = self.list[expires]
82
+ self.flippedList[json.dumps(self.list[expires], sort_keys=True)] = expires
83
+
84
+ if item["type"] == "add":
85
+ self.addValue += item["value"]
86
+ elif item["type"] == "subtract":
87
+ self.subtractValue += item["value"]
88
+ elif item["type"] == "multiply":
89
+ self.multiplyValue += (item["value"] - 1)
90
+ elif item["type"] == "divide":
91
+ self.divideValue += (item["value"] - 1)
92
+
93
+ object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, self.safeSum()))
94
+
95
+ def unsafeAdd(self, item, expires = -1):
96
+ """
97
+ Adds a item to the list using a more unsafe method.
98
+
99
+ Only use this if you know what you are doing!
100
+
101
+ Keyword arguments:
102
+ item -- item you wish to add. Format: {"name":"nameHere", "type":"add/subtract/multiply/divide", "value":float}
103
+ expires -- in seconds on how long until it expires and gets deleted. Set it to -1 to allow it to exist forever (default -1)
104
+ """
105
+ immortal = True if expires == -1 else False
106
+ perf_counter = time.time()
107
+ expires += perf_counter
108
+ self.list[expires] = item
109
+ if not immortal:
110
+ self.expirationList[expires] = self.list[expires]
111
+ self.flippedList[json.dumps(item, sort_keys=True)] = expires
112
+
113
+ if item["type"] == "add":
114
+ self.addValue += item["value"]
115
+ elif item["type"] == "subtract":
116
+ self.subtractValue += item["value"]
117
+ elif item["type"] == "multiply":
118
+ self.multiplyValue += (item["value"] - 1)
119
+ elif item["type"] == "divide":
120
+ self.divideValue += (item["value"] - 1)
121
+
122
+ object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, self.safeSum()))
123
+
124
+
125
+ def calculateSumWithoutUpdate(self):
126
+ """
127
+ Calculates the sum of the list without checking for expired items
128
+
129
+ Use only if you want to access the sum without updating
130
+ """
131
+ self.addValue = 0
132
+ self.subtractValue = 0
133
+ self.multiplyValue = 1
134
+ self.divideValue = 1
135
+ for item in self.list.values():
136
+ if item["type"] == "add":
137
+ self.addValue += item["value"]
138
+ elif item["type"] == "subtract":
139
+ self.subtractValue += item["value"]
140
+ elif item["type"] == "multiply":
141
+ self.multiplyValue += (item["value"] - 1)
142
+ elif item["type"] == "divide":
143
+ self.divideValue += (item["value"] - 1)
144
+
145
+ return self.safeSum()
146
+
147
+
148
+
149
+ def update(self):
150
+ """
151
+ Updates the list and removes any expires items.
152
+
153
+ This is already called upon when accessing the sum or history.
154
+ This function doesn't need to be by the user.
155
+ """
156
+
157
+ # update() ignore the reeze flag because it's assumed the user is calling it with the purpose of updating it manually
158
+ try:
159
+ expiration = min(self.expirationList.keys())
160
+ while expiration < time.time():
161
+ if self.list[expiration]["type"] == "add":
162
+ self.addValue -= self.list[expiration]["value"]
163
+ elif self.list[expiration]["type"] == "subtract":
164
+ self.subtractValue -= self.list[expiration]["value"]
165
+ elif self.list[expiration]["type"] == "multiply":
166
+ self.multiplyValue -= (self.list[expiration]["value"] - 1)
167
+ else:
168
+ self.divideValue -= (self.list[expiration]["value"] - 1)
169
+
170
+ del self.flippedList[json.dumps(self.list[expiration], sort_keys=True)]
171
+ del self.list[expiration]
172
+
173
+ object.__getattribute__(self, "history").append((expiration, self.list, self.expirationList, self.flippedList, self.safeSum()))
174
+ expiration = min(self.expirationList.keys())
175
+ except ValueError as e:
176
+ print(f"[WARNING]: While updating the list, a new error appeared: {e}")
177
+
178
+ def pause(self):
179
+ """
180
+ Prevents the list from auto-updating and prevents deletions of expired items without user input.
181
+ """
182
+ self.freeze = True
183
+
184
+ def resume(self):
185
+ """
186
+ Resumes the list to auto-update and delete expired items automatically.
187
+ """
188
+ self.freeze = False
189
+
190
+ def updateToPresent(self):
191
+ """
192
+ Updates each item in the list to match if the list was in the present. Setting deltaTime changes how much this affects the list.
193
+
194
+ Only use this if you are experienced and know what you are doing.
195
+ """
196
+ newList = {}
197
+ for key, value in self.list.items():
198
+ newList[key + self.deltaTime] = value
199
+ self.deltaTime = 0
200
+
201
+ def restoreState(self, t) -> "GameList":
202
+ """
203
+ Creates a new GameList from the history of the list. Useful if you want to track previous sum values and such.
204
+
205
+ Keyword arguments:
206
+ t -- the time you want the new list to be based on
207
+ """
208
+ self.update()
209
+ lastItem = None
210
+ for item in self.history:
211
+ if item[0] < t:
212
+ lastItem = item
213
+ else:
214
+ break
215
+
216
+ if lastItem == None:
217
+ return GameList()
218
+ else:
219
+ return GameList(lastItem[1], lastItem[2], False, time.time() - lastItem[0])
220
+
221
+ def getOldSums(self, t0, t1) -> list[tuple]:
222
+ """
223
+ Creates a list of tuples with the sum value from t0 -> t1.
224
+
225
+ Format: [(time, sum_value), ...]
226
+
227
+ Keyword arguments:
228
+ t0 -- the time you want the list to start
229
+ t1 -- the time you want the list to end
230
+ """
231
+ self.update()
232
+ items = []
233
+ for item in self.history:
234
+ if item[0] < t0:
235
+ items = [(item[0], item[4])]
236
+ elif item[0] < t1:
237
+ items.append((item[0], item[4]))
238
+ else:
239
+ break
240
+
241
+ return items
242
+
243
+
244
+ def pop(self, name):
245
+ """
246
+ Pops a item from the list with the closest expiration date to the current time
247
+
248
+ Keyword arguments:
249
+ name -- the name you gave the item in the list
250
+ """
251
+ perf_counter = time.time()
252
+ pops = [(key, value) for key, value in self.list.items() if value["name"] == name]
253
+ pops.sort(key=lambda a: a[0])
254
+ if pops:
255
+ stringedList = json.dumps(pops[0][1], sort_keys=True)
256
+
257
+ item = self.list[self.flippedList[stringedList]]
258
+ del self.list[self.flippedList[stringedList]]
259
+ if self.flippedList[stringedList] in self.expirationList: del self.expirationList[self.flippedList[stringedList]]
260
+ del self.flippedList[stringedList]
261
+
262
+ if item["type"] == "add":
263
+ self.addValue -= item["value"]
264
+ elif item["type"] == "subtract":
265
+ self.subtractValue -= item["value"]
266
+ elif item["type"] == "multiply":
267
+ self.multiplyValue -= (item["value"] - 1)
268
+ else:
269
+ self.divideValue -= (item["value"] - 1)
270
+
271
+ object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, self.safeSum()))
272
+
273
+ def popAny(self, name):
274
+ """
275
+ Pops a item from the list with no regards for expiration date
276
+
277
+ Keyword arguments:
278
+ name -- the name you gave the item in the list
279
+ """
280
+ perf_counter = time.time()
281
+ pops = [value for value in self.list.values() if value["name"] == name]
282
+ if pops:
283
+ stringedList = json.dumps(pops[0], sort_keys=True)
284
+
285
+ item = self.list[self.flippedList[stringedList]]
286
+ del self.list[self.flippedList[stringedList]]
287
+ if self.flippedList[stringedList] in self.expirationList: del self.expirationList[self.flippedList[stringedList]]
288
+ del self.flippedList[stringedList]
289
+
290
+ if item["type"] == "add":
291
+ self.addValue -= item["value"]
292
+ elif item["type"] == "subtract":
293
+ self.subtractValue -= item["value"]
294
+ elif item["type"] == "multiply":
295
+ self.multiplyValue -= (item["value"] - 1)
296
+ else:
297
+ self.divideValue -= (item["value"] - 1)
298
+
299
+ object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, self.safeSum()))
300
+
301
+ def popAll(self, name):
302
+ """
303
+ Pops every item from the list with the given name
304
+
305
+ Keyword arguments:
306
+ name -- the name you gave the item(s) in the list
307
+ """
308
+ perf_counter = time.time()
309
+ pops = [value for value in self.list.values() if value["name"] == name]
310
+ if pops:
311
+ for x in range(len(pops)):
312
+ stringedList = json.dumps(pops[x], sort_keys=True)
313
+
314
+
315
+ item = self.list[self.flippedList[stringedList]]
316
+ del self.list[self.flippedList[stringedList]]
317
+ if self.flippedList[stringedList] in self.expirationList: del self.expirationList[self.flippedList[stringedList]]
318
+ del self.flippedList[stringedList]
319
+
320
+ if item["type"] == "add":
321
+ self.addValue -= item["value"]
322
+ elif item["type"] == "subtract":
323
+ self.subtractValue -= item["value"]
324
+ elif item["type"] == "multiply":
325
+ self.multiplyValue -= (item["value"] - 1)
326
+ else:
327
+ self.divideValue -= (item["value"] - 1)
328
+
329
+ object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, self.safeSum()))
330
+
331
+ def remove(self, item):
332
+ """
333
+ Removes a specific item from the list (if it exists)
334
+
335
+ Keyword arguments:
336
+ name -- the name you gave the item(s) in the list
337
+ """
338
+ perf_counter = time.time()
339
+ stringedList = json.dumps(item, sort_keys=True)
340
+ if self.flippedList.get(stringedList, None):
341
+ del self.list[self.flippedList[stringedList]]
342
+ if self.flippedList[stringedList] in self.expirationList: del self.expirationList[self.flippedList[stringedList]]
343
+ del self.flippedList[stringedList]
344
+
345
+ if item["type"] == "add":
346
+ self.addValue -= item["value"]
347
+ elif item["type"] == "subtract":
348
+ self.subtractValue -= item["value"]
349
+ elif item["type"] == "multiply":
350
+ self.multiplyValue -= (item["value"] - 1)
351
+ else:
352
+ self.divideValue -= (item["value"] - 1)
353
+
354
+ object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, self.safeSum()))
355
+
356
+ def unsafeRemove(self, item):
357
+ """
358
+ Removes a specific item from the list (if it exists)
359
+
360
+ More unsafe compared to remove(item), so use only if you know what you are doing!
361
+
362
+ Keyword arguments:
363
+ name -- the name you gave the item(s) in the list
364
+ """
365
+ perf_counter = time.time()
366
+ if item in self.list.values():
367
+ stringedList = json.dumps(item, sort_keys=True)
368
+ del self.list[dict(self.flippedList[stringedList])]
369
+ if dict(self.flippedList[stringedList]) in self.expirationList: del self.expirationList[dict(self.flippedList[stringedList])]
370
+ del self.flippedList[stringedList]
371
+
372
+ if item["type"] == "add":
373
+ self.addValue -= item["value"]
374
+ elif item["type"] == "subtract":
375
+ self.subtractValue -= item["value"]
376
+ elif item["type"] == "multiply":
377
+ self.multiplyValue -= (item["value"] - 1)
378
+ else:
379
+ self.divideValue -= (item["value"] - 1)
380
+
381
+ object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, self.safeSum()))
382
+
383
+ def __getattribute__(self, name):
384
+ """
385
+ Retrieves attributes from the class
386
+
387
+ Updates the list if you grab the sum value or the history data
388
+
389
+ Keyword arguments:
390
+ name -- the name of the attribute you want to grab
391
+ """
392
+ if name == "sum":
393
+ if not object.__getattribute__(self, "freeze"):
394
+ self.update()
395
+ try:
396
+ return (object.__getattribute__(self, "addValue") -
397
+ object.__getattribute__(self, "subtractValue")) * \
398
+ object.__getattribute__(self, "multiplyValue") / \
399
+ object.__getattribute__(self, "divideValue")
400
+ except ZeroDivisionError:
401
+ print("[WARNING]: While retrieving the sum, a ZeroDivisionError showed up. Defaulting to 0")
402
+ return 0
403
+ elif name == "history":
404
+ if not object.__getattribute__(self, "freeze"):
405
+ self.update()
406
+
407
+
408
+ return object.__getattribute__(self, name)
409
+
410
+
411
+
412
+
413
+
414
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: morelists
3
- Version: 0.1.1
3
+ Version: 0.1.3
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "morelists"
7
- version = "0.1.1"
7
+ version = "0.1.3"
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.1",
5
+ version="0.1.3",
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,215 +0,0 @@
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
-
File without changes
File without changes
File without changes