Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Clean up development files and fix misplaced directory

HairyCrabWbad891523603
diff --git a/wger/Implement.txt b/wger/Implement.txt
deleted file mode 100644
index 6aefc8362..000000000
--- a/wger/Implement.txt
+++ /dev/null
@@ -1,315 +0,0 @@
-Use case
-Allow the user to earn trophies
-
-Proposal
-Create a trophy system so the user can earn them while working out.
-
-The system should be able to accommodate trophies based on different parameters like
-
-time ("worked out before x:yz")
-volume ("lifted xyz kg")
-count ("finished xyz nr of workouts", "most trained exercise")
-sequence ("30 day streak")
-other
-For this we will need to create new tables in the database, at the very least a Trophy table and an m2n table linking it to the user. We will have to implement some python classes that can check if a user has earned a certain trophy (should also accept parameters so one class can be used for "lifted 1000 kg", "lifted 10000 kg", etc.). Some trophies can display a progression. While most trophies will be shown to the user, some should be invisible till earned. It's also probably better to make this a new django app, since it will fetch data from other places.
-
-Since there's potentially a lot of data to handle, we need to consider the performance of the calculations, we probably need to add a statistics table that can be updated as the user uses the app and be quickly read when needed. Also note that we already have a celery queue, we can use that if we need to run periodic or long-running tasks. If a user already has a trophy, we should obviously not check again if it can be earned, but the system should be able to re-evaluate some or all trophies (e.g. if the criteria has changed in the meanwhile). Also, we should only process users that have logged in in the last 30 (?) days.
-
-There is code in the routine model (calculate_log_statistics) that calculates some statistics from a routine, we might be able to reuse some of that.
-
-The trophies and their status should be available over an API endpoint, so that clients can check the progress (how and when the user will receive any notifications is not part of this issue).
-
-New trophies are added directly to the db via either an app update (if python), db migration, fixtures, etc., no need for any upload functionality or similar. However, administrators should be able to disable the trophies in the config, as well as users in their preferences.
-
-Also, ✨tests✨
-
-Possible trophies
-To start we could implement these, others can be added later once the system is in place
-
-Beginner: did one workout
-Unstoppable: 30-day workout streak
-Weekend Warrior: worked out on Saturday and Sunday for 4 weekends in a row
-Lifter: lifted a cumulative total of 5000kg
-Atlas: lifted a cumulative total of 100000kg
-Early Bird: worked out before 6:00
-Night Owl: worked out after 21:00
-New Year, New Me: worked out the 1st of January
-Phoenix: Returned to training after being inactive for 30 days
-
-================================================================================
-STEPS TO IMPLEMENT (Backend Only)
-================================================================================
-
-PHASE 1: Foundation - Django App & Database Models
---------------------------------------------------
-1.1 Create new Django app "trophies"
- - Run: python manage.py startapp trophies
- - Add to INSTALLED_APPS in settings_global.py
- - Create app structure (models/, api/, tests/, management/commands/)
-
-1.2 Create database models
- - Trophy model:
- * id, uuid
- * name (CharField)
- * description (TextField)
- * image (ImageField, optional)
- * trophy_type (CharField: time, volume, count, sequence, other)
- * checker_class (CharField - Python path to checker class)
- * checker_params (JSONField - parameters for the checker)
- * is_hidden (BooleanField - hidden until earned)
- * is_progressive (BooleanField - shows progress)
- * is_active (BooleanField - admin can disable)
- * order (PositiveIntegerField)
- * created, updated timestamps
-
- - UserTrophy model (M2M through table):
- * user (ForeignKey to User)
- * trophy (ForeignKey to Trophy)
- * earned_at (DateTimeField)
- * progress (FloatField, 0-100, for progressive trophies)
- * is_notified (BooleanField - for future notification system)
-
- - UserStatistics model (denormalized stats for performance):
- * user (OneToOneField to User)
- * total_weight_lifted (DecimalField) - always stored in kg
- * total_workouts (PositiveIntegerField)
- * current_streak (PositiveIntegerField)
- * longest_streak (PositiveIntegerField)
- * last_workout_date (DateField)
- * earliest_workout_time (TimeField, nullable)
- * latest_workout_time (TimeField, nullable)
- * weekend_workout_streak (PositiveIntegerField)
- * last_complete_weekend_date (DateField, nullable) - for tracking consecutive weekends
- * last_inactive_date (DateField, nullable) - for Phoenix trophy
- * worked_out_jan_1 (BooleanField) - for New Year trophy
- * last_updated (DateTimeField)
-
-1.3 Create and run migrations
- - python manage.py makemigrations trophies
- - python manage.py migrate
-
-1.4 Add user preference for trophies
- - Add "trophies_enabled" (BooleanField, default=True) to UserProfile model
- - Create migration for core app
-
-1.5 Add site-wide config option
- - Add trophy system toggle to config app or WGER_SETTINGS
-
-
-PHASE 2: Trophy Checker System
-------------------------------
-2.1 Create base checker class
- - Abstract base class: BaseTrophyChecker
- - Methods:
- * __init__(self, user, trophy, params)
- * check(self) -> bool (is trophy earned?)
- * get_progress(self) -> float (0-100, for progressive)
- * get_target_value(self) -> any (what user needs to achieve)
- * get_current_value(self) -> any (user's current progress)
-
-2.2 Implement trophy checker classes
- - CountBasedChecker (for workout count trophies)
- * Beginner: params={'count': 1}
-
- - StreakChecker (for consecutive day streaks)
- * Unstoppable: params={'days': 30}
-
- - WeekendWarriorChecker (Saturday + Sunday streaks)
- * Weekend Warrior: params={'weekends': 4}
-
- - VolumeChecker (cumulative weight lifted)
- * Lifter: params={'kg': 5000}
- * Atlas: params={'kg': 100000}
-
- - TimeBasedChecker (workout time of day)
- * Early Bird: params={'before': '06:00'}
- * Night Owl: params={'after': '21:00'}
-
- - DateBasedChecker (specific dates)
- * New Year, New Me: params={'month': 1, 'day': 1}
-
- - InactivityReturnChecker (return after gap)
- * Phoenix: params={'inactive_days': 30}
-
-2.3 Create checker registry
- - Dictionary mapping checker_class strings to actual classes
- - Factory function to instantiate checkers
- - Note: Use simple keys (e.g., 'count_based') rather than full Python paths
- to avoid breakage if module structure changes
-
-
-PHASE 3: Statistics Service
----------------------------
-3.1 Create UserStatisticsService class
- - Methods:
- * update_statistics(user) - full recalculation
- * increment_workout(user, workout_log) - incremental update
- * get_or_create_statistics(user)
-
-3.2 Implement statistics calculations
- - Reuse/adapt code from routine model (calculate_log_statistics)
- - Calculate: total volume, workout count, streaks, times
-
-3.3 Add Django signals
- - Post-save signal on WorkoutLog/WorkoutSession
- - Trigger incremental statistics update
- - Trigger trophy evaluation
-
-3.4 Handle workout deletion and edits
- - Post-delete signal on WorkoutLog/WorkoutSession
- - Pre-save signal to detect edits (compare old vs new values)
- - Recalculate affected statistics on deletion/edit
-
-3.5 Normalize weight units
- - Convert all weight values to kg before storing in total_weight_lifted
- - Use user's weight unit preference for conversion
-
-3.6 Handle timezone for time-based trophies
- - Use user's timezone from profile (if available) or server timezone
- - Store earliest/latest workout times in user's local time
-
-
-PHASE 4: Trophy Evaluation Engine
----------------------------------
-4.1 Create TrophyService class
- - Methods:
- * evaluate_all_trophies(user) - check all unearthed trophies
- * evaluate_trophy(user, trophy) - check single trophy
- * award_trophy(user, trophy) - create UserTrophy record
- * get_user_trophies(user) - list earned trophies
- * get_trophy_progress(user) - list all with progress
- * reevaluate_trophies(trophy_ids=None) - admin re-evaluation
-
-4.2 Implement evaluation logic
- - Skip already earned trophies (unless re-evaluating)
- - Skip users with trophies_enabled=False
- - Skip inactive users (no login in 30 days)
- - Use checker classes to determine eligibility
- - Update progress for progressive trophies
-
-4.3 Add Celery tasks
- - evaluate_user_trophies_task(user_id) - async single user
- - evaluate_all_users_trophies_task() - periodic batch job
- - update_user_statistics_task(user_id) - async stats update
-
-4.4 Optimize bulk operations
- - Use select_related/prefetch_related to avoid N+1 queries
- - Batch database operations where possible
- - Consider chunking for large user sets
-
-
-PHASE 5: API Endpoints
-----------------------
-5.1 Create serializers
- - TrophySerializer (id, name, description, image, type, is_hidden, is_progressive)
- - UserTrophySerializer (trophy, earned_at, progress)
- - TrophyProgressSerializer (trophy, progress, current_value, target_value, is_earned)
-
-5.2 Create API ViewSets
- - TrophyViewSet (read-only list of all active trophies)
- * GET /api/v2/trophy/ - list all visible trophies
- * GET /api/v2/trophy/{id}/ - trophy detail
-
- - UserTrophyViewSet (user's earned trophies)
- * GET /api/v2/user-trophy/ - list user's earned trophies
- * GET /api/v2/user-trophy/progress/ - all trophies with progress
-
-5.3 Create wger/trophies/urls.py
- - Define URL patterns for trophies app
- - Include both API and any web views
-
-5.4 Register URLs
- - Add routes to wger/urls.py under API v2 router
- - Include trophies.urls in main urlpatterns
-
-5.5 Define hidden trophy visibility rules
- - Hidden trophies not earned: exclude from list OR show with placeholder
- - Hidden trophies earned: show normally with full details
- - Document the chosen behavior in API response
-
-
-PHASE 6: Management Commands & Data Loading
--------------------------------------------
-6.1 Create management command: load_trophies
- - Load initial trophy definitions from fixtures or code
- - Idempotent (can run multiple times safely)
-
-6.2 Create management command: evaluate_trophies
- - Manual trigger for trophy evaluation
- - Options: --user, --trophy, --all, --force-reevaluate
-
-6.3 Create management command: recalculate_statistics
- - Rebuild UserStatistics for all/specific users
-
-6.4 Create fixtures
- - Initial trophy definitions (the 9 proposed trophies)
-
-6.5 Add i18n support for trophy content
- - Consider TrophyTranslation model (similar to ExerciseTranslation)
- - Or use Django's translation system with fixture translations
- - Trophy names and descriptions should be translatable
-
-6.6 Updating translation files
- wger uses Django's translation infrastructure. To update translations:
-
- 1. Extract translatable strings from database (exercise categories, muscle names, etc.):
- python manage.py extract-i18n
-
- 2. Update .po files (run in wger subfolder, not root):
- django-admin makemessages --all --extension py,html,tpl
-
- 3. Compile translation files:
- django-admin compilemessages
-
-
-PHASE 7: Testing
-----------------
-7.1 Model tests
- - Trophy model CRUD
- - UserTrophy model constraints
- - UserStatistics calculations
-
-7.2 Checker tests
- - Test each checker class with mock data
- - Edge cases (boundary conditions, empty data)
-
-7.3 Service tests
- - UserStatisticsService accuracy
- - TrophyService evaluation logic
- - Award/skip logic
-
-7.4 API tests
- - Authentication required
- - Correct filtering (user's own trophies only)
- - Hidden trophy visibility rules
- - Progress endpoint accuracy
-
-7.5 Integration tests
- - End-to-end: create workout → stats update → trophy earned
- - Celery task execution (if applicable)
-
-
-PHASE 8: Documentation & Finalization
--------------------------------------
-8.1 Add OpenAPI documentation
- - Document new endpoints in drf-spectacular schema
-
-8.2 Update README/docs
- - Document trophy system configuration
- - Document how to add new trophies
-
-8.3 Create database migration for initial trophies
- - Or use fixture loading in deployment
-
-
-================================================================================
-IMPLEMENTATION ORDER SUMMARY
-================================================================================
-1. Phase 1: Foundation (models, migrations, config)
-2. Phase 2: Checker classes
-3. Phase 3: Statistics service
-4. Phase 4: Trophy evaluation engine
-5. Phase 5: API endpoints
-6. Phase 6: Management commands & data
-7. Phase 7: Tests (can be done alongside each phase)
-8. Phase 8: Documentation
\ No newline at end of file
diff --git a/wger/wger/trophies/tests/__init__.py b/wger/wger/trophies/tests/__init__.py
deleted file mode 100644
index e69de29bb..000000000