Beispiel #1
0
class UI:

    def __init__(self):
        self.__iniC = Configuration(self.readFile())
        self.__p = Problem(self.__iniC)
        self.__contr = Controller(self.__p)

    def readFile(self):
        with open("easyboard") as f:
            content = f.readlines()
        content = [x.strip() for x in content]
        content = [x.replace(' ', '') for x in content]
        n = int(content[0])
        matrix = [[0] * n for i in range(n)]
        content.pop(0)
        for x in content:
            matrix[int(x[0])][int(x[1])] = int(x[2])
        for x in matrix:
            print(x)
        return matrix

    def printMainMenu(self):
        s = ''
        s += "0 - exit \n"
        s += "2 - find a path with BFS \n"
        s += "3 - find a path with BestFS\n"
        print(s)


    def findPathBFS(self):
        startClock = time()
        matrix = self.__contr.BFS(self.__p.getRoot())
        for row in matrix.getValues():
            print(row)
        print('execution time = ', time() - startClock, " seconds")

    def findPathBestFS(self):
        startClock = time()
        print(str(self.__contr.BestFS(self.__p.getRoot())))
        print('execution time = ', time() - startClock, " seconds")

    def run(self):
        runM = True
        self.printMainMenu()
        while runM:
            try:
                command = int(input(">>"))
                if command == 0:
                    runM = False
                elif command == 1:
                    pass
                elif command == 2:
                    self.findPathBFS()
                elif command == 3:

                    self.findPathBestFS()
            except:
                print('invalid command')
 def updateGrade(self,obj):
     self.__undo=copy.copy(self.__data)
     print(obj.getGrade())
     e=self.find(obj.getId(),obj.getLab())
     if e==None:
         raise ValueError("Object does not exist")
     elif e.getGrade()!=0:
         raise ValueError("Grade cannot be modified")
     else:
         idx=self.__data.index(e)
         
         obj2=Problem(obj.getId(),obj.getLab(),e.getProblem(),obj.getGrade())
         self.__data.remove(e)
         self.__data.insert(idx,obj2)
         print(str(obj2.getId()),str(obj2.getLab()),obj2.getProblem(),str(obj2.getGrade()))
         self.__storeToFile()
    def assignLaboratory(self, lab, fName, group):
        list = []
        f = open(fName, 'r')
        t = f.readline().strip()
        while t != '':
            list.append(t)
            t = f.readline().strip()
        f.close()
        studs = self.__repo.getAll()
        i = 0

        self.__undop = 2
        self.__prepop = copy.copy(self.__prepo.getAll())
        self.__redop = None
        self.__undor = None
        self.__redor = None
        for e in studs:
            if e.getGroup() == group:
                try:
                    if i == len(list):
                        i = 0
                    self.__prepo.add(Problem(e.getId(), lab, list[i], 0))
                    i += 1
                except ValueError:
                    pass
Beispiel #4
0
 def __addProblem(self):
     try:
         id=int(input("Input id "))
         lab=int(input("Input lab "))
         problem=input("Input problem ")
         self.__ctrl.addProblem(Problem(id,lab,problem,0))
         
         
     except ValueError as e:
         print(e)
Beispiel #5
0
 def __assignGrade(self):
     try:
         id=int(input("Input id "))
         lab=int(input("Input lab "))
         problem='random'
         grade=int(input('Input grade '))
         if grade<1 or grade>10:
             raise ValueError("wrong grade")
         self.__ctrl.gradeStudent(Problem(id,lab,problem,grade))
         
     except ValueError as e:
         print(e)
Beispiel #6
0
    def __loadFromFile(self):
        try:
            f = open(self._fName, 'r')
            t = f.readline().strip()
            while t != '':
                args = t.split(',')
                self.__data.append(
                    Problem(int(args[0]), int(args[1]), args[2], int(args[3])))
                t = f.readline().strip()

            f.close()
        except IOError:
            return
Beispiel #7
0
    def updateGrade(self, obj):
        self.__undo = copy.copy(self.__data)
        print(obj.getGrade())
        e = self.find(obj.getId(), obj.getLab())
        if e == None:
            raise ValueError("Object does not exist")
        elif e.getGrade() != 0:
            raise ValueError("Grade cannot be modified")
        else:
            idx = self.__data.index(e)

            obj2 = Problem(obj.getId(), obj.getLab(), e.getProblem(),
                           obj.getGrade())
            self.__data.remove(e)
            self.__data.insert(idx, obj2)
            print(str(obj2.getId()), str(obj2.getLab()), obj2.getProblem(),
                  str(obj2.getGrade()))
            self.__storeToFile()
Beispiel #8
0
 def __init__(self):
     self.__iniC = Configuration(self.readFile())
     self.__p = Problem(self.__iniC)
     self.__contr = Controller(self.__p)