def __init__(self): # Создаёт новую игру (при этом не удаляя старую). Генерирует поле, начальные позиции персонажей и т.д. self.board = pygame.Surface([self.FSize * 60] * 2) for i in range(self.FSize): self.field.append([]) for j in range(self.FSize): dmg = randint(1, 3) CType = randint(0, 2) if CType == 0: cl = TFireCell(self.im_lib[CType][dmg - 1], [i * 60, j * 60], damage = dmg) elif CType == 1: cl = TGroundCell(self.im_lib[CType][dmg - 1], [i * 60, j * 60], damage = dmg) elif CType == 2: cl = TWaterCell(self.im_lib[CType][dmg - 1], [i * 60, j * 60], damage = dmg) self.field[-1].append(cl) self.board.blit(cl.img, [i * 60, j * 60]) EImg = ImLoad('assets/enemy.bmp') for i in range(randint(2, 5)):#3): self.enemyes.append(enemy([randint(0, self.FSize - 1) * 60, randint(0, self.FSize - 1) * 60], EImg)) slides = [[ImLoad('assets/TheGreatHelmet1.bmp'), ImLoad('assets/TheGreatHelmet2.bmp'), ImLoad('assets/TheGreatHelmet3.bmp'), ImLoad('assets/TheGreatHelmet2.bmp')], [ImLoad('assets/TheGreatHammer1.bmp'), ImLoad('assets/TheGreatHammer2.bmp'), ImLoad('assets/TheGreatHammer3.bmp'), ImLoad('assets/TheGreatHammer2.bmp')], [ImLoad('assets/finish.bmp')]] self.items = [helmet(self.field[randint(0, self.FSize - 1)][randint(1, self.FSize - 1)], slides[0], 0.15), hammer(self.field[randint(0, self.FSize - 1)][randint(1, self.FSize - 1)], slides[1], 0.1), finish(self.field[randint(0, self.FSize - 1)][randint(1, self.FSize - 1)], slides[2], 0.1)] self.max_items = len(self.items)
poly_collection = db.poly #constants fieldname = "year" #read in file file = open('sample.csv','rb') reader = csv.DictReader(file,delimiter=',') for item in reader : collection.insert(item) keys = uniquekeys(collection) #Regular print "Absolute:" hammer(flags,info,collection,keys) db.drop_collection("flags") db.drop_collection("info") db.drop_collection("poly") flags = db.flags info = db.info poly_collection = db.poly #with polyfit for doc in mr_poly(collection,fieldname,keys).find(): new = {} new["value"] = polyfit(doc["value"]["x"],doc["value"]["y"],1)[0]
#initialize collection conn = Connection() db = conn.profalyzer db.drop_collection("profs") db.drop_collection("flags") db.drop_collection("info") collection = db.profs flags = db.flags info = db.info #read in file while dumping file = open("results_SYDE(2003-2011).txt","r") for row in file.readlines(): new = {} old = ast.literal_eval(row) new["instructor"] = old["instructor"].split(",")[0] new["year"] = str(old["term"]["year"]) new["course"] = str(old["course"]["code"]) new["value"] = old["data"][17]["average"] collection.insert(new) file.close() keys = uniquekeys(collection) file = open("all_avgs_std_devs.txt","w") for doc in hammer(flags,info,collection,keys).find(): file.write(str(doc) + "\n") file.close()