wip
This commit is contained in:
37
common.py
37
common.py
@@ -1,8 +1,14 @@
|
||||
import importlib
|
||||
from threading import Thread, Lock
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from loader import dmt
|
||||
|
||||
|
||||
def calc_intervals(posts):
|
||||
firstpost = dmt(posts).reduce(lambda acc, e: acc if acc < e['CreationDate'] else e['CreationDate'], lambda acc, e: acc if acc < e else e, lambda: posts[0]['CreationDate'], "firstpost").getresults()
|
||||
firstpost = dmt(posts).reduce(lambda acc, e: acc if acc < e['CreationDate'] else e['CreationDate'], lambda acc, e: acc if acc < e else e, lambda: posts[0]['CreationDate'],
|
||||
"firstpost").getresults()
|
||||
lastpost = dmt(posts).reduce(lambda acc, e: acc if acc > e['CreationDate'] else e['CreationDate'], lambda acc, e: acc if acc > e else e, lambda: posts[0]['CreationDate'], "lastpost").getresults()
|
||||
|
||||
# calc quarter beginning
|
||||
@@ -25,5 +31,32 @@ def calc_intervals(posts):
|
||||
print("adding interval: " + cdate.strftime("%d-%m-%Y") + " - " + nextquarter.strftime("%d-%m-%Y"))
|
||||
intervals.append((cdate, nextquarter))
|
||||
cdate = nextquarter
|
||||
# sys.exit(0)
|
||||
return intervals
|
||||
|
||||
|
||||
def imprt(file):
|
||||
spec = importlib.util.spec_from_file_location("module.name", file)
|
||||
foo = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(foo)
|
||||
return foo
|
||||
|
||||
|
||||
class FigSaver():
|
||||
def __init__(self):
|
||||
self.__lock = Lock()
|
||||
self.__threads = []
|
||||
|
||||
def save(self, fig, path, **kwargs):
|
||||
thread = Thread(target=self.__dosave, args=(fig, path, kwargs))
|
||||
with self.__lock:
|
||||
self.__threads.append(thread)
|
||||
thread.start()
|
||||
|
||||
def __dosave(self, fig, path, kwargs):
|
||||
fig.savefig(path, **kwargs)
|
||||
plt.close(fig)
|
||||
|
||||
def join(self):
|
||||
with self.__lock:
|
||||
for thread in self.__threads:
|
||||
thread.join()
|
||||
|
||||
Reference in New Issue
Block a user