Skip to content

Commit

Permalink
feat: pargent (#738)
Browse files Browse the repository at this point in the history
* feat: pargent

Signed-off-by: yihong0618 <zouzou0208@gmail.com>

* fix: add requirements duckdb

Signed-off-by: yihong0618 <zouzou0208@gmail.com>

---------

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
  • Loading branch information
yihong0618 authored Nov 19, 2024
1 parent 46473b6 commit 058a222
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 4 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/run_data_sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ env:
TITLE: Yihong0618 Running
MIN_GRID_DISTANCE: 10 # change min distance here
TITLE_GRID: Over 10km Runs # also here
GITHUB_NAME: "action@github.com" # default Actions bot you can change it to yours
GITHUB_EMAIL: "GitHub Action" # default Actions bot you can change it to yours

# IGNORE_BEFORE_SAVING: True # if you want to ignore some data before saving, set this to True
IGNORE_START_END_RANGE: 10 # Unit meter
Expand All @@ -41,6 +39,7 @@ env:
SAVE_DATA_IN_GITHUB_CACHE: false # if you deploy in the vercal, check the README
DATA_CACHE_PREFIX: 'track_data'
BUILD_GH_PAGES: true # If you do not need GitHub Page please set it to `false`
SAVE_TO_PARQENT: true # If you want to save the data to the repo, set it to `true`

jobs:
sync:
Expand Down Expand Up @@ -210,11 +209,17 @@ jobs:
python run_page/gen_svg.py --from-db --type circular --use-localtime
python run_page/gen_svg.py --from-db --year $(date +"%Y") --language zh_CN --title "$(date +"%Y") Running" --type github --athlete "${{ env.ATHLETE }}" --special-distance 10 --special-distance2 20 --special-color yellow --special-color2 red --output assets/github_$(date +"%Y").svg --use-localtime --min-distance 0.5
- name: Save data to parqent
if: env.SAVE_TO_PARQENT == 'true'
run: |
pip install duckdb
python run_page/save_to_parqent.py
- name: Push new runs
if: env.SAVE_DATA_IN_GITHUB_CACHE != 'true'
run: |
git config --local user.email "${{ env.GITHUB_EMAIL }}"
git config --local user.name "${{ env.GITHUB_NAME }}"
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m 'update new runs' || echo "nothing to commit"
git push || echo "nothing to push"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ garmin-fit-sdk
haversine==2.8.0
garth
pycryptodome
duckdb
101 changes: 101 additions & 0 deletions run_page/save_to_parqent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import duckdb

with duckdb.connect() as conn:
conn.install_extension("sqlite")
conn.load_extension("sqlite")
conn.sql("ATTACH 'run_page/data.db' (TYPE SQLITE);USE data;")
conn.sql(
"COPY (SELECT * FROM activities) TO 'run_page/data.parquet' (FORMAT PARQUET);"
)

"""
examples:
duckdb.sql("select regexp_extract(location_country, '[\u4e00-\u9fa5]{2,}(εΈ‚|θ‡ͺ治州|η‰Ήεˆ«θ‘Œζ”ΏεŒΊ)') as run_location, concat(try_cast(sum(distance/1000) as integer)::varchar,' km') as run_distance from read_parquet('https://github.com/yihong0618/run/raw/refs/heads/master/run_page/data.parquet') where run_location is not NULL group by run_location order by sum(distance) desc;").show(max_rows=50)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ run_location β”‚ run_distance β”‚
β”‚ varchar β”‚ varchar β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ ε€§θΏžεΈ‚ β”‚ 9328 km β”‚
β”‚ ζ²ˆι˜³εΈ‚ β”‚ 2030 km β”‚
β”‚ εŒ—δΊ¬εΈ‚ β”‚ 61 km β”‚
β”‚ ι•Ώζ²™εΈ‚ β”‚ 24 km β”‚
β”‚ ζ‰¬ε·žεΈ‚ β”‚ 21 km β”‚
β”‚ η›˜ι”¦εΈ‚ β”‚ 21 km β”‚
β”‚ ηƒŸε°εΈ‚ β”‚ 21 km β”‚
β”‚ δΈŠζ΅·εΈ‚ β”‚ 12 km β”‚
β”‚ εŒ—δΉε·žεΈ‚ β”‚ 7 km β”‚
β”‚ δΈΉδΈœεΈ‚ β”‚ 5 km β”‚
β”‚ η“¦ζˆΏεΊ—εΈ‚ β”‚ 4 km β”‚
β”‚ η«Ήη”°εΈ‚ β”‚ 3 km β”‚
β”‚ δΌŠδΈ‡ι‡ŒεΈ‚ β”‚ 2 km β”‚
β”‚ ι•Ώζ˜₯εΈ‚ β”‚ 1 km β”‚
β”‚ ι”¦ε·žεΈ‚ β”‚ 1 km β”‚
β”‚ β”‚ 0 km β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 16 rows 2 columns β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
duckdb.sql("select start_date_local, distance, name, location_country from read_parquet('https://github.com/yihong0618/run/raw/refs/heads/master/run_page/data.parquet') order by run_id desc limit 1;")
duckdb.sql("select start_date_local[:4] as year, sum(distance/1000)::integer from read_parquet('https://github.com/yihong0618/run/raw/refs/heads/master/run_page/data.parquet') group by year order by year desc;").show(max_rows=50)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ year β”‚ CAST(sum((distance / 1000)) AS INTEGER) β”‚
β”‚ varchar β”‚ int32 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 2024 β”‚ 1605 β”‚
β”‚ 2023 β”‚ 696 β”‚
β”‚ 2022 β”‚ 758 β”‚
β”‚ 2021 β”‚ 1244 β”‚
β”‚ 2020 β”‚ 1284 β”‚
β”‚ 2019 β”‚ 1344 β”‚
β”‚ 2018 β”‚ 405 β”‚
β”‚ 2017 β”‚ 964 β”‚
β”‚ 2016 β”‚ 901 β”‚
β”‚ 2015 β”‚ 436 β”‚
β”‚ 2014 β”‚ 823 β”‚
β”‚ 2013 β”‚ 790 β”‚
β”‚ 2012 β”‚ 387 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 13 rows 2 columns β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
duckdb.sql("SELECT concat(try_cast(distance/1000 as integer)::varchar,' km') as distance_km,count(*) FROM read_parquet('https://github.com/yihong0618/run/raw/refs/heads/master/run_page/data.parquet') GROUP BY distance_km order by count(*) desc;").show(max_rows=50)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ distance_km β”‚ count_star() β”‚
β”‚ varchar β”‚ int64 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 2 km β”‚ 706 β”‚
β”‚ 3 km β”‚ 639 β”‚
β”‚ 1 km β”‚ 493 β”‚
β”‚ 5 km β”‚ 391 β”‚
β”‚ 4 km β”‚ 337 β”‚
β”‚ 6 km β”‚ 164 β”‚
β”‚ 10 km β”‚ 84 β”‚
β”‚ 8 km β”‚ 55 β”‚
β”‚ 7 km β”‚ 54 β”‚
β”‚ 0 km β”‚ 29 β”‚
β”‚ 12 km β”‚ 25 β”‚
β”‚ 11 km β”‚ 17 β”‚
β”‚ 9 km β”‚ 17 β”‚
β”‚ 15 km β”‚ 15 β”‚
β”‚ 21 km β”‚ 8 β”‚
β”‚ 16 km β”‚ 7 β”‚
β”‚ 14 km β”‚ 6 β”‚
β”‚ 20 km β”‚ 6 β”‚
β”‚ 17 km β”‚ 4 β”‚
β”‚ 18 km β”‚ 3 β”‚
β”‚ 19 km β”‚ 2 β”‚
β”‚ 13 km β”‚ 2 β”‚
β”‚ 43 km β”‚ 2 β”‚
β”‚ 24 km β”‚ 1 β”‚
β”‚ 41 km β”‚ 1 β”‚
β”‚ 28 km β”‚ 1 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 26 rows 2 columns β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
"""

0 comments on commit 058a222

Please sign in to comment.