def parse_csv_with_name(self, filename): manager = FileManager() parser = ConfigParser() config_dto = parser.parse_config() path_to_file = manager.get_path_to_file(DirPath.STATISTICS) csv_dict = {} column_names = config_dto.column_names for name in column_names: csv_dict[name] = [] csv_file = open(os.path.join(path_to_file, filename), 'rt') csv_reader = csv.DictReader(csv_file, fieldnames=column_names, delimiter=' ', quotechar='"') header = next(csv_reader) for row in csv_reader: for key in row: csv_dict[key].append(row[key]) return DTO(filename, path_to_file, column_names, csv_dict)
def transform_to_csv_dto(self, generated_stat, config): manager = FileManager() path_to_file = manager.get_path_to_file(DirPath.STATISTICS) filename = "Statistics for " + config.filename data = self.transform_generated_values(config.column_names, generated_stat) return DTO(filename, path_to_file, config.column_names, data)
def parse_config(self, name): manager = FileManager() filename = name path_to_file = manager.get_path_to_file(DirPath.CONFIGS) config = configparser.ConfigParser() if filename is not None: with open(os.path.join(path_to_file, filename)) as cfg_file: config.readfp(cfg_file) # read and parse entire file sections = {} for section in config.sections(): options = {} for option, value in config.items(section): options[option] = value sections[section] = options column_names = self.get_column_names(sections) return DTO(filename, path_to_file, column_names, sections) return None