def convert_scores_overview_type_csv_to_categories_overview_json(
        scores_csv_location,
        quick_overview_csv_location,
        output_directory,
        check_csv_structure=True):
    if check_csv_structure:
        checker = ScoresOverviewTypeCsvCheckerForCategoryOverviewConversion(
            scores_csv_location)
        checker.check()
        check_overview_type_csv_structure(quick_overview_csv_location)
    _create_on_non_existent_categories_overview_subdirectory(output_directory)

    scores_rows = load_rows_as_list_of_lists(scores_csv_location)
    quick_overview_mappings = load_rows_as_list_of_dicts(
        quick_overview_csv_location)
    categories_overview_init_objs = _create_initial_categories_overview_objects(
        scores_rows, quick_overview_mappings)
    _add_ranks(categories_overview_init_objs)
    total_rank_sorted_objs = list(
        sorted(categories_overview_init_objs,
               key=lambda obj: int(obj[CategoriesOverviewJsonFields.total][
                   CategoriesOverviewJsonIndicatorSubFields.rank])))
    create_json_file(total_rank_sorted_objs,
                     output_directory + CATEGORIES_OVERVIEW_SUBDIRECTORY +
                     'categories-overview.json',
                     json_objects_already_sorted=True)
コード例 #2
0
def convert_difference_type_to_json(csv_location, output_directory):
    check_difference_structure(csv_location)
    rows = load_rows_as_list_of_dicts(csv_location)
    json_objects = [
        _convert_to_json_object(row_as_dict) for row_as_dict in rows
    ]
    create_json_file(json_objects, output_directory + 'difference.json')
コード例 #3
0
def convert_sub_indicator_type_to_jsons(
        csv_location,
        output_directory,
        company_names_row_index=COMPANY_NAMES_ROW_INDEX):
    global COMPANY_NAMES_ROW_INDEX
    if company_names_row_index != COMPANY_NAMES_ROW_INDEX:
        COMPANY_NAMES_ROW_INDEX = company_names_row_index
    _create_indicators_subdirectory(output_directory)

    rows = load_rows_as_list_of_lists(csv_location)
    indicator = rows[0][
        0]  # this is either Governance, Freedom of Expression or Privacy
    sub_indicators_base_data = _get_all_sub_indicators_base_data(
        indicator, rows)
    companies_data = _create_companies_data(rows)

    sub_indicators_objects = [
        _create_sub_indicator_json_data(si_data, companies_data, rows)
        for si_data in sub_indicators_base_data
    ]

    for si_json, si_data in zip(sub_indicators_objects,
                                sub_indicators_base_data):
        create_json_file(si_json,
                         output_directory + INDICATOR_SUBDIRECTORY +
                         si_data.id + '.json',
                         json_objects_already_sorted=True)
def convert_scores_overview_type_csv_to_indicator_overview_json(
        csv_location, output_directory, check_csv_structure=True):
    if check_csv_structure:
        scores_overview_csv_type_checker = ScoresOverviewTypeCsvChecker(
            csv_location)
        scores_overview_csv_type_checker.check()
    rows = load_rows_as_list_of_lists(csv_location)
    indicator_objects = create_indicator_objects(rows)
    create_json_file(indicator_objects,
                     output_directory + 'indicator-overview.json')
コード例 #5
0
def convert_scores_overview_type_csv_to_all_indicator_json(
        csv_location, output_directory, check_csv_structure=True):
    if check_csv_structure:
        scores_overview_type_checker = ScoresOverviewTypeCsvChecker(
            csv_location)
        scores_overview_type_checker.check()
    _create_on_non_existent_all_indicators_subdirectory(output_directory)
    rows = load_rows_as_list_of_lists(csv_location)
    all_indicators_objects = _create_all_indicators_objects(rows)
    create_json_file(all_indicators_objects,
                     output_directory + ALL_INDICATORS_SUBDIRECTORY +
                     'all-indicators.json',
                     json_objects_already_sorted=True)
コード例 #6
0
def convert_multiple_services_type_csv_to_index_service_json(
        csv_location, output_directory, check_csv_structure=True):
    if check_csv_structure:
        checker = MultipleServicesTypeCsvCheckerForIndexServiceJsonConversion(
            csv_location)
        checker.check()
    rows = load_rows_as_list_of_lists(csv_location)
    all_services_related_rows = separate_service_related_rows(rows)
    index_service_objects = []
    for services_related_rows in all_services_related_rows:
        index_service_objects += _create_index_service_objects(
            services_related_rows)

    create_json_file(sorted(
        index_service_objects,
        key=lambda ind_obj: int(ind_obj[IndexServiceJsonFields.id])),
                     output_directory + 'index-service.json',
                     json_objects_already_sorted=True)
コード例 #7
0
 def create(self):
     service_filename = self._parse_service_filename()
     service_objects = self.service_objects_creator.create()
     create_json_file(service_objects, service_filename)
コード例 #8
0
def convert_overview_type_csv_to_json(csv_location, output_directory):
    check_overview_type_csv_structure(csv_location)
    rows = load_rows_as_list_of_dicts(csv_location)
    json_objects = _convert_rows_to_json_objects(rows)
    create_json_file(json_objects, output_directory + 'overview.json')