Ignore:
Timestamp:
31 May 2013, 05:21:11 (12 years ago)
Author:
Henrik Bettermann
Message:

Calculate sessional gpa.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/studycourse.py

    r10250 r10260  
    126126        """
    127127        levels = []
    128         gpa = 0.0
    129         credits_counted = 0
     128        cgpa = 0.0
     129        total_credits_counted = 0
    130130        for level_key, level_val in self.items():
    131131            tickets_1 = []
     
    133133            tickets_3 = []
    134134            tickets = sorted(level_val.values(), key=lambda ticket: ticket.code)
     135            sgpa = 0.0
     136            session_credits_counted = 0
    135137            for ticket in tickets:
    136138                if ticket.semester == 1:
     
    141143                    tickets_3.append(ticket)
    142144                if ticket.score:
    143                     credits_counted += ticket.credits
    144                     gpa += ticket.credits * ticket.weight
     145                    total_credits_counted += ticket.credits
     146                    session_credits_counted += ticket.credits
     147                    cgpa += ticket.credits * ticket.weight
     148                    sgpa += ticket.credits * ticket.weight
     149            if session_credits_counted:
     150                sgpa = round(sgpa/session_credits_counted, 2)
    145151            levels.append(
    146152                dict(level_key=level_key,
     
    148154                     tickets_1=tickets_1,
    149155                     tickets_2=tickets_2,
    150                      tickets_3=tickets_3))
    151         if credits_counted:
    152             gpa = round(gpa/credits_counted, 2)
    153         return sorted(levels, key=lambda level: level['level_key']), gpa
     156                     tickets_3=tickets_3,
     157                     sgpa=sgpa))
     158        if total_credits_counted:
     159            cgpa = round(cgpa/total_credits_counted, 2)
     160        return sorted(levels, key=lambda level: level['level_key']), cgpa
    154161
    155162StudentStudyCourse = attrs_to_fields(StudentStudyCourse)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r10259 r10260  
    18351835        td = self.student['studycourse'].getTranscriptData()
    18361836        self.assertEqual(td[0][0]['level_key'], '100')
     1837        self.assertEqual(td[0][0]['sgpa'], 3.57)
    18371838        self.assertEqual(td[0][0]['level'].level, 100)
    18381839        self.assertEqual(td[0][0]['level'].level_session, 2005)
Note: See TracChangeset for help on using the changeset viewer.