feat: Add --stats option for yearly, quarterly and monthly average prices
- Added --stats YEAR option to generate statistical reports - Calculates yearly, quarterly and monthly average prices for a given year and currency - Includes working day counts for accurate averaging - Supports both normal (minimal) and debug output modes - Automatically downloads required yearly data if not present - Shows detailed processing steps in debug mode - Works with any currency code supported by CNB - Provides formatted output with Czech month names - Example usage: --stats 2024 -c USD
This commit is contained in:
18
src/cli.py
18
src/cli.py
@@ -12,6 +12,7 @@ import data_fetcher
|
||||
import database
|
||||
import rate_finder
|
||||
import rate_reporter
|
||||
import rate_stats
|
||||
import holidays
|
||||
|
||||
# Global debug flag
|
||||
@@ -35,6 +36,7 @@ def check_and_update_yearly_data():
|
||||
holidays.set_debug_mode(DEBUG)
|
||||
rate_finder.set_debug_mode(DEBUG)
|
||||
rate_reporter.set_debug_mode(DEBUG)
|
||||
rate_stats.set_debug_mode(DEBUG)
|
||||
|
||||
# Zkontrolujeme konzistenci dat
|
||||
is_consistent = data_fetcher.check_yearly_data_consistency(current_year, output_dir="data")
|
||||
@@ -63,7 +65,7 @@ def main():
|
||||
parser.add_argument(
|
||||
"-c", "--currency",
|
||||
type=str,
|
||||
help="Kód měny (např. USD) pro měsíční stahování, vyhledání kurzu nebo generování reportu."
|
||||
help="Kód měny (např. USD) pro měsíční stahování, vyhledání kurzu, generování reportu nebo statistik."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--start-date",
|
||||
@@ -106,6 +108,11 @@ def main():
|
||||
metavar=('START_DATE', 'END_DATE'),
|
||||
help="Období, pro které se má vygenerovat report kurzů. Formát: DD.MM.YYYY DD.MM.YYYY"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--stats",
|
||||
type=int,
|
||||
help="Vygeneruje statistiky pro zadaný rok. Formát: ROK"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--debug",
|
||||
action="store_true",
|
||||
@@ -123,13 +130,14 @@ def main():
|
||||
holidays.set_debug_mode(DEBUG)
|
||||
rate_finder.set_debug_mode(DEBUG)
|
||||
rate_reporter.set_debug_mode(DEBUG)
|
||||
rate_stats.set_debug_mode(DEBUG)
|
||||
|
||||
# Kontrola a případná aktualizace ročních dat pro aktuální rok (pouze v debug módu)
|
||||
if DEBUG:
|
||||
check_and_update_yearly_data()
|
||||
else:
|
||||
# V normálním módu zkontrolujeme pouze při stahování dat
|
||||
if args.year or args.start_date or args.date or args.get_rate or args.report_year or args.report_period:
|
||||
if args.year or args.start_date or args.date or args.get_rate or args.report_year or args.report_period or args.stats:
|
||||
current_year = datetime.now().year
|
||||
# Pro jednoduchost v normálním módu nebudeme kontrolovat konzistenci automaticky
|
||||
pass
|
||||
@@ -228,6 +236,12 @@ def main():
|
||||
start_date, end_date = args.report_period
|
||||
debug_print(f"Generuji report pro {args.currency} za období {start_date} - {end_date}...")
|
||||
rate_reporter.generate_period_report(start_date, end_date, args.currency, output_dir="data")
|
||||
elif args.stats and args.currency:
|
||||
# Generování statistik
|
||||
year = args.stats
|
||||
debug_print(f"Generuji statistiky pro {args.currency} za rok {year}...")
|
||||
stats = rate_stats.generate_yearly_stats(year, args.currency, output_dir="data")
|
||||
rate_stats.print_stats(stats)
|
||||
else:
|
||||
if DEBUG:
|
||||
parser.print_help()
|
||||
|
||||
Reference in New Issue
Block a user