-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.py
More file actions
62 lines (44 loc) · 1.59 KB
/
Copy pathexport.py
File metadata and controls
62 lines (44 loc) · 1.59 KB
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
import csv
from collections import defaultdict
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
DATA_FILE = "data.txt"
def export_to_csv():
try:
with open(DATA_FILE, "r") as f, open("report.csv", "w", newline="") as out:
writer = csv.writer(out)
writer.writerow(["Problem", "Difficulty", "Time", "Status", "Date", "Hour"])
for line in f:
parts = line.strip().split(",")
if len(parts) == 6:
writer.writerow(parts)
print("✅ Data exported to report.csv")
except:
print("❌ Error exporting data")
def plot_weekly_graph():
today = datetime.today()
last_7_days = [(today - timedelta(days=i)).strftime("%Y-%m-%d") for i in range(7)]
daily_count = defaultdict(int)
try:
with open(DATA_FILE, "r") as f:
for line in f:
parts = line.strip().split(",")
if len(parts) != 6:
continue
_, _, _, status, date, _ = parts
if status.lower() != "solved":
continue
if date in last_7_days:
daily_count[date] += 1
dates = list(reversed(last_7_days))
values = [daily_count[d] for d in dates]
plt.figure()
plt.plot(dates, values, marker='o')
plt.title("Weekly Coding Activity")
plt.xlabel("Date")
plt.ylabel("Problems Solved")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
except:
print("❌ Error generating graph")