def test_max_min_score(self): #test maximum score is 50 answer_list = ([ '1', '1', '1', '1', '1', '0', '0', '0', '3', '4', '500', '95' ]) self.assertEqual(score.calculate_score(answer_list), 50) # test minimum score is less than 1 answer_list = ([ '0', '0', '0', '0', '0', '1', '1', '1', '6', '2', '175', '21' ]) self.assertLess(score.calculate_score(answer_list), 1)
def main(): filename = 'boggle-dictionary.txt' dictionary = Dictionary(filename) boggle_board = get_board() print("Boggle board after shuffle:") for row in boggle_board: print(row) print("\nWords found in board:") word_list = find_words(boggle_board, dictionary) for word in word_list: print(word) #benchmarking print('\nAverage time taken to find words in standard 4x4 boggle board =') print(benchmarking(dictionary), 'seconds') #Create result object result = dict() result['score'] = calculate_score(word_list) result['words'] = sorted(word_list) print('\nResult object:') print(result) return result
def process(coord_lat="", coord_long="", city=""): with open("restaurant_data.dat", "rb") as f: previous_restaurants = pickle.load(f) #print(previous_restaurants) previous_restaurants = previous_restaurants[-10:] x_vals = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) y_vals = np.array([a[1] for a in previous_restaurants]) price = int(find_price.find_best_next(x_vals, y_vals)) print('price: ', price) print(city) if city == "": businesses = yelp_api.get_nearby_restaurants(coord_lat, coord_long) else: print("searching sittyS") businesses = yelp_api.get_nearby_restaurants(city=city) #print(businesses) scorelist = [] businesslist = [] for business in businesses: #pprint.pprint(business) try: if business['price'].count('$') <= price + 1 and business[ 'price'].count('$') >= price - 1: print(business['name'], score.calculate_score(yelp_api.convertFormat(business))) scorelist.append( score.calculate_score(yelp_api.convertFormat(business))) businesslist.append(business) except: # this means that the business does not have an entry for "price" pass nblist = [] for i in range(3): print(scorelist) try: index = scorelist.index(max(scorelist)) nblist.append(businesslist[index]) businesslist.pop(index) scorelist.pop(index) except: nblist.append(None) #print(nblist) return nblist
def get(self, cpf): manager = Manager() person = manager.get_person(cpf) if person: payload = { 'cpf': person.cpf, 'score': calculate_score(person), 'age': person.age, 'address': person.address, 'assets': [{ 'name': asset.name, 'value': asset.value } for asset in person.assets] } return payload else: abort(400)
render_template( "index.html", graphs={ "confirmed_cases": uk_cases_graph(uk_cases), # "deaths": england_deaths(phe_deaths, excess_deaths, uk_cases), "regional_cases": regional_cases(nhs_region_cases), "regional_deaths": regional_deaths(nhs_deaths), "triage_online": triage_graph(triage_online, "Online triage"), "triage_pathways": triage_graph(triage_pathways, "Phone triage"), "hospital_admissions": hospital_admissions_graph(hospital_admissions), "age_heatmap": age_heatmap(age_rate), }, scores=calculate_score( nhs_deaths, nhs_region_cases, triage_online, triage_pathways, hospital_admissions, ), sources=[ ( "Public Health England", "Coronavirus (COVID-19) in the UK", "https://coronavirus.data.gov.uk", uk_cases.attrs["date"], ), ( "Public Health England", "National COVID-19 surveillance report", "https://www.gov.uk/government/publications/national-covid-19-surveillance-reports", f"Week {age_rate.index.max() + 1}",
parse_dates=["date"], dayfirst=True) triage_online = online_triage_by_nhs_region() triage_pathways = pathways_triage_by_nhs_region() render_template( "index.html", graphs={ "confirmed_cases": uk_cases_graph(uk_cases_combined, ecdc_cases), "deaths": england_deaths(uk_cases, excess_deaths), "regional_cases": regional_cases(nhs_region_cases), "regional_deaths": regional_deaths(nhs_deaths), "triage_online": triage_graph(triage_online, "Online triage"), "triage_pathways": triage_graph(triage_pathways, "Phone triage"), }, scores=calculate_score(nhs_deaths, nhs_region_cases, triage_online, triage_pathways, None), sources=[ ( "European Centres for Disease Control", "Data on the geographic distribution of COVID-19 cases worldwide", "https://www.ecdc.europa.eu/en/publications-data/" "download-todays-data-geographic-distribution-covid-19-cases-worldwide", ecdc_cases.attrs["date"] if ecdc_cases else "Data unavailable", ), ( "Public Health England", "Coronavirus (COVID-19) in the UK", "https://coronavirus.data.gov.uk", uk_cases.attrs["date"], ), (
def calculate(): for user in get_users(): calculate_score(user) return ''
def move_happened(self, gem, new_gem): coords = [(gem.x // 60, gem.y // 60), (new_gem.x // 60, new_gem.y // 60)] row_affected = board.check_match_row(self.board, coords, True) col_affected = board.check_match_col(self.board, coords, True) # IF change occurred return TRUE else FALSE if len(row_affected) > 0 or len( col_affected) > 0 or gem.type == "bomb": scores = {k: 0 for k in JEWELS[:8]} while len(row_affected) > 0 or len( col_affected) > 0 or gem.type == "bomb": self.play_sound("match") if gem.type == "bomb": self.detonate_bomb(new_gem.color) gem.mark_destroy() self.mark_destroy(row_affected) self.mark_destroy(col_affected) for gem in self.all_gems: if gem.action == "destroy" and gem.color[0] in JEWELS[:8]: scores[gem.color[0]] += 1 self.gem_destroy_transition() self.update_destroyed() #self.debug() row_affected = board.check_match_row(self.board) col_affected = board.check_match_col(self.board) result = score.calculate_score(scores, self.player, self.enemy) # result is -1 if the enemy is alive otherwise it contain a message if result != -1: self.enemy_killed_msg = result self.enemy_killed_cooldown = 30 * 2 self.player.gold += self.enemy.gold self.enemies.pop(0) del self.enemy # check if the level have other enemies if len(self.enemies) > 0: self.spawn_enemy() else: self.level_up = True self.level += 1 # check if current stage is < than max stage if len(LEVELS) > self.level: self.play_sound("stage_clear") self.player.level_up(self.level) self.enemies = self.new_level() self.spawn_enemy() else: self.pause = True if board.board_have_moves(self.board) == False: self.reset_board() return True else: return False