Compare commits
12 Commits
0.1-running
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| fbb8bb56ad | |||
| ca29c60881 | |||
| caf650eaef | |||
| 0cb5e2f73f | |||
| a3fce9f7e4 | |||
| 8b9823f48f | |||
| 4fd2e1e278 | |||
| 97541f8cd3 | |||
| 16cb42203d | |||
| 93c9c9d33c | |||
| 92d253680e | |||
| 9727e3381a |
@@ -0,0 +1,22 @@
|
|||||||
|
class NotANumberException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class SubjectNotExistingException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class CategoryNotExistingException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class WrongCaseException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def convertible(string):
|
||||||
|
try:
|
||||||
|
float(string)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
raise NotANumberException
|
||||||
@@ -1,38 +1,54 @@
|
|||||||
import subject
|
import subject
|
||||||
import user_IO
|
import user_IO
|
||||||
|
import serializer
|
||||||
|
import encryption
|
||||||
|
import exceptions
|
||||||
|
import os
|
||||||
|
|
||||||
subjects = []
|
subjects = []
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
user_input = user_IO.user_input()
|
try:
|
||||||
input_or_output = user_input[0]
|
user_input = user_IO.user_input()
|
||||||
if input_or_output == "input":
|
input_or_output = user_input[0]
|
||||||
_edit = user_input[1]
|
if input_or_output == "input":
|
||||||
_subject = user_input[2]
|
_edit = user_input[1]
|
||||||
if _edit == "grade":
|
_subject = user_input[2]
|
||||||
_category = user_input[3]
|
if _edit == "grade":
|
||||||
_grade = user_input[4]
|
_category = user_input[3]
|
||||||
_grade_name = user_input[5]
|
_grade = user_input[4]
|
||||||
subject_edit = subject.get_subject(subjects, _subject)
|
_grade_name = user_input[5]
|
||||||
if subject_edit:
|
subject_edit = subject.get_subject(subjects, _subject)
|
||||||
subject_edit.add_grade(_category, subject.Grade(_grade, _grade_name))
|
if subject_edit:
|
||||||
elif _edit == "category":
|
subject_edit.add_grade(_category, subject.Grade(_grade, _grade_name))
|
||||||
_category = user_input[3]
|
elif _edit == "category":
|
||||||
_rating = user_input[4]
|
_category = user_input[3]
|
||||||
subject_edit = subject.get_subject(subjects, _subject)
|
_rating = user_input[4]
|
||||||
if subject_edit:
|
subject_edit = subject.get_subject(subjects, _subject)
|
||||||
subject_edit.add_grade_category(_category, _rating)
|
if subject_edit:
|
||||||
elif _edit == "subject":
|
subject_edit.add_grade_category(_category, _rating)
|
||||||
_main = user_input[3]
|
elif _edit == "subject":
|
||||||
_oral = user_input[4]
|
_main = user_input[3]
|
||||||
subjects.append(subject.Subject(_subject, _main, _oral))
|
_oral = user_input[4]
|
||||||
elif input_or_output == "output":
|
subjects.append(subject.Subject(_subject, _main, _oral))
|
||||||
_subject = user_input[1]
|
else:
|
||||||
subject_get = subject.get_subject(subjects, _subject)
|
raise exceptions.WrongCaseException
|
||||||
user_IO.user_output(subject_get.name, subject_get.return_grade_categories(),
|
elif input_or_output == "output":
|
||||||
|
_subject = user_input[1]
|
||||||
|
subject_get = subject.get_subject(subjects, _subject)
|
||||||
|
user_IO.user_output(subject_get.name, subject_get.return_grade_categories(),
|
||||||
[subject_get.return_average_of_category(i) for i in subject_get.return_grade_categories()],
|
[subject_get.return_average_of_category(i) for i in subject_get.return_grade_categories()],
|
||||||
subject_get.return_average_of_subject())
|
subject_get.return_average_of_subject())
|
||||||
raise SystemError
|
elif input_or_output == "exit":
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise exceptions.WrongCaseException
|
||||||
|
|
||||||
|
except (exceptions.NotANumberException, exceptions.CategoryNotExistingException,
|
||||||
|
exceptions.SubjectNotExistingException, exceptions.WrongCaseException) as e:
|
||||||
|
user_IO.exception_raised(e)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('ERROR' + str(e))
|
print('ERROR' + str(e))
|
||||||
|
|||||||
@@ -1,6 +1,24 @@
|
|||||||
|
import json
|
||||||
|
import subject
|
||||||
|
|
||||||
|
|
||||||
|
class TempSubject:
|
||||||
|
def __init__(self, string):
|
||||||
|
self.__dict__ = json.loads(string)
|
||||||
|
|
||||||
|
|
||||||
def serialize(subject):
|
def serialize(subject):
|
||||||
string = subject.__dict__
|
string = subject.__dict__
|
||||||
for category in string["grades"]:
|
for category in string["grades"]:
|
||||||
for counter, grade in enumerate(string["grades"][category][0]):
|
for counter, grade in enumerate(string["grades"][category][0]):
|
||||||
string["grades"][category][0][counter] = grade.__dict__
|
string["grades"][category][0][counter] = grade.__dict__
|
||||||
return str(string)
|
return str(string)
|
||||||
|
|
||||||
|
|
||||||
|
def deserialize(string):
|
||||||
|
temp = TempSubject(string)
|
||||||
|
_subject = subject.Subject(temp.name, bool(temp.main_subject), bool(temp.oral_exam))
|
||||||
|
for category in temp.grades:
|
||||||
|
_subject.add_grade_category(category, temp.grades[category][1])
|
||||||
|
return _subject
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -1,4 +1,5 @@
|
|||||||
from datetime import datetime as str_date
|
from datetime import datetime as str_date
|
||||||
|
from exceptions import SubjectNotExistingException, CategoryNotExistingException
|
||||||
|
|
||||||
|
|
||||||
class Subject:
|
class Subject:
|
||||||
@@ -32,6 +33,11 @@ class Subject:
|
|||||||
grade_sum += self.return_average_of_category(i)*self.grades[i][1]
|
grade_sum += self.return_average_of_category(i)*self.grades[i][1]
|
||||||
return grade_sum / rating_sum
|
return grade_sum / rating_sum
|
||||||
|
|
||||||
|
def category_existing(self, category):
|
||||||
|
if category in self.grades:
|
||||||
|
return True
|
||||||
|
raise CategoryNotExistingException
|
||||||
|
|
||||||
|
|
||||||
class Grade:
|
class Grade:
|
||||||
def __init__(self, grade, name, date=str(str_date.now())):
|
def __init__(self, grade, name, date=str(str_date.now())):
|
||||||
@@ -44,4 +50,4 @@ def get_subject(liste, name):
|
|||||||
for subject in liste:
|
for subject in liste:
|
||||||
if subject.name == name:
|
if subject.name == name:
|
||||||
return subject
|
return subject
|
||||||
return None
|
raise SubjectNotExistingException
|
||||||
|
|||||||
+27
-4
@@ -1,5 +1,8 @@
|
|||||||
|
import exceptions
|
||||||
|
|
||||||
|
|
||||||
def user_input():
|
def user_input():
|
||||||
todo = input("Ok, do you want to see them or to edit them [see/edit]?\n")
|
todo = input("Ok, do you want to see them or to edit them [see/edit/exit]?\n")
|
||||||
if todo == "see":
|
if todo == "see":
|
||||||
print("Which subject do you want to know the information?")
|
print("Which subject do you want to know the information?")
|
||||||
subject = input()
|
subject = input()
|
||||||
@@ -14,23 +17,31 @@ def user_input():
|
|||||||
main_subject = True
|
main_subject = True
|
||||||
elif main_subject == 'n':
|
elif main_subject == 'n':
|
||||||
main_subject = False
|
main_subject = False
|
||||||
|
else:
|
||||||
|
raise exceptions.WrongCaseException
|
||||||
oral_exam = input("Will there be an oral exam in this subject [y/n]? \n")
|
oral_exam = input("Will there be an oral exam in this subject [y/n]? \n")
|
||||||
if oral_exam == 'y':
|
if oral_exam == 'y':
|
||||||
oral_exam = True
|
oral_exam = True
|
||||||
elif oral_exam == 'n':
|
elif oral_exam == 'n':
|
||||||
oral_exam = False
|
oral_exam = False
|
||||||
|
else:
|
||||||
|
raise exceptions.WrongCaseException
|
||||||
return "input", "subject", subject, main_subject, oral_exam
|
return "input", "subject", subject, main_subject, oral_exam
|
||||||
elif user_add == "category":
|
elif user_add == "category":
|
||||||
subject = input("To which subject do you want to add the category? \n")
|
subject = input("To which subject do you want to add the category? \n")
|
||||||
category = input("Which category do you want to add? \n")
|
category = input("Which category do you want to add? \n")
|
||||||
rating = float(input("Rating? \n"))
|
rating = float(input("Rating? \n"))
|
||||||
return "input", "category", subject, category, rating
|
if exceptions.convertible(rating):
|
||||||
|
return "input", "category", subject, category, rating
|
||||||
elif user_add == "grade":
|
elif user_add == "grade":
|
||||||
subject = input("To which subject do you want to add the grade? \n")
|
subject = input("To which subject do you want to add the grade? \n")
|
||||||
category = input("To which category do you want to add it? \n")
|
category = input("To which category do you want to add it? \n")
|
||||||
grade = input("Grade? \n")
|
grade = input("Grade? \n")
|
||||||
grade_name = input("What's the name of the grade? \n")
|
grade_name = input("What's the name of the grade? \n")
|
||||||
return "input", "grade", subject, category, grade, grade_name
|
if exceptions.convertible(grade):
|
||||||
|
return "input", "grade", subject, category, grade, grade_name
|
||||||
|
elif todo == "exit":
|
||||||
|
return "exit"
|
||||||
|
|
||||||
|
|
||||||
def user_output(subject, categories, average, average_subject):
|
def user_output(subject, categories, average, average_subject):
|
||||||
@@ -41,4 +52,16 @@ def user_output(subject, categories, average, average_subject):
|
|||||||
for grade in categories[category][0]:
|
for grade in categories[category][0]:
|
||||||
string += str(grade.grade) + ", "
|
string += str(grade.grade) + ", "
|
||||||
print(string + "\n")
|
print(string + "\n")
|
||||||
print("The average of {} is {}.".format(subject, average_subject))
|
print("The average of {} is {}.".format(subject, average_subject))
|
||||||
|
|
||||||
|
|
||||||
|
def exception_raised(exception):
|
||||||
|
print("Dear user you've raised an exception. The cause of the exception is:")
|
||||||
|
if exception is exceptions.SubjectNotExistingException:
|
||||||
|
print("The subject you tried to access is not created")
|
||||||
|
elif exceptions is exceptions.CategoryNotExistingException:
|
||||||
|
print("The category you tried to add something is non-existent in this subject")
|
||||||
|
elif exception is exceptions.NotANumberException:
|
||||||
|
print("The number you gave the program is not a number")
|
||||||
|
elif exception is exceptions.WrongCaseException:
|
||||||
|
print("This was not one of the available choices")
|
||||||
Reference in New Issue
Block a user