Skip to main content

library to extract, parse, and analyze F3 Nation SQL database data

Project description

f3-nation-data

A Python library for extracting, parsing, and analyzing F3 Nation SQL database data.

Overview

This library provides tools for working with F3 Nation database data, focusing on:

  • Users: PAX (participants) information
  • AOs: Areas of Operations (workout locations)
  • Beatdowns: Workout sessions and backblast data

Setup

Environment Variables

Before using this library, you must set the following environment variables to connect to your F3 Nation database:

export F3_NATION_USER="your_database_username"
export F3_NATION_PASSWORD="your_database_password"
export F3_NATION_HOST="your-database-host.com"
export F3_NATION_DATABASE="your_database_name"
export F3_NATION_PORT="3306"  # Optional, defaults to 3306

Security Note: Never commit database credentials to version control. Always use environment variables.

Usage

Example: Gather All Beatdowns for a Given Week

from f3_nation_data.database import get_sql_engine, create_session
from f3_nation_data.fetch import fetch_sql_beatdowns
from f3_nation_data.analytics import get_week_range

# Create database connection
engine = get_sql_engine()
session = create_session(engine)

# Get the current week's date range
week_start, week_end = get_week_range()

# Fetch all beatdowns for the week
beatdowns = fetch_sql_beatdowns(
    session,
    start_date=week_start.date(),
    end_date=week_end.date(),
)

for bd in beatdowns:
    print(f"AO: {bd.ao_id}, Date: {bd.bd_date}, Q: {bd.q_user_id}")

session.close()

Using Context Manager

from f3_nation_data.database import db_session
from f3_nation_data.models.sql import SqlUserModel

with db_session() as session:
    users = session.query(SqlUserModel).all()
    for user in users:
        print(user.user_id, user.user_name)
    # Session automatically commits and closes

Command-Line Interface (CLI)

This project provides a CLI tool for generating weekly F3 Nation beatdown reports directly from your database.

Features

  • Generate a weekly report for any week (default: current week)
  • Region-agnostic analytics and reporting
  • Robust error handling and clear output
  • Options for specifying week, showing version, and more

Usage

To run the CLI and generate a weekly report:

uvx --from f3-nation-data f3-weekly-report [DATE]
  • DATE (optional): Any date within the target week (format: YYYY-MM-DD). If omitted, the current week is used.

Example

uvx --from f3-nation-data f3-weekly-report 2024-03-09

Options

  • --date YYYY-MM-DD : Specify the week by date
  • --version : Show CLI version and exit

Output

The CLI prints a formatted weekly report to stdout, including:

  • Week summary (beatdowns, attendance, unique PAX)
  • Highest attended workout at each AO
  • Top HIMs who posted
  • Leaders in Q counts
  • AO rankings by unique PAX

Error Handling

  • Invalid date format: clear error message and exit
  • Missing environment variable: clear error message and exit
  • No beatdowns found: clear message and exit

See the tests for examples of CLI output and error handling.

Development

Generating SQL Models

This library includes a script to automatically generate SQLAlchemy models from your database schema:

python dev_utilities/generate_models.py

This ensures models stay in sync with any database schema changes.

Code Quality

# Run all code quality checks (formatting, linting, types, complexity, coverage, prettier)
poe ci-checks

You can also run individual tasks (format, lint, test, etc.) if needed, but poe ci-checks is recommended for full validation.

Architecture

  • SQL Models (f3_nation_data/models/sql/): Direct database mappings using SQLAlchemy
  • App Models (f3_nation_data/models/app/): Business logic models using Pydantic
  • Database (f3_nation_data/database.py): Connection utilities
  • Parsing (f3_nation_data/parsing.py): Backblast and data parsing functions
  • Analytics (f3_nation_data/analytics.py): Data analysis utilities

Contributing

See CONTRIBUTING.md for development setup and guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

f3_nation_data-0.0.3.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

f3_nation_data-0.0.3-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file f3_nation_data-0.0.3.tar.gz.

File metadata

  • Download URL: f3_nation_data-0.0.3.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.20

File hashes

Hashes for f3_nation_data-0.0.3.tar.gz
Algorithm Hash digest
SHA256 63bab292f39179b2acb568dea7c752a20996bc4857d5d80328ebc8bf9bde8eed
MD5 b3edd17768205be53799ab1dfcf25e9a
BLAKE2b-256 edfd2a274d76815adf6501352a4f02a128cd44e4597cb4f3f402f21cf2bf2b34

See more details on using hashes here.

File details

Details for the file f3_nation_data-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for f3_nation_data-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 963fa2a4903a5b5eb54d99523859f13fe4e96e996d40dccd3b6ee3c3bbe2d246
MD5 0f065e594e068987ba8dac049bbad348
BLAKE2b-256 a5bcb04e34d5c681bba4a0872f89250594f4dcc8c27d89c6cc1af5e5907eae3f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page