1 | ## $Id: studylevel.py 16817 2022-02-17 09:09:52Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | """ |
---|
19 | Container which holds the data of a student study level |
---|
20 | and contains the course tickets. |
---|
21 | """ |
---|
22 | import grok |
---|
23 | from zope.component.interfaces import IFactory |
---|
24 | from zope.interface import implementedBy |
---|
25 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
26 | from waeup.kofa.students.studylevel import ( |
---|
27 | StudentStudyLevel, CourseTicket, |
---|
28 | CourseTicketFactory, StudentStudyLevelFactory) |
---|
29 | from waeup.kofa.students.interfaces import IStudentNavigation |
---|
30 | from kofacustom.dspg.students.interfaces import ( |
---|
31 | ICustomStudentStudyLevel, ICustomCourseTicket) |
---|
32 | |
---|
33 | |
---|
34 | class CustomStudentStudyLevel(StudentStudyLevel): |
---|
35 | """This is a container for course tickets. |
---|
36 | """ |
---|
37 | grok.implements(ICustomStudentStudyLevel, IStudentNavigation) |
---|
38 | grok.provides(ICustomStudentStudyLevel) |
---|
39 | |
---|
40 | @property |
---|
41 | def total_credits_s1(self): |
---|
42 | total = 0 |
---|
43 | for ticket in self.values(): |
---|
44 | if ticket.semester == 1 and not ticket.outstanding: |
---|
45 | total += ticket.credits |
---|
46 | return total |
---|
47 | |
---|
48 | @property |
---|
49 | def total_credits_s2(self): |
---|
50 | total = 0 |
---|
51 | for ticket in self.values(): |
---|
52 | if ticket.semester == 2 and not ticket.outstanding: |
---|
53 | total += ticket.credits |
---|
54 | return total |
---|
55 | |
---|
56 | @property |
---|
57 | def gpa_params(self): |
---|
58 | """Calculate gpa parameters for this level. |
---|
59 | """ |
---|
60 | credits_weighted = 0.0 |
---|
61 | credits_counted = 0 |
---|
62 | level_gpa = 0.0 |
---|
63 | for ticket in self.values(): |
---|
64 | if ticket.total_score is not None: |
---|
65 | credits_counted += ticket.credits |
---|
66 | credits_weighted += ticket.credits * ticket.weight |
---|
67 | if credits_counted: |
---|
68 | level_gpa = round(credits_weighted / credits_counted, 2) |
---|
69 | # Override level_gpa if value has been imported |
---|
70 | # (not implemented in base package) |
---|
71 | imported_gpa = getattr(self, 'imported_gpa', None) |
---|
72 | if imported_gpa: |
---|
73 | level_gpa = imported_gpa |
---|
74 | return level_gpa, credits_counted, credits_weighted |
---|
75 | |
---|
76 | |
---|
77 | CustomStudentStudyLevel = attrs_to_fields( |
---|
78 | CustomStudentStudyLevel, omit=['total_credits', 'gpa', |
---|
79 | 'total_credits_s1', 'total_credits_s2']) |
---|
80 | |
---|
81 | class CustomStudentStudyLevelFactory(StudentStudyLevelFactory): |
---|
82 | """A factory for student study levels. |
---|
83 | """ |
---|
84 | |
---|
85 | def __call__(self, *args, **kw): |
---|
86 | return CustomStudentStudyLevel() |
---|
87 | |
---|
88 | def getInterfaces(self): |
---|
89 | return implementedBy(CustomStudentStudyLevel) |
---|
90 | |
---|
91 | class CustomCourseTicket(CourseTicket): |
---|
92 | """ |
---|
93 | """ |
---|
94 | grok.implements(ICustomCourseTicket, IStudentNavigation) |
---|
95 | grok.provides(ICustomCourseTicket) |
---|
96 | |
---|
97 | |
---|
98 | @property |
---|
99 | def _getGradeWeightFromScore(self): |
---|
100 | """DSPG Course Grading System |
---|
101 | """ |
---|
102 | if self.total_score is None: |
---|
103 | return (None, None) |
---|
104 | if self.total_score >= 75: |
---|
105 | return ('A',4) |
---|
106 | if self.total_score >= 70: |
---|
107 | return ('AB',3.5) |
---|
108 | if self.total_score >= 65: |
---|
109 | return ('B',3.25) |
---|
110 | if self.total_score >= 60: |
---|
111 | return ('BC',3.0) |
---|
112 | if self.total_score >= 55: |
---|
113 | return ('C',2.75) |
---|
114 | if self.total_score >= 50: |
---|
115 | return ('CD',2.5) |
---|
116 | if self.total_score >= 45: |
---|
117 | return ('D',2.25) |
---|
118 | if self.total_score >= 40: |
---|
119 | return ('E',2) |
---|
120 | return ('F',0) |
---|
121 | |
---|
122 | |
---|
123 | CustomCourseTicket = attrs_to_fields(CustomCourseTicket) |
---|
124 | |
---|
125 | class CustomCourseTicketFactory(CourseTicketFactory): |
---|
126 | """A factory for student study levels. |
---|
127 | """ |
---|
128 | |
---|
129 | def __call__(self, *args, **kw): |
---|
130 | return CustomCourseTicket() |
---|
131 | |
---|
132 | def getInterfaces(self): |
---|
133 | return implementedBy(CustomCourseTicket) |
---|