average-stab
This commit is contained in:
@@ -24,11 +24,16 @@ async def get_all_pattern(uid):
|
||||
|
||||
async def get_average_pattern(pattern):
|
||||
scores = []
|
||||
async for key in redis.scan_iter(pattern):
|
||||
scr = await redis.get(str(key))
|
||||
scr = int(scr)
|
||||
if isinstance(scr, int):
|
||||
scores.append(scr)
|
||||
logger.debug(f"found {len(scores)} messages")
|
||||
toxic_score = math.floor(sum(scores) / len(scores)) if scores else 0
|
||||
return toxic_score
|
||||
toxic_score = 0
|
||||
try:
|
||||
async for key in redis.scan_iter(pattern):
|
||||
scr = await redis.get(str(key))
|
||||
scr = int(scr)
|
||||
if isinstance(scr, int):
|
||||
scores.append(scr)
|
||||
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
|
||||
|
Reference in New Issue
Block a user