Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
taseikyo committed Jan 14, 2021
0 parents commit 1d427bf
Show file tree
Hide file tree
Showing 19 changed files with 664 additions and 0 deletions.
129 changes: 129 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# 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/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Lewis Tian

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
231 changes: 231 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
# 我到底在华科吃了些啥 (华科校园卡年度报告)

<img src="images/hust.jpg" alt="HUST">

## Table of Contents

- [起因](#起因)
- [数据获取](#数据获取)
- [数据分析](#数据分析)
- [2019 数据详情](#2019-数据详情)
- [2020 数据详情](#2020-数据详情)
- [如何使用](#如何使用)

## 起因

今天(2019-12-23)在东一一楼烧腊窗口恰饭,我点的是鸡排饭,然后我没说要啥汁,那个姐姐(感觉叫阿姨不太对)直接说:番茄是吧。我:?,我挺疑惑的,然后在她把饭递给我的时候问了句:你咋知道的?她:因为你经常吃啊(笑)。

想了下好像也没有经常吃吧,虽然之前高中也有过类似的经历,那是因为吃拉面不要香菜、热干面不要葱、炒面炒粉不要葱,然后吃了一段时间就被老板记住了。

很有趣的一次是吃热干面,老板没抬头看,就调好葱姜蒜芝麻酱准备递给我,然后看到我,说:哎呀,你不要葱,这碗给后面的同学,重新给你下一碗 2333。扯远了,因为挺好奇的,于是就打算把今年这一年的吃饭记录都爬下来康康,我这一年都吃的是啥?

## 数据获取

[校园卡服务平台](http://ecard.hust.edu.cn/Default.aspx) 可以查到流水,开始我以为所谓的“导出所有”是把所有记录导出,结果跟“导出当前页流水”是一样的。

所以直接用 Python 写了个爬虫直接把今年(2019)所有月份数据都爬下来,去掉多余的信息,仅保存 *时间**价格**食堂* 这三项数据,然后存为 CSV 文件。

- 过程:

![](images/record.gif)

- 结果:

![](images/TIM20191223152311.png)

## 数据分析

所以这一年到底吃了啥?下面就见分晓!

首先将这些 csv 文件合并,使用 `pandas` 库很简单,下面就是:

```python
def merge_all_files():
files = glob.glob("csv/*.csv")
df = pd.concat([pd.read_csv(file) for file in files])
df.to_csv("csv/2019.csv", index=False, encoding='utf-8-sig')
```

<details>
<summary>2019</summary>

### 2019 数据详情

截止到今天,每个月使用一卡通的消费次数(包括超市和自动售卖机):

```
{
1: 95,
2: 50,
3: 142,
4: 121,
5: 131,
6: 111,
7: 104,
8: 138,
9: 150,
10: 102,
11: 125,
12: 104
}
```

<center>

![](images/consume_times.png)
</center>

各个食堂窗口的食用情况(指的是刷卡次数,吃个晚饭可能会刷几次卡)TOP10

```bash
集贤楼食堂红案: 249
集贤楼蒸菜净荤组: 123
东一二楼特色菜品: 108
集贤楼食堂商店: 99
东一二楼华科速7: 84
东一一楼蒸点稀食: 81
东一二楼湘味小钵: 70
东一一楼烧腊饭: 68
东一二楼大众菜(一): 66
集贤楼食堂煎烙: 65
```

<center>

![](images/windows_times.png)
</center>

各个食堂的食用情况

```
{
'东一': 581,
'集贤楼': 575,
'自助售货机': 9,
'西一': 139,
'百品屋': 8,
'集锦园': 4,
'校园网': 6,
'图书馆': 1,
'东学超市': 3,
'东三': 27,
'紫荆园': 4,
'百景': 12,
'喻园': 4
}
```

<center>

![](images/hall_times.png)
</center>

</details>

<details>
<summary>2020</summary>

### 2020 数据详情

上面过程和分析都是 19 年写的,偶然翻代码翻到这个东西,于是今年(2021)更新了下。

1、各个食堂的食用情况

| 食堂 | 消费次数 |
|:----------:|:-------:|
| 东一 | 587 |
| 自助售货机 | 58 |
| 东学超市 | 9 |
| 集贤楼 | 6 |
| 校医院 | 2 |
| 集锦园 | 4 |
| 东三 | 2 |
| 校园网 | 2 |
| 后勤开水机 | 2 |
| 百景 | 10 |

![](images/hall_times_2020.png)

2、各个窗口的食用情况 top 10

| 窗口 | 消费次数 |
|:--------------------:|:-------:|
| 东一二楼华科速7 | 58 |
| 东一二楼大众菜(二) | 60 |
| 自助售货机 | 58 |
| 东一二楼香霸王卤肉饭 | 30 |
| 东一一楼蒸点稀食 | 101 |
| 东一二楼特色菜品 | 55 |
| 东学超市柜三 | 2 |
| 东学超市柜一 | 6 |
| 东一二楼湘味小钵 | 81 |
| 东一一楼烧腊饭 | 7 |

![](images/windows_times_2020.png)

3、各时间段的食用情况

![](images/hours_2020.png)

4、各个月的食用情况

![](images/consume_times_2020.png)

5、总体概况

在 2020,你连续在 东一二楼大众菜(一) 窗口消费了 4 次,看来你很喜欢这个窗口!

在 2020,你一共消费了 682 次,共花费 3331.35 元!

</details>

## 如何使用

运行 `ecard.py` 前需要登录拿到 `JSESSIONID` 然后填到 `ecard.py` 对应位置;画图前记得解压字体文件:`SourceHanSansCN-Light.7z`,也可以自定义字体,修改 `utils.py` 中的 `myfont = FontProperties(fname="SourceHanSansCN-Light.otf")` 即可。

```Bash
git clone [email protected]:taseikyo/hust-ecard-annual.git
cd hust-ecard-annual
pip3 install -r requirements.txt
# 获取数据
python3 ecard.py
# 画图
python3 utils.py
```

由于校园卡消费记录的是食堂窗口,所以为了提取出食堂我是设了几个食堂关键词:

```
HALLS = {
"东一",
"集贤楼",
"自助售货机",
"西一",
"百品屋",
"集锦园",
"校园网",
"图书馆",
"东学超市",
"东三",
"紫荆园",
"百景",
"喻园",
}
```

当然这些肯定是不全的,毕竟有一共三十多个食堂,所以在代码里面不在 `HALLS` 的食堂直接保存。

```Python
has_found = False
for hall in HALLS:
if row[-1].find(hall) >= 0:
has_found = True
halls[hall] += 1
break
if not has_found:
halls[row[-1]] += 1
```

## LICENSE

Copyright (c) 2019 Lewis Tian. Licensed under the MIT license.
Binary file added SourceHanSansCN-Light.7z
Binary file not shown.
Binary file added csv/2019.7z
Binary file not shown.
Binary file added csv/2020.7z
Binary file not shown.
Loading

0 comments on commit 1d427bf

Please sign in to comment.