[10765] | 1 | ## $Id: studylevel.py 15097 2018-08-03 09:54:07Z 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 |
---|
[14716] | 30 | from kofacustom.dspg.students.interfaces import ( |
---|
[10765] | 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 | |
---|
[15097] | 40 | @property |
---|
| 41 | def gpa_params(self): |
---|
| 42 | """Calculate gpa parameters for this level. |
---|
| 43 | """ |
---|
| 44 | credits_weighted = 0.0 |
---|
| 45 | credits_counted = 0 |
---|
| 46 | level_gpa = 0.0 |
---|
| 47 | for ticket in self.values(): |
---|
| 48 | if ticket.total_score is not None: |
---|
| 49 | credits_counted += ticket.credits |
---|
| 50 | credits_weighted += ticket.credits * ticket.weight |
---|
| 51 | if credits_counted: |
---|
| 52 | level_gpa = round(credits_weighted / credits_counted, 2) |
---|
| 53 | # Override level_gpa if value has been imported |
---|
| 54 | # (not implemented in base package) |
---|
| 55 | imported_gpa = getattr(self, 'imported_gpa', None) |
---|
| 56 | if imported_gpa: |
---|
| 57 | level_gpa = imported_gpa |
---|
| 58 | return level_gpa, credits_counted, credits_weighted |
---|
| 59 | |
---|
| 60 | |
---|
[10765] | 61 | CustomStudentStudyLevel = attrs_to_fields( |
---|
| 62 | CustomStudentStudyLevel, omit=['total_credits', 'gpa']) |
---|
| 63 | |
---|
| 64 | class CustomStudentStudyLevelFactory(StudentStudyLevelFactory): |
---|
| 65 | """A factory for student study levels. |
---|
| 66 | """ |
---|
| 67 | |
---|
| 68 | def __call__(self, *args, **kw): |
---|
| 69 | return CustomStudentStudyLevel() |
---|
| 70 | |
---|
| 71 | def getInterfaces(self): |
---|
| 72 | return implementedBy(CustomStudentStudyLevel) |
---|
| 73 | |
---|
| 74 | class CustomCourseTicket(CourseTicket): |
---|
| 75 | """ |
---|
[14988] | 76 | """ |
---|
[10765] | 77 | grok.implements(ICustomCourseTicket, IStudentNavigation) |
---|
| 78 | grok.provides(ICustomCourseTicket) |
---|
| 79 | |
---|
| 80 | |
---|
[14988] | 81 | @property |
---|
| 82 | def _getGradeWeightFromScore(self): |
---|
| 83 | """DSPG Course Grading System |
---|
| 84 | """ |
---|
| 85 | if self.total_score is None: |
---|
| 86 | return (None, None) |
---|
| 87 | if self.total_score >= 75: |
---|
| 88 | return ('A',4) |
---|
| 89 | if self.total_score >= 70: |
---|
| 90 | return ('AB',3.5) |
---|
| 91 | if self.total_score >= 65: |
---|
| 92 | return ('B',3.25) |
---|
| 93 | if self.total_score >= 60: |
---|
| 94 | return ('BC',3.0) |
---|
| 95 | if self.total_score >= 55: |
---|
| 96 | return ('C',2.75) |
---|
| 97 | if self.total_score >= 50: |
---|
| 98 | return ('CD',2.5) |
---|
| 99 | if self.total_score >= 45: |
---|
| 100 | return ('D',2.25) |
---|
| 101 | if self.total_score >= 40: |
---|
| 102 | return ('E',2) |
---|
| 103 | return ('F',0) |
---|
| 104 | |
---|
| 105 | |
---|
[10765] | 106 | CustomCourseTicket = attrs_to_fields(CustomCourseTicket) |
---|
| 107 | |
---|
| 108 | class CustomCourseTicketFactory(CourseTicketFactory): |
---|
| 109 | """A factory for student study levels. |
---|
| 110 | """ |
---|
| 111 | |
---|
| 112 | def __call__(self, *args, **kw): |
---|
| 113 | return CustomCourseTicket() |
---|
| 114 | |
---|
| 115 | def getInterfaces(self): |
---|
| 116 | return implementedBy(CustomCourseTicket) |
---|