Ejemplo n.º 1
0
def interact():
    stat = Statistics()
    black = BlackList()

    while True:
        print("Объяснение: ")
        word = explanator.get_random_word()
        explanation = explanator.explain(word)
        print(explanation)

        input("Нажмите enter, чтобы узнать ответ")
        print("Ответ: " + word)

        result = input("Угадали? Если объяснение некорректно, введите i. (y/n/i) ")
        while result != "y" and result != "n" and result != "i":
            result = input("Некорректный ввод. Введите y/n/i ")
        if result == 'i':
            black.blame(explanation)
        else:
            stat.update(explanation, 'SUCCESS' if result == 'y' else 'FAIL')

        result = input("Продолжить? (y/n) ")
        while result != "y" and result != "n":
            result = input("Некорректный ввод. Введите y/n ")
        if result == "n":
            print("Спасибо!")
            break
    stat.save()
    black.save()
Ejemplo n.º 2
0
 def __init__(self):
     self._undo = UndoController()
     self._stud = StudentController(Repository(), StudentValidator(),
                                    self._undo)
     self._assign = AssignmnetController(Repository(),
                                         AssignmentValidator(), self._undo)
     self._grade = GradeController(Repository(), GradeValidator(),
                                   self._stud, self._assign, self._undo)
     self._stat = Statistics(self._grade)
Ejemplo n.º 3
0
class Goals:
    def __init__(self, user: User) -> None:
        self.user = user
        self.statistics = Statistics(user)

    def set(self, name: str, volume: int) -> None:
        models.Goal.objects.update_or_create(user=self.user, name=name, defaults={'volume': volume})

    def delete(self, name: str) -> None:
        models.Goal.objects.filter(user=self.user, name=name).delete()

    def get(self, name) -> Goal:
        for goal in self.all():
            if goal.name == name:
                return goal
        return None

    def _has_goal(self, name: str) -> bool:
        return True if self.get(name) else False

    def workouts_not_having_goal(self):
        workouts = self.statistics.most_popular_workouts()
        return [workout.name for workout in workouts if not self._has_goal(workout.name)]

    def all(self, now=timezone.now()) -> List[Goal]:
        volumes = {f.name: f.volume for f in self.statistics.favourites_this_month()}

        def calculate_forecast(percent):
            date_progress = dates.this_month(now=now).progress(now)

            if percent >= 100:
                return Forecast.DONE

            if percent > date_progress + 10:
                return Forecast.AHEAD

            if percent < date_progress - 10:
                return Forecast.BEHIND

            return Forecast.ON_TRACK

        def make_goal(goal):
            current = volumes.get(goal.name, units.Volume(0))

            percent = 0
            if goal.volume > 0:
                percent = round(current.number() / goal.volume * 100)

            return Goal(name=goal.name,
                        volume=goal.volume,
                        progress=current,
                        percent=percent,
                        forecast=calculate_forecast(percent),
                        left=current.left_to(goal.volume))

        return [make_goal(g) for g in models.Goal.objects.filter(user=self.user)]
Ejemplo n.º 4
0
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        seed(5)
        self.testData = randint(0, 10, 20)
        self.statistics = Statistics()

    def test_instantiate_calculator(self):
        self.assertIsInstance(self.statistics, Statistics)

    def test_mean_calculator(self):
        mean = self.statistics.mean(self.testData)
        self.assertEqual(mean, 4.25)
Ejemplo n.º 5
0
    grRepo = BinRepository("data\\" + sets.repoGr, Grade)
elif sets.repo == "json_file":
    stRepo = JsonRepository("data\\" + sets.repoSt, Student)
    asRepo = JsonRepository("data\\" + sets.repoAs, Assignment)
    grRepo = JsonRepository("data\\" + sets.repoGr, Grade)
elif sets.repo == "mongoDB":
    stRepo = MongoRepository(Student)
    asRepo = MongoRepository(Assignment)
    grRepo = MongoRepository(Grade)
else:
    raise ValueError("Repo must be from memory/text_file/binary_file/json_file/mongoDB")

stCtr = StudentController(stRepo, StudentValidator(), undoCtr)
asCtr = AssignmnetController(asRepo, AssignmentValidator(), undoCtr)
grCtr = GradeController(grRepo, GradeValidator(), stCtr, asCtr, undoCtr)
stat = Statistics(grCtr)
if sets.ui == "cli":
    menu = CliMenu(undoCtr, stCtr, asCtr, grCtr, stat)
    menu.mainMenu()
elif sets.ui == "gui":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    StudentsManagement = QtWidgets.QMainWindow()
    ui = Ui_StudentsManagement(undoCtr, stCtr, asCtr, grCtr, stat)
    ui.setupUi(StudentsManagement)
    StudentsManagement.show()
    sys.exit(app.exec_())

else:
    raise ValueError("UI must be cli/gui!")
Ejemplo n.º 6
0
 def __init__(self, user: User) -> None:
     self.user = user
     self.statistics = Statistics(user)
Ejemplo n.º 7
0
class Menu:
    def __init__(self):
        self._undo = UndoController()
        self._stud = StudentController(Repository(), StudentValidator(),
                                       self._undo)
        self._assign = AssignmnetController(Repository(),
                                            AssignmentValidator(), self._undo)
        self._grade = GradeController(Repository(), GradeValidator(),
                                      self._stud, self._assign, self._undo)
        self._stat = Statistics(self._grade)

    @staticmethod
    def printMenu():
        men = "\nAvailable commands:\n"
        men += "\t 1 - Add student\n"
        men += "\t 2 - Remove student\n"
        men += "\t 3 - Update student infos\n"
        men += "\t 4 - List students\n"
        men += "\t 5 - Add assignment\n"
        men += "\t 6 - Remove assignment\n"
        men += "\t 7 - Update assignment infos\n"
        men += "\t 8 - List assignments\n"
        men += "\t 9 - Add assignment to student/group\n"
        men += "\t10 - List grades\n"
        men += "\t11 - Set grade\n"
        men += "\t12 - All students who received a given assignment, ordered alphabetically or by average grade for that assignment\n"
        men += "\t13 - All students who are late in handing in at least one assignment. These are all the students who have an ungraded assignment for which the deadline has passed\n"
        men += "\t14 - Students with the best school situation, sorted in descending order of the average grade received for all assignments\n"
        men += "\t15 - All assignments for which there is at least one grade, sorted in descending order of the average grade received by all students who received that assignment\n"
        men += "\t16 - Undo\n"
        men += "\t17 - Redo\n"
        men += "\t18 - Help\n"
        men += "\t 0 - Exit\n"
        print(men)

    def mainMenu(self):
        Menu.printMenu()
        populateStCtrDYN(self._stud, 100)
        populateAsCtrDYN(self._assign, 100)
        populateGrCtrDYN(self._grade, 100)
        #populateStCtrSTATIC(self._stud)
        #populateAsCtrSTATIC(self._assign)
        #populateGrCtrSTATIC(self._grade)
        while True:
            try:
                cmd = input("Enter command: ").strip()
                if cmd == '0':
                    print(
                        "Thank you for using grading system! Have a great day! :)"
                    )
                    return 0
                elif cmd == '1':
                    self.uiAddStud()
                elif cmd == '2':
                    self.uiRmvStud()
                elif cmd == '3':
                    self.uiUpdateStud()
                elif cmd == '4':
                    self.uiListStud()
                elif cmd == '5':
                    self.uiAddAssig()
                elif cmd == '6':
                    self.uiRmvAssig()
                elif cmd == '7':
                    self.uiUpdateAssig()
                elif cmd == '8':
                    self.uiListAssig()
                elif cmd == '9':
                    self.uiAddAssigToStGr()
                elif cmd == '10':
                    self.uiListGrades()
                elif cmd == '11':
                    self.uiGradeStud()
                elif cmd == '12':
                    self.uiStat1()
                elif cmd == '13':
                    self.uiStat2()
                elif cmd == '14':
                    self.uiStat3()
                elif cmd == '15':
                    self.uiStat4()
                elif cmd == '16':
                    self._undo.undo()
                elif cmd == '17':
                    self._undo.redo()
                elif cmd == '18':
                    Menu.printMenu()
                else:
                    print("Invalid CMD!")
            except Exception as er:
                print("Error: " + str(er))

    def uiAddStud(self):
        sID = (input("Student ID: "))
        if sID.isnumeric():
            sID = int(sID)
        else:
            raise TypeError("ID must be an int!")
        sName = input("Student name: ")
        sGroup = input("Student group: ")
        stu = Student(sID, sName, sGroup)
        self._stud.add(stu)
        return True

    def uiRmvStud(self):
        sID = input("ID of student you want to delete: ")
        if sID.isnumeric():
            sID = int(sID)
        else:
            raise TypeError("ID must be an int!")
        self._grade.removeStud(sID)

    def uiUpdateStud(self):
        cmd = input(
            "To update a student specific info type 1\n or 0 for complete infos:"
        ).strip()
        s = Student(-1, -1, -1)
        if cmd == '1':
            info = input("To modify: Name type 1, Group type 2: ").strip()
            if info == '1':
                s.id = int(input("Students ID you want to update: "))
                s.name = input("Enter new name: ")
                s.group = self._stud.findByID(s.id).group
                StudentValidator().validate(s)
                self._stud.update(s)
                return True
            elif info == '2':
                s.id = int(input("Students ID you want to update: "))
                s.group = input("Enter new grop: ")
                s.name = self._stud.findByID(s.id).name
                StudentValidator().validate(s)
                self._stud.update(s)
                return True
            else:
                print("Invalid command!")
        elif cmd == '0':
            s.id = int(input("Students ID you want to update: "))
            s.name = input("Enter new name: ")
            s.group = input("Enter new grop: ")
            StudentValidator().validate(s)
            self._stud.update(s)
            return True
        else:
            print("Invalid command!")

    def uiListStud(self):
        print(self._stud)

    def uiAddAssig(self):
        aID = input("Assignment ID: ")
        if aID.isnumeric():
            aID = int(aID)
        else:
            raise TypeError("ID must be an int!")
        aDesc = input("Assignment description: ")
        aDeadline = input("Assignment deadline: ")
        assig = Assignment(aID, aDesc, aDeadline)
        self._assign.add(assig)
        return True

    def uiRmvAssig(self):
        aID = input("ID of assignment you want to delete: ")
        if aID.isnumeric():
            aID = int(aID)
        else:
            raise TypeError("ID must be an int!")
        self._grade.removeAssign(aID)

    def uiUpdateAssig(self):
        cmd = input(
            "To update an assignment specific info type 1\nor 2 for complete infos:"
        ).strip()
        assign = Assignment(-1, -1, -1)
        if cmd == '1':
            info = input(
                "To modify: Description type 1, Deadline type 2: ").strip()
            if info == '1':
                assign.id = int(input("Assignments ID you want to update: "))
                newDesc = input("Enter new description: ")
                assign.description = newDesc
                assign.deadline = self._assign.findByID(assign.id).deadline
                AssignmentValidator().validate(assign)
                self._assign.update(assign)
                return True
            elif info == '2':
                assign.id = int(input("Assignments ID you want to update: "))
                newDeadline = input("Enter new deadline: ")
                assign.deadline = newDeadline
                assign.description = self._assign.findByID(
                    assign.id).description
                AssignmentValidator().validate(assign)
                self._assign.update(assign)
                return True
            else:
                print("Invalid command!")
        elif cmd == '2':
            assign.id = int(input("Assignment ID you are looking to update: "))
            assign.description = input("Enter new description: ")
            assign.deadline = input("Enter new deadline: ")
            AssignmentValidator().validate(assign)
            self._assign.update(assign)
            return True
        else:
            print("Invalid command!")

    def uiListAssig(self):
        print(self._assign)

    def uiListGrades(self):
        print(self._grade)

    def uiAddAssigToStGr(self):
        cmd = input(
            "Type 1 for setting an assignment to a student or 2 to set it to a group: "
        ).strip()
        if (cmd == '1'):
            aID = input("Assignment ID: ")
            sID = input("Student ID: ")
            if aID.isnumeric() and sID.isnumeric():
                aID = int(aID)
                sID = int(sID)
            else:
                raise TypeError("ID must be an int!")
            self._grade.setAssigStud(aID, sID)
        elif (cmd == '2'):
            gr = input("Group: ")
            aID = input("Assignment ID: ")
            if aID.isnumeric():
                aID = int(aID)
            else:
                raise TypeError("ID must be an int!")
            self._grade.giveAssigToGroup(aID, gr)
        else:
            print("Invalid command!")

    def uiGradeStud(self):
        sID = input("Write the id of student you want to grade: ")
        if not sID.isnumeric():
            raise Exception("Student id must be a positive int")
        sID = int(sID)
        if type(self._stud.findByID(sID)) != Student:
            raise ValueError("No student with such an id!")
        x = self._grade.getStudUngrade(sID)
        if len(x) == 0:
            raise Exception("No assignments to grade!")
        assigIDs = []
        for i in x:
            assigIDs.append(i.assignID)
            print("\t" + str(i))
        aID = input("Write the assignment id from the above list: ")
        if not aID.isnumeric():
            raise Exception("Assignment id must be a positive int")
        aID = int(aID)
        if aID not in assigIDs:
            raise ValueError("Assignment id must be from the above list!")
        grade = float(input("Write the grade:"))
        x = self._grade.setGrade(sID, aID, grade)
        print(x)

    def uiStat1(self):
        aID = input("Write the assignment id for the statistic: ")
        if not aID.isnumeric():
            raise Exception("Assignment id must be a positive int")
        aID = int(aID)
        x = self._stat.getStudGivenAssig(aID)
        if len(x) > 0:
            print(
                "All students who received a given assignment, ordered alphabetically or by average grade for that assignment"
            )
            for i in x:
                print(str(i))
        else:
            print("No student satisffies this condition!")

    def uiStat2(self):
        x = self._stat.getLateStuds()
        if len(x) > 0:
            print(
                "All students who are late in handing in at least one assignment.\nThese are all the students who have an ungraded assignment for which the deadline has passed"
            )
            for i in x:
                print(str(i))
        else:
            print("No student satisffies this condition!")

    def uiStat3(self):
        x = self._stat.getStudBestGrSchool()
        if len(x) > 0:
            print(
                "Students with the best school situation, sorted in descending order of the average grade received for all assignments"
            )
            for i in x:
                print(i)
        else:
            print("No student satisffies this condition!")

    def uiStat4(self):
        x = self._stat.getAssigByGrade()
        if len(x) > 0:
            print(
                "All assignments for which there is at least one grade, sorted in descending order of the average grade received by all students who received that assignment"
            )
            for i in x:
                print(i)
        else:
            print("No assignmnet satisffies this condition!")
Ejemplo n.º 8
0
 def setUp(self) -> None:
     seed(5)
     self.testData = randint(0, 10, 20)
     self.statistics = Statistics()
Ejemplo n.º 9
0
from portfolio_handler import PortfolioHandler
from order_sizing.order_sizer import OrderSizer
from strategy import Test
from prices import FetchCassPrices
from risk_management.risk_manager import RiskManager
from statistics.statistics import Statistics


if __name__ == "__main__":
    instruments = ['brent', "wti"]
    dates = {'start_date': "2016-01-01",
             "end_date": "2016-01-08"}
    strategy_params = {"division": 5}

    backtest = Backtest(
        instruments=instruments,
        data_handler=FetchCassPrices,
        dates=dates,
        strategy=Test,
        strategy_params=strategy_params,
        portfolio_handler=PortfolioHandler,
        execution=SimExecution,
        order_sizer=OrderSizer,
        risk_manager=RiskManager,
    )

    backtest.start_backtest()
    stats = Statistics()
    stats.generate_results()
    stats.plot_results()