forked from Scouterna/skojjt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
groupsummary.py
121 lines (107 loc) · 4.37 KB
/
groupsummary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
from data import Meeting, Person, Semester, UserPrefs
from google.appengine.ext import ndb
from flask import Blueprint, render_template
import datetime
groupsummary = Blueprint('groupsummary_page', __name__, template_folder='templates')
@groupsummary.route('/<sgroup_url>')
@groupsummary.route('/<sgroup_url>/')
def scoutgroupsummary(sgroup_url):
user = UserPrefs.current()
if not user.canImport():
return "denied", 403
if sgroup_url is None:
return "missing group", 404
if user.activeSemester is None:
semester = Semester.getOrCreateCurrent()
else:
semester = user.activeSemester.get()
sgroup_key = ndb.Key(urlsafe=sgroup_url)
scoutgroup = sgroup_key.get()
breadcrumbs = [{'link':'/', 'text':'Hem'}]
baselink = "/groupsummary/" + sgroup_url
section_title = "Föreningsredovisning - " + scoutgroup.getname()
breadcrumbs.append({'link':baselink, 'text':section_title})
class Item():
age = 0
women = 0
womenMeetings = 0
men = 0
menMeetings = 0
def __init__(self, age, women=0, womenMeetings=0, men=0, menMeetings=0):
self.age = age
self.women = women
self.womenMeetings = womenMeetings
self.men = men
self.menMeetings = menMeetings
year = semester.year
women = 0
womenMeetings = 0
men = 0
menMeetings = 0
startage = 7
endage = 25
ages = [Item('0 - 6')]
ages.extend([Item(i) for i in range(startage, endage+1)])
ages.append(Item('26 - 64'))
ages.append(Item('65 -'))
leaders = [Item(u't.o.m. 25 år'), Item(u'över 25 år')]
boardmebers = [Item('')]
from_date_time = datetime.datetime.strptime(str(semester.year) + "-01-01 00:00", "%Y-%m-%d %H:%M")
to_date_time = datetime.datetime.strptime(str(semester.year) + "-12-31 00:00", "%Y-%m-%d %H:%M")
emails = []
for person in Person.query(Person.scoutgroup==sgroup_key).fetch():
if person.member_years is None or semester.year not in person.member_years:
continue
if person.email is not None and len(person.email) != 0 and person.email not in emails:
emails.append(person.email)
age = person.getyearsoldthisyear(year)
if scoutgroup.attendance_incl_hike:
number_of_meetings = Meeting.query(Meeting.attendingPersons==person.key,
Meeting.datetime >= from_date_time,
Meeting.datetime <= to_date_time).count()
else:
meetings = Meeting.query(Meeting.attendingPersons==person.key,
Meeting.datetime >= from_date_time,
Meeting.datetime <= to_date_time)
nr_all = meetings.count()
nr_hike_meetings = meetings.filter(Meeting.ishike == True).count()
number_of_meetings = nr_all - nr_hike_meetings
index = 0
if 7 <= age <= 25:
index = age-startage + 1
elif age < 7:
index = 0
elif 26 <= age <= 64:
index = endage - startage + 2
else:
index = endage - startage + 3
if person.isFemale():
women += 1
ages[index].women += 1
else:
men += 1
ages[index].men += 1
if number_of_meetings >= scoutgroup.attendance_min_year:
if person.isFemale():
womenMeetings += 1
ages[index].womenMeetings += 1
else:
menMeetings += 1
ages[index].menMeetings += 1
if person.isBoardMember():
if person.isFemale():
boardmebers[0].women += 1
else:
boardmebers[0].men += 1
if person.isLeader():
index = 0 if age <= 25 else 1
if person.isFemale():
leaders[index].women += 1
else:
leaders[index].men += 1
ages.append(Item("Totalt", women, womenMeetings, men, menMeetings))
return render_template('groupsummary.html', ages=ages, boardmebers=boardmebers, leaders=leaders,
breadcrumbs=breadcrumbs, emails=emails, year=semester.year,
min_nr_meetings=str(scoutgroup.attendance_min_year),
incl_hikes=scoutgroup.attendance_incl_hike)