average-stab
This commit is contained in:
parent
21591df427
commit
773a01cdb1
|
@ -48,12 +48,10 @@ async def messages_routing(msg, state):
|
||||||
reply_to_msg_id = reply_msg.get("message_id")
|
reply_to_msg_id = reply_msg.get("message_id")
|
||||||
if not reply_to_msg_id and latest_toxic_message_id:
|
if not reply_to_msg_id and latest_toxic_message_id:
|
||||||
reply_to_msg_id = int(latest_toxic_message_id)
|
reply_to_msg_id = int(latest_toxic_message_id)
|
||||||
try:
|
|
||||||
# count average between all of messages
|
# count average between all of messages
|
||||||
toxic_pattern = f"toxic:{cid}:{uid}:*"
|
toxic_pattern = f"toxic:{cid}:{uid}:*"
|
||||||
toxic_score = await get_average_pattern(toxic_pattern)
|
toxic_score = await get_average_pattern(toxic_pattern)
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# current mesasage toxicity
|
# current mesasage toxicity
|
||||||
if reply_to_msg_id:
|
if reply_to_msg_id:
|
||||||
|
|
|
@ -24,11 +24,16 @@ async def get_all_pattern(uid):
|
||||||
|
|
||||||
async def get_average_pattern(pattern):
|
async def get_average_pattern(pattern):
|
||||||
scores = []
|
scores = []
|
||||||
async for key in redis.scan_iter(pattern):
|
toxic_score = 0
|
||||||
scr = await redis.get(str(key))
|
try:
|
||||||
scr = int(scr)
|
async for key in redis.scan_iter(pattern):
|
||||||
if isinstance(scr, int):
|
scr = await redis.get(str(key))
|
||||||
scores.append(scr)
|
scr = int(scr)
|
||||||
logger.debug(f"found {len(scores)} messages")
|
if isinstance(scr, int):
|
||||||
toxic_score = math.floor(sum(scores) / len(scores)) if scores else 0
|
scores.append(scr)
|
||||||
return toxic_score
|
logger.debug(f"found {len(scores)} messages")
|
||||||
|
toxic_score = math.floor(sum(scores) / len(scores)) if scores else 0
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
return toxic_score
|
||||||
|
|
Loading…
Reference in New Issue
Block a user