本文整理汇总了Python中group.Group.find_by_scoutid_without_senior_duplicates方法的典型用法代码示例。如果您正苦于以下问题:Python Group.find_by_scoutid_without_senior_duplicates方法的具体用法?Python Group.find_by_scoutid_without_senior_duplicates怎么用?Python Group.find_by_scoutid_without_senior_duplicates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类group.Group
的用法示例。
在下文中一共展示了Group.find_by_scoutid_without_senior_duplicates方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: group_payments
# 需要导入模块: from group import Group [as 别名]
# 或者: from group.Group import find_by_scoutid_without_senior_duplicates [as 别名]
def group_payments(osm, auth, outfile):
important_fields = ['first_name',
'last_name',
'joined',
'started',
'date_of_birth']
# Define payment schedules that we are interested in.
payment_schedules_list = [
('2016 - Spring Term - Part 1', datetime.date(2016, 1, 4)),
('2016 - Spring Term - Part 2', datetime.date(2016, 2, 22)),
('2016 - Summer Term - Part 1', datetime.date(2016, 4, 11)),
('2016 - Summer Term - Part 2', datetime.date(2016, 6, 6)),
('2016 - Autumn Term - Part 1', datetime.date(2016, 9, 5)),
('2016 - Autumn Term - Part 2', datetime.date(2016, 10, 31)),
('2017 - Spring Term - Part 1', datetime.date(2017, 1, 9)),
('2017 - Spring Term - Part 2', datetime.date(2017, 2, 20))
]
payment_dates = collections.OrderedDict(payment_schedules_list)
schedules = [_[0] for _ in payment_schedules_list]
first_date = min([_[1] for _ in payment_schedules_list])
last_date = max([_[1] for _ in payment_schedules_list])
# Payment amounts. Assumes all schedules use the same quantity.
general_amount = 17.95
discount_amount = 12.13
# Fetch all of the available data for each term on which a payment is due.
group_by_date = {}
for name, date in payment_dates.items():
group_by_date[name] = Group(osm, auth, important_fields, on_date=date)
# Get a list of all members in all terms across the whole group.
all_yp_members = []
for group in group_by_date.values():
all_yp_members.extend(group.all_yp_members_without_leaders())
all_yp_by_scout_id = {member['member_id']: member for member in all_yp_members}
# Get the current group data for the current term.
current = Group(osm, auth, important_fields)
res = []
for scoutid, member in all_yp_by_scout_id.items():
current_member = current.find_by_scoutid_without_senior_duplicates(str(scoutid))
section = current_member[0]._section['sectionname'] if len(current_member) else 'Unknown'
d = collections.OrderedDict((('scoutid', scoutid), ('First name', member['first_name']),
('Last name', member['last_name']), ('joined', member['started']),
('left', member['end_date']),
('section', section)))
joined = datetime.datetime.strptime(member['started'], "%Y-%m-%d").date()
ended = datetime.datetime.strptime(member['end_date'], "%Y-%m-%d").date() if member['end_date'] else False
amount = discount_amount if member['customisable_data.cf_subs_type_n_g_d_'] == 'D' else general_amount
for schedule, date_ in payment_dates.items():
d[schedule] = amount if ((joined < date_ and not ended) or
(joined < date_ and ended > date_)) else 0
res.append(d)
tbl = pd.DataFrame(res)
tbl.set_index(["Last name", "First name"], inplace=True)
all_sections = list(Group.SECTIONIDS.keys())
def fetch_section(section_name):
section = group._sections.sections[Group.SECTIONIDS[section_name]]
payments = section.get_payments(first_date.strftime('%Y-%m-%d'),
last_date.strftime('%Y-%m-%d'))
return pd.read_csv(StringIO(payments.content.decode())) if payments is not None else pd.DataFrame()
all = pd.concat([fetch_section(name) for name in all_sections], ignore_index=True)
all['Schedule'] = all['Schedule'].str.replace('^General Subscriptions.*$', 'General Subscriptions')
all['Schedule'] = all['Schedule'].str.replace('^Discounted Subscriptions.*$', 'Discounted Subscriptions')
subs = all[(all['Schedule'] == 'General Subscriptions') | (all['Schedule'] == 'Discounted Subscriptions')]
pv = pd.pivot_table(subs, values='Net', index=['Last name', 'First name'], columns=['Schedule', 'Payment'])
for schedule in schedules:
pv['General Subscriptions'][schedule].fillna(
pv['Discounted Subscriptions'][schedule], inplace=True)
del pv['Discounted Subscriptions']
pv.columns = pv.columns.droplevel()
del pv['2015/Q3']
combined = tbl.join(pv, lsuffix='_est', rsuffix='_act', how='outer')
for schedule in schedules:
for suffix in ['_est', '_act']:
combined[schedule + suffix].fillna(0, inplace=True)
for schedule in schedules:
combined[schedule + '_var'] = combined.apply(lambda row: row[schedule + '_est'] - row[schedule + '_act'],
axis=1)
combined.to_excel(outfile, sheet_name="Data", merge_cells=False)