[M] Move non-course-related files to misc
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
node_modules
|
||||
dist
|
||||
.parcel-cache
|
||||
*.log
|
||||
@@ -0,0 +1,6 @@
|
||||
const serveStatic = require("serve-static");
|
||||
|
||||
module.exports = function (app) {
|
||||
app.use(serveStatic("node_modules/@ffmpeg/core/dist"));
|
||||
app.use(serveStatic("data"));
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
# anichart-template
|
||||
|
||||
Quick start anichart project.
|
||||
|
||||
## Start
|
||||
|
||||
``` bash
|
||||
parcel index.html --open
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
``` build
|
||||
parcel build index.html
|
||||
```
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
@@ -0,0 +1,7 @@
|
||||
id,date,value
|
||||
A,2021-01-01,1
|
||||
A,2021-01-02,2
|
||||
A,2021-01-03,3
|
||||
B,2021-01-01,2
|
||||
B,2021-01-02,3
|
||||
B,2021-01-03,1
|
||||
|
@@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Anichart Typescript</title>
|
||||
<meta charset="UTF-8" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script type="module" src="src/index.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "anichart-template",
|
||||
"version": "1.0.1",
|
||||
"description": "Starter of anichart.js.",
|
||||
"scripts": {
|
||||
"start": "parcel index.html --open",
|
||||
"build": "parcel build index.html"
|
||||
},
|
||||
"dependencies": {
|
||||
"anichart": "2.3.1-alpha",
|
||||
"serve-static": "^1.14.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"parcel": "^2.0.0-rc.0",
|
||||
"typescript": "^4.3.5"
|
||||
},
|
||||
"keywords": [
|
||||
"chart",
|
||||
"data",
|
||||
"anichart"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import * as ANI from "anichart";
|
||||
|
||||
const stage = new ANI.Stage();
|
||||
stage.options.fps = 60;
|
||||
stage.options.sec = 40;
|
||||
|
||||
const userid: {[id: string]: string} = {
|
||||
'user1868166081': '桂',
|
||||
}
|
||||
|
||||
// Bar chart
|
||||
ANI.recourse.loadCSV("./output.csv", "data");
|
||||
let bar = new ANI.BarChart({
|
||||
dateLabelOptions: {},
|
||||
});
|
||||
|
||||
// Disable name display
|
||||
bar.barInfoFormat = (id, meta, data) => ''
|
||||
bar.showRankLabel = false
|
||||
console.log(bar.data);
|
||||
|
||||
|
||||
// Avatars
|
||||
for (let key in userid) {
|
||||
let user = userid[key]
|
||||
ANI.recourse.loadImage(`./avatar/${user}.jpg`, user);
|
||||
}
|
||||
|
||||
stage.canvas.width = 1920;
|
||||
stage.canvas.height = 1080;
|
||||
const rect = new ANI.Rect({
|
||||
shape: { width: 1920, height: 1080 },
|
||||
fillStyle: "#1e1e1e",
|
||||
});
|
||||
stage.addChild(rect);
|
||||
stage.addChild(bar);
|
||||
|
||||
const center = new ANI.Text({ text: "uwu", font: 'Microsoft Yahei UI' })
|
||||
center.fontSize = 90
|
||||
stage.addChild(center);
|
||||
|
||||
stage.play();
|
||||
stage.output = true;
|
||||
|
||||
// new ANI.MapChart({});
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"module": "commonjs",
|
||||
"jsx": "preserve",
|
||||
"esModuleInterop": true,
|
||||
"sourceMap": true,
|
||||
"allowJs": false,
|
||||
"lib": ["es6", "dom"],
|
||||
"rootDir": "src",
|
||||
"moduleResolution": "node"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,47 @@
|
||||
import io
|
||||
import os
|
||||
|
||||
import json5
|
||||
import requests
|
||||
|
||||
if __name__ == '__main__':
|
||||
"""
|
||||
This method doesn't work
|
||||
"""
|
||||
token = os.environ.get('tg-bot-token')
|
||||
|
||||
with io.open('userid_to_name.json5', mode='r', encoding='utf-8') as f:
|
||||
userid_to_name = json5.loads(f.read())
|
||||
|
||||
for user_id in userid_to_name:
|
||||
user = userid_to_name[user_id]
|
||||
|
||||
# Get photo
|
||||
r = requests.get(f'https://api.telegram.org/bot{token}/getUserProfilePhotos',
|
||||
params={'user_id': user_id[4:]})
|
||||
|
||||
o = r.json()
|
||||
if 'result' not in o:
|
||||
print(f'Result not in o for {user}')
|
||||
print(o)
|
||||
continue
|
||||
|
||||
o = o['result']
|
||||
if o['total_count'] == 0:
|
||||
print(f'Total count is 0 for user {user}')
|
||||
continue
|
||||
|
||||
photo = max(o['photos'][0], key=lambda x: x['height'])
|
||||
|
||||
# Get file
|
||||
r = requests.get(f'https://api.telegram.org/bot{token}/getFile',
|
||||
params={'file_id': photo['file_id']})
|
||||
o = r.json()['result']
|
||||
|
||||
# Download file
|
||||
r = requests.get(f'https://api.telegram.org/file/bot{token}/{o["file_path"]}',
|
||||
params={'file_id': photo['file_id']})
|
||||
|
||||
# Write file
|
||||
with io.open(f'avatars/{userid_to_name[user_id]}.jpg', 'wb') as f:
|
||||
f.write(r.content)
|
||||
@@ -0,0 +1,29 @@
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
if __name__ == '__main__':
|
||||
file = "./result-full.json"
|
||||
start = '2021-06-25T12:01:01'
|
||||
end = '2021-11-02T14:01:01'
|
||||
|
||||
with open(file, 'r') as f:
|
||||
obj = json.load(f)
|
||||
|
||||
messages: list = obj['messages']
|
||||
messages = [m for m in messages if start < m['date'] < end
|
||||
and m['type'] == 'message'
|
||||
# and m['from'] == 'Hykilpikonna'
|
||||
]
|
||||
|
||||
timezone_delta = timedelta(hours=12)
|
||||
dates = [datetime.fromisoformat(m['date']) - timezone_delta for m in messages]
|
||||
|
||||
plt.xticks(rotation=90)
|
||||
plt.tight_layout()
|
||||
plt.hist(dates, bins=300, color='#ffcccc')
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import io
|
||||
import json
|
||||
import json5
|
||||
|
||||
if __name__ == '__main__':
|
||||
"""
|
||||
|
||||
"""
|
||||
file = "./result.json"
|
||||
start = '2021-06-25T12:01:01'
|
||||
end = '2021-11-02T14:01:01'
|
||||
|
||||
with io.open(file, mode='r', encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
obj = json.loads(content)
|
||||
|
||||
with io.open('userid_to_name.json5', mode='r', encoding='utf-8') as f:
|
||||
userid_to_name = json5.loads(f.read())
|
||||
|
||||
messages: list = obj['messages']
|
||||
messages = [m for m in messages if True
|
||||
# and start < m['date'] < end
|
||||
and m['type'] == 'message'
|
||||
# and m['from'] == 'Hykilpikonna'
|
||||
]
|
||||
|
||||
date_data = {}
|
||||
for m in messages:
|
||||
date = m['date'][:10]
|
||||
if date not in date_data:
|
||||
date_data[date] = {}
|
||||
user = m['from_id']
|
||||
if user not in userid_to_name:
|
||||
userid_to_name[user] = m['from']
|
||||
user = userid_to_name[user]
|
||||
if user not in date_data[date]:
|
||||
date_data[date][user] = 0
|
||||
date_data[date][user] += 1
|
||||
|
||||
print(userid_to_name)
|
||||
|
||||
user_totals = {}
|
||||
lines = ['id,date,value']
|
||||
for date in date_data:
|
||||
users = date_data[date]
|
||||
for u in users:
|
||||
if u not in user_totals:
|
||||
user_totals[u] = []
|
||||
user_totals[u].append(users[u])
|
||||
|
||||
for u in user_totals:
|
||||
if u not in users:
|
||||
user_totals[u].append(0)
|
||||
total = sum(user_totals[u][-7:])
|
||||
if u in userid_to_name:
|
||||
u = userid_to_name[u]
|
||||
lines.append(f'{u},{date},{total}')
|
||||
|
||||
with io.open('output.csv', mode='w', encoding='utf-8') as f:
|
||||
f.write('\n'.join(lines))
|
||||
|
||||
Reference in New Issue
Block a user