source: main/kofacustom.dspg/trunk/src/kofacustom/dspg/students/studylevel.py @ 15284

Last change on this file since 15284 was 15097, checked in by Henrik Bettermann, 6 years ago

Customize gpa_params and round gpa.

  • Property svn:keywords set to Id
File size: 3.8 KB
RevLine 
[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"""
19Container which holds the data of a student study level
20and contains the course tickets.
21"""
22import grok
23from zope.component.interfaces import IFactory
24from zope.interface import implementedBy
25from waeup.kofa.utils.helpers import attrs_to_fields
26from waeup.kofa.students.studylevel import (
27    StudentStudyLevel, CourseTicket,
28    CourseTicketFactory, StudentStudyLevelFactory)
29from waeup.kofa.students.interfaces import IStudentNavigation
[14716]30from kofacustom.dspg.students.interfaces import (
[10765]31    ICustomStudentStudyLevel, ICustomCourseTicket)
32
33
34class 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]61CustomStudentStudyLevel = attrs_to_fields(
62    CustomStudentStudyLevel, omit=['total_credits', 'gpa'])
63
64class 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
74class 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]106CustomCourseTicket = attrs_to_fields(CustomCourseTicket)
107
108class 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)
Note: See TracBrowser for help on using the repository browser.