-
Notifications
You must be signed in to change notification settings - Fork 0
/
dao.py
92 lines (80 loc) · 2.87 KB
/
dao.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import sqlite3
import pandas as ps
from enum import IntEnum
class ActivityType(IntEnum):
JOIN_ROOM = 0
MET_PLAYER = 1
SEND_INVITE = 2
RECEVED_INVITE = 3
SEND_REQUEST_INVITE = 4
RECEIVED_REQUEST_INVITE = 5
SEND_FRIEND_REQUEST = 6
RECEIVED_FRIEND_REQUEST = 7
ACCEPT_FRIEND_REQUEST = 8
LEAVE_PLAYER = 99
class VRChatActivityLogsDao:
__table_name = "ActivityLogs"
__column_name = {
"id": "ID",
"activity_type": "ActivityType",
"timestamp": "Timestamp",
"notificaton_id": "NotificationID",
"user_id": "UserID",
"user_name": "UserName",
"world_id": "WorldID",
"world_name": "WorldName",
}
def __init__(self, db_name="./VRChatActivityLog.db"):
self.conn = sqlite3.connect(db_name)
def __del__(self):
if self.conn:
self.conn.close()
def meets_counts(self, limit=20):
df = ps.read_sql(
f"""
select
{self.__column_name["user_name"]},
count(*)
from {self.__table_name}
where {self.__column_name["activity_type"]}
= {int(ActivityType.MET_PLAYER)}
group by {self.__column_name["user_name"]}
order by 2 desc
limit {limit}
""", self.conn)
return df
def fetch_world_join_time(self):
df = ps.read_sql(
f"""
select
{self.__column_name["world_name"]},
{self.__column_name["timestamp"]}
from {self.__table_name}
where
{self.__column_name["activity_type"]}
= {int(ActivityType.JOIN_ROOM)}
order by {self.__column_name["timestamp"]} asc
""", self.conn)
return df
def fetch_user_meet_data(self, time_start, time_end):
df = ps.read_sql(
f"""
select
{self.__column_name["user_name"]},
{self.__column_name["timestamp"]},
{self.__column_name["activity_type"]}
from {self.__table_name}
where
{self.__column_name["activity_type"]}
in ({int(ActivityType.MET_PLAYER)},
{int(ActivityType.LEAVE_PLAYER)})
and {self.__column_name["timestamp"]}
between '{time_start}' and '{time_end}'
order by {self.__column_name["timestamp"]} asc
""", self.conn)
return df
def query(self, query):
return ps.read_sql(query, self.conn)
if __name__ == "__main__":
dao = VRChatActivityLogsDao()
print(dao.meets_counts())