Skip to content

Commit

Permalink
Merge branch 'refs/heads/upstream'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/run_data_sync.yml
#	README-CN.md
#	README.md
#	assets/github.svg
#	assets/github_2024.svg
#	assets/grid.svg
#	assets/year_2024.svg
#	src/static/activities.json
#	yarn.lock
  • Loading branch information
ben-29 committed Feb 3, 2025
2 parents 4bf2b14 + ceccf2b commit e32fa8d
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 4,023 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,8 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'

- uses: pnpm/action-setup@v3
name: Install pnpm
with:
version: 8
run_install: false
- name: Enable corepack
run: npm install -g corepack@latest && corepack enable pnpm

- name: Get pnpm store directory
shell: bash
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/run_data_sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,13 @@ jobs:
- name: Make svg GitHub profile
if: env.RUN_TYPE != 'pass'
run: |
python run_page/gen_svg.py --from-db --title "${{ env.TITLE }}" --type github --athlete "${{ env.ATHLETE }}" --special-distance 10 --special-distance2 20 --special-color yellow --special-color2 red --output assets/github.svg --use-localtime --min-distance 0.5
python run_page/gen_svg.py --from-db --title "${{ env.TITLE }}" --type github --github-style "align-firstday" --athlete "${{ env.ATHLETE }}" --special-distance 10 --special-distance2 20 --special-color yellow --special-color2 red --output assets/github.svg --use-localtime --min-distance 0.5
python run_page/gen_svg.py --from-db --title "${{ env.TITLE_GRID }}" --type grid --athlete "${{ env.ATHLETE }}" --output assets/grid.svg --special-color yellow --special-color2 red --special-distance 20 --special-distance2 40 --use-localtime --min-distance "${{ env.MIN_GRID_DISTANCE }}"
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") Workouts" --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
python run_page/gen_svg.py --from-db --year $(date +"%Y") --language zh_CN --title "$(date +"%Y") Workouts" --type github --github-style "align-firstday" --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
# if you want use the style:the start day of each year always aligns with Monday. please use the following script:
# python run_page/gen_svg.py --from-db --title "${{ env.TITLE }}" --type github --github-style "align-monday" --athlete "${{ env.ATHLETE }}" --special-distance 10 --special-distance2 20 --special-color yellow --special-color2 red --output assets/github.svg --use-localtime --min-distance 0.5
# python run_page/gen_svg.py --from-db --year $(date +"%Y") --language zh_CN --title "$(date +"%Y") Running" --type github --github-style "align-monday" --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'
Expand Down
16 changes: 7 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
FROM python:3.10.5-slim AS develop-py
WORKDIR /root/running_page
COPY ./requirements.txt /root/running_page/requirements.txt
# Add proxy for apt.
# ENV http_proxy http://ip_address:port
# ENV https_proxy http://ip_address:port
RUN apt-get update \
RUN sed -i 's@http://archive.ubuntu.com/ubuntu/@https://mirrors.tuna.tsinghua.edu.cn/ubuntu/@g' /etc/apt/sources.list \
&& sed -i 's@http://security.ubuntu.com/ubuntu/@https://mirrors.tuna.tsinghua.edu.cn/ubuntu/@g' /etc/apt/sources.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends git \
&& apt-get purge -y --auto-remove \
&& rm -rf /var/lib/apt/lists/* \
Expand All @@ -17,10 +16,9 @@ FROM node:18 AS develop-node
WORKDIR /root/running_page
COPY ./package.json /root/running_page/package.json
COPY ./pnpm-lock.yaml /root/running_page/pnpm-lock.yaml
RUN npm config rm proxy&&npm config set registry https://registry.npmjs.org/ \
&&npm install -g corepack \
&&corepack enable \
&&yarn install
RUN npm config set registry https://registry.npmmirror.com \
&& corepack enable \
&& COREPACK_NPM_REGISTRY=https://registry.npmmirror.com pnpm install

FROM develop-py AS data
ARG app
Expand Down Expand Up @@ -61,7 +59,7 @@ RUN python3 run_page/gen_svg.py --from-db --title "my running page" --type grid
FROM develop-node AS frontend-build
WORKDIR /root/running_page
COPY --from=data /root/running_page /root/running_page
RUN yarn run build
RUN pnpm run build

FROM nginx:alpine AS web
COPY --from=frontend-build /root/running_page/dist /usr/share/nginx/html/
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 yihong
Copyright (c) 2025 yihong

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 10 additions & 0 deletions run_page/gen_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ def main():
help="activities db file",
)

args_parser.add_argument(
"--github-style",
dest="github_style",
metavar="GITHUB_STYLE",
type=str,
default="align-firstday",
help='github svg style; "align-firstday", "align-monday" (default: "align-firstday").',
)

for _, drawer in drawers.items():
drawer.create_args(args_parser)

Expand Down Expand Up @@ -246,6 +255,7 @@ def main():
p.drawer_type = "plain" if is_circular else "title"
if args.type == "github":
p.height = 55 + p.years.real_year * 43
p.github_style = args.github_style
# for special circular
if is_circular:
years = p.years.all()[:]
Expand Down
33 changes: 26 additions & 7 deletions run_page/gpxtrackposter/github_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,26 @@ def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY):
year_length_style = f"font-size:{110 * 3.0 / 80.0}px; font-family:Arial;"
month_names_style = f"font-size:2.5px; font-family:Arial"
total_length_year_dict = self.poster.total_length_year_dict

is_align_monday = self.poster.github_style == "align-monday"
for year in range(self.poster.years.from_year, self.poster.years.to_year + 1)[
::-1
]:
start_date_weekday, _ = calendar.monthrange(year, 1)
github_rect_first_day = datetime.date(year, 1, 1)
# Github profile the first day start from the last Monday of the last year or the first Monday of this year
# It depands on if the first day of this year is Monday or not.
github_rect_day = github_rect_first_day + datetime.timedelta(
-start_date_weekday
)

# default GitHub svg style: the start day of each year always aligns with first day.
github_rect_day = github_rect_first_day
first_day_weekday = github_rect_first_day.weekday()

if is_align_monday:
# This is an earlier GitHub style: the start day of each year always aligns with Monday.
# If you want to use this, please add the command-line argument "--github-style align-monday" .
github_rect_day = github_rect_first_day + datetime.timedelta(
-start_date_weekday
)
first_day_weekday = 0

year_length = total_length_year_dict.get(year, 0)
year_length = format_float(self.poster.m2u(year_length))

Expand Down Expand Up @@ -110,10 +120,19 @@ def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY):

rect_x = 10.0
dom = (2.6, 2.6)

# add every day of this year for 53 weeks and per week has 7 days
for i in range(54):
rect_y = offset.y + year_size + 2
for j in range(7):
# the first day of the first week of the year may not Monday
# so we need to skip some empty spaces
if i == 0:
rect_y = offset.y + year_size + 2 + 3.5 * first_day_weekday
else:
# the first day of the n week (n >1) must be Monday
# so set first_day_weekday = 0
first_day_weekday = 0
rect_y = offset.y + year_size + 2
for j in range(7 - first_day_weekday):
if int(github_rect_day.year) > year:
break
rect_y += 3.5
Expand Down
1 change: 1 addition & 0 deletions run_page/gpxtrackposter/poster.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __init__(self):
self.trans = None
self.set_language(None)
self.tc_offset = datetime.now(pytz.timezone("Asia/Shanghai")).utcoffset()
self.github_style = "align-firstday"

def set_language(self, language):
if language:
Expand Down
38 changes: 33 additions & 5 deletions run_page/joyrun_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def login_by_phone(self):

def get_runs_records_ids(self):
payload = {
"year": 0,
"year": 0, # as of the "year". when set to 2023, it means fetch records during currentYear ~ 2023. set to 0 means fetch all.
}
r = self.session.post(
f"{self.base_url}/userRunList.aspx",
Expand Down Expand Up @@ -363,18 +363,37 @@ def parse_raw_data_to_nametuple(self, run_data, old_gpx_ids, with_gpx=False):
}
return namedtuple("x", d.keys())(*d.values())

def get_all_joyrun_tracks(self, old_tracks_ids, with_gpx=False):
def get_all_joyrun_tracks(self, old_tracks_ids, with_gpx=False, threshold=10):
run_ids = self.get_runs_records_ids()
old_tracks_ids = [int(i) for i in old_tracks_ids if i.isdigit()]

old_gpx_ids = os.listdir(GPX_FOLDER)
old_gpx_ids = [i.split(".")[0] for i in old_gpx_ids if not i.startswith(".")]
new_run_ids = list(set(run_ids) - set(old_tracks_ids))
tracks = []
seen_runs = {} # Dictionary to keep track of unique runs with start time as key
for i in new_run_ids:
run_data = self.get_single_run_record(i)
track = self.parse_raw_data_to_nametuple(run_data, old_gpx_ids, with_gpx)
tracks.append(track)
start_time = datetime.fromtimestamp(run_data["runrecord"]["starttime"])
distance = run_data["runrecord"]["meter"]

is_duplicate = False
for seen_start in list(seen_runs.keys()):
if abs((start_time - seen_start).total_seconds()) <= threshold:
if distance > seen_runs[seen_start]["distance"]:
seen_runs[seen_start] = {
"run_data": run_data,
"distance": distance,
}
is_duplicate = True
break
if not is_duplicate:
seen_runs[start_time] = {"run_data": run_data, "distance": distance}
for run in seen_runs.values():
track = self.parse_raw_data_to_nametuple(
run["run_data"], old_gpx_ids, with_gpx
)
tracks.append(track)
return tracks


Expand Down Expand Up @@ -479,6 +498,13 @@ def _generate_svg_profile(athlete, min_grid_distance):
action="store_true",
help="from uid and sid for download datas",
)
parser.add_argument(
"--threshold",
dest="threshold",
help="threshold in seconds to consider runs as duplicates",
type=int,
default=10,
)
options = parser.parse_args()
if options.from_uid_sid:
j = Joyrun.from_uid_sid(
Expand All @@ -494,7 +520,9 @@ def _generate_svg_profile(athlete, min_grid_distance):

generator = Generator(SQL_FILE)
old_tracks_ids = generator.get_old_tracks_ids()
tracks = j.get_all_joyrun_tracks(old_tracks_ids, options.with_gpx)
tracks = j.get_all_joyrun_tracks(
old_tracks_ids, options.with_gpx, options.threshold
)
generator.sync_from_app(tracks)
activities_list = generator.load()
with open(JSON_FILE, "w") as f:
Expand Down
Loading

0 comments on commit e32fa8d

Please sign in to comment.