#!/usr/bin/env python
"""
Script to manually trigger recalculation of user work hours
"""
import sys
import functools
from app import create_app
from app.services.work_hours_service import calculate_and_store_real_work_hours
from app.scheduler import job_wrapper

# Create the app instance (same as what Flask does on startup)
app = create_app()

print("Starting manual recalculation of work hours...")
try:
    # Call the calculation function exactly as the scheduler would, but with force_recalculate=True
    # This ensures we process all events from scratch rather than only new ones
    wrapped_job_func = job_wrapper(
        functools.partial(calculate_and_store_real_work_hours, app, force_recalculate=True),
        app,
        'manual_calc_real_work_hours'
    )
    wrapped_job_func()
    print("Recalculation completed successfully.")
except Exception as e:
    print(f"Error during recalculation: {e}")
    sys.exit(1) 