danielrosehill
commited on
Commit
·
c793389
1
Parent(s):
a05037b
updated
Browse files- .github/scripts/update_stats.py +57 -16
- README.md +4 -2
- backups/readme-versions/050124.md +0 -0
.github/scripts/update_stats.py
CHANGED
@@ -1,24 +1,65 @@
|
|
1 |
import requests
|
2 |
import csv
|
3 |
from datetime import datetime
|
|
|
4 |
|
5 |
API_URL = "https://huggingface.co/api/datasets/danielrosehill/ifvi_valuefactors_deriv?expand[]=downloads&expand[]=downloadsAllTime"
|
6 |
-
response = requests.get(API_URL)
|
7 |
-
data = response.json()
|
8 |
-
downloads = data.get('downloads', 0)
|
9 |
-
today = datetime.now().strftime('%Y-%m-%d')
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
22 |
else:
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import requests
|
2 |
import csv
|
3 |
from datetime import datetime
|
4 |
+
import os
|
5 |
|
6 |
API_URL = "https://huggingface.co/api/datasets/danielrosehill/ifvi_valuefactors_deriv?expand[]=downloads&expand[]=downloadsAllTime"
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
def update_csv():
|
9 |
+
response = requests.get(API_URL)
|
10 |
+
data = response.json()
|
11 |
+
downloads = data.get('downloads', 0)
|
12 |
+
today = datetime.now().strftime('%Y-%m-%d')
|
13 |
+
|
14 |
+
try:
|
15 |
+
with open('daily_downloads.csv', mode='r') as file:
|
16 |
+
reader = csv.reader(file)
|
17 |
+
rows = list(reader)
|
18 |
+
except FileNotFoundError:
|
19 |
+
rows = [["Date", "Total Downloads"]]
|
20 |
+
|
21 |
+
with open('daily_downloads.csv', mode='w', newline='') as file:
|
22 |
+
writer = csv.writer(file)
|
23 |
+
writer.writerows(rows)
|
24 |
+
writer.writerow([today, downloads])
|
25 |
+
|
26 |
+
return rows[1:] + [[today, downloads]] # Return all data except header
|
27 |
+
|
28 |
+
def generate_mermaid_chart(data):
|
29 |
+
# Create time series chart
|
30 |
+
mermaid_syntax = '''```
|
31 |
+
graph TD
|
32 |
+
subgraph Download Statistics
|
33 |
+
'''
|
34 |
+
for date, downloads in data[-7:]: # Last 7 days
|
35 |
+
mermaid_syntax += f' {date}["{date}: {downloads} downloads"]\n'
|
36 |
+
|
37 |
+
mermaid_syntax += ' end\n```'
|
38 |
+
return mermaid_syntax
|
39 |
|
40 |
+
def update_readme(mermaid_chart):
|
41 |
+
with open('README.md', 'r') as file:
|
42 |
+
content = file.read()
|
43 |
+
|
44 |
+
# Find the section between ## Download Statistics and the next ## or end of file
|
45 |
+
start_marker = "## Download Statistics"
|
46 |
+
if "## Download Statistics" not in content:
|
47 |
+
# Add section if it doesn't exist
|
48 |
+
content += f"\n\n{start_marker}\n\n{mermaid_chart}\n"
|
49 |
else:
|
50 |
+
# Replace existing section
|
51 |
+
parts = content.split(start_marker)
|
52 |
+
next_section = parts[1].find("##")
|
53 |
+
if next_section == -1:
|
54 |
+
parts[1] = f"\n\n{mermaid_chart}\n"
|
55 |
+
else:
|
56 |
+
parts[1] = f"\n\n{mermaid_chart}\n" + parts[1][next_section:]
|
57 |
+
content = start_marker.join(parts)
|
58 |
+
|
59 |
+
with open('README.md', 'w') as file:
|
60 |
+
file.write(content)
|
61 |
+
|
62 |
+
if __name__ == "__main__":
|
63 |
+
data = update_csv()
|
64 |
+
mermaid_chart = generate_mermaid_chart(data)
|
65 |
+
update_readme(mermaid_chart)
|
README.md
CHANGED
@@ -34,9 +34,11 @@ The GVFD covers 430 different environmental impacts across four main categories
|
|
34 |
|
35 |
## Download Statistics
|
36 |
|
|
|
37 |
graph TD
|
38 |
-
|
39 |
-
|
|
|
40 |
|
41 |
---
|
42 |
|
|
|
34 |
|
35 |
## Download Statistics
|
36 |
|
37 |
+
```mermaid
|
38 |
graph TD
|
39 |
+
A[Downloads] --> B[Time]
|
40 |
+
B --> C[Daily Count]
|
41 |
+
```
|
42 |
|
43 |
---
|
44 |
|
backups/readme-versions/050124.md
ADDED
The diff for this file is too large to render.
See raw diff
|
|