├── .gitignore ├── Caddyfile ├── Dockerfile ├── LICENSE ├── README.md ├── account.png ├── backend ├── app.py └── requirements.txt ├── card.png ├── demo.png ├── docker-compose.yml ├── frontend ├── index.html ├── package.json ├── postcss.config.cjs ├── src │ ├── App.vue │ ├── components │ │ ├── ConfigForm.vue │ │ ├── ConsumptionReport.vue │ │ ├── EatingTimeHeatmap.vue │ │ ├── LocationAnalysis.vue │ │ ├── TransactionCard.vue │ │ └── UnusualTransactions.vue │ ├── index.css │ ├── main.js │ └── services │ │ └── cardApi.js ├── tailwind.config.cjs └── vite.config.js ├── hallticket.png ├── main.py └── start.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # User data 2 | config.json 3 | result.png 4 | 5 | # Byte-compiled / optimized / DLL files 6 | __pycache__/ 7 | *.py[cod] 8 | *$py.class 9 | 10 | # C extensions 11 | *.so 12 | 13 | # Distribution / packaging 14 | .Python 15 | build/ 16 | develop-eggs/ 17 | dist/ 18 | downloads/ 19 | eggs/ 20 | .eggs/ 21 | lib/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | wheels/ 27 | share/python-wheels/ 28 | *.egg-info/ 29 | .installed.cfg 30 | *.egg 31 | MANIFEST 32 | 33 | # PyInstaller 34 | # Usually these files are written by a python script from a template 35 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 36 | *.manifest 37 | *.spec 38 | 39 | # Installer logs 40 | pip-log.txt 41 | pip-delete-this-directory.txt 42 | 43 | # Unit test / coverage reports 44 | htmlcov/ 45 | .tox/ 46 | .nox/ 47 | .coverage 48 | .coverage.* 49 | .cache 50 | nosetests.xml 51 | coverage.xml 52 | *.cover 53 | *.py,cover 54 | .hypothesis/ 55 | .pytest_cache/ 56 | cover/ 57 | 58 | # Translations 59 | *.mo 60 | *.pot 61 | 62 | # Django stuff: 63 | *.log 64 | local_settings.py 65 | db.sqlite3 66 | db.sqlite3-journal 67 | 68 | # Flask stuff: 69 | instance/ 70 | .webassets-cache 71 | 72 | # Scrapy stuff: 73 | .scrapy 74 | 75 | # Sphinx documentation 76 | docs/_build/ 77 | 78 | # PyBuilder 79 | .pybuilder/ 80 | target/ 81 | 82 | # Jupyter Notebook 83 | .ipynb_checkpoints 84 | 85 | # IPython 86 | profile_default/ 87 | ipython_config.py 88 | 89 | # pyenv 90 | # For a library or package, you might want to ignore these files since the code is 91 | # intended to run in multiple environments; otherwise, check them in: 92 | # .python-version 93 | 94 | # pipenv 95 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 96 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 97 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 98 | # install all needed dependencies. 99 | #Pipfile.lock 100 | 101 | # UV 102 | # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. 103 | # This is especially recommended for binary packages to ensure reproducibility, and is more 104 | # commonly ignored for libraries. 105 | #uv.lock 106 | 107 | # poetry 108 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 109 | # This is especially recommended for binary packages to ensure reproducibility, and is more 110 | # commonly ignored for libraries. 111 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 112 | #poetry.lock 113 | 114 | # pdm 115 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 116 | #pdm.lock 117 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 118 | # in version control. 119 | # https://pdm.fming.dev/latest/usage/project/#working-with-version-control 120 | .pdm.toml 121 | .pdm-python 122 | .pdm-build/ 123 | 124 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 125 | __pypackages__/ 126 | 127 | # Celery stuff 128 | celerybeat-schedule 129 | celerybeat.pid 130 | 131 | # SageMath parsed files 132 | *.sage.py 133 | 134 | # Environments 135 | .env 136 | .venv 137 | env/ 138 | venv/ 139 | ENV/ 140 | env.bak/ 141 | venv.bak/ 142 | 143 | # Spyder project settings 144 | .spyderproject 145 | .spyproject 146 | 147 | # Rope project settings 148 | .ropeproject 149 | 150 | # mkdocs documentation 151 | /site 152 | 153 | # mypy 154 | .mypy_cache/ 155 | .dmypy.json 156 | dmypy.json 157 | 158 | # Pyre type checker 159 | .pyre/ 160 | 161 | # pytype static type analyzer 162 | .pytype/ 163 | 164 | # Cython debug symbols 165 | cython_debug/ 166 | 167 | # PyCharm 168 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 169 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 170 | # and can be added to the global gitignore or merged into this file. For a more nuclear 171 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 172 | .idea/ 173 | 174 | # PyPI configuration file 175 | .pypirc 176 | -------------------------------------------------------------------------------- /Caddyfile: -------------------------------------------------------------------------------- 1 | :80 { 2 | # Enable logging 3 | log { 4 | format console 5 | level DEBUG 6 | } 7 | 8 | # Serve static files 9 | handle { 10 | root * /app/frontend/dist 11 | try_files {path} /index.html 12 | file_server 13 | } 14 | 15 | # Proxy /api requests to the Flask backend 16 | handle /api/* { 17 | reverse_proxy localhost:5000 18 | } 19 | } -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Build stage for Vue frontend 2 | FROM hub.geekery.cn/library/node:18 AS frontend-build 3 | WORKDIR /app/frontend 4 | COPY frontend/package.json . 5 | RUN npm config set registry https://registry.npmmirror.com 6 | RUN npm install 7 | COPY frontend/postcss.config.cjs . 8 | COPY frontend/tailwind.config.cjs . 9 | COPY frontend/src ./src 10 | COPY frontend/index.html . 11 | COPY frontend/vite.config.js . 12 | RUN npm run build 13 | 14 | # Final stage 15 | FROM hub.geekery.cn/library/python:3.9-slim 16 | WORKDIR /app 17 | # Setup backend 18 | COPY backend/requirements.txt . 19 | RUN pip install -r requirements.txt 20 | 21 | # Install system dependencies for matplotlib 22 | RUN apt-get update && \ 23 | apt-get install -y \ 24 | debian-keyring \ 25 | debian-archive-keyring \ 26 | apt-transport-https \ 27 | curl \ 28 | python3-tk \ 29 | libfreetype6-dev \ 30 | libpng-dev \ 31 | && curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg \ 32 | && curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list \ 33 | && apt-get update \ 34 | && apt-get install -y caddy \ 35 | && rm -rf /var/lib/apt/lists/* 36 | 37 | # Create directory for frontend files 38 | RUN mkdir -p /app/frontend/dist 39 | 40 | # Copy frontend build 41 | COPY --from=frontend-build /app/frontend/dist /app/frontend/dist 42 | 43 | 44 | 45 | COPY backend /app/backend 46 | COPY Caddyfile /etc/caddy/Caddyfile 47 | COPY start.sh /app/start.sh 48 | RUN chmod +x /app/start.sh 49 | 50 | EXPOSE 80 51 | 52 | CMD ["/app/start.sh"] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Attribution-NonCommercial-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International 58 | Public License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-NonCommercial-ShareAlike 4.0 International Public License 63 | ("Public License"). To the extent this Public License may be 64 | interpreted as a contract, You are granted the Licensed Rights in 65 | consideration of Your acceptance of these terms and conditions, and the 66 | Licensor grants You such rights in consideration of benefits the 67 | Licensor receives from making the Licensed Material available under 68 | these terms and conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Adapter's License means the license You apply to Your Copyright 84 | and Similar Rights in Your contributions to Adapted Material in 85 | accordance with the terms and conditions of this Public License. 86 | 87 | c. BY-NC-SA Compatible License means a license listed at 88 | creativecommons.org/compatiblelicenses, approved by Creative 89 | Commons as essentially the equivalent of this Public License. 90 | 91 | d. Copyright and Similar Rights means copyright and/or similar rights 92 | closely related to copyright including, without limitation, 93 | performance, broadcast, sound recording, and Sui Generis Database 94 | Rights, without regard to how the rights are labeled or 95 | categorized. For purposes of this Public License, the rights 96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 97 | Rights. 98 | 99 | e. Effective Technological Measures means those measures that, in the 100 | absence of proper authority, may not be circumvented under laws 101 | fulfilling obligations under Article 11 of the WIPO Copyright 102 | Treaty adopted on December 20, 1996, and/or similar international 103 | agreements. 104 | 105 | f. Exceptions and Limitations means fair use, fair dealing, and/or 106 | any other exception or limitation to Copyright and Similar Rights 107 | that applies to Your use of the Licensed Material. 108 | 109 | g. License Elements means the license attributes listed in the name 110 | of a Creative Commons Public License. The License Elements of this 111 | Public License are Attribution, NonCommercial, and ShareAlike. 112 | 113 | h. Licensed Material means the artistic or literary work, database, 114 | or other material to which the Licensor applied this Public 115 | License. 116 | 117 | i. Licensed Rights means the rights granted to You subject to the 118 | terms and conditions of this Public License, which are limited to 119 | all Copyright and Similar Rights that apply to Your use of the 120 | Licensed Material and that the Licensor has authority to license. 121 | 122 | j. Licensor means the individual(s) or entity(ies) granting rights 123 | under this Public License. 124 | 125 | k. NonCommercial means not primarily intended for or directed towards 126 | commercial advantage or monetary compensation. For purposes of 127 | this Public License, the exchange of the Licensed Material for 128 | other material subject to Copyright and Similar Rights by digital 129 | file-sharing or similar means is NonCommercial provided there is 130 | no payment of monetary compensation in connection with the 131 | exchange. 132 | 133 | l. Share means to provide material to the public by any means or 134 | process that requires permission under the Licensed Rights, such 135 | as reproduction, public display, public performance, distribution, 136 | dissemination, communication, or importation, and to make material 137 | available to the public including in ways that members of the 138 | public may access the material from a place and at a time 139 | individually chosen by them. 140 | 141 | m. Sui Generis Database Rights means rights other than copyright 142 | resulting from Directive 96/9/EC of the European Parliament and of 143 | the Council of 11 March 1996 on the legal protection of databases, 144 | as amended and/or succeeded, as well as other essentially 145 | equivalent rights anywhere in the world. 146 | 147 | n. You means the individual or entity exercising the Licensed Rights 148 | under this Public License. Your has a corresponding meaning. 149 | 150 | 151 | Section 2 -- Scope. 152 | 153 | a. License grant. 154 | 155 | 1. Subject to the terms and conditions of this Public License, 156 | the Licensor hereby grants You a worldwide, royalty-free, 157 | non-sublicensable, non-exclusive, irrevocable license to 158 | exercise the Licensed Rights in the Licensed Material to: 159 | 160 | a. reproduce and Share the Licensed Material, in whole or 161 | in part, for NonCommercial purposes only; and 162 | 163 | b. produce, reproduce, and Share Adapted Material for 164 | NonCommercial purposes only. 165 | 166 | 2. Exceptions and Limitations. For the avoidance of doubt, where 167 | Exceptions and Limitations apply to Your use, this Public 168 | License does not apply, and You do not need to comply with 169 | its terms and conditions. 170 | 171 | 3. Term. The term of this Public License is specified in Section 172 | 6(a). 173 | 174 | 4. Media and formats; technical modifications allowed. The 175 | Licensor authorizes You to exercise the Licensed Rights in 176 | all media and formats whether now known or hereafter created, 177 | and to make technical modifications necessary to do so. The 178 | Licensor waives and/or agrees not to assert any right or 179 | authority to forbid You from making technical modifications 180 | necessary to exercise the Licensed Rights, including 181 | technical modifications necessary to circumvent Effective 182 | Technological Measures. For purposes of this Public License, 183 | simply making modifications authorized by this Section 2(a) 184 | (4) never produces Adapted Material. 185 | 186 | 5. Downstream recipients. 187 | 188 | a. Offer from the Licensor -- Licensed Material. Every 189 | recipient of the Licensed Material automatically 190 | receives an offer from the Licensor to exercise the 191 | Licensed Rights under the terms and conditions of this 192 | Public License. 193 | 194 | b. Additional offer from the Licensor -- Adapted Material. 195 | Every recipient of Adapted Material from You 196 | automatically receives an offer from the Licensor to 197 | exercise the Licensed Rights in the Adapted Material 198 | under the conditions of the Adapter's License You apply. 199 | 200 | c. No downstream restrictions. You may not offer or impose 201 | any additional or different terms or conditions on, or 202 | apply any Effective Technological Measures to, the 203 | Licensed Material if doing so restricts exercise of the 204 | Licensed Rights by any recipient of the Licensed 205 | Material. 206 | 207 | 6. No endorsement. Nothing in this Public License constitutes or 208 | may be construed as permission to assert or imply that You 209 | are, or that Your use of the Licensed Material is, connected 210 | with, or sponsored, endorsed, or granted official status by, 211 | the Licensor or others designated to receive attribution as 212 | provided in Section 3(a)(1)(A)(i). 213 | 214 | b. Other rights. 215 | 216 | 1. Moral rights, such as the right of integrity, are not 217 | licensed under this Public License, nor are publicity, 218 | privacy, and/or other similar personality rights; however, to 219 | the extent possible, the Licensor waives and/or agrees not to 220 | assert any such rights held by the Licensor to the limited 221 | extent necessary to allow You to exercise the Licensed 222 | Rights, but not otherwise. 223 | 224 | 2. Patent and trademark rights are not licensed under this 225 | Public License. 226 | 227 | 3. To the extent possible, the Licensor waives any right to 228 | collect royalties from You for the exercise of the Licensed 229 | Rights, whether directly or through a collecting society 230 | under any voluntary or waivable statutory or compulsory 231 | licensing scheme. In all other cases the Licensor expressly 232 | reserves any right to collect such royalties, including when 233 | the Licensed Material is used other than for NonCommercial 234 | purposes. 235 | 236 | 237 | Section 3 -- License Conditions. 238 | 239 | Your exercise of the Licensed Rights is expressly made subject to the 240 | following conditions. 241 | 242 | a. Attribution. 243 | 244 | 1. If You Share the Licensed Material (including in modified 245 | form), You must: 246 | 247 | a. retain the following if it is supplied by the Licensor 248 | with the Licensed Material: 249 | 250 | i. identification of the creator(s) of the Licensed 251 | Material and any others designated to receive 252 | attribution, in any reasonable manner requested by 253 | the Licensor (including by pseudonym if 254 | designated); 255 | 256 | ii. a copyright notice; 257 | 258 | iii. a notice that refers to this Public License; 259 | 260 | iv. a notice that refers to the disclaimer of 261 | warranties; 262 | 263 | v. a URI or hyperlink to the Licensed Material to the 264 | extent reasonably practicable; 265 | 266 | b. indicate if You modified the Licensed Material and 267 | retain an indication of any previous modifications; and 268 | 269 | c. indicate the Licensed Material is licensed under this 270 | Public License, and include the text of, or the URI or 271 | hyperlink to, this Public License. 272 | 273 | 2. You may satisfy the conditions in Section 3(a)(1) in any 274 | reasonable manner based on the medium, means, and context in 275 | which You Share the Licensed Material. For example, it may be 276 | reasonable to satisfy the conditions by providing a URI or 277 | hyperlink to a resource that includes the required 278 | information. 279 | 3. If requested by the Licensor, You must remove any of the 280 | information required by Section 3(a)(1)(A) to the extent 281 | reasonably practicable. 282 | 283 | b. ShareAlike. 284 | 285 | In addition to the conditions in Section 3(a), if You Share 286 | Adapted Material You produce, the following conditions also apply. 287 | 288 | 1. The Adapter's License You apply must be a Creative Commons 289 | license with the same License Elements, this version or 290 | later, or a BY-NC-SA Compatible License. 291 | 292 | 2. You must include the text of, or the URI or hyperlink to, the 293 | Adapter's License You apply. You may satisfy this condition 294 | in any reasonable manner based on the medium, means, and 295 | context in which You Share Adapted Material. 296 | 297 | 3. You may not offer or impose any additional or different terms 298 | or conditions on, or apply any Effective Technological 299 | Measures to, Adapted Material that restrict exercise of the 300 | rights granted under the Adapter's License You apply. 301 | 302 | 303 | Section 4 -- Sui Generis Database Rights. 304 | 305 | Where the Licensed Rights include Sui Generis Database Rights that 306 | apply to Your use of the Licensed Material: 307 | 308 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 309 | to extract, reuse, reproduce, and Share all or a substantial 310 | portion of the contents of the database for NonCommercial purposes 311 | only; 312 | 313 | b. if You include all or a substantial portion of the database 314 | contents in a database in which You have Sui Generis Database 315 | Rights, then the database in which You have Sui Generis Database 316 | Rights (but not its individual contents) is Adapted Material, 317 | including for purposes of Section 3(b); and 318 | 319 | c. You must comply with the conditions in Section 3(a) if You Share 320 | all or a substantial portion of the contents of the database. 321 | 322 | For the avoidance of doubt, this Section 4 supplements and does not 323 | replace Your obligations under this Public License where the Licensed 324 | Rights include other Copyright and Similar Rights. 325 | 326 | 327 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 328 | 329 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 330 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 331 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 332 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 333 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 334 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 335 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 336 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 337 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 338 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 339 | 340 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 341 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 342 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 343 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 344 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 345 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 346 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 347 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 348 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 349 | 350 | c. The disclaimer of warranties and limitation of liability provided 351 | above shall be interpreted in a manner that, to the extent 352 | possible, most closely approximates an absolute disclaimer and 353 | waiver of all liability. 354 | 355 | 356 | Section 6 -- Term and Termination. 357 | 358 | a. This Public License applies for the term of the Copyright and 359 | Similar Rights licensed here. However, if You fail to comply with 360 | this Public License, then Your rights under this Public License 361 | terminate automatically. 362 | 363 | b. Where Your right to use the Licensed Material has terminated under 364 | Section 6(a), it reinstates: 365 | 366 | 1. automatically as of the date the violation is cured, provided 367 | it is cured within 30 days of Your discovery of the 368 | violation; or 369 | 370 | 2. upon express reinstatement by the Licensor. 371 | 372 | For the avoidance of doubt, this Section 6(b) does not affect any 373 | right the Licensor may have to seek remedies for Your violations 374 | of this Public License. 375 | 376 | c. For the avoidance of doubt, the Licensor may also offer the 377 | Licensed Material under separate terms or conditions or stop 378 | distributing the Licensed Material at any time; however, doing so 379 | will not terminate this Public License. 380 | 381 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 382 | License. 383 | 384 | 385 | Section 7 -- Other Terms and Conditions. 386 | 387 | a. The Licensor shall not be bound by any additional or different 388 | terms or conditions communicated by You unless expressly agreed. 389 | 390 | b. Any arrangements, understandings, or agreements regarding the 391 | Licensed Material not stated herein are separate from and 392 | independent of the terms and conditions of this Public License. 393 | 394 | 395 | Section 8 -- Interpretation. 396 | 397 | a. For the avoidance of doubt, this Public License does not, and 398 | shall not be interpreted to, reduce, limit, restrict, or impose 399 | conditions on any use of the Licensed Material that could lawfully 400 | be made without permission under this Public License. 401 | 402 | b. To the extent possible, if any provision of this Public License is 403 | deemed unenforceable, it shall be automatically reformed to the 404 | minimum extent necessary to make it enforceable. If the provision 405 | cannot be reformed, it shall be severed from this Public License 406 | without affecting the enforceability of the remaining terms and 407 | conditions. 408 | 409 | c. No term or condition of this Public License will be waived and no 410 | failure to comply consented to unless expressly agreed to by the 411 | Licensor. 412 | 413 | d. Nothing in this Public License constitutes or may be interpreted 414 | as a limitation upon, or waiver of, any privileges and immunities 415 | that apply to the Licensor or You, including from the legal 416 | processes of any jurisdiction or authority. 417 | 418 | ======================================================================= 419 | 420 | Creative Commons is not a party to its public 421 | licenses. Notwithstanding, Creative Commons may elect to apply one of 422 | its public licenses to material it publishes and in those instances 423 | will be considered the “Licensor.” The text of the Creative Commons 424 | public licenses is dedicated to the public domain under the CC0 Public 425 | Domain Dedication. Except for the limited purpose of indicating that 426 | material is shared under a Creative Commons public license or as 427 | otherwise permitted by the Creative Commons policies published at 428 | creativecommons.org/policies, Creative Commons does not authorize the 429 | use of the trademark "Creative Commons" or any other trademark or logo 430 | of Creative Commons without its prior written consent including, 431 | without limitation, in connection with any unauthorized modifications 432 | to any of its public licenses or any other arrangements, 433 | understandings, or agreements concerning use of licensed material. For 434 | the avoidance of doubt, this paragraph does not form part of the 435 | public licenses. 436 | 437 | Creative Commons may be contacted at creativecommons.org. 438 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PKU-Annual-Eat 2 | 3 | 一年过去了,你在白鲸食堂里花的钱都花在哪儿了? 4 | 5 | ## 项目简介 6 | 7 | > 项目的 idea 来源于 [Rose-max111](https://github.com/Rose-max111)。 8 | 9 | 本项目是一个用于统计白鲸大学学生校园卡消费情况的脚本。通过模拟登录大学校园卡网站,获取学生的校园卡消费记录,并通过数据可视化的方式展示。 10 | 11 | 本项目fork自[THU-Annual-Eat](https://github.com/leverimmy/THU-Annual-Eat),感谢原作者的贡献。 12 | 13 | ![demo](./demo.png) 14 | 15 | ## 使用方法 16 | 17 | ### 0. 获取account和hallticket 18 | 19 | 首先,登录校园卡账号后,在[白鲸大学校园卡网站](https://card.pku.edu.cn/user/user)获取你的`account`和`hallticket`。方法如下: 20 | 21 | ![card](./card.png) 22 | 23 | 点击`账号管理`,在弹出的页面中找到`账号`,复制其值。 24 | 25 | ![account](./account.png) 26 | 27 | `F12` 打开开发者工具,切换到`Network`标签页,然后`Ctrl+R`刷新页面,找到 `GetCardInfoByAccountNoParm` 这个请求,进入`Cookies`选项卡,复制其中`hallticket`字段的**value**,后面会用到。 28 | 29 | ![hallticket](./hallticket.png) 30 | 31 | ### 1. 安装依赖 32 | 33 | 本项目依赖于 `requests`、`matplotlib`,请确保你的 Python 环境中已经安装了这些库。 34 | 35 | ```bash 36 | pip install requests matplotlib 37 | ``` 38 | 39 | ### 2. 运行脚本 40 | 41 | ```bash 42 | python main.py 43 | ``` 44 | 45 | 首次运行时,请输入你的`account`和`hallticket`,会自动保存在 `config.json` 文件中。 46 | 47 | ### 3.(可选)修改配置 48 | 49 | 如果你想修改`account`或者`hallticket`,可以直接修改 `config.json` 文件。 50 | 51 | ```json 52 | { 53 | "account": "你的account", 54 | "hallticket": "你的hallticket" 55 | } 56 | ``` 57 | 58 | ## LICENSE 59 | 60 | 除非另有说明,本仓库的内容采用 [CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/) 许可协议。在遵守许可协议的前提下,您可以自由地分享、修改本文档的内容,但不得用于商业目的。 61 | 62 | 如果您认为文档的部分内容侵犯了您的合法权益,请联系项目维护者,我们会尽快删除相关内容。 63 | -------------------------------------------------------------------------------- /account.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuohaoyu/PKU-Annual-Eat/a83edcdcefe9f5dcfb3f546a062177f473402ec0/account.png -------------------------------------------------------------------------------- /backend/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, request, jsonify 2 | from flask_cors import CORS 3 | import json 4 | import requests 5 | from datetime import datetime 6 | import matplotlib.pyplot as plt 7 | import io 8 | import base64 9 | app = Flask(__name__) 10 | CORS(app) 11 | 12 | def analyze_special_transactions(transactions): 13 | # Filter dining transactions (negative amounts) 14 | dining_transactions = [t for t in transactions if t["TRANAMT"] < 0] 15 | 16 | # Early birds (5:00-7:00) 17 | early_birds = [t for t in dining_transactions if 5 <= datetime.strptime(t["OCCTIME"], "%Y-%m-%d %H:%M:%S").hour < 7] 18 | early_birds.sort(key=lambda x: datetime.strptime(x["OCCTIME"], "%Y-%m-%d %H:%M:%S")) 19 | 20 | # Night owls (21:00-23:59) 21 | night_owls = [t for t in dining_transactions if datetime.strptime(t["OCCTIME"], "%Y-%m-%d %H:%M:%S").hour >= 21] 22 | night_owls.sort(key=lambda x: datetime.strptime(x["OCCTIME"], "%Y-%m-%d %H:%M:%S"), reverse=True) 23 | 24 | # Big spenders (top 5 largest transactions) 25 | big_spenders = sorted(dining_transactions, key=lambda x: abs(x["TRANAMT"]), reverse=True) 26 | 27 | return { 28 | "early_birds": early_birds[:5], 29 | "night_owls": night_owls[:5], 30 | "big_spenders": big_spenders[:5] 31 | } 32 | 33 | @app.route('/api/report', methods=['POST']) 34 | def generate_report(): 35 | try: 36 | data = request.json 37 | account = data.get('account') 38 | hallticket = data.get('hallticket') 39 | session_id = data.get('sessionId') 40 | sdate = data.get('sdate') 41 | edate = data.get('edate') 42 | 43 | if not all([account, hallticket, session_id, sdate, edate]): 44 | logger.error("Missing required parameters") 45 | return jsonify({'error': '请提供完整的信息'}), 400 46 | 47 | # Call campus card API with all headers 48 | url = "https://card.pku.edu.cn/Report/GetPersonTrjn" 49 | headers = { 50 | 'Accept': 'application/json, text/javascript, */*; q=0.01', 51 | 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7,ja;q=0.6', 52 | 'Connection': 'keep-alive', 53 | 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 54 | 'Origin': 'https://card.pku.edu.cn', 55 | 'Referer': 'https://card.pku.edu.cn/Page/Page', 56 | 'Sec-Fetch-Dest': 'empty', 57 | 'Sec-Fetch-Mode': 'cors', 58 | 'Sec-Fetch-Site': 'same-origin', 59 | 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', 60 | 'X-Requested-With': 'XMLHttpRequest', 61 | 'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"', 62 | 'sec-ch-ua-mobile': '?0', 63 | 'sec-ch-ua-platform': '"macOS"' 64 | } 65 | 66 | cookies = { 67 | "hallticket": hallticket, 68 | "ASP.NET_SessionId": session_id 69 | } 70 | 71 | post_data = { 72 | "sdate": sdate, 73 | "edate": edate, 74 | "account": account, 75 | "page": "1", 76 | "rows": "9000", 77 | } 78 | 79 | response = requests.post(url, headers=headers, cookies=cookies, data=post_data) 80 | 81 | if not response.ok: 82 | return jsonify({'error': '获取数据失败'}), 400 83 | 84 | data = response.json() 85 | if not data.get('rows'): 86 | return jsonify({'error': '未找到交易记录'}), 404 87 | 88 | transactions = data["rows"] 89 | 90 | # Filter dining transactions 91 | dining_transactions = [t for t in transactions if float(t["TRANAMT"]) < 0] 92 | 93 | # Calculate consumption by location 94 | all_data = {} 95 | for item in dining_transactions: 96 | try: 97 | merc_name = item["MERCNAME"].strip() 98 | if merc_name in all_data: 99 | all_data[merc_name] += abs(float(item["TRANAMT"])) 100 | else: 101 | all_data[merc_name] = abs(float(item["TRANAMT"])) 102 | except Exception: 103 | continue 104 | 105 | all_data = {k: round(v, 2) for k, v in all_data.items()} 106 | 107 | # Generate summary 108 | summary = { 109 | "total_categories": len(all_data), 110 | "total_transactions": len(dining_transactions), 111 | "total_amount": round(sum(all_data.values()), 2) 112 | } 113 | 114 | # Analyze special transactions 115 | special_transactions = analyze_special_transactions(transactions) 116 | 117 | return jsonify({ 118 | 'summary': summary, 119 | 'consumption_data': all_data, 120 | 'transactions': dining_transactions, 121 | 'special_transactions': special_transactions 122 | }) 123 | 124 | except Exception as e: 125 | return jsonify({'error': str(e)}), 500 126 | 127 | if __name__ == '__main__': 128 | app.run(debug=True) -------------------------------------------------------------------------------- /backend/requirements.txt: -------------------------------------------------------------------------------- 1 | flask==3.0.0 2 | flask-cors==4.0.0 3 | requests==2.31.0 4 | matplotlib==3.8.2 -------------------------------------------------------------------------------- /card.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuohaoyu/PKU-Annual-Eat/a83edcdcefe9f5dcfb3f546a062177f473402ec0/card.png -------------------------------------------------------------------------------- /demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuohaoyu/PKU-Annual-Eat/a83edcdcefe9f5dcfb3f546a062177f473402ec0/demo.png -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | services: 3 | web: 4 | build: . 5 | ports: 6 | - "2380:80" 7 | volumes: 8 | - ./backend:/app/backend 9 | environment: 10 | - FLASK_ENV=development -------------------------------------------------------------------------------- /frontend/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 百鲸大学食堂年度总结 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pku-dining-report", 3 | "version": "1.0.0", 4 | "type": "module", 5 | "scripts": { 6 | "dev": "vite", 7 | "build": "vite build", 8 | "preview": "vite preview" 9 | }, 10 | "dependencies": { 11 | "vue": "^3.3.4", 12 | "flowbite": "^2.3.0", 13 | "echarts": "^5.4.3" 14 | }, 15 | "devDependencies": { 16 | "@vitejs/plugin-vue": "^4.2.3", 17 | "autoprefixer": "^10.4.14", 18 | "postcss": "^8.4.24", 19 | "tailwindcss": "^3.3.2", 20 | "vite": "^4.3.9" 21 | } 22 | } -------------------------------------------------------------------------------- /frontend/postcss.config.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } -------------------------------------------------------------------------------- /frontend/src/App.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | -------------------------------------------------------------------------------- /frontend/src/components/ConfigForm.vue: -------------------------------------------------------------------------------- 1 | 253 | 254 | 258 | 259 | -------------------------------------------------------------------------------- /frontend/src/components/ConsumptionReport.vue: -------------------------------------------------------------------------------- 1 | 206 | 207 | -------------------------------------------------------------------------------- /frontend/src/components/EatingTimeHeatmap.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | -------------------------------------------------------------------------------- /frontend/src/components/LocationAnalysis.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | -------------------------------------------------------------------------------- /frontend/src/components/TransactionCard.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | -------------------------------------------------------------------------------- /frontend/src/components/UnusualTransactions.vue: -------------------------------------------------------------------------------- 1 | 97 | 98 | -------------------------------------------------------------------------------- /frontend/src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /frontend/src/main.js: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import App from './App.vue' 3 | import './index.css' 4 | 5 | createApp(App).mount('#app') -------------------------------------------------------------------------------- /frontend/src/services/cardApi.js: -------------------------------------------------------------------------------- 1 | // Option 2: Using our backend as a proxy 2 | const baseUrl = '/api/proxy/card' 3 | 4 | export async function fetchTransactions(account, hallticket, startDate, endDate) { 5 | const params = new URLSearchParams({ 6 | sdate: startDate, 7 | edate: endDate, 8 | account: account, 9 | }) 10 | 11 | try { 12 | const response = await fetch(`/api/proxy/card?${params.toString()}`, { 13 | method: 'GET', 14 | headers: { 15 | 'Accept': 'application/json', 16 | 'hallticket': hallticket 17 | } 18 | }) 19 | 20 | if (!response.ok) { 21 | const error = await response.json() 22 | throw new Error(error.error || 'Failed to fetch transactions') 23 | } 24 | 25 | const data = await response.json() 26 | 27 | // The PKU card system returns data in {rows: [...]} format 28 | const transactions = data.rows || [] 29 | return processTransactions(transactions) 30 | } catch (error) { 31 | throw new Error(`获取数据失败: ${error.message}`) 32 | } 33 | } 34 | 35 | function processTransactions(data) { 36 | if (!Array.isArray(data)) { 37 | throw new Error('Invalid data format') 38 | } 39 | 40 | // Filter dining transactions (negative amounts) 41 | const diningTransactions = data.filter(t => t.TRANAMT < 0) 42 | 43 | // Calculate summary 44 | const summary = { 45 | total_amount: Math.abs(diningTransactions.reduce((sum, t) => sum + t.TRANAMT, 0)).toFixed(2), 46 | total_transactions: diningTransactions.length, 47 | total_categories: new Set(diningTransactions.map(t => t.MERCNAME.trim())).size 48 | } 49 | 50 | return { 51 | transactions: diningTransactions, 52 | summary 53 | } 54 | } -------------------------------------------------------------------------------- /frontend/tailwind.config.cjs: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [ 4 | "./index.html", 5 | "./src/**/*.{vue,js,ts,jsx,tsx}", 6 | "./node_modules/flowbite/**/*.js" 7 | ], 8 | theme: { 9 | extend: {}, 10 | }, 11 | plugins: [ 12 | require('flowbite/plugin') 13 | ], 14 | } -------------------------------------------------------------------------------- /frontend/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import vue from '@vitejs/plugin-vue' 3 | 4 | export default defineConfig({ 5 | plugins: [vue()], 6 | server: { 7 | host: '0.0.0.0', 8 | port: 3000 9 | }, 10 | build: { 11 | outDir: 'dist' 12 | } 13 | }) -------------------------------------------------------------------------------- /hallticket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuohaoyu/PKU-Annual-Eat/a83edcdcefe9f5dcfb3f546a062177f473402ec0/hallticket.png -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import json 2 | import matplotlib.pyplot as plt 3 | import requests 4 | import platform 5 | from datetime import datetime 6 | 7 | account = "" 8 | hallticket = "" 9 | all_data = dict() 10 | 11 | if __name__ == "__main__": 12 | # 读入账户信息 13 | try: 14 | with open("config.json", "r", encoding='utf-8') as f: 15 | config = json.load(f) 16 | account = config["account"] 17 | hallticket = config["hallticket"] 18 | except Exception as e: 19 | print("账户信息读取失败,请重新输入") 20 | account = input("请输入account: ") 21 | hallticket = input("请输入hallticket: ") 22 | with open("config.json", "w", encoding='utf-8') as f: 23 | json.dump({"account": account, "hallticket": hallticket}, f, indent=4) 24 | 25 | # 默认日期 26 | default_sdate = "2024-01-01" 27 | default_edate = "2024-12-31" 28 | 29 | def is_valid_date(date_str): 30 | """检查日期是否符合YYYY-MM-DD格式且为有效日期""" 31 | try: 32 | datetime.strptime(date_str, "%Y-%m-%d") 33 | return True 34 | except ValueError: 35 | return False 36 | def format_date(date_str): 37 | """确保日期始终以两位数显示月份和日期""" 38 | date_obj = datetime.strptime(date_str, "%Y-%m-%d") 39 | return date_obj.strftime("%Y-%m-%d") # 格式化为YYYY-MM-DD 40 | 41 | # 获取用户输入的开始日期 42 | sdate = input("请输入开始日期(YYYY-MM-DD,默认2024-01-01): ").strip() 43 | if not is_valid_date(sdate): 44 | print(f"输入的开始日期无效,使用默认值: {default_sdate}") 45 | sdate = default_sdate 46 | else: 47 | sdate = format_date(sdate) 48 | 49 | # 获取用户输入的结束日期 50 | edate = input("请输入结束日期(YYYY-MM-DD,默认2024-12-31): ").strip() 51 | if not is_valid_date(edate): 52 | print(f"输入的结束日期无效,使用默认值: {default_edate}") 53 | edate = default_edate 54 | else: 55 | edate = format_date(edate) 56 | 57 | print(f"开始日期: {sdate}, 结束日期: {edate}") 58 | # 发送请求,得到加密后的字符串 59 | url = f"https://card.pku.edu.cn/Report/GetPersonTrjn" 60 | cookie = { 61 | "hallticket": hallticket, 62 | } 63 | post_data = { 64 | "sdate": sdate, 65 | "edate": edate, 66 | "account": account, 67 | "page": "1", 68 | "rows": "9000", 69 | } 70 | response = requests.post(url, cookies=cookie, data=post_data) 71 | 72 | data = json.loads(response.text)["rows"] 73 | 74 | # 整理数据 75 | for item in data: 76 | try: 77 | if(item["TRANAMT"] < 0): 78 | if item["MERCNAME"].strip() in all_data: 79 | all_data[item["MERCNAME"].strip()] += abs(item["TRANAMT"]) 80 | else: 81 | all_data[item["MERCNAME"].strip()] = abs(item["TRANAMT"]) 82 | except Exception as e: 83 | pass 84 | all_data = {k: round(v, 2) for k, v in all_data.items()} 85 | summary = f"统计总种类数:{len(all_data)}\n总消费次数:{len(data)}\n总消费金额:{round(sum(all_data.values()), 1)}" 86 | print(summary) 87 | # 输出结果 88 | all_data = dict(sorted(all_data.items(), key=lambda x: x[1], reverse=False)) 89 | if len(all_data) > 50: 90 | # Get top 10 and bottom 10 91 | top_10 = dict(list(all_data.items())[:20]) 92 | bottom_10 = dict(list(all_data.items())[-20:]) 93 | # Add a separator between top and bottom groups 94 | middle_values = list(all_data.values())[20:-20] 95 | separator = {"中间省略": round(sum(middle_values), 2)} # Sum of middle values 96 | all_data = {**top_10, **separator, **bottom_10} 97 | 98 | if platform.system() == "Darwin": 99 | plt.rcParams['font.sans-serif'] = ['Arial Unicode MS'] 100 | elif platform.system() == "Linux": 101 | plt.rcParams['font.family'] = ['Droid Sans Fallback', 'DejaVu Sans'] 102 | else: 103 | plt.rcParams['font.sans-serif'] = ['SimHei'] 104 | 105 | plt.figure(figsize=(12, len(all_data) / 66 * 18)) 106 | plt.barh(list(all_data.keys()), list(all_data.values())) 107 | for index, value in enumerate(list(all_data.values())): 108 | plt.text(value + 0.01 * max(all_data.values() or [0]), 109 | index, 110 | str(value), 111 | va='center') 112 | 113 | # plt.tight_layout() 114 | plt.xlim(0, 1.2 * max(all_data.values() or [0])) 115 | plt.title(f"白鲸大学食堂消费情况\n({post_data['sdate']} 至 {post_data['edate']})") 116 | plt.xlabel("消费金额(元)") 117 | plt.text(0.8, 0.1, summary, ha='center', va='center', transform=plt.gca().transAxes) 118 | plt.savefig("result.png",bbox_inches='tight') 119 | plt.show() 120 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Start Flask backend 5 | cd /app/backend 6 | python app.py & 7 | 8 | # Start Caddy in foreground 9 | exec caddy run --config /etc/caddy/Caddyfile --adapter caddyfile --------------------------------------------------------------------------------