Ejemplo n.º 1
0
 def reserve(self, timeSlot, date):
     # time: 00:00
     # date: dd/mm/jjjj
     usedSeats = Table("stack")
     entered = Table("stack")
     return self.allReservations.insert(
         (date + " " + str(timeSlot), (usedSeats, entered)))
Ejemplo n.º 2
0
class Users:
    def __init__(self):
        self.allUsers = Table("hsep", 10, "bst")  # datastructure
        self.totalUsers = 0

    def addUser(self, firstName, lastName, mail, userID):
        newUser = SingleUser(userID, firstName, lastName, mail)
        insertSucces = self.allUsers.insert((userID, newUser))
        if insertSucces:
            self.totalUsers += 1
        return insertSucces

    def getUserInfo(self, userID):
        userExists, userData = self.allUsers.retrieve(userID)
        return userData.firstName, userData.lastName, userData.mail

    def changeUserMail(self, userID, newMail):
        userExists, userInfo = self.allUsers.retrieve(userID)
        if userExists:
            userInfo[1].mail = newMail
            return True
        return False

    def getUsers(self):
        return self.allUsers.traverse()
Ejemplo n.º 3
0
class Movies:
    def __init__(self):
        self.allFilms = Table("bst") #datastructure
        self.totalFilms = 0

    def addMovie(self, movie, rating=0.7, movieID=0):
        if type(movie) != SingleMovie:
            movie = SingleMovie(movie, rating, movieID)
        rv = self.allFilms.insert((movie.movieID, movie))
        if rv is True:
            self.totalFilms += 1
        return rv

    def deleteMovie(self, movieID):
        rv = self.allFilms.delete(movieID)
        if rv is True:
            self.totalFilms -= 1
        return rv

    def getMovies(self):
        return self.allFilms.traverse()

    def changeRating(self, movieID, newRating):
        if self.allFilms.retrieve(movieID)[0] is False:
            return False
        film = self.allFilms.retrieve(movieID)[1]
        film.rating = newRating
        return True

    def getMovieTitle(self, movieID):
        return self.allFilms.retrieve(movieID)[1].title
Ejemplo n.º 4
0
class Slots:
    def __init__(self):
        self.allSlots = Table("23")

    def addSlot(self, time, slotID):
        return self.allSlots.insert((slotID, time))

    def setupDefaultSlots(self):
        self.addSlot("14:30", 1)
        self.addSlot("17:00", 2)
        self.addSlot("20:00", 3)
        self.addSlot("22:30", 4)

    def slotIDToTime(self, slotID):
        return self.allSlots.retrieve(slotID)[1]

    def listAllSlots(self):
        returnList = []
        idList = self.allSlots.traverse()
        for slot in idList:
            returnList.append(self.slotIDToTime(slot))
        return returnList
Ejemplo n.º 5
0
    def executeInstruction(self, instruction):
        splitInstruction = instruction.split()
        if splitInstruction[0][:4] == "type":
            print("\nCreating datatype: " + splitInstruction[0][5:])
            if splitInstruction[0][5:9] == "hlin":
                size = splitInstruction[0].split(",")[1]
                self.table = Table("hlin", int(size))
                self.type = "hlin"
            elif splitInstruction[0][5:10] == "hquad":
                size = splitInstruction[0].split(",")[1]
                self.table = Table("hquad", int(size))
                self.type = "hquad"
            elif splitInstruction[0][5:9] == "hsep":
                size = splitInstruction[0].split(",")[1]
                chain = splitInstruction[0].split(",")[2]
                self.table = Table("hsep", int(size), chain)
                self.type = "hsep"
            else:
                self.table = Table(splitInstruction[0][5:])
                self.type = splitInstruction[0][5:]

        elif splitInstruction[0] == "insert":
            print(instruction)
            newItem = int(splitInstruction[1])
            self.table.insert(newItem)

        elif splitInstruction[0] == "delete":
            print(instruction)
            if len(splitInstruction) == 1:
                self.table.delete()
            else:
                searchKey = int(splitInstruction[1])
                self.table.delete(searchKey)

        elif splitInstruction[0] == "print":
            i = 1
            while path.exists("Output/ADTgraph/" + self.type + "-" + str(i) +
                              ".dot"):
                i += 1
            outputFile = open(
                "Output/ADTgraph/" + self.type + "-" + str(i) + ".dot", "a+")
            outputFile.write("digraph G {\n")
            code = self.table.visualize()
            outputFile.write(code)
            outputFile.write("\n}")
            outputFile.close()
            print("Output file created")
Ejemplo n.º 6
0
 def __init__(self):
     self.allSlots = Table("23")
Ejemplo n.º 7
0
 def __init__(self):
     self.allUsers = Table("hsep", 10, "bst")  # datastructure
     self.totalUsers = 0
Ejemplo n.º 8
0
 def __init__(self, allRooms, allMovies):
     self.allPlays = Table("ll")
     self.allRooms = allRooms
     self.allMovies = allMovies
Ejemplo n.º 9
0
class Plays:
    def __init__(self, allRooms, allMovies):
        self.allPlays = Table("ll")
        self.allRooms = allRooms
        self.allMovies = allMovies

    def getAllPlays(self):
        self.allPlays.table.bubbleSort("Play") # sort for linked lists
        return self.allPlays.traverse()

    def addPlay(self, roomName, timeSlot, date, movieID, playID):
        toegevoegd = False
        if self.allRooms.isFree(roomName, timeSlot, date):
            self.allRooms.reserveRoom(roomName, timeSlot, date)
            newPlay = SinglePlay(roomName, timeSlot, date, movieID, playID)
            self.allPlays.insert((playID, newPlay))
            toegevoegd = True
        return toegevoegd

    def removePlay(self, playID):
        playExists, playData = self.allPlays.retrieve(playID)
        if playExists:
            self.allRooms.cancelReservation(playData.roomName, playData.timeSlot, playData.date)
            return self.allPlays.delete(playID)
        return playExists

    def getInfo(self, playID):
        playExists, playData = self.allPlays.retrieve(playID)
        return playData.roomName, playData.timeSlot, playData.date, playData.movieID

    def changeRoomName(self, playID, newRoomName):
        veranderd = False
        playExists, playData = self.allPlays.retrieve(playID)
        if playExists:
            if self.allRooms.isFree(newRoomName, playData.timeSlot, playData.date):
                playData.roomName = newRoomName
                veranderd = True
            return veranderd
        return playExists

    def changeTime(self, playID, newTimeSlot):
        veranderd = False
        playExists, playData = self.allPlays.retrieve(playID)
        if playExists:
            if self.allRooms.isFree(playData.roomName, newTimeSlot, playData.date):
                playData.timeSlot = newTimeSlot
                veranderd = True
            return veranderd
        return playExists

    def changeDate(self, playID, newDate):
        veranderd = False
        playExists, playData = self.allPlays.retrieve(playID)
        if playExists:
            if self.allRooms.isFree(playData.roomName, playData.timeSlot, newDate):
                playData.date = newDate
                veranderd = True
            return veranderd
        return playExists

    def changeMovie(self, playID, newMovieID):
        playExists, playData = self.allPlays.retrieve(playID)
        if playExists:
            playData.movieID = newMovieID
        return playExists
Ejemplo n.º 10
0
 def __init__(self):
     self.allFilms = Table("bst") #datastructure
     self.totalFilms = 0
Ejemplo n.º 11
0
 def __init__(self):
     self.allRooms = Table("hsep", 10, "dll")  # datastructure
     self.totalRooms = 0
Ejemplo n.º 12
0
class Rooms:
    def __init__(self):
        self.allRooms = Table("hsep", 10, "dll")  # datastructure
        self.totalRooms = 0

    def addRoom(self, room, seats=100):
        if type(room) != SingleRoom:
            room = SingleRoom(room, seats)
        roomName = room.roomName
        rv = self.allRooms.insert((roomName, room))
        if rv is True:
            self.totalRooms += 1
        return rv

    def deleteRoom(self, roomName):
        rv = self.allRooms.delete(roomName)
        if rv is True:
            self.totalRooms -= 1
        return rv

    def retrieveRoom(self, roomName):
        return self.allRooms.retrieve(roomName)[1]

    def showRooms(self):
        return self.allRooms.traverse()

    def showReservations(self, roomName):
        room = self.allRooms.retrieve(roomName)[1]
        return room.showReservations()

    def reserveRoom(self, roomName, timeSlot, date):
        room = self.allRooms.retrieve(roomName)[1]
        return room.reserve(timeSlot, date)

    def cancelReservation(self, roomName, timeSlot, date):
        room = self.allRooms.retrieve(roomName)[1]
        return room.cancel(timeSlot, date)

    def showEmptySeats(self, roomName, timeSlot, date):
        room = self.allRooms.retrieve(roomName)[1]
        return room.showEmptySeats(timeSlot, date)

    def isFree(self, roomName, timeSlot, date):
        room = self.allRooms.retrieve(roomName)[1]
        return room.isFree(timeSlot, date)

    def changeEmptySeats(self, roomName, timeSlot, date, seats):
        if self.allRooms.retrieve(roomName) is False:
            return False
        room = self.allRooms.retrieve(roomName)[1]
        return room.changeSeats(seats, timeSlot, date)
Ejemplo n.º 13
0
 def __init__(self, roomName, seats):
     self.roomName = roomName
     self.seats = seats
     self.allReservations = Table("23")  # datastructure
Ejemplo n.º 14
0
class SingleRoom:
    def __init__(self, roomName, seats):
        self.roomName = roomName
        self.seats = seats
        self.allReservations = Table("23")  # datastructure

    def reserve(self, timeSlot, date):
        # time: 00:00
        # date: dd/mm/jjjj
        usedSeats = Table("stack")
        entered = Table("stack")
        return self.allReservations.insert(
            (date + " " + str(timeSlot), (usedSeats, entered)))

    def cancel(self, timeSlot, date):
        return self.allReservations.delete(date + " " + str(timeSlot))

    def showReservations(self):
        return self.allReservations.traverse()

    def showEmptySeats(self, timeSlot, date):
        usedSeats = self.allReservations.retrieve(date + " " +
                                                  str(timeSlot))[1]
        if usedSeats is None:
            return self.seats
        return self.seats - usedSeats[0].table.size

    def isFree(self, timeSlot, date):
        return not self.allReservations.retrieve(date + " " + str(timeSlot))[0]

    def changeSeats(self, seats, timeSlot, date):
        # Positive seats decreases emptySeats
        # Negative seats increases emptySeats
        usedSeats = self.allReservations.retrieve(date + " " + str(timeSlot))
        if usedSeats[1] is None:
            return False
        else:
            usedSeats = usedSeats[1][0]
        if seats < 0:
            if abs(seats) <= usedSeats.table.size:
                for _ in range(abs(seats)):
                    usedSeats.table.pop()
                return True
            return False
        elif seats > 0:
            if seats + usedSeats.table.size <= self.seats:
                for _ in range(seats):
                    usedSeats.table.push("X")
                return True
            return False

    def enterRoom(self, timeSlot, date, peopleAmount):
        self.changeSeats((-1) * peopleAmount, timeSlot, date)
        entered = self.allReservations.retrieve(date + " " + str(timeSlot))[1]
        if entered is not None:
            entered = entered[1]
            for _ in range(peopleAmount):
                entered.table.push("X")

    def entered(self, timeSlot, date):
        entered = self.allReservations.retrieve(date + " " + str(timeSlot))[1]
        if entered is not None:
            return entered[1].table.size
        return 0