Skip to content

Commit be1960c

Browse files
committed
feat: added data sampling
1 parent 6886c2f commit be1960c

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

bot.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,32 +1631,36 @@ async def settings(ctx, module: str = None, value: str = None):
16311631

16321632

16331633
@bot.slash_command(guild_only=True, guild_ids=[int(SECURITY_GUILD)])
1634-
async def metrics(ctx):
1634+
async def metrics(ctx, sample: int = 5):
16351635
if str(ctx.author.id) == str(OWNER):
16361636
metricList = await GetMetrics()
16371637
commandDict = {}
16381638
finalList = {}
16391639
# prepare data
1640+
iterations = 0
16401641
for metric in metricList:
16411642
_, commandType, timestamp = metric
1643+
iterations += 1
16421644
commandDict[commandType] = commandDict.get(commandType, 0) + 1
1643-
provList = finalList.get(commandType, [])
1644-
provList.append({
1645-
"t":
1646-
str(datetime.datetime.fromtimestamp(int(timestamp))),
1647-
"y":
1648-
commandDict[commandType],
1649-
})
1650-
finalList[commandType] = provList
1645+
if (iterations > sample): # sample every 10 data points without losing accuracy
1646+
provList = finalList.get(commandType, [])
1647+
provList.append({
1648+
"t":
1649+
str(datetime.datetime.fromtimestamp(int(timestamp))),
1650+
"y":
1651+
commandDict[commandType],
1652+
})
1653+
finalList[commandType] = provList
1654+
iterations = 0
16511655
# prepare datasets
16521656
final = []
16531657
for (
1654-
command,
1658+
botcommand,
16551659
data,
16561660
) in finalList.items():
16571661
final.append({
16581662
"fill": False,
1659-
"label": [command],
1663+
"label": [botcommand],
16601664
"lineTension": 0,
16611665
"data": data,
16621666
})

0 commit comments

Comments
 (0)