예제 #1
0
#
# data_f = (row for row in data2 if row.gender == 'Female')
# sorted_data_m = sorted(data_m, key=group_key)
# groups_m = itertools.groupby(sorted_data_m, key=group_key)


def filter_key(cutoff_date, gender, row):
    return row.last_updated >= cutoff_date and row.gender == gender


cutoff_date = datetime.datetime(2017, 3, 1)

result_f = parse_utils.group_data(constants.fnames,
                                  constants.class_names,
                                  constants.parsers,
                                  constants.compress_fields,
                                  filter_key=partial(filter_key, cutoff_date,
                                                     'Female'),
                                  group_key=lambda row: row.vehicle_make)

result_m = parse_utils.group_data(constants.fnames,
                                  constants.class_names,
                                  constants.parsers,
                                  constants.compress_fields,
                                  filter_key=partial(filter_key, cutoff_date,
                                                     'Male'),
                                  group_key=lambda row: row.vehicle_make)

for row in result_f:
    print(row)
예제 #2
0
import constants
from parse_utils import group_data
from datetime import datetime


def group_key(item):
    return item.vehicle_make


cutoff_date = datetime(2017, 3, 1)

for gender in ('Female', 'Male'):
    group = group_data(constants.fnames,
                       constants.class_names,
                       constants.parsers,
                       constants.compress_fields,
                       cutoff_date,
                       group_key,
                       gender)
    print(f'***** {gender} *****')
    print(group[0:5], end='\n\n')


예제 #3
0
from functools import partial
from datetime import datetime

import constants
from parse_utils import group_data


def group_key(row):
    return row.vehicle_make


def filter_key(cutoff_date, gender, row):
    return row.last_updated >= cutoff_date and row.gender == gender


cutoff_date = datetime(2017, 3, 1)

for gender in ('Female', 'Male'):
    results = group_data(constants.fnames,
                         constants.class_names,
                         constants.parsers,
                         constants.compress_fields,
                         filter_key=partial(filter_key, cutoff_date, gender),
                         group_key=lambda row: row.vehicle_make)

    print(f'***************** {gender} *****************')
    print(list(results))
예제 #4
0
# group_f_counts = ((g[0], len(list(g[1]))) for g in groups_f)
# print('group_f')
# for row in group_f_counts:
#     print(row)

cutoff_date = datetime(2017, 3, 1)


def filter_key(cutoff_date, gender, row):
    return row.last_updated >= cutoff_date and row.gender == gender


results_f = parse_utils.group_data(arguments.fnames,
                                   arguments.class_names,
                                   arguments.parsers,
                                   arguments.compress_fields,
                                   filter_key=partial(filter_key, cutoff_date,
                                                      'Female'),
                                   group_key=lambda row: row.vehicle_make)

results_m = parse_utils.group_data(
    arguments.fnames,
    arguments.class_names,
    arguments.parsers,
    arguments.compress_fields,
    filter_key=lambda row: filter_key(cutoff_date, 'Male', row),
    group_key=lambda row: row.vehicle_make)
print('results_f')
for row in results_f:
    print(row)
print()