Added get_ontime_overlaps script
This commit is contained in:
parent
b11ce18ac9
commit
53cdaf3fa0
@ -16,29 +16,23 @@
|
||||
"technician": "src/modules/technician/technician.json",
|
||||
"get-version": "tools/get_version/get-version.json",
|
||||
"post-build": "tools/post_build/post-build.json",
|
||||
"set-version": "tools/set_version/set-version.json"
|
||||
"set-version": "tools/set_version/set-version.json",
|
||||
"tools/checks": "tools/tools/checks/tools/checks.json"
|
||||
},
|
||||
"Scripts": {
|
||||
"format": "black ./",
|
||||
|
||||
"sv": "cpl set-version $ARGS",
|
||||
"set-version": "cpl run set-version $ARGS --dev; echo '';",
|
||||
|
||||
"gv": "cpl get-version",
|
||||
"get-version": "export VERSION=$(cpl run get-version --dev); echo $VERSION;",
|
||||
|
||||
"pre-build": "cpl set-version $ARGS; black ./;",
|
||||
"post-build": "cpl run post-build --dev; black ./;",
|
||||
|
||||
"pre-prod": "cpl build",
|
||||
"prod": "export KDB_ENVIRONMENT=production; export KDB_NAME=KDB-Prod; cpl start;",
|
||||
|
||||
"pre-stage": "cpl build",
|
||||
"stage": "export KDB_ENVIRONMENT=staging; export KDB_NAME=KDB-Stage; cpl start;",
|
||||
|
||||
"pre-dev": "cpl build",
|
||||
"dev": "export KDB_ENVIRONMENT=development; export KDB_NAME=KDB-Dev; cpl start;",
|
||||
|
||||
"docker-build": "cpl build $ARGS; docker build -t kdb-bot/kdb-bot:$(cpl gv) .;",
|
||||
"dc-up": "docker-compose up -d",
|
||||
"dc-down": "docker-compose down",
|
||||
|
4088
kdb-bot/tools/checks/UserJoinedVoiceChannel.json
Normal file
4088
kdb-bot/tools/checks/UserJoinedVoiceChannel.json
Normal file
File diff suppressed because it is too large
Load Diff
1
kdb-bot/tools/checks/__init__.py
Normal file
1
kdb-bot/tools/checks/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# imports
|
46
kdb-bot/tools/checks/checks.json
Normal file
46
kdb-bot/tools/checks/checks.json
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"ProjectSettings": {
|
||||
"Name": "checks",
|
||||
"Version": {
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
"Description": "",
|
||||
"LongDescription": "",
|
||||
"URL": "",
|
||||
"CopyrightDate": "",
|
||||
"CopyrightName": "",
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.12.1.post3"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli>=2022.12.1.post3"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {
|
||||
"linux": ""
|
||||
},
|
||||
"Classifiers": []
|
||||
},
|
||||
"BuildSettings": {
|
||||
"ProjectType": "library",
|
||||
"SourcePath": "",
|
||||
"OutputPath": "../../dist",
|
||||
"Main": "checks.main",
|
||||
"EntryPoint": "checks",
|
||||
"IncludePackageData": false,
|
||||
"Included": [],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {},
|
||||
"ProjectReferences": []
|
||||
}
|
||||
}
|
81
kdb-bot/tools/checks/get_ontime_overlaps.py
Normal file
81
kdb-bot/tools/checks/get_ontime_overlaps.py
Normal file
@ -0,0 +1,81 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
|
||||
class UserJoinedVoiceChannel:
|
||||
def __init__(self):
|
||||
self.JoinId = None
|
||||
self.UserId = None
|
||||
self.DiscordChannelId = None
|
||||
self.JoinedOn = None
|
||||
self.LeavedOn = None
|
||||
self.CreatedAt = None
|
||||
self.LastModifiedAt = None
|
||||
|
||||
@property
|
||||
def ontime(self) -> int:
|
||||
return round((self.LeavedOn - self.JoinedOn).total_seconds() / 3600, 2)
|
||||
|
||||
def from_dict(self, data: dict):
|
||||
self.JoinId = data["JoinId"]
|
||||
self.UserId = data["UserId"]
|
||||
self.DiscordChannelId = data["DiscordChannelId"]
|
||||
self.JoinedOn = datetime.strptime(data["JoinedOn"], "%Y-%m-%d %H:%M:%S.%f")
|
||||
self.LeavedOn = datetime.strptime(data["LeavedOn"], "%Y-%m-%d %H:%M:%S.%f")
|
||||
self.CreatedAt = data["CreatedAt"]
|
||||
self.LastModifiedAt = data["LastModifiedAt"]
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.JoinId}: {self.UserId} {self.JoinedOn} {self.LeavedOn}"
|
||||
|
||||
|
||||
def main():
|
||||
data = json.loads(open("UserJoinedVoiceChannel.json", "r").read())
|
||||
ujvcs = List(UserJoinedVoiceChannel)
|
||||
for x in data:
|
||||
ujvc = UserJoinedVoiceChannel()
|
||||
ujvc.from_dict(x)
|
||||
ujvcs.append(ujvc)
|
||||
|
||||
users = ujvcs.order_by(lambda x: x.UserId).select(lambda x: x.UserId).distinct()
|
||||
groups = {}
|
||||
for user in users:
|
||||
groups[user] = List(UserJoinedVoiceChannel)
|
||||
groups[user].extend(ujvcs.where(lambda x: x.UserId == user))
|
||||
|
||||
for group in groups:
|
||||
|
||||
values: List[UserJoinedVoiceChannel] = groups[group]
|
||||
|
||||
def find_overlaps(x: UserJoinedVoiceChannel) -> bool:
|
||||
for y in values:
|
||||
if x == y:
|
||||
continue
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
Range = namedtuple("Range", ["start", "end"])
|
||||
r1 = Range(start=x.JoinedOn, end=x.LeavedOn)
|
||||
r2 = Range(start=y.LeavedOn, end=y.LeavedOn)
|
||||
latest_start = max(r1.start, r2.start)
|
||||
earliest_end = min(r1.end, r2.end)
|
||||
delta = (earliest_end - latest_start).days + 1
|
||||
overlap = max(0, delta)
|
||||
if overlap > 0:
|
||||
return True
|
||||
|
||||
overlaps = values.where(find_overlaps)
|
||||
if overlaps.count() == 0:
|
||||
continue
|
||||
|
||||
print(overlaps.select(lambda x: x.JoinId))
|
||||
print(f"{group} has {overlaps.count()} of {values.count()}")
|
||||
ontime = overlaps.sum(lambda x: x.ontime)
|
||||
print(f"ontime: {ontime}")
|
||||
print(f"xp: {ontime * 8}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user