# Path: evaluator.py
# def evaluate(self,answers):
# 	value = 0.0
# 	count = 0
# 	for a in answers:
# 		if a[1]:
# 			count += 1
# 			if (not self.isMultiple) and (count>1):
# 				return 0.0
# 			value += self.getOptionValue(a[0])[0]
# 		else:
# 			value += self.getOptionValue(a[0])[1]
# 	if self.min_value is not None and value < self.min_value:
# 		return self.min_value
# 	if self.max_value is not None and value > self.max_value:
# 		return self.max_value
# 	return value


from PyQt4.QtGui import *
from PyQt4 import uic
from os.path import join
from evaluator import evaluate
import os
import random
import csv

class ResultsPage(QWizardPage):
    path = "qtui/ui/page5_results.ui"

    def __init__(self, project, parentW=None):
        super(ResultsPage, self).__init__()
        self.ui = uic.loadUi(join(os.environ['AUTOEXAM_FOLDER'], self.path), self)
        self.project = project
        self.parentWizard = parentW

    def initializePage(self):
        super(ResultsPage, self).initializePage()

        self.results = self.parentWizard.results
        # TODO: Unwire this

# Path: evaluator.py
# def evaluate(self,answers):
# 	value = 0.0
# 	count = 0
# 	for a in answers:
# 		if a[1]:
# 			count += 1
# 			if (not self.isMultiple) and (count>1):
# 				return 0.0
# 			value += self.getOptionValue(a[0])[0]
# 		else:
# 			value += self.getOptionValue(a[0])[1]
# 	if self.min_value is not None and value < self.min_value:
# 		return self.min_value
# 	if self.max_value is not None and value > self.max_value:
# 		return self.max_value
# 	return value


# Path: qtui/results_page.py
from PyQt4.QtGui import *
from PyQt4 import uic
from os.path import join
from evaluator import evaluate
import os
import random
import csv


class ResultsPage(QWizardPage):
    path = "qtui/ui/page5_results.ui"

    def __init__(self, project, parentW=None):
        super(ResultsPage, self).__init__()
        self.ui = uic.loadUi(join(os.environ['AUTOEXAM_FOLDER'], self.path), self)
        self.project = project
        self.parentWizard = parentW

    def initializePage(self):
        super(ResultsPage, self).initializePage()

        self.results = self.parentWizard.results
        # TODO: Unwire this

        self.grades = evaluate('generated/last/grader.txt', 'generated/last/results.json')