def visit(ShortAddr): database = Database(filename) LongAddr = database.find(ShortAddr) if (LongAddr == ''): return render_template('home.html', ShortAddr="", LongAddr="", status=2) else: return redirect(LongAddr)
def register(): status = 0 if request.method == 'POST': user_name = request.form['user_name'] if not user_name.isalnum(): return render_template('register.html', status=-4, language=session['language'], user_name=user_name) user_email = request.form['user_email'] # 检查是否合法邮件地址 if not ifValidEmail(user_email): return render_template('register.html', status=-5, language=session['language'], user_name=user_name) password = request.form['password'] password1 = request.form['password1'] database = Database(filename) status = database.insertUser(user_name, user_email, password, password1) if status != 0 and status != -1 and status != -2 and status != -3 and status != -4 and status != -5 and status != -6: session['user_id'] = status return redirect(url_for('result')) return render_template('register.html', status=status, language=session['language'], user_name='Guest')
def __init__(self, threadID, lock, region): threading.Thread.__init__(self) self.player_region = region self.threadID = threadID self.lock = lock self.database = Database(DATABASE_DETAILS) self.m = Misc()
def verify(verification_code): database = Database(filename) status = database.verifyEmail(verification_code) if status == -1: return '错误的激活链接' else: session['user_id'] = status return redirect(url_for('result'))
def fridges_delete(): database = Database(filename) user_id = session['user_id'] #user_id = 1 material = request.args['name'] #print 'calling deleteFromFridge({},{})'.format(user_id, [material]) database.deleteFromFridge(user_id, [material]) return redirect(url_for('fridges'))
def __init__(self, threadID, lock, database_details, api_key): threading.Thread.__init__(self) self.threadID = threadID self.lock = lock self.api_key = api_key self.database_details = database_details self.database = Database(database_details) self.static = Static(api_key) self.misc = Misc()
def admin_my_recipes_delete(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" user_id = request.args['current_user_id'] database = Database(filename) database.deleteMyRecipeEntry(user_id, request.args['id']) return redirect(url_for('admin_my_recipes', user_id=user_id))
def profile(): user_id = session['user_id'] database = Database(filename) user_profile = database.findUserProfile(user_id) user_name = database.findUserName(user_id) return render_template('profile.html', user_id=user_id, user_profile=user_profile, user_name=user_name, language=session['language'])
def debug(): user_id = session['user_id'] database = Database(filename) user_group = database.findUserGroup(user_id) user_name = database.findUserName(user_id) return render_template('debug.html', user_id=user_id, user_group=user_group, user_name=user_name, language=session['language'])
def DBFunc(): x = Database() function = request.args['function'] print(function) if function == "init": get_db() elif function == "fill": x.objToDB() elif function == "drop": delete_db() return jsonify(True)
def recipes(): if 'user_id' in session: user_id = session['user_id'] database = Database(filename) user_name = database.findUserName(user_id) recipes = database.deliverRecipe() return render_template('recipes.html', user_id=session['user_id'], recipes=recipes, user_name=user_name, language=session['language']) return render_template('login_name.html', language=session['language'])
def fridges_insert(): database = Database(filename) user_id = session['user_id'] #user_id = 1 # user_fridge is a list of what is already in fridge if request.method == 'POST': add_stock_text = request.form['content'] if add_stock_text == '': return redirect(url_for('fridges')) add_stock_text = add_stock_text.split(' ') database.insertToFridge(user_id, add_stock_text) return redirect(url_for('fridges'))
def admin_fridges_delete(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" user_id = request.args['current_user_id'] database = Database(filename) #user_id = 1 material = request.args['name'] #print 'calling deleteFromFridge({},{})'.format(user_id, [material]) database.deleteFromFridge(user_id, [material]) return redirect(url_for('admin_fridges', user_id=user_id))
def recipes_insert(): database = Database(filename) if request.method == 'POST': content = request.form['content'] if content == '': return redirect(url_for('recipes')) content = Unicode_to_UTF8(content) content = content.split(' ') dish_name = content[0] content.remove(dish_name) components = content database.insertRecipeEntry(dish_name, components) return redirect(url_for('recipes'))
def result(): if 'user_id' in session: database = Database(filename) user_id = session['user_id'] user_name = database.findUserName(user_id) #user_id = 1 recipes = database.deliverMyRecipe(user_id) fridge = database.deliverFridge(user_id) if len(fridge) != 0: fridge = fridge[0][1] fridge = fridge.split(' ') # fridge is a list of what you have-unicode # recipes is a list of tuple recipe_list = list(recipes) result_list = [] for one_recipe in recipes: dish_num = one_recipe[0] dish_name = one_recipe[1] still_need = one_recipe[2].split( ' ') #components is a list of materials. what_i_have = [] for item in fridge: if item in still_need: still_need.remove(item) what_i_have.append(item) this_entry = [] this_entry.append(dish_num) this_entry.append(dish_name) this_entry.append(what_i_have) this_entry.append(still_need) this_entry.append(len(still_need)) result_list.append(this_entry) sorted_result = [] while len(result_list) != 0: min = 10000 to_delete = 0 for line in result_list: if line[4] < min: min = line[4] to_delete = line sorted_result.append(to_delete) result_list.remove(to_delete) # soted_result is a list: # [dish_num, dish_name, list(what_i_have), list(material still needed), item number still needed] return render_template('result.html', user_id=session['user_id'], data=sorted_result, user_name=user_name, language=session['language']) return render_template('login_name.html', language=session['language'])
def admin_my_recipes(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" user_id = request.args['user_id'] recipes = [] if request.method == 'POST': user_id = request.form['next_user_id'] database = Database(filename) recipes = database.deliverMyRecipe(user_id) return render_template('admin_my_recipes.html', user_id=user_id, recipes=recipes)
def my_recipes(): if 'user_id' in session: user_id = session['user_id'] database = Database(filename) user_name = database.findUserName(user_id) user_group = database.findUserGroup(user_id) if user_group == 2: return "您必须先验证邮箱才能使用功能" recipes = database.deliverMyRecipe(user_id) return render_template('my_recipes.html', user_id=session['user_id'], recipes=recipes, user_name=user_name, language=session['language']) return render_template('login_name.html', language=session['language'])
def admin_fridges_insert(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" user_id = 0 if request.method == 'POST': user_id = request.form['current_user_id'] database = Database(filename) # user_fridge is a list of what is already in fridge add_stock_text = request.form['content'] if add_stock_text == '': return redirect(url_for('admin_fridges', user_id=user_id)) add_stock_text = add_stock_text.split(' ') database.insertToFridge(user_id, add_stock_text) return redirect(url_for('admin_fridges', user_id=user_id))
def admin_fridges(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" user_id = request.args['user_id'] if request.method == 'POST': user_id = request.form['next_user_id'] database = Database(filename) fridges = database.deliverFridge(user_id) if len(fridges) != 0: fridges = fridges[0][1].split(' ') # now fridges is a list of stock return render_template('admin_fridges.html', user_id=user_id, fridges=fridges)
def fridges(): if 'user_id' in session: database = Database(filename) user_id = session['user_id'] user_name = database.findUserName(user_id) user_group = database.findUserGroup(user_id) if user_group == 2: return "您必须先验证邮箱才能使用功能" #user_id = 1 fridges = database.deliverFridge(user_id) if len(fridges) != 0: fridges = fridges[0][1].split(' ') # now fridges is a list of stock return render_template('fridges.html', user_id=session['user_id'], fridges=fridges, user_name=user_name, language=session['language']) return render_template('login_name.html', language=session['language'])
def admin_my_recipes_insert(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" user_id = 0 if request.method == 'POST': user_id = request.form['current_user_id'] database = Database(filename) content = request.form['content'] if content == '': return redirect(url_for('admin_my_recipes', user_id=user_id)) content = Unicode_to_UTF8(content) content = content.split(' ') dish_name = content[0] content.remove(dish_name) components = content database.insertMyRecipeEntry(user_id, dish_name, components) return redirect(url_for('admin_my_recipes', user_id=user_id))
def login_email(): status = 0 if request.method == 'POST': user_email = request.form['user_email'] password = request.form['password'] database = Database(filename) user_id = database.verifyPassword_user_email(user_email, password) if user_id == -1: # user does not exist status = -1 elif user_id == -2: # mismatch password status = -2 elif user_id == 0: session['user_id'] = user_id return redirect(url_for('admin')) else: # 判断用户名密码是否匹配 session['user_id'] = user_id return redirect(url_for('result')) return render_template('login_email.html', status=status, language=session['language'])
def home(): LongAddr = "" ShortAddr = "" status = 0 # status=0: Nothing input. # status=1: Input is not a valid url. # status=2: You are trying to visit a short address not existing in the database. if (request.method == 'POST'): LongAddr = request.form['LongAddr'] if (not IfValidUrl(LongAddr)): status = 1 return render_template('home.html', ShortAddr=ShortAddr, LongAddr=LongAddr, status=status) database = Database(filename) digit = 4; ShortAddr = GenerateShort(LongAddr,digit) search = database.find(ShortAddr) while(search != ''): if (search == LongAddr): break; else: digit = digit + 1 ShortAddr = GenerateShort(LongAddr, digit) search = database.find(ShortAddr) if (search == ''): database.insert(ShortAddr, LongAddr) ShortAddr = 'http://hoogle.xyz/'+ShortAddr return render_template('home.html', ShortAddr=ShortAddr, LongAddr=LongAddr, status=status)
def admin_user_list(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" database = Database(filename) conn = sqlite3.connect(filename) c = conn.cursor() users = c.execute('SELECT * FROM users') # users is a cursor object users = list( users ) # users is a list of tuple, like [(0,'admin','*****@*****.**'),(1,'111','*****@*****.**'),(2,'222','*****@*****.**')] return render_template('admin_user_list.html', users=users)
def admin_statistics(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" database = Database(filename) conn = sqlite3.connect(filename) c = conn.cursor() num_recipes = c.execute('select count(*) from recipes') num_recipes = num_recipes.fetchone()[0] num_users = c.execute('select count(*) from users') num_users = num_users.fetchone()[0] return render_template('admin_statistics.html', num_users=num_users, num_recipes=num_recipes)
def __init__(self, region, database_details): threading.Thread.__init__(self) self.player_region = region self.database = Database(database_details)
class Get_summoners(threading.Thread): def __init__(self, region, database_details): threading.Thread.__init__(self) self.player_region = region self.database = Database(database_details) def run(self): #player = Player(player_id, player_region, API_KEY) if self.player_region == 'EUW1': player_list = [28809850] elif self.player_region == 'KR': player_list = [ 209305531, 5977905, 2620061, 6476762, 7835424, 200579114 ] elif self.player_region == 'NA1': player_list = [ 31273666, 209000695, 206087402, 36584704, 232202464, 42732981 ] elif self.player_region == 'OC1': player_list = [ 200615925, 200059234, 200286310, 200008599, 201844220, 200236338 ] start_time = time.time() misc = Misc() misc.logging(self.player_region, "Running the summoner retreivel algorithm", "log") #The purpose of the function below is to find as many players that play mainly ARAM games as possible. #This is done by recursively going through players' games and extracting the 10 participants' ID's self.get_players(player_list, self.player_region, self.database, API_KEY, 4, 0, 20000) misc.logging(self.player_region, "Summoner retreival algorithm completed", "log") print("Time taken: %s seconds ---" % (time.time() - start_time)) self.database.close_db() def get_players(self, player_list, player_region, database, api_key, i, j, total_num_players): #i determines the depth of the execution i = i - 1 if not player_list or i == 0: print "returning" return for player in player_list: print player_list player_o = Player(player_region, api_key, account_id=player) #player_o = Player(player, player_region, api_key) recent_games = player_o.get_games() if recent_games == -1 or recent_games == -2 or recent_games.__len__( ) < 10: continue print list(recent_games)[:20] for game in list(recent_games)[:20]: #time.sleep(0.61) if not database.insert_items(player_region + "_games_checked", "id", str(game)): database.update_numberof_games( player_region + "_games_checked", "id", str(game), "times_hit", 1) else: player_list1 = [] game_details = Game(game, player_region, api_key).game_details() game_participants = Json_ops( game_details).participants_id() for current_player in game_participants: if database.get_row_count( player_region + "_players_checked") >= total_num_players: print "ads" return if not current_player == player: player_list1.append(current_player) if not database.insert_items( player_region + "_players_checked", "id", str(current_player)): database.update_numberof_games( player_region + "_players_checked", "id", str(current_player), "times_hit", 1) self.get_players(player_list1, player_region, database, api_key, i, j, total_num_players)
class Second_step: def __init__(self, region): self.region = region self.database = Database(DATABASE_DETAILS) self.games_folder = GAMES_FOLDERS_PATH + region self.s = Stat_rating() self.misc = Misc() def update_tables(self, checked_games_players): #database = Database(DATABASE_DETAILS) # misc = Misc() for player_id in checked_games_players: current_file = os.path.join(self.games_folder, player_id) with open(current_file, "r") as games_file: wins = 0 #player_id = os.path.basename(games_file.name) if os.stat(current_file).st_size == 0: self.misc.logging( self.region, player_id + "' games file is empty. Skipping ..", "error") continue #print player_id all_games = games_file.readlines() existing_champs = list( self.database.get_all_items("Base_champ_list", "id")) for game in all_games: champ_names = dict() try: json_game = json.loads(game.strip()) except ValueError: self.misc.logging( self.region, "Json error in file: " + str(player_id) + ".. Ignoring", "error") continue if json_game == -1: continue output = Json_ops(json_game) game_id = output.game_id() if game_id == -1: self.misc.logging( self.region, "Found a non Json object in file: " + str(player_id) + ".. Ignoring", "error") print "Found a non Json object .. Ignoring" continue if str(game_id) in checked_games_players[player_id]: all_champs = output.get_all_champs() new_champ_check = False for champ in all_champs: if not champ in existing_champs: new_champ_check = True break if new_champ_check == True: self.misc.logging( self.region, "New champ found in game " + str(game_id) + ". Ignoring this game..", "error") self.database.delete_line(self.region + "_games", "id", str(game_id)) self.database.update_numberof_games( self.region + "_summoners", "id", player_id, "aram_games", -1) self.database.update_numberof_games( self.region + "_summoners", "id", player_id, "total_games", -1) continue for i in range(10): champ_names["champ_" + str(i + 1)] = all_champs[i] if i == output.player_position(player_id): player = all_champs[i] champ_names["winning_team"] = output.winning_team() champ_names["date"] = output.game_date() self.database.update_fields(self.region + "_games", "id", game_id, champ_names) for champ in all_champs: self.database.insert_items( self.region + "_" + str(champ), "game_id", game_id) result = output.did_win(champ) if champ == player: wins += result if not result == 2: stats = output.get_champ_stat( champ, "damage_dealt", "damage_to_champs", "damage_to_turrets", "damage_taken", "physical_damage", "magical_damage", "true_damage", "time_alive", "cc_score", "minions_killed", "kills", "deaths", "assists", "rank", "damage_mitigated") stats["game_duration"] = output.game_duration() stats["result"] = result # stats = output.get_champ_stat(champ) rank = output.get_rank(champ) rank_number = self.s.rank_mapping(rank) stats["rank"] = rank_number #print stats self.database.update_fields( self.region + "_" + str(champ), "game_id", game_id, stats) self.database.update_numberof_games( self.region + "_champ_stats", "id", champ, "games_analysed", 1) self.database.update_fields( self.region + "_games", "id", game_id, {"duration": stats["game_duration"]}) [aram_games, total_games, won_games] = self.database.get_database_row_items( self.region + "_summoners", {"id": player_id}, "aram_games, total_games, won_games") if total_games == 0 or aram_games == 0: continue self.database.update_fields( self.region + "_summoners", "id", player_id, { "aram_games_percentage": 100 * aram_games / total_games, "won_games": won_games + wins, "win_rate": 100 * (won_games + wins) / aram_games }) try: os.remove(os.path.join(self.games_folder, player_id)) except OSError as e: self.misc.logging( self.region, "Error while deleting game file: " + e.message, "error")
def __init__(self, region): self.region = region self.database = Database(DATABASE_DETAILS) self.games_folder = GAMES_FOLDERS_PATH + region self.s = Stat_rating() self.misc = Misc()
class Third_step(threading.Thread): def __init__(self, threadID, lock, region): threading.Thread.__init__(self) self.player_region = region self.threadID = threadID self.lock = lock self.database = Database(DATABASE_DETAILS) self.m = Misc() def run(self): time_check = time.time() checking_period = 3600 self.m.logging( self.player_region, "Running the Regular updates thread for the first time", "log") while True: self.lock[self.threadID].acquire() if time.time() - time_check >= checking_period: print self.player_region, " ", self.threadID, " ", time.time() time_check = time.time() with open(STATIC_DATA_PATH + "End_Exec", "r") as end_check: status = list(end_check.readlines())[0].strip() if status == "True": self.m.logging( self.player_region, "Regular updates thread: End of execution was requested. This thread will exit now", "log") print self.player_region, "Regular updates thread: End of execution was requested. This thread will now exit." break self.m.logging( self.player_region, "Running the Regular updates thread (hourly runs)", "log") if self.update_averages() == 1: print self.player_region + " checkpoint 1" self.update_final_stats() self.update_champ_stats() self.update_game_stats() self.lock[self.threadID].release() else: print self.player_region + " checkpoint 2" self.lock[self.threadID].release() time.sleep(checking_period) else: print self.player_region + " checkpoint 3" self.lock[self.threadID].release() time.sleep(checking_period) def update_averages(self): self.m.logging( self.player_region, "Updating the averages for region " + self.player_region, "log") one_off_values_avg = dict() columns = list(self.database.get_column_names("Base_champ")) all_champs = list(self.database.get_all_items("Base_champ_list", "id")) for champ in all_champs: games_analysed = self.database.get_database_item( self.player_region + "_champ_stats", "id", champ, "games_analysed") magic_dmg = self.database.get_sum( self.player_region + "_" + str(champ), "magical_damage") deaths = self.database.get_sum( self.player_region + "_" + str(champ), "deaths") if games_analysed == 0 or magic_dmg == 0 or deaths == 0: self.m.logging( self.player_region, "Unable to update the averages for region " + self.player_region + " due to insufficient games. This thread will sleep until the next scheduled execution ", "error") return -1 for champ in all_champs: self.database.update_column_values( self.player_region + "_" + str(champ), "games_analysed", games_analysed) for i in range(columns.__len__()): one_off_values_avg[columns[i]] = self.database.get_sum( self.player_region + "_" + str(champ), columns[i]) / games_analysed deaths = self.database.get_sum( self.player_region + "_" + str(champ), "deaths") one_off_values_avg["total_tankiness"] = ( self.database.get_sum(self.player_region + "_" + str(champ), "damage_taken") + self.database.get_sum(self.player_region + "_" + str(champ), "damage_mitigated")) / games_analysed one_off_values_avg["kill_ratio"] = self.database.get_sum( self.player_region + "_" + str(champ), "kills") / deaths one_off_values_avg["assist_ratio"] = self.database.get_sum( self.player_region + "_" + str(champ), "assists") / deaths one_off_values_avg["dmg_ratio"] = self.database.get_sum( self.player_region + "_" + str(champ), "physical_damage") / self.database.get_sum( self.player_region + "_" + str(champ), "magical_damage") if one_off_values_avg["dmg_ratio"] >= 100: one_off_values_avg["dmg_ratio"] = 99 one_off_values_avg["game_id"] = 99 one_off_values_avg["result"] = 99 one_off_values_avg["rank"] = 99 one_off_values_avg["games_analysed"] = games_analysed self.database.update_fields(self.player_region + "_averages", "champ_id", champ, one_off_values_avg) return 1 def update_final_stats(self): self.m.logging(self.player_region, "Updating Final_stats tables", "log") self.m.logging( self.player_region, "Updating the final stats table for region " + self.player_region, "log") one_off_values_avg = dict() columns = list(self.database.get_column_names("Base_final_stats")) all_champs = list(self.database.get_all_items("Base_champ_list", "id")) for i in range(columns.__len__()): one_off_values_avg[columns[i]] = 0 for champ in all_champs: for i in range(columns.__len__()): one_off_values_avg[columns[i]] = one_off_values_avg[ columns[i]] + self.database.get_database_item( self.player_region + "_averages", "champ_id", champ, columns[i]) for i in range(columns.__len__()): one_off_values_avg[columns[i]] = one_off_values_avg[ columns[i]] / all_champs.__len__() one_off_values_avg["game_id"] = 1 self.database.update_fields(self.player_region + "_final_stats", "game_id", 1, one_off_values_avg) # max's one_off_values_max = dict() columns = list( self.database.get_column_names(self.player_region + "_final_stats")) for i in range(columns.__len__()): one_off_values_max[columns[i]] = 0 for i in range(columns.__len__()): one_off_values_max[columns[i]] = self.database.get_max( self.player_region + "_averages", columns[i]) one_off_values_max["game_id"] = 2 one_off_values_max["result"] = 99 self.database.update_fields(self.player_region + "_final_stats", "game_id", 2, one_off_values_max) # min's one_off_values_min = dict() columns = list( self.database.get_column_names(self.player_region + "_final_stats")) for i in range(columns.__len__()): one_off_values_min[columns[i]] = 0 for i in range(columns.__len__()): one_off_values_min[columns[i]] = self.database.get_min( self.player_region + "_averages", columns[i]) one_off_values_min["game_id"] = 0 one_off_values_min["result"] = 99 self.database.update_fields(self.player_region + "_final_stats", "game_id", 0, one_off_values_min) return def update_champ_stats(self): s = Stat_rating() self.m.logging( self.player_region, "Updating the champ stats table for region " + self.player_region, "log") all_champs = self.database.get_all_items("Base_champ_list", "id") for champ in all_champs: damage_ratios = s.damage_type_rating( self.database.get_sum(self.player_region + "_" + str(champ), "physical_damage"), self.database.get_sum(self.player_region + "_" + str(champ), "magical_damage"), self.database.get_sum(self.player_region + "_" + str(champ), "true_damage"), self.database.get_sum(self.player_region + "_" + str(champ), "damage_to_champs")) values = dict() games_played = self.database.get_database_item( self.player_region + "_champ_stats", "id", champ, "games_analysed") values["damage_dealt"] = s.stat_percent( self.database.get_database_item( self.player_region + "_averages", "champ_id", champ, "damage_dealt"), self.database.get_database_item( self.player_region + "_final_stats", "game_id", 2, "damage_dealt")) values["win_rate"] = s.stat_percent( self.database.get_sum(self.player_region + "_" + str(champ), "result"), games_played) values["damage_to_turrets"] = s.stat_percent( self.database.get_database_item( self.player_region + "_averages", "champ_id", champ, "damage_to_turrets"), self.database.get_database_item( self.player_region + "_final_stats", "game_id", 2, "damage_to_turrets")) values["waveclear"] = s.stat_percent( self.database.get_database_item( self.player_region + "_averages", "champ_id", champ, "minions_killed"), self.database.get_database_item( self.player_region + "_final_stats", "game_id", 2, "minions_killed")) values["tankiness"] = s.stat_percent( self.database.get_database_item( self.player_region + "_averages", "champ_id", champ, "total_tankiness"), self.database.get_database_item( self.player_region + "_final_stats", "game_id", 2, "total_tankiness")) values["cc_score"] = s.stat_percent( self.database.get_database_item( self.player_region + "_averages", "champ_id", champ, "cc_score"), self.database.get_database_item( self.player_region + "_final_stats", "game_id", 2, "cc_score")) values["p_type"] = damage_ratios[0] values["m_type"] = damage_ratios[1] values["t_type"] = damage_ratios[2] values["p_dmg"] = s.stat_percent( self.database.get_database_item( self.player_region + "_averages", "champ_id", champ, "physical_damage"), self.database.get_database_item( self.player_region + "_final_stats", "game_id", 2, "physical_damage")) values["m_dmg"] = s.stat_percent( self.database.get_database_item( self.player_region + "_averages", "champ_id", champ, "magical_damage"), self.database.get_database_item( self.player_region + "_final_stats", "game_id", 2, "magical_damage")) values["t_dmg"] = s.stat_percent( self.database.get_database_item( self.player_region + "_averages", "champ_id", champ, "true_damage"), self.database.get_database_item( self.player_region + "_final_stats", "game_id", 2, "true_damage")) values["total_dmg"] = s.stat_percent( self.database.get_database_item( self.player_region + "_averages", "champ_id", champ, "damage_to_champs"), self.database.get_database_item( self.player_region + "_final_stats", "game_id", 2, "damage_to_champs")) values["dmg_ratio"] = s.stat_percent( self.database.get_database_item( self.player_region + "_averages", "champ_id", champ, "dmg_ratio"), self.database.get_database_item( self.player_region + "_final_stats", "game_id", 2, "dmg_ratio")) values["assist_ratio"] = s.stat_percent( self.database.get_database_item( self.player_region + "_averages", "champ_id", champ, "assist_ratio"), self.database.get_database_item( self.player_region + "_final_stats", "game_id", 2, "assist_ratio")) values["kill_ratio"] = s.stat_percent( self.database.get_database_item( self.player_region + "_averages", "champ_id", champ, "kill_ratio"), self.database.get_database_item( self.player_region + "_final_stats", "game_id", 2, "kill_ratio")) if values["dmg_ratio"] > 100: print "champ stats dmg ratio", values["dmg_ratio"], champ self.database.update_fields(self.player_region + "_champ_stats", "id", champ, values) def update_game_stats(self): self.m.logging( self.player_region, "Updating the game stats table for region " + self.player_region, "log") games = self.database.get_all_items(self.player_region + "_games", "id") stat_names = list( self.database.get_column_names("Base_champ_stats"))[2:] for game_id in games: champs = list( self.database.get_row(self.player_region + "_games", "id", game_id))[4:] if not champs: continue if champs[1] == 0: continue winning_team = champs.pop(0) values1 = dict() values2 = dict() for stat_name in stat_names: values1[stat_name + "_1"] = values2[stat_name + "_2"] = 0 counter = 0 for champ in champs: details = list( self.database.get_row(self.player_region + "_champ_stats", "id", champ))[2:] if counter < 5: for i in range(stat_names.__len__()): values1[stat_names[i] + "_1"] += details[i] counter += 1 else: for i in range(stat_names.__len__()): values2[stat_names[i] + "_2"] += details[i] for a in values1: values1[a] = values1[a] / 5 for b in values2: values2[b] = values2[b] / 5 values = values2.copy() values.update(values1) values["winning_team"] = winning_team self.database.insert_items(self.player_region + "_game_stats", "id", game_id) self.database.update_fields(self.player_region + "_game_stats", "id", game_id, values)