2022-07-21 12:39:59 +00:00
|
|
|
import main
|
2022-07-21 12:40:01 +00:00
|
|
|
from twisted.internet.task import LoopingCall
|
2022-07-21 12:39:59 +00:00
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2018-02-24 12:42:27 +00:00
|
|
|
def event(name, eventType):
|
2022-07-21 12:40:05 +00:00
|
|
|
if "local" not in main.counters.keys():
|
2018-03-14 20:13:40 +00:00
|
|
|
main.counters["local"] = {}
|
2022-07-21 12:40:05 +00:00
|
|
|
if "global" not in main.counters.keys():
|
2018-03-14 20:13:40 +00:00
|
|
|
main.counters["global"] = {}
|
2022-07-21 12:40:05 +00:00
|
|
|
if name not in main.counters["local"].keys():
|
2018-03-14 20:13:40 +00:00
|
|
|
main.counters["local"][name] = {}
|
|
|
|
if eventType not in main.counters["local"][name].keys():
|
|
|
|
main.counters["local"][name][eventType] = 0
|
2018-02-24 12:42:27 +00:00
|
|
|
|
2018-03-14 20:13:40 +00:00
|
|
|
if eventType not in main.counters["global"]:
|
|
|
|
main.counters["global"][eventType] = 0
|
2018-02-24 12:42:27 +00:00
|
|
|
|
2018-03-14 20:13:40 +00:00
|
|
|
main.counters["local"][name][eventType] += 1
|
|
|
|
main.counters["global"][eventType] += 1
|
2019-07-28 14:07:46 +00:00
|
|
|
main.runningSample += 1
|
2018-02-24 12:42:27 +00:00
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2018-02-24 12:42:27 +00:00
|
|
|
def getEvents(name=None):
|
2022-07-21 12:40:05 +00:00
|
|
|
if name is None:
|
2018-03-14 20:13:40 +00:00
|
|
|
if "global" in main.counters.keys():
|
|
|
|
return main.counters["global"]
|
2018-02-24 12:42:27 +00:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
else:
|
2018-03-14 20:13:40 +00:00
|
|
|
if name in main.counters["local"].keys():
|
|
|
|
return main.counters["local"][name]
|
2018-02-24 12:42:27 +00:00
|
|
|
else:
|
|
|
|
return None
|
2019-07-28 14:07:46 +00:00
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2019-07-28 14:07:46 +00:00
|
|
|
def takeSample():
|
|
|
|
main.lastMinuteSample = main.runningSample
|
|
|
|
main.runningSample = 0
|
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2019-07-28 14:07:46 +00:00
|
|
|
def setupCounterLoop():
|
|
|
|
lc = LoopingCall(takeSample)
|
|
|
|
lc.start(60)
|