2018-03-14 20:13:40 +00:00
|
|
|
import main
|
2019-07-28 14:07:46 +00:00
|
|
|
from twisted.internet.task import LoopingCall
|
2018-02-24 12:42:27 +00:00
|
|
|
|
|
|
|
def event(name, eventType):
|
2018-03-14 20:13:40 +00:00
|
|
|
if not "local" in main.counters.keys():
|
|
|
|
main.counters["local"] = {}
|
|
|
|
if not "global" in main.counters.keys():
|
|
|
|
main.counters["global"] = {}
|
|
|
|
if not name in main.counters["local"].keys():
|
|
|
|
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
|
|
|
|
|
|
|
def getEvents(name=None):
|
|
|
|
if name == 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
|
|
|
|
|
|
|
def takeSample():
|
|
|
|
main.lastMinuteSample = main.runningSample
|
|
|
|
main.runningSample = 0
|
|
|
|
|
|
|
|
def setupCounterLoop():
|
|
|
|
lc = LoopingCall(takeSample)
|
|
|
|
lc.start(60)
|