Revert "chore: prepare for rescraping"
This reverts commit fce1b69893.
this time it works
This commit is contained in:
@@ -58,10 +58,7 @@ def __czy_x_istnieje(typ, **id):
|
||||
return False
|
||||
|
||||
def czy_sportowiec_istnieje(id_zawodnika: str):
|
||||
return __czy_x_istnieje("sportowcy", id_zawodnika=int(id_zawodnika))
|
||||
|
||||
def czy_klub_istnieje(id_klubu: str):
|
||||
return __czy_x_istnieje("kluby", id_klubu=id_klubu)
|
||||
return __czy_x_istnieje("sportowcy", id_zawodnika=id_zawodnika)
|
||||
|
||||
# GET /api/v1
|
||||
def stub_hello():
|
||||
@@ -136,80 +133,6 @@ def get_matches(r = None, id_zawodnika: str | None = None, rok: int | None = Non
|
||||
# print(f"zwracam mecze: {response_json}")
|
||||
return 200, "ok", response_json
|
||||
|
||||
# GET /api/v1/player_stats
|
||||
def player_stats(r = None, id_zawodnika: str | None = None):
|
||||
"""
|
||||
Zwraca mecze.
|
||||
Przykład wywołania:
|
||||
player_stats(r, id_zawodnika=1), tożsame z GET /api/v1/player_stats?id_zawodnika=1
|
||||
player_stats(r), tożsame z GET /api/v1/player_stats
|
||||
"""
|
||||
response_json = []
|
||||
|
||||
if id_zawodnika is None:
|
||||
# Gdy nie podano id wprost, sprawdź, czy podano je przez parametr.
|
||||
id_zawodnika = r.args.get('id_zawodnika', 0)
|
||||
|
||||
# Sprawdź, czy sportowiec o podanym (lub niepodanym) id istnieje.
|
||||
# Jeśli nie istnieje, wypisz wszystkie mecze.
|
||||
elif not czy_sportowiec_istnieje(id_zawodnika=id_zawodnika):
|
||||
return 404, "error", {"error_msg": "This sportsman has not been found in the database. Try: id_zawodnika=1"}
|
||||
|
||||
# Gdy sportowiec istnieje, wypisz jego mecze.
|
||||
else:
|
||||
staty = getDb().get_basic_stats(id_zawodnika=id_zawodnika)
|
||||
|
||||
# for stat in staty:
|
||||
response_json.append({
|
||||
'unique_items': staty[0],
|
||||
'time_played': staty[1],
|
||||
'goals': staty[2],
|
||||
'assists': staty[3],
|
||||
'yellow_cards': staty[4],
|
||||
'red_cards': staty[5],
|
||||
'avg_score': staty[6],
|
||||
}
|
||||
)
|
||||
print(f"zwracam staty: {response_json}")
|
||||
return 200, "ok", response_json
|
||||
|
||||
# GET /api/v1/robert_stats
|
||||
def robert_stats(r = None, id_klubu: str | None = None):
|
||||
"""
|
||||
Zwraca mecze.
|
||||
Przykład wywołania:
|
||||
robert_stats(r, id_zawodnika=1), tożsame z GET /api/v1/robert_stats?id_klubu=barcelona
|
||||
robert_stats(r), tożsame z GET /api/v1/robert_stats
|
||||
"""
|
||||
response_json = []
|
||||
|
||||
if id_klubu is None:
|
||||
# Gdy nie podano id wprost, sprawdź, czy podano je przez parametr.
|
||||
id_klubu = r.args.get('id_klubu', 0)
|
||||
|
||||
# Sprawdź, czy sportowiec o podanym (lub niepodanym) id istnieje.
|
||||
# Jeśli nie istnieje, wypisz wszystkie mecze.
|
||||
elif not czy_klub_istnieje(id_klubu=id_klubu):
|
||||
return 404, "error", {"error_msg": "This club has not been found in the database. Try: id_klubu=barcelona"}
|
||||
|
||||
# Gdy sportowiec istnieje, wypisz jego mecze.
|
||||
else:
|
||||
staty = getDb().get_sportsman_club_stats(id_zawodnika=1, id_klubu=id_klubu)
|
||||
|
||||
# for stat in staty:
|
||||
response_json.append({
|
||||
'unique_items': staty[0],
|
||||
'time_played': staty[1],
|
||||
'goals': staty[2],
|
||||
'assists': staty[3],
|
||||
'yellow_cards': staty[4],
|
||||
'red_cards': staty[5],
|
||||
'avg_score': staty[6],
|
||||
}
|
||||
)
|
||||
print(f"zwracam staty roberta: {response_json}")
|
||||
return 200, "ok", response_json
|
||||
|
||||
# GET /api/v1/debugger_halt?token=XXX...
|
||||
@require_authentication
|
||||
def debugger_halt(r):
|
||||
@@ -264,4 +187,4 @@ def lookup(data, request):
|
||||
return get_matches(r = request)
|
||||
case _:
|
||||
increment_bad_requests()
|
||||
return not_implemented(data)
|
||||
return not_implemented(data)
|
||||
@@ -553,72 +553,6 @@ class baza():
|
||||
|
||||
return query.all()
|
||||
|
||||
@exit_gracefully
|
||||
def get_basic_stats(self, id_zawodnika = None, zewnetrzne_id_zawodnika = None):
|
||||
|
||||
# Spróbuj otrzymać id zawodnika z zewnętrznego id.
|
||||
if zewnetrzne_id_zawodnika is not None:
|
||||
id_zawodnika = self.get_id_zawodnika_by_zewnetrzne_id(zewnetrzne_id_zawodnika)
|
||||
|
||||
if id_zawodnika is None:
|
||||
return []
|
||||
|
||||
# Aliasy
|
||||
SportowcyWMeczach = self.entities["sportowcy_w_meczach"]
|
||||
|
||||
query = self.session.query(
|
||||
func.count(SportowcyWMeczach.id_rekordu ).label('unique_items'),
|
||||
func.sum( SportowcyWMeczach.czas_gry ).label('time_played'),
|
||||
func.sum( SportowcyWMeczach.goli ).label('goals'),
|
||||
func.sum( SportowcyWMeczach.asyst ).label('assists'),
|
||||
func.sum( SportowcyWMeczach.zolte_kartki ).label('yellow_cards'),
|
||||
func.sum( SportowcyWMeczach.czerwone_kartki).label('red_cards'),
|
||||
func.avg( SportowcyWMeczach.wynik ).label('avg_score'),
|
||||
).where(
|
||||
SportowcyWMeczach.czas_gry > 0
|
||||
).where(
|
||||
SportowcyWMeczach.id_zawodnika == id_zawodnika
|
||||
)
|
||||
|
||||
return query.all()[0]
|
||||
|
||||
@exit_gracefully
|
||||
def get_sportsman_club_stats(self, id_zawodnika = None, zewnetrzne_id_zawodnika = None, id_klubu = None):
|
||||
|
||||
# Spróbuj otrzymać id zawodnika z zewnętrznego id.
|
||||
if zewnetrzne_id_zawodnika is not None:
|
||||
id_zawodnika = self.get_id_zawodnika_by_zewnetrzne_id(zewnetrzne_id_zawodnika)
|
||||
|
||||
if id_zawodnika is None:
|
||||
return []
|
||||
|
||||
if id_klubu is None:
|
||||
return self.get_basic_stats(id_zawodnika=id_zawodnika)
|
||||
else:
|
||||
if self.simple_select_all("kluby", id_klubu=id_klubu) == []:
|
||||
return []
|
||||
|
||||
# Aliasy
|
||||
SportowcyWMeczach = self.entities["sportowcy_w_meczach"]
|
||||
|
||||
query = self.session.query(
|
||||
func.count(SportowcyWMeczach.id_rekordu ).label('unique_items'),
|
||||
func.sum( SportowcyWMeczach.czas_gry ).label('time_played'),
|
||||
func.sum( SportowcyWMeczach.goli ).label('goals'),
|
||||
func.sum( SportowcyWMeczach.asyst ).label('assists'),
|
||||
func.sum( SportowcyWMeczach.zolte_kartki ).label('yellow_cards'),
|
||||
func.sum( SportowcyWMeczach.czerwone_kartki).label('red_cards'),
|
||||
func.avg( SportowcyWMeczach.wynik ).label('avg_score'),
|
||||
).where(
|
||||
SportowcyWMeczach.czas_gry > 0
|
||||
).where(
|
||||
SportowcyWMeczach.id_zawodnika == id_zawodnika
|
||||
).where(
|
||||
SportowcyWMeczach.klub_id == id_klubu
|
||||
)
|
||||
|
||||
return query.all()[0]
|
||||
|
||||
@exit_gracefully
|
||||
def sample_data_init(self, override_safety_check=False):
|
||||
"""
|
||||
|
||||
@@ -3,42 +3,39 @@ import lewy_api_v1
|
||||
import lewy_db
|
||||
import lewy_globals
|
||||
import json
|
||||
from lewy_api_v1 import get_matches, player_stats, robert_stats
|
||||
from lewy_api_v1 import get_matches
|
||||
def get_lewy_stats():
|
||||
stats = player_stats(id_zawodnika=1)[2][0]
|
||||
polska = robert_stats(id_klubu="polska")[2][0]
|
||||
barcelona = robert_stats(id_klubu="barcelona")[2][0]
|
||||
return {
|
||||
'all_time_stats': {
|
||||
'goals': stats["goals"], # 589+85
|
||||
'assists': stats["assists"], # 154+35
|
||||
'matches': stats["unique_items"] # 791+158
|
||||
},
|
||||
'club_stats': {
|
||||
'goals': barcelona["goals"], # 589
|
||||
'assists': barcelona["assists"], # 154
|
||||
'matches': barcelona["unique_items"] # 791 # to trochę na wyrost, bo w części meczy był kontuzjowany
|
||||
},
|
||||
'nation_stats': {
|
||||
'goals': polska["goals"], # 85
|
||||
'assists': polska["assists"], # 35
|
||||
'matches': polska["unique_items"] # 158
|
||||
},
|
||||
'international_cups': {
|
||||
'goals': 110,
|
||||
'assists': 19,
|
||||
'matches': 152,
|
||||
},
|
||||
'national_cups': {
|
||||
'goals': 58,
|
||||
'assists': 4,
|
||||
'matches': 74,
|
||||
},
|
||||
'cards': {
|
||||
'yellow': stats["yellow_cards"], # 86
|
||||
'red': stats["red_cards"], # 2
|
||||
}
|
||||
}
|
||||
return {
|
||||
'all_time_stats': {
|
||||
'goals': 589+85,
|
||||
'assists':154+35,
|
||||
'matches': 791+158,
|
||||
},
|
||||
'club_stats': {
|
||||
'goals': 589,
|
||||
'assists': 154,
|
||||
'matches': 791,
|
||||
},
|
||||
'nation_stats': {
|
||||
'goals': 85,
|
||||
'assists': 35,
|
||||
'matches': 158,
|
||||
},
|
||||
'international_cups': {
|
||||
'goals': 110,
|
||||
'assists': 19,
|
||||
'matches': 152,
|
||||
},
|
||||
'national_cups': {
|
||||
'goals': 58,
|
||||
'assists': 4,
|
||||
'matches': 74,
|
||||
},
|
||||
'cards': {
|
||||
'yellow': 86,
|
||||
'red': 2,
|
||||
}
|
||||
}
|
||||
|
||||
def index():
|
||||
dark_mode = request.cookies.get('darkMode', 'disabled')
|
||||
@@ -68,7 +65,7 @@ def mecze():
|
||||
except:
|
||||
selected_date = 2025
|
||||
#with open("static/lewandowski_matches.json", "r") as file:
|
||||
# data = json.load(file)
|
||||
# data = json.load(file)
|
||||
status, msg, matches = get_matches(None, id_zawodnika=1, rok=selected_date)
|
||||
|
||||
return render_template('matches.html', matches=matches, selected_date=selected_date)
|
||||
@@ -88,14 +85,13 @@ def clubs():
|
||||
return render_template('club.html', clubs=clubs, selected_club=selected_club)
|
||||
|
||||
def representation():
|
||||
polska = robert_stats(id_klubu="polska")[2][0]
|
||||
nation_stats = {
|
||||
'goals': polska["goals"],
|
||||
'assists': polska["assists"],
|
||||
'matches': polska["unique_items"],
|
||||
'minutes_played': polska["time_played"],
|
||||
'yellow_card':polska["yellow_cards"],
|
||||
'red_card': polska["red_cards"],
|
||||
'goals': 85,
|
||||
'assists': 35,
|
||||
'matches': 158,
|
||||
'minutes_played': 12108,
|
||||
'yellow_card':10,
|
||||
'red_card': 0,
|
||||
'wins':75,
|
||||
'draws': 35,
|
||||
'lost': 48
|
||||
|
||||
Reference in New Issue
Block a user