## $Id: studylevel.py 15013 2018-05-20 19:44:44Z henrik $
##
## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
"""
Container which holds the data of a student study level
and contains the course tickets.
"""
import grok
from zope.component.interfaces import IFactory
from zope.interface import implementedBy
from waeup.kofa.utils.helpers import attrs_to_fields
from waeup.kofa.students.studylevel import (
    StudentStudyLevel, CourseTicket,
    CourseTicketFactory, StudentStudyLevelFactory)
from waeup.kofa.students.interfaces import IStudentNavigation
from kofacustom.edopoly.students.interfaces import (
    ICustomStudentStudyLevel, ICustomCourseTicket)


class CustomStudentStudyLevel(StudentStudyLevel):
    """This is a container for course tickets.
    """
    grok.implements(ICustomStudentStudyLevel, IStudentNavigation)
    grok.provides(ICustomStudentStudyLevel)

CustomStudentStudyLevel = attrs_to_fields(
    CustomStudentStudyLevel, omit=['total_credits', 'gpa'])

class CustomStudentStudyLevelFactory(StudentStudyLevelFactory):
    """A factory for student study levels.
    """

    def __call__(self, *args, **kw):
        return CustomStudentStudyLevel()

    def getInterfaces(self):
        return implementedBy(CustomStudentStudyLevel)

class CustomCourseTicket(CourseTicket):
    """
    """
    grok.implements(ICustomCourseTicket, IStudentNavigation)
    grok.provides(ICustomCourseTicket)

    @property
    def _getGradeWeightFromScore(self):
        """EdoPoly Course Grading System
        """
        if self.total_score is None:
            return (None, None)
        if self.total_score >= 75:
            return ('AA',4)
        if self.total_score >= 70:
            return ('A',3.5)
        if self.total_score >= 65:
            return ('AB',3.25)
        if self.total_score >= 60:
            return ('B',3.0)
        if self.total_score >= 55:
            return ('BC',2.75)
        if self.total_score >= 50:
            return ('C',2.5)
        if self.total_score >= 45:
            return ('CD',2.25)
        if self.total_score >= 40:
            return ('D',2)
        return ('F',0)

CustomCourseTicket = attrs_to_fields(CustomCourseTicket)

class CustomCourseTicketFactory(CourseTicketFactory):
    """A factory for student study levels.
    """

    def __call__(self, *args, **kw):
        return CustomCourseTicket()

    def getInterfaces(self):
        return implementedBy(CustomCourseTicket)
