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
|
return False
|
||||||
|
|
||||||
def czy_sportowiec_istnieje(id_zawodnika: str):
|
def czy_sportowiec_istnieje(id_zawodnika: str):
|
||||||
return __czy_x_istnieje("sportowcy", id_zawodnika=int(id_zawodnika))
|
return __czy_x_istnieje("sportowcy", id_zawodnika=id_zawodnika)
|
||||||
|
|
||||||
def czy_klub_istnieje(id_klubu: str):
|
|
||||||
return __czy_x_istnieje("kluby", id_klubu=id_klubu)
|
|
||||||
|
|
||||||
# GET /api/v1
|
# GET /api/v1
|
||||||
def stub_hello():
|
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}")
|
# print(f"zwracam mecze: {response_json}")
|
||||||
return 200, "ok", 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...
|
# GET /api/v1/debugger_halt?token=XXX...
|
||||||
@require_authentication
|
@require_authentication
|
||||||
def debugger_halt(r):
|
def debugger_halt(r):
|
||||||
@@ -264,4 +187,4 @@ def lookup(data, request):
|
|||||||
return get_matches(r = request)
|
return get_matches(r = request)
|
||||||
case _:
|
case _:
|
||||||
increment_bad_requests()
|
increment_bad_requests()
|
||||||
return not_implemented(data)
|
return not_implemented(data)
|
||||||
@@ -553,72 +553,6 @@ class baza():
|
|||||||
|
|
||||||
return query.all()
|
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
|
@exit_gracefully
|
||||||
def sample_data_init(self, override_safety_check=False):
|
def sample_data_init(self, override_safety_check=False):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -3,42 +3,39 @@ import lewy_api_v1
|
|||||||
import lewy_db
|
import lewy_db
|
||||||
import lewy_globals
|
import lewy_globals
|
||||||
import json
|
import json
|
||||||
from lewy_api_v1 import get_matches, player_stats, robert_stats
|
from lewy_api_v1 import get_matches
|
||||||
def get_lewy_stats():
|
def get_lewy_stats():
|
||||||
stats = player_stats(id_zawodnika=1)[2][0]
|
return {
|
||||||
polska = robert_stats(id_klubu="polska")[2][0]
|
'all_time_stats': {
|
||||||
barcelona = robert_stats(id_klubu="barcelona")[2][0]
|
'goals': 589+85,
|
||||||
return {
|
'assists':154+35,
|
||||||
'all_time_stats': {
|
'matches': 791+158,
|
||||||
'goals': stats["goals"], # 589+85
|
},
|
||||||
'assists': stats["assists"], # 154+35
|
'club_stats': {
|
||||||
'matches': stats["unique_items"] # 791+158
|
'goals': 589,
|
||||||
},
|
'assists': 154,
|
||||||
'club_stats': {
|
'matches': 791,
|
||||||
'goals': barcelona["goals"], # 589
|
},
|
||||||
'assists': barcelona["assists"], # 154
|
'nation_stats': {
|
||||||
'matches': barcelona["unique_items"] # 791 # to trochę na wyrost, bo w części meczy był kontuzjowany
|
'goals': 85,
|
||||||
},
|
'assists': 35,
|
||||||
'nation_stats': {
|
'matches': 158,
|
||||||
'goals': polska["goals"], # 85
|
},
|
||||||
'assists': polska["assists"], # 35
|
'international_cups': {
|
||||||
'matches': polska["unique_items"] # 158
|
'goals': 110,
|
||||||
},
|
'assists': 19,
|
||||||
'international_cups': {
|
'matches': 152,
|
||||||
'goals': 110,
|
},
|
||||||
'assists': 19,
|
'national_cups': {
|
||||||
'matches': 152,
|
'goals': 58,
|
||||||
},
|
'assists': 4,
|
||||||
'national_cups': {
|
'matches': 74,
|
||||||
'goals': 58,
|
},
|
||||||
'assists': 4,
|
'cards': {
|
||||||
'matches': 74,
|
'yellow': 86,
|
||||||
},
|
'red': 2,
|
||||||
'cards': {
|
}
|
||||||
'yellow': stats["yellow_cards"], # 86
|
}
|
||||||
'red': stats["red_cards"], # 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def index():
|
def index():
|
||||||
dark_mode = request.cookies.get('darkMode', 'disabled')
|
dark_mode = request.cookies.get('darkMode', 'disabled')
|
||||||
@@ -68,7 +65,7 @@ def mecze():
|
|||||||
except:
|
except:
|
||||||
selected_date = 2025
|
selected_date = 2025
|
||||||
#with open("static/lewandowski_matches.json", "r") as file:
|
#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)
|
status, msg, matches = get_matches(None, id_zawodnika=1, rok=selected_date)
|
||||||
|
|
||||||
return render_template('matches.html', matches=matches, selected_date=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)
|
return render_template('club.html', clubs=clubs, selected_club=selected_club)
|
||||||
|
|
||||||
def representation():
|
def representation():
|
||||||
polska = robert_stats(id_klubu="polska")[2][0]
|
|
||||||
nation_stats = {
|
nation_stats = {
|
||||||
'goals': polska["goals"],
|
'goals': 85,
|
||||||
'assists': polska["assists"],
|
'assists': 35,
|
||||||
'matches': polska["unique_items"],
|
'matches': 158,
|
||||||
'minutes_played': polska["time_played"],
|
'minutes_played': 12108,
|
||||||
'yellow_card':polska["yellow_cards"],
|
'yellow_card':10,
|
||||||
'red_card': polska["red_cards"],
|
'red_card': 0,
|
||||||
'wins':75,
|
'wins':75,
|
||||||
'draws': 35,
|
'draws': 35,
|
||||||
'lost': 48
|
'lost': 48
|
||||||
|
|||||||
Reference in New Issue
Block a user