reformated columns into seperete functions

This commit is contained in:
Andrei Stoica 2024-02-01 13:31:00 -05:00
parent 47d8865be8
commit 2536280844
1 changed files with 257 additions and 114 deletions

View File

@ -1,3 +1,4 @@
from types import NoneType
from typing import TypeVar
T = TypeVar("T")
@ -17,9 +18,54 @@ def score_to_text(score: list[int]) -> str:
return "-".join(map(str, score))
# maybe could get columns form db
def cols_from_player_stats(player_stats: dict) -> dict:
cols = [
## returns column names if the form:
## {"<table_name>": ([<names from api>]}, [<names from db>])}
def get_cols(table_name=None):
cols = {
"profile_game": (
[
"leetifyUserId",
"ctLeetifyRating",
"ctLeetifyRatingRounds",
"dataSource",
"elo",
"gameFinishedAt",
"gameId",
"isCs2",
"mapName",
"matchResult",
"scores",
"skillLevel",
"tLeetifyRating",
"tLeetifyRatingRounds",
"deaths",
"hasBannedPlayer",
"kills",
"partySize",
],
[
"leetify_user_id",
"ct_Leetify_rating",
"ct_Leetify_rating_rounds",
"data_source",
"elo",
"game_finished_at",
"game_id",
"is_cs2",
"map_name",
"match_result",
"scores",
"skill_level",
"t_leetify_rating",
"t_leetify_rating_rounds",
"deaths",
"has_banned_player",
"kills",
"party_size",
],
),
"player_stats": (
[
"id",
"gameId",
"gameFinishedAt",
@ -102,31 +148,137 @@ def cols_from_player_stats(player_stats: dict) -> dict:
"isCollector",
"isProPlan",
"isLeetifyStaff",
]
],
[
"id",
"game_id",
"game_finished_at",
"steam64_id",
"name",
"preaim",
"reaction_time",
"accuracy",
"accuracy_enemy_spotted",
"accuracy_head",
"shots_fired_enemy_spotted",
"shots_fired",
"shots_hit_enemy_spotted",
"shots_hit_friend",
"shots_Hit_Friend_Head",
"shots_Hit_Foe",
"shots_Hit_Foe_Head",
"utility_On_Death_Avg",
"he_foes_damage_avg",
"he_friends_damage_avg",
"he_thrown",
"molotov_thrown",
"smoke_thrown",
"smoke_thrown_ct",
"smoke_thrown_ct_good",
"smoke_thrown_ct_good_ratio",
"smoke_thrown_ct_foes",
"counter_strafing_shots_all",
"counter_strafing_shots_bad",
"counter_strafing_shots_good",
"counter_strafing_shots_good_ratio",
"flashbang_hit_foe",
"flashbang_leading_to_kill",
"flashbang_hit_foe_avg_duration",
"flashbang_hit_friend",
"flashbang_thrown",
"flash_assist",
"score",
"initial_Team_Number",
"mvps",
"ct_rounds_won",
"ct_rounds_lost",
"t_rounds_won",
"t_rounds_lost",
"spray_accuracy",
"molotov_foes_damage_avg",
"molotov_friends_damage_avg",
"color",
"total_kills",
"total_deaths",
"kd_ratio",
"multi2k",
"multi3k",
"multi4k",
"multi5k",
"hltv_rating",
"hsp",
"rounds_survived",
"rounds_survived_percentage",
"dpr",
"total_assists",
"total_damage",
"trade_kill_opportunities",
"trade_kill_attempts",
"trade_kills_succeeded",
"trade_kill_attempts_percentage",
"trade_kills_success_percentage",
"trade_kill_opportunities_per_round",
"traded_death_opportunities",
"traded_death_attempts",
"traded_death_attempts_percentage",
"traded_deaths_succeeded",
"traded_deaths_success_percentage",
"traded_deaths_opportunities_per_round",
"leetify_rating",
"personal_performance_rating",
"ct_leetify_rating",
"t_leetify_rating",
"leetify_user_id",
"is_collector",
"is_pro_plan",
"is_leetify_staff",
],
),
"profile_meta": (
[
"name",
"steam64Id",
"isCollector",
"isLeetifyStaff",
"isProPlan",
"leetifyUserId",
"faceitNickname",
],
[
"name",
"steam64_id",
"is_collector",
"is_leetify_staff",
"is_pro_plan",
"leetify_user_id",
"faceit_nickname",
],
),
}
if table_name:
return cols[table_name]
return cols
def get_api_cols(table_name: str | NoneType = None):
col_pos = 0
if table_name:
return get_cols(table_name)[col_pos]
return {key: val[col_pos] for key, val in get_cols().items()}
def get_db_cols(table_name = None):
col_pos = 1
if table_name:
return get_cols(table_name)[col_pos]
return {key: val[col_pos] for key, val in get_cols().items()}
# maybe could get columns form db
def cols_from_player_stats(player_stats: dict) -> dict:
cols = get_api_cols("player_stats")
return extract_cols(player_stats, cols)
def cols_from_profile_game(game: dict) -> dict:
cols = [
"ctLeetifyRating",
"ctLeetifyRatingRounds",
"dataSource",
"elo",
"gameFinishedAt",
"gameId",
"isCs2",
"mapName",
"matchResult",
"scores",
"skillLevel",
"tLeetifyRating",
"tLeetifyRatingRounds",
"deaths",
"hasBannedPlayer",
"kills",
"partySize",
]
cols = get_api_cols("profile_game")
return extract_cols(game, cols)
@ -135,16 +287,7 @@ def meta_from_profile(profile: dict) -> dict:
if not meta:
raise Exception("Could not get profile metadata", profile)
cols = [
"name",
"steam64Id",
"isCollector",
"isLeetifyStaff",
"isProPlan",
"leetifyUserId",
"faceitNickname",
]
cols = get_api_cols("profile_meta")
return extract_cols(meta, cols)