Skip to content

Commit

Permalink
Merge pull request #1 from tmu-nlp/hajime
Browse files Browse the repository at this point in the history
init test
  • Loading branch information
kiyama-hajime authored Apr 8, 2024
2 parents 8bc02c8 + 158e904 commit 71da257
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .automation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# .automation

This folder holds an automation script to visualize the progress.

## make_progress.py

This script uses GitHub Actions so that when a push to the repository is committed, it will complete the following:

- Checkout the source code
- Update progress.png
- Update progress.json
122 changes: 122 additions & 0 deletions .automation/make_progress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
from pathlib import Path
from pprint import pprint
from typing import List

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns

import datetime


class User:
def __init__(self, name, path):
self.name = name
self.path = path
self.progress = [0] * 10


def get_progress() -> List[User]:
cur = Path(".")
users = list(
filter(lambda x: x.is_dir() and not is_ignored(
x.name), sorted(cur.iterdir()))
)

progress = list()
# user ごとの progress を取得する
for user in users:
u = User(user.name, user)
for chap, max_cnt in enumerate(QUESTIONS):
# user/chapterXX の path (章だけ 1-indexed なので num+1)
chapter_path = Path(user / f"chapter{chap+1:02d}")
# user/chapterXX に含まれる .py, .sh, .ipynb ファイルの数をカウント
cnt = 0
for ext in ["py", "sh", "ipynb"]:
cnt += len(list(chapter_path.glob(f"*.{ext}")))
# 問題数は max_cnt が上限で、それ以上のファイル数が含まれる場合は max_cnt にする
solved_cnt = min(cnt, max_cnt)
u.progress[chap] = solved_cnt
progress.append(u)

return progress


def plot_progress(users: np.array, scores: np.array):
# 描画されるグラフのサイズを指定
plt.figure(figsize=(8, 6))

# 各章ごとに棒グラフを積み上げていく
for chap in range(CHAPTER):
label = f"chapter {chap+1:02d}"
bottom = np.sum(scores[:, :chap], axis=1)
plt.bar(
users,
scores[:, chap],
bottom=bottom,
align="center",
tick_label=users,
label=label,
)
today = datetime.date.today()
date_list = list()
date_list.append(datetime.date(2023, 4, 22))
date_list.append(datetime.date(2023, 5, 13))
date_list.append(datetime.date(2023, 5, 20))
date_list.append(datetime.date(2023, 5, 27))
date_list.append(datetime.date(2023, 6, 10))
date_list.append(datetime.date(2023, 6, 17))
date_list.append(datetime.date(2023, 6, 24))
date_list.append(datetime.date(2023, 7, 8))
date_list.append(datetime.date(2023, 7, 29))
# print(date_list)
d = [date for date in date_list if today >= date]
# print(date_list)
# print(d)
# print(len(d))
xmin, xmax = plt.xlim()
if len(d) != 10 and len(d) != 0:
label = "{}Border".format(str(date_list[len(d)])[5:])
plt.hlines((len(d)+1) * 10, xmin, xmax, linewidth=2,
linestyle='dashed', color="gray", label=label)
plt.xlim(xmin, xmax)

if len(d) != 0:
label = "{}Border".format(str(d[-1])[5:])
plt.hlines(len(d) * 10, xmin, xmax, linewidth=4,
color="red", label=label)

plt.xlim(xmin, xmax)

# グラフの設定
plt.xticks(rotation=30, fontsize=10)
# 縦軸のラベルを 10 問刻みにする
whole = sum(QUESTIONS)
plt.ylim(0, whole+1)
plt.yticks(np.arange(0, whole + 1, 10))
# 凡例をグラフの外側に表示する
plt.legend(bbox_to_anchor=(1.28, 1.0))
plt.subplots_adjust(right=0.8)
# グラフを書き出す
plt.savefig("progress.png")


def main():
data = get_progress()
users = np.array([user.name for user in data])
scores = np.array([user.progress for user in data])

if scores.size:
plot_progress(users, scores)


if __name__ == "__main__":
sns.set()
# 章数と各章の問題数
CHAPTER = 10
QUESTIONS = [10] * CHAPTER
# progress bar に表示しないディレクトリ名
IGNORE = [""]
def is_ignored(name): return name in IGNORE or name.startswith(".")

main()
4 changes: 4 additions & 0 deletions .automation/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
numpy
matplotlib
seaborn
datetime
52 changes: 52 additions & 0 deletions .github/workflows/Update-progress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Update-Progress

on:
push:
branches:
- 'main'
- 'master'

workflow_dispatch:
inputs:
purpose:
description: "Purpose to manually run"
required: true
default: "test"

jobs:
update:
name: Update
runs-on: ubuntu-latest
env:
FILE_NAME: "progress.png"

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Echo your purpose
if: ${{ github.event.inputs.purpose != '' }}
run: |
echo "Purpose: ${{ github.event.inputs.purpose }}"
- name: Print Python info
run: |
echo "python --version: `python --version`"
echo "python3 --version: `python3 --version`"
- name: Update ${{ env.FILE_NAME }}
run: |
python -m pip install -r .automation/requirements.txt
python .automation/make_progress.py
- name: Configure your Git username/email
run: |
git config user.name ${NAME}
git config user.email ${EMAIL}
env:
NAME: "hajime kiyama"
EMAIL: "hajime.7393@gmail.com"

- name: Commit ${{ env.FILE_NAME }}
run: |
git add $FILE_NAME
git diff-index --quiet HEAD || git commit -m "[Bot] Update ${FILE_NAME}"
git push
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
.DS_Store
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
},
"python.formatting.provider": "none"
}

0 comments on commit 71da257

Please sign in to comment.