feat: Initial commit of FitTrack_GarminSync project

This commit is contained in:
2025-10-10 12:20:48 -07:00
parent d0e29fbeb4
commit 18f9f6fa18
229 changed files with 21035 additions and 42 deletions

View File

@@ -0,0 +1,37 @@
[alembic]
script_location = migrations/versions
sqlalchemy.url = sqlite:///data/garmin.db
[loggers]
keys = root,sqlalchemy,alembic
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
qualname =
[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
[logger_alembic]
level = WARN
handlers =
qualname = alembic
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S

View File

@@ -0,0 +1,36 @@
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('power_analysis', sa.Column('peak_power_1s', sa.Float(), nullable=True))
op.add_column('power_analysis', sa.Column('peak_power_5s', sa.Float(), nullable=True))
op.add_column('power_analysis', sa.Column('peak_power_20s', sa.Float(), nullable=True))
op.add_column('power_analysis', sa.Column('peak_power_300s', sa.Float(), nullable=True))
op.add_column('power_analysis', sa.Column('normalized_power', sa.Float(), nullable=True))
op.add_column('power_analysis', sa.Column('intensity_factor', sa.Float(), nullable=True))
op.add_column('power_analysis', sa.Column('training_stress_score', sa.Float(), nullable=True))
op.add_column('gearing_analysis', sa.Column('estimated_chainring_teeth', sa.Integer(), nullable=True))
op.add_column('gearing_analysis', sa.Column('estimated_cassette_teeth', sa.Integer(), nullable=True))
op.add_column('gearing_analysis', sa.Column('gear_ratio', sa.Float(), nullable=True))
op.add_column('gearing_analysis', sa.Column('gear_inches', sa.Float(), nullable=True))
op.add_column('gearing_analysis', sa.Column('development_meters', sa.Float(), nullable=True))
op.add_column('gearing_analysis', sa.Column('confidence_score', sa.Float(), nullable=True))
op.add_column('gearing_analysis', sa.Column('analysis_method', sa.String(), default="singlespeed_estimation"))
def downgrade():
op.drop_column('power_analysis', 'peak_power_1s')
op.drop_column('power_analysis', 'peak_power_5s')
op.drop_column('power_analysis', 'peak_power_20s')
op.drop_column('power_analysis', 'peak_power_300s')
op.drop_column('power_analysis', 'normalized_power')
op.drop_column('power_analysis', 'intensity_factor')
op.drop_column('power_analysis', 'training_stress_score')
op.drop_column('gearing_analysis', 'estimated_chainring_teeth')
op.drop_column('gearing_analysis', 'estimated_cassette_teeth')
op.drop_column('gearing_analysis', 'gear_ratio')
op.drop_column('gearing_analysis', 'gear_inches')
op.drop_column('gearing_analysis', 'development_meters')
op.drop_column('gearing_analysis', 'confidence_score')
op.drop_column('gearing_analysis', 'analysis_method')

View File

@@ -0,0 +1,23 @@
"""Add avg_heart_rate and calories columns to activities table
Revision ID: 20240822165438
Revises: 20240821150000
Create Date: 2024-08-22 16:54:38.123456
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '20240822165438'
down_revision = '20240821150000'
branch_labels = None
depends_on = None
def upgrade():
op.add_column('activities', sa.Column('avg_heart_rate', sa.Integer(), nullable=True))
op.add_column('activities', sa.Column('calories', sa.Integer(), nullable=True))
def downgrade():
op.drop_column('activities', 'avg_heart_rate')
op.drop_column('activities', 'calories')

View File

@@ -0,0 +1,31 @@
"""Add reprocessed column
Revision ID: 20240823000000
Revises: 20240822165438_add_hr_and_calories_columns
Create Date: 2025-08-23 00:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '20240823000000'
down_revision = '20240822165438_add_hr_and_calories_columns'
branch_labels = None
depends_on = None
def upgrade():
# Add reprocessed column to activities table
op.add_column('activities', sa.Column('reprocessed', sa.Boolean(), nullable=True, server_default='0'))
# Set default value for existing records
op.execute("UPDATE activities SET reprocessed = 0 WHERE reprocessed IS NULL")
# Make the column NOT NULL after setting default values
with op.batch_alter_table('activities') as batch_op:
batch_op.alter_column('reprocessed', existing_type=sa.Boolean(), nullable=False)
def downgrade():
# Remove reprocessed column
with op.batch_alter_table('activities') as batch_op:
batch_op.drop_column('reprocessed')

View File

@@ -0,0 +1,72 @@
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
# this is the Alembic Config object, which provides
# access to the values within the .ini file you've provided
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = None
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()