-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Richer activity title with more sport types and locations #733
Merged
yihong0618
merged 10 commits into
yihong0618:master
from
NaturezzZ:better-activity-name
Nov 24, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d95b27a
show activity name with more detailed type
NaturezzZ 7d27837
Added a flag for whether to turn on rich activity titles
NaturezzZ b1c436c
reformat
NaturezzZ 55b7bb9
nits
NaturezzZ d34f4d9
use title from garmin
NaturezzZ a3d0314
fix duplicated gpx download in fit mode
NaturezzZ 4b5bbdd
add column if not exist
NaturezzZ c86d040
nits
NaturezzZ d9ae3ac
change track fallback name to ''
NaturezzZ bed31c1
nits
NaturezzZ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,16 @@ | |
|
||
import geopy | ||
from geopy.geocoders import Nominatim | ||
from sqlalchemy import Column, Float, Integer, Interval, String, create_engine | ||
from sqlalchemy import ( | ||
Column, | ||
Float, | ||
Integer, | ||
Interval, | ||
String, | ||
create_engine, | ||
inspect, | ||
text, | ||
) | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
|
@@ -29,6 +38,7 @@ def randomword(): | |
"distance", | ||
"moving_time", | ||
"type", | ||
"subtype", | ||
"start_date", | ||
"start_date_local", | ||
"location_country", | ||
|
@@ -47,6 +57,7 @@ class Activity(Base): | |
moving_time = Column(Interval) | ||
elapsed_time = Column(Interval) | ||
type = Column(String) | ||
subtype = Column(String) | ||
start_date = Column(String) | ||
start_date_local = Column(String) | ||
location_country = Column(String) | ||
|
@@ -106,6 +117,7 @@ def update_or_create_activity(session, run_activity): | |
moving_time=run_activity.moving_time, | ||
elapsed_time=run_activity.elapsed_time, | ||
type=run_activity.type, | ||
subtype=run_activity.subtype, | ||
start_date=run_activity.start_date, | ||
start_date_local=run_activity.start_date_local, | ||
location_country=location_country, | ||
|
@@ -123,6 +135,7 @@ def update_or_create_activity(session, run_activity): | |
activity.moving_time = run_activity.moving_time | ||
activity.elapsed_time = run_activity.elapsed_time | ||
activity.type = run_activity.type | ||
activity.subtype = run_activity.subtype | ||
activity.average_heartrate = run_activity.average_heartrate | ||
activity.average_speed = float(run_activity.average_speed) | ||
activity.summary_polyline = ( | ||
|
@@ -135,10 +148,37 @@ def update_or_create_activity(session, run_activity): | |
return created | ||
|
||
|
||
def add_missing_columns(engine, model): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
inspector = inspect(engine) | ||
table_name = model.__tablename__ | ||
columns = {col["name"] for col in inspector.get_columns(table_name)} | ||
missing_columns = [] | ||
|
||
for column in model.__table__.columns: | ||
if column.name not in columns: | ||
missing_columns.append(column) | ||
if missing_columns: | ||
with engine.connect() as conn: | ||
for column in missing_columns: | ||
column_type = str(column.type) | ||
conn.execute( | ||
text( | ||
f"ALTER TABLE {table_name} ADD COLUMN {column.name} {column_type}" | ||
) | ||
) | ||
|
||
|
||
def init_db(db_path): | ||
engine = create_engine( | ||
f"sqlite:///{db_path}", connect_args={"check_same_thread": False} | ||
) | ||
Base.metadata.create_all(engine) | ||
session = sessionmaker(bind=engine) | ||
return session() | ||
|
||
# check missing columns | ||
add_missing_columns(engine, Activity) | ||
|
||
sm = sessionmaker(bind=engine) | ||
session = sm() | ||
# apply the changes | ||
session.commit() | ||
return session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new column is not present in the SQLite file if the user syncs before this pull request. Users may face difficulties adding this column manually, or else syncing will fail. Perhaps you should add instructions in the readme or include a script to assist users in doing this easily, as seen in this ref1 ref2. There might be a simpler solution that I'm unaware of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The db checks whether the new column exists after commit c86d040. If any column defined in
class Activity
does not exist, it will add a new column in data.db.