# Path: ratechecker/dataset.py
# class Dataset(object):
#     loaders = {
#         "adjustment": AdjustmentLoader,
#         "product": ProductLoader,
#         "rate": RateLoader,
#         "region": RegionLoader,
#     }
# 
#     def __init__(self, f):
#         self.zf = ZipFile(f)
# 
#     @cached_property
#     def cover_sheet(self):
#         with self.zf.open("CoverSheet.xml") as f:
#             return CoverSheet(f)
# 
#     @cached_property
#     def timestamp(self):
#         ts = datetime.combine(self.cover_sheet.date, time.min)
#         return timezone.make_aware(ts, timezone.get_current_timezone())
# 
#     @cached_property
#     def filename_prefix(self):
#         return self.cover_sheet.date.strftime("%Y%m%d")
# 
#     def load(self):
#         # Sort the list of loaders so that Region loads last, as a bellwether
#         for key, loader_cls in sorted(self.loaders.items()):
#             try:
#                 f = self.datafile(key)
#             except KeyError:
#                 # The fees data is expected to be temporarily unavailable,
#                 # so if the fees file is not found, we skip it and
#                 # continue loading the other data types.
#                 if key == "fee":
#                     continue
#                 raise
# 
#             # The zip file may be opened as binary, but we want to process the
#             # files that it contains as text.
#             f_text = io.TextIOWrapper(f)
#             loader = loader_cls(f_text, data_timestamp=self.timestamp)
#             loader.load()
# 
#     def datafile(self, name):
#         filename = "{}_{}.txt".format(self.filename_prefix, name)
#         return self.zf.open(filename)
# 
# Path: ratechecker/validation.py
# class ScenarioValidator(object):
#     def __init__(self, verbose=True):
#         self.verbose = verbose
# 
#     def print(self, *args, **kwargs):
#         if self.verbose:  # pragma: no cover
#             print(*args, **kwargs)
# 
#     def validate_file(self, scenario_file, dataset, scenario_id=None):
#         scenarios = ScenarioLoader().load(scenario_file)
#         expected_results = dataset.cover_sheet.expected_scenario_results
# 
#         if scenario_id is not None:
#             scenarios = {scenario_id: scenarios[scenario_id]}
# 
#         return self.validate_scenarios(scenarios, expected_results)
# 
#     def validate_scenarios(self, scenarios, expected_results):
#         failures = OrderedDict()
# 
#         for scenario_id, scenario in scenarios.items():
#             self.print("validating scenario", scenario_id)
# 
#             try:
#                 expected_result = expected_results[scenario_id]
#                 self.validate_scenario(scenario, expected_result)
#             except ScenarioValidationError as e:
#                 failures[scenario_id] = e
# 
#         if failures:
#             raise ValidationError(failures)
# 
#     def validate_scenario(self, scenario, expected_result):
#         serializer = ParamsSerializer(data=scenario)
#         serializer.is_valid(raise_exception=True)
# 
#         rates = get_rates(serializer.validated_data, data_load_testing=True)
#         computed_rates = rates.get("data")
# 
#         return self.compare_result(computed_rates, expected_result)
# 
#     def compare_result(self, computed_rates, expected_result):
#         if not computed_rates:
#             self.print("no rates computed for this scenario, skipping")
#             return
# 
#         expected_rate, expected_points = expected_result
# 
#         if expected_rate is None:
#             self.print("no rates expected for this scenario, skipping")
#             return
# 
#         if computed_rates.get(expected_rate) == expected_points:
#             self.print("scenario matches: ", expected_result, computed_rates)
#             return
# 
#         raise ScenarioValidationError(computed_rates, expected_result)


import argparse
import traceback
import warnings
from django.core.management.base import BaseCommand, CommandError
from django.db import connection
from ratechecker.dataset import Dataset
from ratechecker.validation import ScenarioValidator




class Command(BaseCommand):
    help = "Loads daily interest rate data from a zip archive with CSV files."

    def add_arguments(self, parser):
        parser.add_argument(
            "archive_filename",
            type=argparse.FileType("rb"),
            help="Archive containing interest rate data",
        )
        parser.add_argument(
            "-s",
            "--validation-scenario-file",
            type=argparse.FileType("r"),
            help="JSON-line file containing validation scenario parameters",
        )
        parser.add_argument(

# Path: ratechecker/dataset.py
# class Dataset(object):
#     loaders = {
#         "adjustment": AdjustmentLoader,
#         "product": ProductLoader,
#         "rate": RateLoader,
#         "region": RegionLoader,
#     }
# 
#     def __init__(self, f):
#         self.zf = ZipFile(f)
# 
#     @cached_property
#     def cover_sheet(self):
#         with self.zf.open("CoverSheet.xml") as f:
#             return CoverSheet(f)
# 
#     @cached_property
#     def timestamp(self):
#         ts = datetime.combine(self.cover_sheet.date, time.min)
#         return timezone.make_aware(ts, timezone.get_current_timezone())
# 
#     @cached_property
#     def filename_prefix(self):
#         return self.cover_sheet.date.strftime("%Y%m%d")
# 
#     def load(self):
#         # Sort the list of loaders so that Region loads last, as a bellwether
#         for key, loader_cls in sorted(self.loaders.items()):
#             try:
#                 f = self.datafile(key)
#             except KeyError:
#                 # The fees data is expected to be temporarily unavailable,
#                 # so if the fees file is not found, we skip it and
#                 # continue loading the other data types.
#                 if key == "fee":
#                     continue
#                 raise
# 
#             # The zip file may be opened as binary, but we want to process the
#             # files that it contains as text.
#             f_text = io.TextIOWrapper(f)
#             loader = loader_cls(f_text, data_timestamp=self.timestamp)
#             loader.load()
# 
#     def datafile(self, name):
#         filename = "{}_{}.txt".format(self.filename_prefix, name)
#         return self.zf.open(filename)
# 
# Path: ratechecker/validation.py
# class ScenarioValidator(object):
#     def __init__(self, verbose=True):
#         self.verbose = verbose
# 
#     def print(self, *args, **kwargs):
#         if self.verbose:  # pragma: no cover
#             print(*args, **kwargs)
# 
#     def validate_file(self, scenario_file, dataset, scenario_id=None):
#         scenarios = ScenarioLoader().load(scenario_file)
#         expected_results = dataset.cover_sheet.expected_scenario_results
# 
#         if scenario_id is not None:
#             scenarios = {scenario_id: scenarios[scenario_id]}
# 
#         return self.validate_scenarios(scenarios, expected_results)
# 
#     def validate_scenarios(self, scenarios, expected_results):
#         failures = OrderedDict()
# 
#         for scenario_id, scenario in scenarios.items():
#             self.print("validating scenario", scenario_id)
# 
#             try:
#                 expected_result = expected_results[scenario_id]
#                 self.validate_scenario(scenario, expected_result)
#             except ScenarioValidationError as e:
#                 failures[scenario_id] = e
# 
#         if failures:
#             raise ValidationError(failures)
# 
#     def validate_scenario(self, scenario, expected_result):
#         serializer = ParamsSerializer(data=scenario)
#         serializer.is_valid(raise_exception=True)
# 
#         rates = get_rates(serializer.validated_data, data_load_testing=True)
#         computed_rates = rates.get("data")
# 
#         return self.compare_result(computed_rates, expected_result)
# 
#     def compare_result(self, computed_rates, expected_result):
#         if not computed_rates:
#             self.print("no rates computed for this scenario, skipping")
#             return
# 
#         expected_rate, expected_points = expected_result
# 
#         if expected_rate is None:
#             self.print("no rates expected for this scenario, skipping")
#             return
# 
#         if computed_rates.get(expected_rate) == expected_points:
#             self.print("scenario matches: ", expected_result, computed_rates)
#             return
# 
#         raise ScenarioValidationError(computed_rates, expected_result)


# Path: ratechecker/management/commands/load_daily_data.py
import argparse
import traceback
import warnings
from django.core.management.base import BaseCommand, CommandError
from django.db import connection
from ratechecker.dataset import Dataset
from ratechecker.validation import ScenarioValidator





class Command(BaseCommand):
    help = "Loads daily interest rate data from a zip archive with CSV files."

    def add_arguments(self, parser):
        parser.add_argument(
            "archive_filename",
            type=argparse.FileType("rb"),
            help="Archive containing interest rate data",
        )
        parser.add_argument(
            "-s",
            "--validation-scenario-file",
            type=argparse.FileType("r"),
            help="JSON-line file containing validation scenario parameters",
        )
        parser.add_argument(

            "--validate-only",