async def on_message(self, message): if self.filter_optout(message.author): print("ignoring user {}".format(message.author.id)) return #BREAKOUT ROOMS, ill move this somewhere else eventually if message.content.startswith('!breakout'): if message.author.id not in GODS: await message.channel.send("f**k you") args = message.content.split() #default number of groups is 3 try: groups = int(args[1]) except IndexError: groups = 3 try: #get all members in same vc as me victims = message.author.voice.channel.members except AttributeError: #if in not in a VC dont do anything return #shuffle victims to make sure its more random random.shuffle(victims) #list of all voice channels channels = message.guild.voice_channels #remove channels that arent in the specified category channels = [x for x in channels if x.category_id == CATEGORY] #random indexes corresponding to all_channels rooms = random.sample(range(0, len(channels) ), groups) i = 0 for v in victims: index = i % groups print ("moving %s to %s" % (v, index)) await v.edit(voice_channel=channels[rooms[index]]) i = i+1 if message.author.id == self.user.id: # dont trigger on own messages return if message.author.bot == True: return try: if message.content.split()[0] in self.COMMANDS : output = generate_output(message, self.conn) await message.channel.send(embed=output) except IndexError: return
def copy_output(): # generate output with open(os.path.join(APP_PATH, "CMakeLists.txt"), 'r') as readfile: lines = readfile.readlines() for line in lines: if line.startswith("project"): project_name = line.replace(')', '(').split('(')[1] use_custom_partition_table = False with open(os.path.join(APP_PATH, "sdkconfig"), 'r') as readfile: lines = readfile.readlines() for line in lines: if line.startswith("CONFIG_PARTITION_TABLE_CUSTOM=y"): use_custom_partition_table = True elif line.startswith("CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="): custom_partition_name = line.replace('"', '=').split('=')[2] elif line.startswith("CONFIG_PARTITION_TABLE_FILENAME="): partition_name = line.replace('"', '=').split('=')[2] if use_custom_partition_table: partition_name = custom_partition_name output_list = [ os.path.join(APP_PATH, "build", "ota_data_initial.bin"), os.path.join(APP_PATH, "build", "bootloader", "bootloader.bin"), os.path.join(APP_PATH, "build", project_name + ".bin"), os.path.join(APP_PATH, "build", "partition_table", "partition-table.bin"), ] qrgen_image = get_qrgen_image() if qrgen_image: output_list.append(os.path.join(qrgen_image)) debug_list = [ os.path.join(APP_PATH, "build", project_name + ".elf"), os.path.join(APP_PATH, "build", project_name + ".map"), os.path.join(APP_PATH, "build", "bootloader", "bootloader.elf"), os.path.join(APP_PATH, "build", "bootloader", "bootloader.map"), os.path.join(APP_PATH, "sdkconfig"), ] sys.path.append(COMMON_TOOLS_PATH) from generate_output import generate_output generate_output(os.environ["STDK_REF_PATH"], BSP_NAME, APP_NAME, output_list, debug_list)
def processDirectory(datasize, dirName): fileQueue, fileCount = getFileList(dirName) fileOutQueue = mp.Queue() statListInQueue = mp.Queue() statListOutQueue = mp.Queue() heapInQueue = mp.Queue() statListCount = 0 statFinalList = [] #Some counts if(fileCount < 8): fileWorkerThreadCount = fileCount else: fileWorkerThreadCount = 8 if(fileCount/4 < 4): statWorkerThreadCount = fileCount/4 + 1 else: statWorkerThreadCount = 4 #keep track of processes fileworkerList = [] statworkerList = [] #statList statList = [] for i in range(0, fileWorkerThreadCount): fileworker = mp.Process(target = processFile, args = ("fileworker" + str(i), fileQueue, fileOutQueue, )) fileworker.start() fileworkerList.append(fileworker) for i in range(0, statWorkerThreadCount): statworker = mp.Process(target = processBulkStats, args = ("statListWorker" + str(i), statListInQueue, statListOutQueue, )) statworker.start() statworkerList.append(statworker) #Deal with heaplaw heapworker = mp.Process(target = processHeapLaw, args = ("heapworker", heapInQueue, fileCount, datasize, )) heapworker.start() for i in range(0, fileCount): try: queueElement = fileOutQueue.get(True, 240) statList.append(queueElement) heapL = heapLaw() heapL.bookWordSet = queueElement.bookWordSet heapL.wordCount = queueElement.wordCount heapInQueue.put(heapL) if(len(statList) == 20 or i == fileCount-1): statListInQueue.put(statList) print "element going into statlistinqueue {} {}".format(i, fileCount) touch(statList) statListCount += 1 del statList[:] gc.collect() except: print traceback.format_exc() break cleanUpProcesses(fileworkerList) print "statListcount {}".format(statListCount) #Do a final sweep and add all the stats to be processed to the list for i in range(0, statListCount): try: statFinalList.append(statListOutQueue.get(True, 240)) print "received statlists {}".format(i) if(i % 100 == 0): gc.collect() except: print traceback.format_exc() break cleanUpProcesses(statworkerList) print "FINAL STATS COMPILATION" finalstats = processFinalStats(statFinalList) #printStats(finalstats) computeExtraStats(datasize, finalstats) generate_output(datasize, finalstats) heapworker.terminate()
def main(): global number_of_population number_of_population = 150 print('initializing population...') population = Population(number_of_population) population.sort(key=Chromosome.compute_fitness_value) first_pen = population[0].penalty generation_number = 1000 iteration = 0 best_fit = math.inf best_cnt = 0 cnt_limit = 100 while True: p_r = 0.05 p_c = 0.75 number_of_population = len(population) iteration += 1 best_cnt += 1 population.sort(key=Chromosome.compute_fitness_value) print(iteration, population[0].num_of_hard_conflicts, population[0].num_of_soft_conflicts, population[0].compute_fitness_value(), population[0].penalty, len(population)) if population[0].num_of_hard_conflicts != 0 or population[ 0].penalty != first_pen: if best_fit > population[0].compute_fitness_value(): best_fit = population[0].compute_fitness_value() best_cnt = 0 # cnt_limit += 5 elif best_cnt == cnt_limit: # i = 0 # while population[0][i] == -1 or i >= population[0].size // 2: # i += 1 # population[0][i] = population[0][i + population[0].size // 2 if i < population[0].size / 2 else # i - population[0].size // 2] = -1 # for p in population: # p[i] = p[i + p.size // 2] = -1 # population[-1] = Chromosome(True) # population.fit() # population.sort(key=Chromosome.compute_fitness_value) best_cnt = 0 cnt_limit = 100 p_r = 0.3 if population.is_mundane() or iteration == generation_number: if population[0].num_of_hard_conflicts == 0 or population[ 0].penalty == first_pen: break else: # i = 0 # while population[0][i] == -1 and i < population[0].size // 2: # i += 1 # for p in population: # p[i] = p[i + p.size // 2] = -1 # iteration = 0 generation_number += 200 p_r = 0.3 if generation_number >= 2000: break children = crossover(population, p_c) mutation(children, p_r) children.fit() population = children # for i in population[0].conflicting_genes: # population[0][i] = -1 # population.fit() # print(population[0].num_of_hard_conflicts, population[0].num_of_soft_conflicts, population[0].penalty) generate_output(population[0])