def __init__(self, resId, resName): # take the dura self.name = resName self.id = resId freeSlot = Slot() freeSlot.resourceOnSlot = self self.freeSlots=[] self.freeSlots.append(freeSlot)
def __init__(self, meetingID): self.meeting = meetingID self.usersList = self.populateUsersList() self.user1List = [] self.user2List = [] db = pymysql.connect(host = "us-cdbr-iron-east-05.cleardb.net", user = "******", password = "******", database = "heroku_66bd76f57e3f221") cursor = db.cursor() firstUser = self.usersList[0] cursor.execute("SELECT * FROM slot WHERE userID = %s", [firstUser]) user1RawList = cursor.fetchall() for r in user1RawList: tempSlot = Slot(r) self.user1List.append(tempSlot) db.commit() cursor.close() db.close() db = pymysql.connect(host="localhost", user="******", password="******", database="SlotDatabase") cursor2 = db.cursor() secondUser = self.usersList[1] cursor2.execute("SELECT * FROM slot WHERE userID = %s", [secondUser]) user2RawList = cursor2.fetchall() for i in user2RawList: tempSlot2 = Slot(i) self.user2List.append(tempSlot2) db.commit() cursor2.close() db.close()
def getSuitableSlotDuration(task,flag): global globalFreeSlots for freeSlot in globalFreeSlots: maxPredEndDay = getMaxPredEndDay(task) if task.duration<=freeSlot.slotDuration and freeSlot.start > maxPredEndDay: if(not flag and (task.startDay < freeSlot.start or task.endDay> freeSlot.end)): continue task.resourceOnTask = freeSlot.resourceOnSlot if flag == True: task.startDay = freeSlot.start task.endDay = task.startDay + task.duration-1 adjustSuccessors(task) if task.startDay - freeSlot.start>0: remFreeSlot1 = Slot(freeSlot.start, task.startDay-1) remFreeSlot1.resourceOnSlot = freeSlot.resourceOnSlot globalFreeSlots.append(remFreeSlot1) #remFreeSlot1.resourceOnSlot.freeSlots.remove(freeSlot) remFreeSlot1.resourceOnSlot.freeSlots.append(remFreeSlot1) if freeSlot.end - task.endDay>0: remFreeSlot2 = Slot(task.endDay+1, freeSlot.end) remFreeSlot2.resourceOnSlot = freeSlot.resourceOnSlot globalFreeSlots.append(remFreeSlot2) #remFreeSlot2.resourceOnSlot.freeSlots.remove(freeSlot) remFreeSlot2.resourceOnSlot.freeSlots.append(remFreeSlot2) freeSlot.resourceOnSlot.freeSlots.remove(freeSlot) globalFreeSlots.remove(freeSlot) updateFreeSlots() globalFreeSlots.sort(key = lambda x:(x.start,x.slotDuration),reverse = False) return return
def __init__(self, game): self.game = game self.image = pygame.transform.scale(pygame.image.load(player_path_img), (30, 120)) # chargement de l'image self.imageL = pygame.transform.flip(self.image, False, False) self.imageR = pygame.transform.flip(self.image, True, False) self.image = self.imageL self.rect = self.image.get_rect() # position du joueur au debut self.rect.x = SCREEN_WIDTH // 2 self.rect.y = 360 # taille du joueur self.width = self.image.get_width() self.height = self.image.get_height() # vitesse du joueur self.velocity = 5 # gestion de la gravite ne pas changer ! self.vel_y = 0 # le joueur ne saute pas au debut self.jumped = False # est ce que le joueur est dans les airs self.in_air = True # inventaire du joueur self.inventory = {} self.dont_play = False # chargement des images self.inventory_img = pygame.image.load(inventory_gui_path_img) self.hotbar_img = pygame.image.load(hotbar_gui_path_img) self.hotbar_img_rect = self.hotbar_img.get_rect() self.hotbar_img_rect.center = (SCREEN_WIDTH // 2, SCREEN_HEIGHT - 33) self.select_hotbar = pygame.image.load(select_gui_path_img) self.select_hotbar_rect = self.select_hotbar.get_rect() self.move_items = False # l = [4, 1, 2, 3] for j in [4, 1, 2, 3]: for i in range(1, 10): self.inventory["Slot" + str(i) + "_" + str(j)] = Slot( None, i, j, 0) for j in range(1, 3): for i in range(1, 3): self.inventory["Slot" + str(i) + "_" + str(j) + "_Craft"] = Slot(None, i, j, 0, "craft_small") self.inventory["Slot0_0_Craft"] = Slot(None, 0, 0, 0, "result_craft_small") self.move_items = [False, None, None] self.decy = 0 self.crafts = {} self.init_crafts()
def generateSlots(self): """ for space time constraints """ index = 0 for days in self.days: for period in Coordinator.periods: for rooms in Coordinator.rooms: s = Slot(days, period, rooms) self.slots.append(s) s.index = index index += 1
def __init__(self, slotCount): ''' Constructor ''' slotstatus = True self.__slotCount = slotCount for i in range(self.__slotCount): slotNumber = i + 1 self.__slots.append(Slot(slotNumber)) self.__slotreader = Slot(slotNumber) if self.__slots[i].getSlotId( ) == slotNumber and self.__slots[i].checkIfCarParked() == False: slotstatus = slotstatus = True else: slotstatus = slotstatus = False if slotstatus == True: print('Created parking of {} slots'.format(self.__slotCount))
def runAndPrint(filename): print("Loading data from file %s..." % filename) count = 0 slots = [] # slot object array bids = [] # bid object array with open(filename) as infile: for line in infile: line = line.strip() count += 1 # read auction term if count == 1: term = line # read click through rate if count == 2: parts = line.split(' ') for ctr in parts: slot = Slot(ctr) slots.append(slot) # read bids information if count > 2: bid = Bid(line) bids.append(bid) print("\nAuction for \"%s\" with %d slots and %d bidders:" % (term, len(slots), len(bids))) for slot in slots: print("slot: %6.2f %8.2f %8.2f %s" % (float(slot.clickThruRate), float(slot.price), float( slot.profit), slot.bidder)) print(" <-- click through rates") print(" ") auction = Auction(term, bids) # print bid information print "Bids sorted from high to low:" for b in auction.bids: # print ("%s\t%s" % (b.value, b.name)) print("bid:%6.2f %s" % (float(b.value), b.name)) auction.executeVCG(slots) print(" ") print("%12s %8s %8s %8s\n" % ("clicks", "price", "profit", "bidder")) # print slots for slot in slots: print("slot: %6.2f %8.2f %8.2f %s" % (float(slot.clickThruRate), float(slot.price), float( slot.profit), slot.bidder)) # print sums cls = 0 rev = 0 val = 0 for s in slots: cls += float(s.clickThruRate) rev += float(s.price) val += float(s.profit) print("sums: %6.2f %8.2f %8.2f\n" % (cls, rev, val))
def __init__(self): self.prevFrame = "" self.width = 25 self.height = 25 #stats self.generation = 0 self.aliveCells = 0 self.deadCells = 0 self.grid = [[Slot() for y in range(self.width)] for x in range(self.height)]
def runAndPrint(filename): print("loading Auction from file %s" % filename) count = 0 slots = [] bids = [] with open(filename) as infile: for line in infile: line = line.strip() count += 1 if count == 1: term = line if count == 2: parts = line.split(' ') for ctr in parts: slot = Slot(ctr) slots.append(slot) if count > 2: bid = Bid(line) bids.append(bid) print("Auction for \"%s\" with %d slots and %d bidders" % (term, len(slots), len(bids))) for slot in slots: print("slot: %6.2f %8.2f %8.2f %s" % (float(slot.clickThruRate), float(slot.price), float( slot.profit), slot.bidder)) print(" <-- click through rates") print(" ") auction = Auction(term, bids) for b in auction.bids: # print ("%s\t%s"%(b.value,b.name)) print("bid:%6.2f %s" % (float(b.value), b.name)) auction.executeVCG(slots) print(" ") print("%12s %8s %8s %8s\n" % ("clicks", "price", "profit", "bidder")) for slot in slots: print("slot: %6.2f %8.3f %8.3f %s" % (float(slot.clickThruRate), float(slot.price), float( slot.profit), slot.bidder)) cls = 0 rev = 0 val = 0 for s in slots: cls += float(s.clickThruRate) rev += float(s.price) val += float(s.profit) print("sums: %6.2f %8.3f %8.3f\n" % (cls, rev, val))
def addCar(self, sRegisration, sColor): """ Add car to the lot if free lot is present """ index = self.isSlotFree() if index != -1: self.lSlot[index] = Slot(sRegisration, sColor) self.dSlotCars[sRegisration] = index if sColor in self.dCarsColor: self.dCarsColor[sColor].append(sRegisration) else: self.dCarsColor[sColor] = [sRegisration] return "Allocated slot number: {}".format(index + 1) return "Sorry, parking lot is full"
def __init__(self, w = 5, h = 5): super(Environment, self).__init__() # w = int(str(sys.argv[1])) # h = int(str(sys.argv[0])) self.mapa = [[ Slot() for x in range(w)] for y in range(h)] self.w = w self.h = h self.agent_x = random.randrange(w) self.agent_y = random.randrange(h) self.agent_dir = random.choice(['U', 'D', 'L', 'R']) self.this_slot = self.mapa[self.agent_x][self.agent_y] self.fwd_slot = self.getLookedSlot() self.agent = Agent() self.agent.setPerceps(self.this_slot,self.fwd_slot ) init()
def coords_parking(self) -> List[Slot]: width_parking = self.width / self.columns height_parking = self.height / self.rows slots = [] id = 0 for row in np.arange(self.rows): for column in np.arange(self.columns): point_upper_left = Point(column * width_parking, row * height_parking) point_lower_right = Point(point_upper_left.x + width_parking, point_upper_left.y + height_parking) slots.append(Slot(id, point_upper_left, point_lower_right)) id += 1 return slots
def _getSlotInfo(slotName, payload): """ Parses slots from payload into objects containing all slot info. Only takes the slots corresponding to the given name :param slotName: string :param payload: dict :return: list """ slots = [] try: if 'slots' in payload: for slot in payload['slots']: if slot['slotName'] != slotName: continue slots.append(Slot(slot)) return slots except Exception as e: print(e) return slots
def __init__(self, skeletonData): super(Skeleton, self).__init__() self.data = skeletonData self.skin = None self.r = 1.0 self.g = 1.0 self.b = 1.0 self.a = 1.0 self.time = 0.0 self.bones = [] self.slots = [] self.drawOrder = [] self.flipX = False self.flipY = False if not self.data: raise Exception('skeletonData can not be null.') boneCount = len(self.data.bones) self.bones = [None] * boneCount for i in range(boneCount): boneData = self.data.bones[i] bone = Bone(data=boneData) if boneData.parent: for ii in range(boneCount): if self.data.bones[ii] == boneData.parent: bone.parent = self.bones[ii] break self.bones[i] = bone slotCount = len(self.data.slots) self.slots = [None] * slotCount for i in range(slotCount): slotData = self.data.slots[i] bone = None for ii in range(boneCount): if self.data.bones[ii] == slotData.boneData: bone = self.bones[ii] break slot = Slot(slotData=slotData, skeleton=self, bone=bone) self.slots[i] = slot self.drawOrder.append(slot)
Course("Image Recognition", ["MI-4"], "Ryabokon"), Course("Refactoring Problems", ["MI-4"], "Kulyabko"), Course("Algorithms", ["K-26"], "Zavadsky", ["Taranukha", "Zavadsky"]), Course("DBMS", ["K-26"], "Kulyabko", ["Kulyabko", "Taranukha", "Zavadsky"]), Course("Computational Geometry", ["TTP-32"], "Tereschenko", ["Tereschenko"]), Course("Quantum Computation", ["TTP-32"], "Zavadsky"), Course("Operating Systems", ["TTP-32"], "Panchenko", ["Panchenko", "Fedorova"]), Course("Artificial Intelligence", ["TK-4"], "Pashko", ["Pashko"]), Course("Programming Paradigms", ["TK-4"], "Pashko", ["Pashko"]) ] Slot.slots = [ Slot("08:40", "10:15", "Mon"), Slot("10:35", "12:10", "Mon"), Slot("12:20", "13:55", "Mon"), Slot("08:40", "10:15", "Tue"), Slot("10:35", "12:10", "Tue"), Slot("12:20", "13:55", "Tue"), Slot("08:40", "10:15", "Wed"), Slot("10:35", "12:10", "Wed"), Slot("12:20", "13:55", "Wed"), Slot("08:40", "10:15", "Thu"), Slot("10:35", "12:10", "Thu"), Slot("12:20", "13:55", "Thu"), Slot("08:40", "10:15", "Fri"), Slot("10:35", "12:10", "Fri"), Slot("12:20", "13:55", "Fri"), ]
def update(self, screen): """ Method qui update la position du joueur (le monde bouge pour que le joueur soit toujours au centre de l'ecran) """ # futur position du joueur dx = 0 dy = 0 # recuperation des touches presser self.velocity = 5 key = pygame.key.get_pressed() # si on appuye sur la touche espace et qu'on est sur le sol if not self.dont_play: if key[pygame.K_SPACE] and not self.jumped and not self.in_air: self.vel_y = -13 self.jumped = True if not key[pygame.K_SPACE]: self.jumped = False if key[pygame.K_LCTRL]: self.velocity = 7 # deplacement sur la gauche if key[pygame.K_q]: dx += self.velocity self.image = self.imageR # deplacement sur la droite if key[pygame.K_d]: dx -= self.velocity self.image = self.imageL # gravite (ne pas chercher a comprendre sauf si vous voulez reflechir ;p), en vrai c'est simple self.vel_y += 1 if self.vel_y > 10: self.vel_y = 10 dy -= self.vel_y # collision # self.in_air = True for value in self.game.visible_map.values(): if value.have_hitbox: # x direction while pygame.rect.Rect( value.get_rect().x * TILE_SIZE + value.get_chunk() * 10 * TILE_SIZE + self.game.world.decalagex, value.get_rect().y * (-TILE_SIZE) + self.game.world.decalagey, value.get_rect().w, value.get_rect().h) \ .colliderect(self.rect.x - dx, self.rect.y, self.width, self.height): if dx > 0: dx -= 1 elif dx < 0: dx += 1 # y direction if pygame.rect.Rect( value.get_rect().x * TILE_SIZE + value.get_chunk() * 10 * TILE_SIZE + self.game.world.decalagex, value.get_rect().y * (-TILE_SIZE) + self.game.world.decalagey, value.get_rect().w, value.get_rect().h) \ .colliderect(self.rect.x, self.rect.y - dy, self.width, self.height): # en dessous du sol if self.vel_y < 0: # print("Hello there") # dy = self.rect.top + value.get_rect().bottom - self.game.world.decalagey * TILE_SIZE # print(self.rect.top) # print(value.get_rect().bottom) dy = 0 self.vel_y = 0 # au dessus du sol elif self.vel_y >= 0: dy = self.rect.bottom - value.get_rect().top * ( -TILE_SIZE) - self.game.world.decalagey # print(self.rect.bottom, value.get_rect().top, self.game.world.decalagey) self.vel_y = 0 self.in_air = False # update de la position self.game.x += dx self.game.y += dy self.decy += dy self.game.world.cow.set_pos(self.game.world.cow.pos_x, self.game.world.cow.pos_y + dy) self.game.world.update_position(dx, dy) if self.game.open_inventory: for key, value in self.inventory.items(): if value.click(): if value.item: if not self.move_items[0]: self.move_items = [True, value, key] if value.item is None and self.move_items[ 0] and self.move_items[2] == "Slot0_0_Craft": value.item = self.move_items[1].item value.count = self.move_items[1].count self.inventory[self.move_items[2]] = Slot( None, int(self.move_items[2][4]), int(self.move_items[2][6]), 0, self.move_items[1].where) self.move_items = [False, None, None] self.inventory_update(screen) self.crafts["planks"].use_slot.count -= 1 if self.crafts["planks"].use_slot.count <= 0: self.crafts["planks"].use_slot.item = None self.crafts["planks"].use_slot.count = 0 if value.item is None and self.move_items[ 0] and key != "Slot0_0_Craft": value.item = self.move_items[1].item value.count = self.move_items[1].count self.inventory[self.move_items[2]] = \ Slot(None, int(self.move_items[2][4]), int(self.move_items[2][6]), 0, self.move_items[1].where) self.move_items = [False, None, None] self.inventory_update(screen) if self.game.open_inventory: self.crafts["planks"].show_result()
def __create_slots(self): for slot_id in xrange(1, self.slots_count + 1): self.slots[slot_id] = Slot(slot_id)
bawls = Drinks(200, "bawls") ##Dictionaries for each drink with odds for each slot, winmessage, and credit value ##6th dictionary containing all drink dictionaries for makeSlot function ##Odds numbers based on calculations in google docs spreadsheet dict__coke = {'odds1' : [5,4,3,2,1], 'odds2': [5,4,3,2,1], 'odds3' : [8,2,2,2,1], 'winmessage' : "You have won 50 credits", 'drinkobj': coke} dict_welchs = {'odds1' : [5,4,3,2,1], 'odds2': [4,5,3,2,1], 'odds3' : [5,4,3,2,1], 'winmessage' : "You have won 75 credits", 'drinkobj': welchs} dict_ibc = {'odds1' : [5,4,3,2,1], 'odds2': [2,2,7,2,2], 'odds3' : [3,4,4,2,3], 'winmessage' : "You have won 100 credits", 'drinkobj': ibc} dict_jolt = {'odds1' : [5,4,3,2,1], 'odds2': [2,2,2,7,2], 'odds3' : [1,2,3,4,3], 'winmessage' : "You have won 125 credits", 'drinkobj': jolt} dict_bawls = {'odds1' : [5,4,3,2,1], 'odds2': [1,1,1,1,11], 'odds3' : [4,4,3,3,1], 'winmessage' : "You have won 200 credits", 'drinkobj': bawls} all_drink = {'coke': dict_coke, 'welchs': dict_welchs, 'ibc': dict_ibc, 'jolt': dict_jolt, 'bawls': dict_bawls} drink_array = [coke, welchs, ibc, jolt, bawls] ##Creates slot1 ##Executes makeSlot to add drinks ino slot1's array based on coke's odds1 slot1 = Slot() makeSlot('coke', 'odds1', slot1, all_drink, drink_array) ##For debugging ##print (len(slot1.Drinks)) ##Pauses for suspense time.sleep(1) ##Picks drink, assigns name, prints test1 = slot1.pickDrink() cprint (test1.getName(), test1.printName()) ##Creates slot2 ##Executes makeSlot to add drinks ino slot2's array based on first slot's drink using odds 2 slot2 = Slot() makeSlot(test1.getName(), 'odds2', slot2, all_drink, drink_array)