Beispiel #1
0
    def get(self):
        import cea.scripts
        config = current_app.cea_config
        locator = cea.inputlocator.InputLocator(config.scenario)
        schemas = cea.schemas.schemas(plugins=[])
        validator = InputFileValidator(locator, plugins=config.plugins)
        out = OrderedDict()

        for db_name, schema_keys in DATABASES_SCHEMA_KEYS.items():
            for schema_key in schema_keys:
                schema = schemas[schema_key]
                if schema_key != 'get_database_standard_schedules_use':
                    db_path = locator.__getattribute__(schema_key)()
                    try:
                        df = pandas.read_excel(db_path, sheet_name=None)
                        errors = validator.validate(df, schema)
                        if errors:
                            out[db_name] = errors
                    except IOError as e:
                        out[db_name] = [{}, 'Could not find or read file: {}'.format(db_path)]
                else:
                    for use_type in get_all_schedule_names(locator.get_database_use_types_folder()):
                        db_path = locator.__getattribute__(schema_key)(use_type)
                        try:
                            df = schedule_to_dataframe(db_path)
                            errors = validator.validate(df, schema)
                            if errors:
                                out[use_type] = errors
                        except IOError as e:
                            out[use_type] = [{}, 'Could not find or read file: {}'.format(db_path)]
        return out
Beispiel #2
0
def main():
    import cea.config
    import cea.inputlocator
    from cea.utilities.schedule_reader import schedule_to_dataframe
    import pprint

    config = cea.config.Configuration()
    locator = cea.inputlocator.InputLocator(config.scenario)
    _schemas = schemas(plugins=[])
    validator = InputFileValidator(locator, plugins=config.plugins)
    locator_methods = [
        'get_database_construction_standards',
        'get_database_use_types_properties', 'get_database_supply_assemblies',
        'get_database_air_conditioning_systems',
        'get_database_envelope_systems', 'get_database_conversion_systems',
        'get_database_distribution_systems', 'get_database_feedstocks'
    ]

    for locator_method in locator_methods:
        db_path = locator.__getattribute__(locator_method)()
        df = pd.read_excel(db_path, sheet_name=None)
        print('Validating {}'.format(db_path))
        schema = _schemas[locator_method]
        errors = validator.validate(df, schema)
        if errors:
            pprint.pprint(errors)
        else:
            print("No errors found")

    for use_types in get_all_schedule_names(
            locator.get_database_use_types_folder()):
        db_path = locator.get_database_standard_schedules_use(use_types)
        df = schedule_to_dataframe(db_path)
        print('Validating {}'.format(db_path))
        schema = _schemas['get_database_standard_schedules_use']
        errors = validator.validate(df, schema)
        if errors:
            pprint.pprint(errors)
        else:
            print("No errors found")
def schedule_to_dict(schedule_path):
    out = OrderedDict()
    schedule_df = schedule_to_dataframe(schedule_path)
    for df_name, df in schedule_df.items():
        out[df_name] = df.to_dict(orient='records', into=OrderedDict)
    return out