-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze.py
72 lines (53 loc) · 2 KB
/
analyze.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import importlib
import pandas as pd
# Import functions from query
query_module = importlib.import_module("query")
# Preferred finished date, accepted values: "Finished", "Lastmod"
DATE_COL = "Finished"
def playtime(filename):
df = pd.read_csv(filename)
# Debug preview
# print(df.head())
# Rough estimation
if filename == "clean.csv":
# Get the start and end dates of the month
month_start, month_end = query_module.get_last_month_dates()
# Convert columns to Timestamp
df["Date"] = pd.to_datetime(df["Date"])
df[DATE_COL] = pd.to_datetime(df[DATE_COL])
# Filter rows for the month and games that occupy more than 15 days
month_rows = df[
(df[DATE_COL] >= month_start)
& (df[DATE_COL] <= month_end)
& (df[DATE_COL] - df["Date"] <= pd.Timedelta(days=15))
]
# Convert playtime of month to time strings and sum them
month_playtime = pd.to_timedelta(month_rows["Playtime"]).sum()
# Accurate calculation
else:
month_playtime = pd.to_timedelta(df["Playtime"]).sum()
# Format month_playtime to HH:MM:SS
total_seconds = month_playtime.total_seconds()
hours = int(total_seconds // 3600)
minutes = int((total_seconds % 3600) // 60)
seconds = int(total_seconds % 60)
month_playtime_str = f"{hours:02d}:{minutes:02d}:{seconds:02d}"
print(month_playtime_str)
def rating(filename):
df = pd.read_csv(filename)
df.dropna(subset=["Rating"], inplace=True)
# Debug preview
# print(df)
# Rated titles
m = len(df)
# Average rating, did not consider 100/100 scale rating
n = round(df["Rating"].mean(), 3)
# SD, same result as VAR.P in Excel
# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.std.html
sd = round(df["Rating"].var(ddof=0), 3)
print(f"∑={m}, μ={n}/10, σ²={sd}")
playtime("clean.csv")
playtime("monthly.csv")
rating("monthly.csv")