def handle(data): app = current_app if app is None: ak = '18691b8e4206238f331ad2e1ca88357e' else: ak = app.config.get('BAIDU_AK') city = get_city(data) if not city: return '不会自己去看天气预报啊' res = weather(ak, city)[:3] ret = [] attaches = [] for idx, day in enumerate(res): if idx == 0: current = TEMPERATURE_REGEX.search(day['date']).groups()[0] text = u'{0}: {1} {2} {3} 温度: {4}'.format( DAY[idx], current, day['weather'], day['wind'], day['temperature']) else: text = u'{0}: {1} {2} 温度: {3}'.format( DAY[idx], day['weather'], day['wind'], day['temperature']) ret.append(text) type = 'dayPictureUrl' if check_time() == 'day' else 'dayPictureUrl' attaches.append(gen_attachment(text, day[type], image_type='thumb', title=u'{}天气预报'.format(city), title_link='')) return '\n'.join(ret), attaches
def main(): found_words = [] words_value = 0 search_range = 3 fail_counter = 0 MAX_FAILS = 30 t, n, s, puzzles, possibile_solutions = get_input() start_time = time.time() dic = HmapStructure() with open('z2/dict.txt') as f: max_len = dic.load(f) population = init_population(dic, puzzles, 1000, inhabitant_start_size=max_len) while check_time(start_time, t) or True: prev_value = words_value words_value += search_for_words(found_words, population, dic, puzzles, search_range) if prev_value == words_value: fail_counter += 1 if fail_counter == MAX_FAILS: search_range += 1 fail_counter = 0 else: fail_counter = 0 population.recombinate() population.mutate() print(words_value)
def search(dic, puzzles, all_puzzle_keys, t, starter_words): best_word = ("", 0) MAX_ELITE_PERCENTAGE = 1.0 MIN_ELITE_PERCENTAGE = 0.85 elite_percentage = MAX_ELITE_PERCENTAGE fail_counter = 0 MAX_FAILS = 55 population = init_population(500, all_puzzle_keys, starter_words) start_time = time.time() while check_time(start_time, t): prev_word = best_word best_word = search_for_words(population, dic, puzzles, best_word) if prev_word[1] <= best_word[1]: fail_counter += 1 if fail_counter == MAX_FAILS: fail_counter = 0 if elite_percentage > MIN_ELITE_PERCENTAGE: elite_percentage -= 0.1 else: fail_counter = 0 elite_percentage = MAX_ELITE_PERCENTAGE population.recombinate(elite_percentage) population.mutate() print(best_word, time.time() - start_time, fail_counter) sys.stdout.write(str(best_word[1])) sys.stderr.write(str(best_word[0]))
def main(): found_words = [] words_value = 0 search_range = 2 fail_counter = 0 MAX_FAILS = 10 t, n, s, puzzles, possibile_solutions, all_puzzle_keys = get_input() start_time = time.time() dic = HmapStructure() with open('z2/dict.txt') as f: dic.load(f) max_len = len(all_puzzle_keys) population = init_population(dic, puzzles, 100, all_puzzle_keys) while check_time(start_time, t) or True: prev_value = words_value words_value += search_for_words(found_words, population, dic, puzzles, search_range) if prev_value == words_value and search_range <= max_len: fail_counter += 1 if fail_counter == MAX_FAILS*search_range: search_range += 1 fail_counter = 0 else: fail_counter = 0 population.recombinate() population.mutate() print(words_value, time.time()-start_time)
def swarm(t, x, e, swarm_size=100, omega=0.8, fip=2.4, fig=1.9): swarm = Swarm(e, swarm_size) start = time.time() while check_time(start,t): swarm.update_particles_velocity(e, omega, fip, fig) print(swarm.best_swarm_x, swarm.best_swarm_val)
def swarm(t, x, e, swarm_size=100, omega=0.8, fip=1.4, fig=1.3): swarm = Swarm(e, swarm_size) start = time.time() while check_time(start, t): swarm.update_particles_velocity(e, omega, fip, fig) print(swarm.best_swarm_x, swarm.best_swarm_val) sys.stdout.write(str(swarm.best_swarm_val) + " " + str(swarm.best_swarm_x))
def sa(pos, grid, n, m, t, p, starters): best_path = [] counter = 0 moves_manager = MovesManager(grid, pos, n, m) population = Population(p, starters, moves_manager) start_time = time.time() while check_time(start_time, t): counter = 0 cur_pos = pos.copy() cur_path = [] while (not moves_manager.check_for_exit( cur_pos, grid)) and time.time() - start < t: cur_pos = pos.copy() cur_path = moves_manager.random_moves(cur_pos, grid, n, m, (n - 2) * (m - 2)) if check_time(start_time, t): return best_path if len(best_path) == 0 or len(cur_path) < len(best_path): best_path = cur_path.copy() treshold = min(n, m) * len(cur_path) while counter < treshold and T > 0 and time.time() - start < t: temp_path = gen_neighbour(cur_path) temp_path, exit_found = moves_manager.explore( pos.copy(), temp_path, grid) if exit_found: if len(temp_path) <= len(cur_path): cur_path = temp_path.copy() if len(cur_path) < len(best_path): best_path = cur_path.copy() elif uniform(0, 1) <= calculate_probability( len(temp_path) - len(cur_path), T): cur_path = temp_path.copy() T = decrease_temperature(T, c) else: counter += 1 return best_path
def search(dic, puzzles, all_puzzle_keys, t, starter_words): best_word = ("", 0) elite_percentage = 0.6 population = init_population(128, all_puzzle_keys, starter_words) start_time = time.time() while check_time(start_time, t): best_word = search_for_words(population, dic, puzzles, best_word) population.recombinate() population.mutate() print(best_word, time.time() - start_time)
def search(dic, puzzles, all_puzzle_keys, t, starter_words): best_word = ("", 0) population = init_population(50, all_puzzle_keys, starter_words) start_time = time.time() while check_time(start_time, t) or True: best_word = search_for_words(population, dic, puzzles, best_word) population.recombinate() population.mutate() print(best_word, time.time() - start_time)
def handle(data, cache=None, app=None): if app is None: ak = "18691b8e4206238f331ad2e1ca88357e" else: ak = app.config.get("BAIDU_AK") city = get_city(data) if not city: return "不会自己去看天气预报啊" res = weather(ak, city)[0] current = TEMPERATURE_REGEX.search(res["date"]).groups()[0] text = u"当前: {0} {1} {2} 温度: {3}".format(current, res["weather"], res["wind"], res["temperature"]) type = "dayPictureUrl" if check_time() == "day" else "dayPictureUrl" attaches = [gen_attachment(text, res[type], image_type="thumb", title=u"{}天气预报".format(city), title_link="")] return text, attaches
def get(self, page=1, date=None): if date is None and page=='all': device_list = self.collection.find() else: if date is None: _, _, today, _ = check_time() date = today date = get_date_several_months_before(date, delta=2) device_list = self.collection.find({'endDate': {"$gt": date}}) if page == 'all': return device_list else: get_page = Page(page) return get_page.paginate(device_list)
def search(pos, grid, n, m, t, p, starters): best_path = [] elite_percentage = 0.5 moves_manager = MovesManager(grid, pos, n, m) population = Population(p, starters, moves_manager) start_time = time.time() while check_time(start_time, t): best_path = get_best_path(population) population.recombinate(elite_percentage) population.mutate() print(best_path, len(best_path), time.time()-start_time) return best_path
def main(): found_words = [] words_value = 0 t, n, s, puzzles, possibile_solutions = get_input() start_time = time.time() dic = HmapStructure() with open('z2/dict.txt') as f: max_len = dic.load(f) population = init_population(dic, puzzles, inhabitant_start_size=max_len) while check_time(start_time, t) or True: words_value += search_for_words(found_words, population, dic, puzzles, max_len) population.mutate() print(words_value)
def sa(pos, grid, n, m, t, p, starters): best_path = [] counter = 0 elite_percentage = 0.5 moves_manager = MovesManager(grid, pos, n, m) population = Population(p, starters, moves_manager) start_time = time.time() while check_time(start_time, t): best_word = search_for_words(population, dic, puzzles, best_word) population.recombinate(elite_percentage) population.mutate() print(best_word, time.time()-start_time) return best_path
def handle(data, app=None, **kwargs): if app is None: ak = '18691b8e4206238f331ad2e1ca88357e' else: ak = app.config.get('BAIDU_AK') city = get_city(data) if not city: return '不会自己去看天气预报啊' res = weather(ak, city)[0] current = TEMPERATURE_REGEX.search(res['date']).groups()[0] text = u'当前: {0} {1} {2} 温度: {3}'.format( current, res['weather'], res['wind'], res['temperature']) type = 'dayPictureUrl' if check_time() == 'day' else 'dayPictureUrl' attaches = [gen_attachment(text, res[type], image_type='thumb', title=u'{}天气预报'.format(city), title_link='')] return text, attaches
def search(dic, puzzles, all_puzzle_keys, t, starter_words): best_word = ("", 0) fail_counter = 0 MAX_FAILS = 15 max_len = len(all_puzzle_keys) population = init_population(100, all_puzzle_keys, starter_words) start_time = time.time() while check_time(start_time, t) or True: prev_value = best_word[1] best_word = search_for_words(population, dic, puzzles, best_word) population.recombinate() population.mutate() print(best_word, time.time() - start_time, search_range)
def search(): max_len = len(all_puzzle_keys) population = init_population(dic, puzzles, 100, all_puzzle_keys) while check_time(start_time, t) or True: prev_value = words_value words_value += search_for_words(found_words, population, dic, puzzles, search_range) if prev_value == words_value and search_range < max_len: fail_counter += 1 if fail_counter == MAX_FAILS*search_range//2: search_range += 1 fail_counter = 0 else: fail_counter = 0 population.recombinate() population.mutate() print(words_value, int(time.time()-start_time), search_range)
def main(): found_words = [] words_value = 0 t, n, s, puzzles, possibile_solutions, all_puzzle_keys = get_input() start_time = time.time() dic = HmapStructure() with open('z2/dict.txt') as f: dic.load(f) population = init_population(dic, puzzles, 100, all_puzzle_keys) while check_time(start_time, t) or True: prev_value = words_value words_value += search_for_words(found_words, population, dic, puzzles, max_len) population.recombinate() population.mutate() print(words_value, int(time.time() - start_time))
def swarm(t, x, e, swarm_size=1000, omega=0.5): swarm = Swarm(e, swarm_size) start = time.time() while check_time(start, t): swarm.update_velocity()
return whole_value def search(): start_time = time.time() found_words = [] words_value = 0 search_range = 2 fail_counter = 0 MAX_FAILS = 25 max_len = len(all_puzzle_keys) population = init_population(dic, puzzles, 100, all_puzzle_keys) while check_time(start_time, t) or True: prev_value = words_value words_value += search_for_words(found_words, population, dic, puzzles, search_range) if prev_value == words_value and search_range < max_len: fail_counter += 1 if fail_counter == MAX_FAILS*search_range//2: search_range += 1 fail_counter = 0 else: fail_counter = 0 population.recombinate() population.mutate() print(words_value, int(time.time()-start_time), search_range) def main():
def swarm(t, x, e, swarm_size=1000): swarm = Swarm(e, ) start = time.time() while check_time(start,t): for particle in S
def get_sharepoint(): _, yesterday, today, this_month = check_time() start = this_month['start'] end = this_month['end'] collection = db['calendar']
def get_calls_info(self, calc_entities): calls = [] for call in self.calls: tmp_stories = [] tmp_widgets = [] tmp_measurements = [] tmp_runtime = 0 tmp_get_response_type = '' tmp_ds_runtime = 0 tmp_datasources = [] if call['request']['url'].__contains__('GetResponse'): # Getting Get_Response call type: Batch/Analytics/Planning: if 'Metadata' in json.loads(call['request']['postData']['text']).keys(): tmp_get_response_type = json.loads(call['request']['postData']['text'])['Metadata']['Context'] elif 'Planning' in json.loads(call['request']['postData']['text']).keys(): tmp_get_response_type = 'Planning' # If it is Batch, collect Views/Dimensions/DataSources/Runtime Info elif 'Batch' in json.loads(call['request']['postData']['text']).keys(): tmp_get_response_type = 'Batch' batches_request = json.loads(call['request']['postData']['text'])['Batch'] batches_response = json.loads(call['response']['content']['text'])['Batch'] for batch_req in batches_request: dim_members = {} # DS ID only for getting runtime from response + cache info tmp_ds_id = batch_req['Analytics']['DataSource']['InstanceId'] for batch_res in batches_response: if batch_res['DataSource']['InstanceId'] == tmp_ds_id: tmp_ds_runtime = round(float(batch_res['PerformanceData']['Runtime']), 3) for message in batch_res['Grids'][0]['Messages']: if 'cache' in message['Text']: tmp_cache = str(message['Text']).replace(' (post process)', '') # tmp_ds_type = batch_req['Analytics']['DataSource']['Type'] if 'Name' in batch_req['Analytics']['Definition'].keys(): tmp_view = batch_req['Analytics']['Definition']['Name'] try: calc_entity = next((x for x in calc_entities if x.id == tmp_view)) except StopIteration: continue if calc_entity: tmp_ds_name = calc_entity.name tmp_ds_type = calc_entity.type else: tmp_view = 'Result Set' tmp_ds_name = 'Fetching Result Set' tmp_ds_type = 'Result Set' dim_number = 1 for dimension in batch_req['Analytics']['Definition']['Dimensions']: dim_name = str(dim_number) + '. ' + dimension['Name'] dim_number += 1 dim_members[dim_name] = [] if dimension['Axis'] == 'Columns' and 'Members' in dimension.keys(): for member in dimension['Members']: if 'Name' in member.keys(): try: calc_entity = next((x for x in calc_entities if x.id == member['Name'].rstrip('.ID'))) except StopIteration: continue if calc_entity: if tmp_view != 'Result Set': tmp_member_name = member['Name'] + ' (' + \ calc_entity.name + ' \ ' + \ calc_entity.type + ') ' dim_members[dim_name].append(tmp_member_name) datasource_tmp = objects.DataSource(ds_id=tmp_ds_id, dimensions=dim_members, ds_runtime=tmp_ds_runtime, view=tmp_view, ds_name=tmp_ds_name, ds_type=tmp_ds_type, ds_cache=tmp_cache) tmp_datasources.append(datasource_tmp) del datasource_tmp # Getting Story Name: if "ClientInfo" in json.loads(call['request']['postData']['text']).keys(): tmp_stories.append( json.loads(call['request']['postData']['text'])['ClientInfo']['Context']['StoryName']) # Getting Widget IDs: if "WidgetId" in json.loads(call['request']['postData']['text'])['ClientInfo']['Context'].keys(): for widget in json.loads(call['request']['postData']['text'])['ClientInfo']['Context'][ 'WidgetId']: widget = widget.replace('-', '') if widget not in set(tmp_widgets): tmp_widgets.append(widget) # Getting Common Runtime: if 'PerformanceData' in json.loads(call['response']['content']['text']).keys(): tmp_runtime = json.loads(call['response']['content']['text'])['PerformanceData']['Runtime'] # Getting Measurements. Measurements is a list of dictionaries formatted like {'Description': '', # 'Time': '', 'Calls': ''} for measure in json.loads(call['response']['content']['text'])['PerformanceData']['Measurements']: tmp_measurements.append(measure) # Create Call of type Get_Response: call_2_tmp = objects.Call_2(url=call['request']['url'], get_response_type=tmp_get_response_type, start_timestamp=call['startedDateTime'], total_time=call['time'], body_size=call['request']['bodySize'], resource_type=call['_resourceType'], status=call['response']['status'], transfer_size=call['response']['_transferSize'], timings=utils.check_time(call['timings']), stories=tmp_stories, widgets=tmp_widgets, runtime=tmp_runtime, measurements=tmp_measurements, datasources=tmp_datasources) calls.append(call_2_tmp) del call_2_tmp # If it's not a Get_Response call, create a basic Call object else: call_tmp = objects.Call(url=call['request']['url'], start_timestamp=call['startedDateTime'], total_time=call['time'], body_size=call['request']['bodySize'], resource_type=call['_resourceType'], status=call['response']['status'], transfer_size=call['response']['_transferSize'], timings=utils.check_time(call['timings'])) calls.append(call_tmp) del call_tmp return calls
import get import parse import utils manager = urllib3.PoolManager() str_time_deb = parse.get_time_flag(sys.argv, 1) str_time_fin = parse.get_time_flag(sys.argv, 0) urls = parse.parse_args(sys.argv, str_time_deb, str_time_fin) for url in urls: ressource = manager.request('GET', url) contenu = ressource.data soupe = BeautifulSoup(contenu, 'html.parser') name = get.cinema(soupe) print('') print('-----------', name, '------------') print('') titles = soupe.find_all('h2', {'class': 'meta-title'}) hours = soupe.find_all('div', {'class': 'hours'}) real = soupe.find_all('div', {'class': 'meta-body-item meta-body-direction'}) length = soupe.find_all('div', {'class': 'meta-body-item meta-body-info'}) nb_entries = min(len(titles), len(real), len(hours), len(length)) for i in range(nb_entries): str_title = get.title(titles[i]) str_real = get.real(real[i]) str_length = get.length(length[i]) str_hours = get.hours(hours[i]) str_hours = utils.check_time(str_hours, str_time_deb, str_time_fin, str_length) if len(str_hours) > 0: print(str_real, '-', str_title, '-', str_hours)
def use_swarm(t, x, e): start = time.time() while check_time(start, t): pass
def __init__(self): self.hour, self.yesterday, self.today, self.this_month = check_time()
def __init__(self): self.collection = db['report'] self.employee = Employee() self.mac = Mac() self.hour, self.today, self.this_month = check_time()