Implement storing analytics on a LIST response
This commit is contained in:
parent
15b394bd79
commit
06d3dd4d7e
25
core/bot.py
25
core/bot.py
|
@ -11,6 +11,7 @@ from copy import deepcopy
|
|||
from modules import userinfo
|
||||
from modules import counters
|
||||
from modules import monitor
|
||||
from modules import chankeep
|
||||
|
||||
from core.relay import sendRelayNotification
|
||||
from utils.dedup import dedup
|
||||
|
@ -119,6 +120,8 @@ class IRCBot(IRCClient):
|
|||
self._tempList = ([], []) # Temporary storage for gathering LIST info
|
||||
self.listOngoing = False
|
||||
|
||||
self.chanLimit = 0
|
||||
|
||||
def parsen(self, user):
|
||||
step = user.split("!")
|
||||
nick = step[0]
|
||||
|
@ -314,13 +317,15 @@ class IRCBot(IRCClient):
|
|||
d = Deferred()
|
||||
self._tempList = ([], [])
|
||||
self._tempList[0].append(d)
|
||||
self.sendLine("LIST")
|
||||
self.sendLine("LIST >0")
|
||||
return d
|
||||
|
||||
def list(self):
|
||||
if not self.listOngoing:
|
||||
self._list().addCallback(self.got_list)
|
||||
self.listOngoing = True
|
||||
|
||||
def irc_RPL_LISTSTART(self, prefix, params):
|
||||
self.listOngoing = True
|
||||
|
||||
def irc_RPL_LIST(self, prefix, params):
|
||||
channel = params[1]
|
||||
|
@ -337,7 +342,20 @@ class IRCBot(IRCClient):
|
|||
self._tempList[1].clear()
|
||||
|
||||
def got_list(self, listinfo):
|
||||
print("have list", listinfo)
|
||||
chankeep.initialList(self.net, self.num, listinfo, self.chanLimit)
|
||||
|
||||
def isupport(self, options):
|
||||
for i in options:
|
||||
if i.startswith("CHANLIMIT"):
|
||||
if "#" in i:
|
||||
split = i.split("#")
|
||||
if len(split) >= 2:
|
||||
chanLimit = split[-1].replace(":", "")
|
||||
try:
|
||||
self.chanLimit = int(chanLimit)
|
||||
return
|
||||
except TypeError:
|
||||
error("Invalid CHANLIMIT: %s" % i)
|
||||
|
||||
#twisted sucks so i have to do this to actually get the user info
|
||||
def irc_JOIN(self, prefix, params):
|
||||
|
@ -489,6 +507,7 @@ class IRCBotFactory(ReconnectingClientFactory):
|
|||
def __init__(self, net, num=None, relayCommands=None, user=None, stage2=None):
|
||||
if net == None:
|
||||
self.num = num
|
||||
self.net = None
|
||||
self.name = "relay - %i" % num
|
||||
self.relay = True
|
||||
else:
|
||||
|
|
|
@ -1 +1,45 @@
|
|||
import main
|
||||
from utils.logging.log import *
|
||||
|
||||
# make this into a threaded function
|
||||
def initialList(net, num, listinfo, chanLimit):
|
||||
#listinfo = sorted(listinfo, key=lambda x: xdd[0])
|
||||
listLength = len(listinfo)
|
||||
cumul = 0
|
||||
try:
|
||||
cumul += sum(int(i[1]) for i in listinfo)
|
||||
except TypeError:
|
||||
warn("Bad LIST data received from %s - %i" % (net, num))
|
||||
return
|
||||
mean = cumul/listLength
|
||||
sigLength = 0
|
||||
insigLength = 0
|
||||
sigCumul = 0
|
||||
insigCumul = 0
|
||||
for i in listinfo:
|
||||
if int(i[1]) > mean:
|
||||
sigLength += 1
|
||||
sigCumul += int(i[1])
|
||||
elif int(i[1]) < mean:
|
||||
insigLength += 1
|
||||
insigCumul += int(i[1])
|
||||
|
||||
if not net in main.network.keys():
|
||||
warn("Cannot write list info - no network entry for %s" % net)
|
||||
return
|
||||
main.network[net].list["mean"] = mean
|
||||
main.network[net].list["total"] = listLength
|
||||
main.network[net].list["sigtotal"] = sigLength
|
||||
main.network[net].list["insigtotal"] = insigLength
|
||||
main.network[net].list["sigperc"] = sigLength/listLength*100
|
||||
main.network[net].list["insigperc"] = insigLength/listLength*100
|
||||
main.network[net].list["cumul"] = cumul
|
||||
main.network[net].list["sigcumul"] = sigCumul
|
||||
main.network[net].list["insigcumul"] = insigCumul
|
||||
main.network[net].list["relay"] = listLength/chanLimit
|
||||
main.network[net].list["sigrelay"] = sigLength/chanLimit
|
||||
main.network[net].list["insigrelay"] = insigLength/chanLimit
|
||||
|
||||
# Rounding
|
||||
main.network[net].list = {x: round(y, 4) for x, y in main.network[net].list.items()}
|
||||
main.saveConf("network")
|
||||
|
|
|
@ -19,6 +19,7 @@ class Network:
|
|||
self.last = 0
|
||||
self.relays = {}
|
||||
self.aliases = {}
|
||||
self.list = {}
|
||||
|
||||
def add_relay(self, num=None):
|
||||
if not num:
|
||||
|
|
Loading…
Reference in New Issue