Compare commits
11 Commits
frontend-f
...
323a8b4973
| Author | SHA1 | Date | |
|---|---|---|---|
| 323a8b4973 | |||
| 8bc1dcb876 | |||
| fc5acd28f7 | |||
| 19e100b4b2 | |||
| fcf11d4a0d | |||
| fc1e636cfd | |||
| fce1b69893 | |||
| 7b457475b4 | |||
| d1f5f8f3f4 | |||
| 56e68ed751 | |||
| 416b2ccfe0 |
@@ -95,11 +95,12 @@ def stats():
|
|||||||
return 200, "ok", data_to_send
|
return 200, "ok", data_to_send
|
||||||
|
|
||||||
# GET /api/v1/matches
|
# GET /api/v1/matches
|
||||||
def get_matches(r = None, id_zawodnika: str | None = None):
|
def get_matches(r = None, id_zawodnika: str | None = None, rok: int | None = None):
|
||||||
"""
|
"""
|
||||||
Zwraca mecze.
|
Zwraca mecze.
|
||||||
Przykład wywołania:
|
Przykład wywołania:
|
||||||
get_matches(r, id_zawodnika=1), tożsame z GET /api/v1/matches?id_zawodnika=1
|
get_matches(r, id_zawodnika=1), tożsame z GET /api/v1/matches?id_zawodnika=1
|
||||||
|
get_matches(r, rok=2024), tożsame z GET /api/v1/matches?rok=2024
|
||||||
get_matches(r), tożsame z GET /api/v1/matches
|
get_matches(r), tożsame z GET /api/v1/matches
|
||||||
"""
|
"""
|
||||||
response_json = []
|
response_json = []
|
||||||
@@ -109,9 +110,14 @@ def get_matches(r = None, id_zawodnika: str | None = None):
|
|||||||
# Gdy nie podano id wprost, sprawdź, czy podano je przez parametr.
|
# Gdy nie podano id wprost, sprawdź, czy podano je przez parametr.
|
||||||
id_zawodnika = r.args.get('id_zawodnika', -1)
|
id_zawodnika = r.args.get('id_zawodnika', -1)
|
||||||
|
|
||||||
|
if rok is None:
|
||||||
|
# Gdy nie podano roku wprost, sprawdź, czy podano je przez parametr.
|
||||||
|
# Jeśli nie, przyjmij None (2025).
|
||||||
|
rok = r.args.get('rok', None)
|
||||||
|
|
||||||
# Sprawdź, czy podano jakiekolwiek ID sportowca. Jeżeli nie, wypisz wszystkie mecze.
|
# Sprawdź, czy podano jakiekolwiek ID sportowca. Jeżeli nie, wypisz wszystkie mecze.
|
||||||
if id_zawodnika == -1:
|
if id_zawodnika == -1:
|
||||||
mecze = getDb().simple_select_all("mecze")
|
mecze = getDb().get_sportsman_matches(year=rok)
|
||||||
|
|
||||||
# Sprawdź, czy sportowiec o podanym (lub niepodanym) id istnieje.
|
# Sprawdź, czy sportowiec o podanym (lub niepodanym) id istnieje.
|
||||||
# Jeśli nie istnieje, wypisz wszystkie mecze.
|
# Jeśli nie istnieje, wypisz wszystkie mecze.
|
||||||
@@ -120,13 +126,123 @@ def get_matches(r = None, id_zawodnika: str | None = None):
|
|||||||
|
|
||||||
# Gdy sportowiec istnieje, wypisz jego mecze.
|
# Gdy sportowiec istnieje, wypisz jego mecze.
|
||||||
else:
|
else:
|
||||||
mecze = getDb().get_sportsman_matches(id_zawodnika=id_zawodnika)
|
mecze = getDb().get_sportsman_matches(id_zawodnika=id_zawodnika, year=rok)
|
||||||
|
|
||||||
for mecz in mecze:
|
for mecz in mecze:
|
||||||
response_json.append(mecz.jsonify())
|
response_json.append(mecz.jsonify())
|
||||||
# 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 statystyki gracza.
|
||||||
|
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.
|
||||||
|
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 statystyki.
|
||||||
|
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],
|
||||||
|
'wins': staty[7],
|
||||||
|
'draws': staty[8],
|
||||||
|
'losses': staty[9]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
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 statystyki Roberta w danym klubie.
|
||||||
|
Przykład wywołania:
|
||||||
|
robert_stats(r, id_klubu="barcelona"), tożsame z GET /api/v1/robert_stats?id_klubu=barcelona
|
||||||
|
"""
|
||||||
|
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', "non-existent-club-id")
|
||||||
|
|
||||||
|
# Sprawdź, czy klub o podanym (lub niepodanym) id istnieje.
|
||||||
|
if 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 klub istnieje, wypisz statystyki z tego klubu.
|
||||||
|
else:
|
||||||
|
staty = getDb().get_sportsman_club_stats(id_zawodnika=1, id_klubu=id_klubu)
|
||||||
|
|
||||||
|
# for stat in staty:
|
||||||
|
print(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],
|
||||||
|
'wins': staty[7],
|
||||||
|
'draws': staty[8],
|
||||||
|
'losses': staty[9]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
print(f"zwracam staty roberta: {response_json}")
|
||||||
|
return 200, "ok", response_json
|
||||||
|
|
||||||
|
# GET /api/v1/clubs
|
||||||
|
def clubs(r, id_klubu: str = None):
|
||||||
|
"""
|
||||||
|
Zwraca informacje o klubach.
|
||||||
|
Przykład wywołania:
|
||||||
|
clubs(r, id_klubu="barcelona"), tożsame z GET /api/v1/clubs?id_klubu=barcelona
|
||||||
|
clubs(r), tożsame z GET /api/v1/clubs
|
||||||
|
"""
|
||||||
|
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', -1)
|
||||||
|
|
||||||
|
if id_klubu == -1:
|
||||||
|
kluby = getDb().simple_select_all("kluby")
|
||||||
|
|
||||||
|
# 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:
|
||||||
|
kluby = getDb().simple_select_all("kluby", id_klubu=id_klubu)
|
||||||
|
|
||||||
|
for klub in kluby:
|
||||||
|
response_json.append(klub.jsonify())
|
||||||
|
|
||||||
|
print(f"zwracam kluby: {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):
|
||||||
@@ -179,6 +295,12 @@ def lookup(data, request):
|
|||||||
return debugger_halt(r = request)
|
return debugger_halt(r = request)
|
||||||
case 'matches':
|
case 'matches':
|
||||||
return get_matches(r = request)
|
return get_matches(r = request)
|
||||||
|
case 'player_stats':
|
||||||
|
return player_stats(r = request)
|
||||||
|
case 'robert_stats':
|
||||||
|
return robert_stats(r = request)
|
||||||
|
case 'clubs':
|
||||||
|
return clubs(r = request)
|
||||||
case _:
|
case _:
|
||||||
increment_bad_requests()
|
increment_bad_requests()
|
||||||
return not_implemented(data)
|
return not_implemented(data)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from sqlalchemy import ForeignKey, select, insert, update
|
|
||||||
from sqlalchemy.orm import Mapped, mapped_column, DeclarativeBase, Session, relationship
|
from sqlalchemy.orm import Mapped, mapped_column, DeclarativeBase, Session, relationship
|
||||||
from typing import List
|
from typing import List
|
||||||
import time
|
import time
|
||||||
@@ -105,6 +105,8 @@ class baza():
|
|||||||
czerwone_kartki: Mapped[ int] = mapped_column()
|
czerwone_kartki: Mapped[ int] = mapped_column()
|
||||||
wygrana: Mapped[ int] = mapped_column()
|
wygrana: Mapped[ int] = mapped_column()
|
||||||
wynik: Mapped[ float] = mapped_column()
|
wynik: Mapped[ float] = mapped_column()
|
||||||
|
klub_id: Mapped[ int] = mapped_column(ForeignKey(f"{tnp}kluby.id_klubu"))
|
||||||
|
klub: Mapped[ "kluby"] = relationship()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<{self.zawodnik.imie} {self.zawodnik.nazwisko} w meczu {self.mecz.gospodarze.skrocona_nazwa} vs. {self.mecz.goscie.skrocona_nazwa}>"
|
return f"<{self.zawodnik.imie} {self.zawodnik.nazwisko} w meczu {self.mecz.gospodarze.skrocona_nazwa} vs. {self.mecz.goscie.skrocona_nazwa}>"
|
||||||
@@ -143,6 +145,13 @@ class baza():
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Klub #{self.id_klubu} ({self.skrocona_nazwa})>"
|
return f"<Klub #{self.id_klubu} ({self.skrocona_nazwa})>"
|
||||||
|
|
||||||
|
def jsonify(self):
|
||||||
|
return {
|
||||||
|
"id_klubu": self.id_klubu,
|
||||||
|
"pelna_nazwa": self.pelna_nazwa,
|
||||||
|
"skrocona_nazwa": self.skrocona_nazwa
|
||||||
|
}
|
||||||
|
|
||||||
class mecze(Base):
|
class mecze(Base):
|
||||||
__tablename__ = tnp + "mecze"
|
__tablename__ = tnp + "mecze"
|
||||||
id_meczu: Mapped[ int] = mapped_column(primary_key=True, autoincrement=True)
|
id_meczu: Mapped[ int] = mapped_column(primary_key=True, autoincrement=True)
|
||||||
@@ -201,12 +210,12 @@ class baza():
|
|||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
self.session = Session(self.db.engine)
|
self.session = Session(self.db.engine)
|
||||||
|
|
||||||
def exit_gracefully(func):
|
def exit_gracefully(fun):
|
||||||
@wraps(func)
|
@wraps(fun)
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
return_val = None
|
return_val = None
|
||||||
try:
|
try:
|
||||||
return_val = func(self, *args, **kwargs)
|
return_val = fun(self, *args, **kwargs)
|
||||||
except:
|
except:
|
||||||
print(f"{c.FAIL}"
|
print(f"{c.FAIL}"
|
||||||
f"Wystąpił błąd podczas wykonywania zapytania SQL:"
|
f"Wystąpił błąd podczas wykonywania zapytania SQL:"
|
||||||
@@ -517,8 +526,9 @@ class baza():
|
|||||||
return query.all()
|
return query.all()
|
||||||
|
|
||||||
@exit_gracefully
|
@exit_gracefully
|
||||||
def get_sportsman_matches(self, id_zawodnika = None, zewnetrzne_id_zawodnika = None, order = "DESC"):
|
def get_sportsman_matches(self, id_zawodnika = None, zewnetrzne_id_zawodnika = None, order = "DESC", year = None):
|
||||||
|
|
||||||
|
# Spróbuj otrzymać id zawodnika z zewnętrznego id.
|
||||||
if zewnetrzne_id_zawodnika is not None:
|
if zewnetrzne_id_zawodnika is not None:
|
||||||
id_zawodnika = self.get_id_zawodnika_by_zewnetrzne_id(zewnetrzne_id_zawodnika)
|
id_zawodnika = self.get_id_zawodnika_by_zewnetrzne_id(zewnetrzne_id_zawodnika)
|
||||||
|
|
||||||
@@ -531,19 +541,154 @@ class baza():
|
|||||||
Mecze
|
Mecze
|
||||||
).join(
|
).join(
|
||||||
SportowcyWMeczach, Mecze.zewnetrzne_id_meczu == SportowcyWMeczach.zewnetrzne_id_meczu
|
SportowcyWMeczach, Mecze.zewnetrzne_id_meczu == SportowcyWMeczach.zewnetrzne_id_meczu
|
||||||
).join(
|
)
|
||||||
|
|
||||||
|
if id_zawodnika is not None:
|
||||||
|
query = query.join(
|
||||||
Sportowcy, SportowcyWMeczach.id_zawodnika == Sportowcy.id_zawodnika
|
Sportowcy, SportowcyWMeczach.id_zawodnika == Sportowcy.id_zawodnika
|
||||||
).filter(
|
).filter(
|
||||||
Sportowcy.id_zawodnika == id_zawodnika
|
Sportowcy.id_zawodnika == id_zawodnika
|
||||||
)
|
)
|
||||||
|
|
||||||
# print(f"get_sportsman_matches: {query}")
|
if year is not None:
|
||||||
|
query = query.filter(
|
||||||
|
extract("year", Mecze.data) == year
|
||||||
|
)
|
||||||
|
|
||||||
if order.lower() == "desc":
|
if order.lower() == "desc":
|
||||||
query = query.order_by(Mecze.data.desc())
|
query = query.order_by(Mecze.data.desc())
|
||||||
|
|
||||||
|
# print(f"get_sportsman_matches: {query}")
|
||||||
|
|
||||||
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"]
|
||||||
|
|
||||||
|
# Zlicz liczbę zwycięstw, remisów i przegranych.
|
||||||
|
# https://stackoverflow.com/a/3975328
|
||||||
|
# https://stackoverflow.com/a/49064561
|
||||||
|
# Czy da się to zrobić prościej? Nie wiem. ~ sherl
|
||||||
|
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'),
|
||||||
|
|
||||||
|
# Kompatybilne z każdą bazą.
|
||||||
|
# https://docs.sqlalchemy.org/en/20/core/sqlelement.html#sqlalchemy.sql.expression.case
|
||||||
|
# https://modern-sql.com/feature/filter
|
||||||
|
func.sum(
|
||||||
|
case(
|
||||||
|
(SportowcyWMeczach.wygrana == 1, 1),
|
||||||
|
else_ = 0
|
||||||
|
)
|
||||||
|
).label('wins'),
|
||||||
|
|
||||||
|
func.sum(
|
||||||
|
case(
|
||||||
|
(SportowcyWMeczach.wygrana == 0, 1),
|
||||||
|
else_ = 0
|
||||||
|
)
|
||||||
|
).label('draws'),
|
||||||
|
|
||||||
|
func.sum(
|
||||||
|
case(
|
||||||
|
(SportowcyWMeczach.wygrana == -1, 1),
|
||||||
|
else_ = 0
|
||||||
|
)
|
||||||
|
).label('losses'),
|
||||||
|
|
||||||
|
).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"]
|
||||||
|
|
||||||
|
# Zlicz liczbę zwycięstw, remisów i przegranych.
|
||||||
|
# https://stackoverflow.com/a/3975328
|
||||||
|
# https://stackoverflow.com/a/49064561
|
||||||
|
# Czy da się to zrobić prościej? Nie wiem. ~ sherl
|
||||||
|
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'),
|
||||||
|
|
||||||
|
# Kompatybilne z każdą bazą.
|
||||||
|
# https://docs.sqlalchemy.org/en/20/core/sqlelement.html#sqlalchemy.sql.expression.case
|
||||||
|
# https://modern-sql.com/feature/filter
|
||||||
|
func.sum(
|
||||||
|
case(
|
||||||
|
(SportowcyWMeczach.wygrana == 1, 1),
|
||||||
|
else_ = 0
|
||||||
|
)
|
||||||
|
).label('wins'),
|
||||||
|
|
||||||
|
# UWAGA! Jeśli jest remis, to nie wiemy dla którego klubu grał sportowiec!
|
||||||
|
# Poniższe wyrażenie jest poprawne, to dane zwracane przez flashscore są
|
||||||
|
# niewystarczające, aby stwierdzić w którym klubie grał sportowiec!
|
||||||
|
func.sum(
|
||||||
|
case(
|
||||||
|
(SportowcyWMeczach.wygrana == 0, 1),
|
||||||
|
else_ = 0
|
||||||
|
)
|
||||||
|
).label('draws'),
|
||||||
|
|
||||||
|
func.sum(
|
||||||
|
case(
|
||||||
|
(SportowcyWMeczach.wygrana == -1, 1),
|
||||||
|
else_ = 0
|
||||||
|
)
|
||||||
|
).label('losses'),
|
||||||
|
|
||||||
|
).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,39 +3,47 @@ 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
|
from lewy_api_v1 import get_matches, player_stats, robert_stats, clubs as get_clubs
|
||||||
def get_lewy_stats():
|
def get_lewy_stats():
|
||||||
return {
|
stats = player_stats(id_zawodnika=1)[2][0]
|
||||||
'all_time_stats': {
|
polska = robert_stats(id_klubu="polska")[2][0]
|
||||||
'goals': 589+85,
|
barcelona = robert_stats(id_klubu="barcelona")[2][0]
|
||||||
'assists':154+35,
|
return {
|
||||||
'matches': 791+158,
|
'all_time_stats': {
|
||||||
},
|
'goals': stats["goals"], # 589+85
|
||||||
'club_stats': {
|
'assists': stats["assists"], # 154+35
|
||||||
'goals': 589,
|
'matches': stats["unique_items"] # 791+158
|
||||||
'assists': 154,
|
},
|
||||||
'matches': 791,
|
'club_stats': {
|
||||||
},
|
'goals': barcelona["goals"], # 589
|
||||||
'nation_stats': {
|
'assists': barcelona["assists"], # 154
|
||||||
'goals': 85,
|
'matches': barcelona["unique_items"] # 791 # to trochę na wyrost, bo w części meczy był kontuzjowany
|
||||||
'assists': 35,
|
},
|
||||||
'matches': 158,
|
'nation_stats': {
|
||||||
},
|
'goals': polska["goals"], # 85
|
||||||
'international_cups': {
|
'assists': polska["assists"], # 35
|
||||||
'goals': 110,
|
'matches': polska["unique_items"] # 158
|
||||||
'assists': 19,
|
},
|
||||||
'matches': 152,
|
'international_cups': {
|
||||||
},
|
'goals': 110,
|
||||||
'national_cups': {
|
'assists': 19,
|
||||||
'goals': 58,
|
'matches': 152,
|
||||||
'assists': 4,
|
},
|
||||||
'matches': 74,
|
'national_cups': {
|
||||||
},
|
'goals': 58,
|
||||||
'cards': {
|
'assists': 4,
|
||||||
'yellow': 86,
|
'matches': 74,
|
||||||
'red': 2,
|
},
|
||||||
}
|
'cards': {
|
||||||
}
|
'yellow': stats["yellow_cards"], # 86
|
||||||
|
'red': stats["red_cards"], # 2
|
||||||
|
},
|
||||||
|
'wins_losses': {
|
||||||
|
'wins': stats["wins"],
|
||||||
|
'draws': stats["draws"],
|
||||||
|
'losses': stats["losses"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def index():
|
def index():
|
||||||
dark_mode = request.cookies.get('darkMode', 'disabled')
|
dark_mode = request.cookies.get('darkMode', 'disabled')
|
||||||
@@ -60,9 +68,13 @@ def index():
|
|||||||
def mecze():
|
def mecze():
|
||||||
# Możesz dostarczyć szczegóły dotyczące meczów
|
# Możesz dostarczyć szczegóły dotyczące meczów
|
||||||
selected_date = request.args.get("date", '2025')
|
selected_date = request.args.get("date", '2025')
|
||||||
|
try:
|
||||||
|
selected_date = int(selected_date)
|
||||||
|
except:
|
||||||
|
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)
|
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)
|
||||||
|
|
||||||
@@ -71,28 +83,68 @@ def statystyki():
|
|||||||
return render_template('stats.html', **dane)
|
return render_template('stats.html', **dane)
|
||||||
|
|
||||||
def clubs():
|
def clubs():
|
||||||
selected_club = request.args.get("club","FC Barcelona")
|
selected_club = request.args.get("club", "barcelona")
|
||||||
clubs = [
|
#clubs = [
|
||||||
{'club': 'FC Barcelona', 'goals': 101,'assist':20, 'matches':147,'minutes_played': 11684,'yellow_card':12,'red_card': 1, 'wins':101, 'draws': 14,'lost': 32},
|
# {'club': 'FC Barcelona', 'goals': 101,'assist':20, 'matches':147,'minutes_played': 11684,'yellow_card':12,'red_card': 1, 'wins':101, 'draws': 14,'lost': 32},
|
||||||
{'club': 'Bayern Monachium', 'goals': 344,'assist':73,'matches':375,'minutes_played': 31759,'yellow_card':36,'red_card': 0, 'wins':307, 'draws': 35,'lost': 33},
|
# {'club': 'Bayern Monachium', 'goals': 344,'assist':73,'matches':375,'minutes_played': 31759,'yellow_card':36,'red_card': 0, 'wins':307, 'draws': 35,'lost': 33},
|
||||||
{'club': 'Borussia Dortmund', 'goals': 103,'assist':42,'matches':187,'minutes_played': 14374,'yellow_card':19,'red_card': 1, 'wins':120, 'draws': 40,'lost': 27},
|
# {'club': 'Borussia Dortmund', 'goals': 103,'assist':42,'matches':187,'minutes_played': 14374,'yellow_card':19,'red_card': 1, 'wins':120, 'draws': 40,'lost': 27},
|
||||||
{'club': 'Lech Poznan', 'goals': 41,'assist':19,'matches':82,'minutes_played': 6858,'yellow_card':9,'red_card': 0, 'wins':'-', 'draws': '-','lost': '-'},
|
# {'club': 'Lech Poznan', 'goals': 41,'assist':19,'matches':82,'minutes_played': 6858,'yellow_card':9,'red_card': 0, 'wins':'-', 'draws': '-','lost': '-'},
|
||||||
]
|
#]
|
||||||
return render_template('club.html', clubs=clubs, selected_club=selected_club)
|
response_json = {
|
||||||
|
"club": "Błędny klub",
|
||||||
|
"goals": 0,
|
||||||
|
"assist": 0,
|
||||||
|
"matches": 0,
|
||||||
|
"minutes_played": 0,
|
||||||
|
"yellow_card": 0,
|
||||||
|
"red_card": 0,
|
||||||
|
"wins": 0,
|
||||||
|
"draws": 0,
|
||||||
|
"lost": 0
|
||||||
|
}
|
||||||
|
|
||||||
|
club = get_clubs(request, id_klubu=selected_club)
|
||||||
|
if club[1] == "ok": # gdy nie wystąpił bład, bo jest taki klub
|
||||||
|
club = club[2][0]
|
||||||
|
staty = robert_stats(id_klubu=club["id_klubu"])[2][0]
|
||||||
|
response_json["club"] = club["pelna_nazwa"]
|
||||||
|
response_json["goals"] = staty["goals"]
|
||||||
|
response_json["assist"] = staty["assists"]
|
||||||
|
response_json["matches"] = staty["unique_items"]
|
||||||
|
response_json["minutes_played"] = staty["time_played"]
|
||||||
|
response_json["yellow_card"] = staty["yellow_cards"]
|
||||||
|
response_json["red_card"] = staty["red_cards"]
|
||||||
|
response_json["wins"] = staty["wins"]
|
||||||
|
response_json["draws"] = staty["draws"]
|
||||||
|
response_json["lost"] = staty["losses"]
|
||||||
|
|
||||||
|
return render_template('club.html', clubs=clubs, selected_club=selected_club, resp_json=response_json)
|
||||||
|
|
||||||
def representation():
|
def representation():
|
||||||
nation_stats = {
|
# nation_stats = {
|
||||||
'goals': 85,
|
# 'goals': 85,
|
||||||
'assists': 35,
|
# 'assists': 35,
|
||||||
'matches': 158,
|
# 'matches': 158,
|
||||||
'minutes_played': 12108,
|
# 'minutes_played': 12108,
|
||||||
'yellow_card':10,
|
# 'yellow_card':10,
|
||||||
'red_card': 0,
|
# 'red_card': 0,
|
||||||
'wins':75,
|
# 'wins':75,
|
||||||
'draws': 35,
|
# 'draws': 35,
|
||||||
'lost': 48
|
# 'lost': 48
|
||||||
}
|
# }
|
||||||
return render_template('representation.html', nation_stats=nation_stats)
|
response_json = {}
|
||||||
|
staty = robert_stats(id_klubu="polska")[2][0]
|
||||||
|
response_json["goals"] = staty["goals"]
|
||||||
|
response_json["assist"] = staty["assists"]
|
||||||
|
response_json["matches"] = staty["unique_items"]
|
||||||
|
response_json["minutes_played"] = staty["time_played"]
|
||||||
|
response_json["yellow_card"] = staty["yellow_cards"]
|
||||||
|
response_json["red_card"] = staty["red_cards"]
|
||||||
|
response_json["wins"] = staty["wins"]
|
||||||
|
response_json["draws"] = staty["draws"]
|
||||||
|
response_json["lost"] = staty["losses"]
|
||||||
|
return render_template('representation.html', nation_stats=response_json)
|
||||||
|
|
||||||
def compare():
|
def compare():
|
||||||
selected_player = request.args.get("player","Leo Messi")
|
selected_player = request.args.get("player","Leo Messi")
|
||||||
lewy=get_lewy_stats()
|
lewy=get_lewy_stats()
|
||||||
|
|||||||
@@ -386,6 +386,34 @@ header button {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@media (max-width: 600px){
|
||||||
|
.section__matches
|
||||||
|
{
|
||||||
|
font-size: 10px;
|
||||||
|
}
|
||||||
|
.section__matches th{
|
||||||
|
padding: 3px;
|
||||||
|
}
|
||||||
|
.club-stats-grid
|
||||||
|
{
|
||||||
|
grid-template-columns: 1fr 1fr !important;
|
||||||
|
}
|
||||||
|
.club-stats-grid .stat-box
|
||||||
|
{
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.section-stats-center .section-stats .stats
|
||||||
|
{
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.section-stats-center .section-stats .stats .stat-box
|
||||||
|
{
|
||||||
|
width: 100%;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,59 +4,59 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<section class="choose-club">
|
<section class="choose-club">
|
||||||
<a href="{{ url_for('clubs', club='FC Barcelona') }}">
|
<a href="{{ url_for('clubs', club='barcelona') }}">
|
||||||
<button><img src="{{ url_for('static', filename='FC_Barcelona.png') }}"></button>
|
<button><img src="{{ url_for('static', filename='FC_Barcelona.png') }}"></button>
|
||||||
</a>
|
</a>
|
||||||
<a href="{{ url_for('clubs', club='Bayern Monachium') }}">
|
<a href="{{ url_for('clubs', club='bayern') }}">
|
||||||
<button><img src="{{ url_for('static', filename='FC_Bayern.png') }}"></button>
|
<button><img src="{{ url_for('static', filename='FC_Bayern.png') }}"></button>
|
||||||
</a>
|
</a>
|
||||||
<a href="{{ url_for('clubs', club='Borussia Dortmund') }}">
|
<a href="{{ url_for('clubs', club='dortmund') }}">
|
||||||
<button><img src="{{ url_for('static', filename='Borussia_Dortmund.png') }}"></button>
|
<button><img src="{{ url_for('static', filename='Borussia_Dortmund.png') }}"></button>
|
||||||
</a>
|
</a>
|
||||||
<!--Jak nie będzie statysytk dla lecha to usunać-->
|
<!--Jak nie będzie statysytk dla lecha to usunać-->
|
||||||
<a href="{{ url_for('clubs', club='Lech Poznan') }}">
|
<!-- <a href="{{ url_for('clubs', club='Lech Poznan') }}">
|
||||||
<button><img src="{{ url_for('static', filename='Lech_Poznan.png') }}"></button>
|
<button><img src="{{ url_for('static', filename='Lech_Poznan.png') }}"></button>
|
||||||
</a>
|
</a> -->
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<!-- Wyświetlanie danych tylko dla wybranego klubu -->
|
<!-- Wyświetlanie danych tylko dla wybranego klubu -->
|
||||||
{% for stats in clubs %}
|
{#{% for stats in clubs %}#}
|
||||||
{% if stats.club == selected_club %}
|
{#{% if stats.club == selected_club %}#}
|
||||||
<section class="club-stats">
|
<section class="club-stats">
|
||||||
<h2>Statystyki dla {{selected_club}}</h2>
|
<h2>Statystyki dla {{resp_json.club}}</h2>
|
||||||
<div class="wybrany{{selected_club}}"></div>
|
<div class="wybrany{{resp_json.club}}"></div>
|
||||||
<div class="club-stats-grid">
|
<div class="club-stats-grid">
|
||||||
<div class="stat-box">
|
<div class="stat-box">
|
||||||
<p>Gole:</p> <span class="stat-box-special"> {{ stats.goals }} </span>
|
<p>Gole:</p> <span class="stat-box-special"> {{ resp_json.goals }} </span>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat-box">
|
<div class="stat-box">
|
||||||
<p>Asysty:</p> <span class="stat-box-special"> {{ stats.assist }} </span>
|
<p>Asysty:</p> <span class="stat-box-special"> {{ resp_json.assist }} </span>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat-box">
|
<div class="stat-box">
|
||||||
<p>Występy:</p> <span class="stat-box-special"> {{ stats.matches }} </span>
|
<p>Występy:</p> <span class="stat-box-special"> {{ resp_json.matches }} </span>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat-box">
|
<div class="stat-box">
|
||||||
<p>Łączny czas gry:</p> <span class="stat-box-special"> {{ stats.minutes_played }}</span>
|
<p>Łączny czas gry:</p> <span class="stat-box-special"> {{ resp_json.minutes_played }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat-box">
|
<div class="stat-box">
|
||||||
<p>Żółte kartki:</p> <span class="stat-box-special"> {{ stats.yellow_card }}</span>
|
<p>Żółte kartki:</p> <span class="stat-box-special"> {{ resp_json.yellow_card }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat-box">
|
<div class="stat-box">
|
||||||
<p>Czerwone kartki:</p> <span class="stat-box-special"> {{ stats.red_card }}</span>
|
<p>Czerwone kartki:</p> <span class="stat-box-special"> {{ resp_json.red_card }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat-box">
|
<div class="stat-box">
|
||||||
<p>Zwycięstwa:</p> <span class="stat-box-special"> {{ stats.wins }}</span>
|
<p>Zwycięstwa:</p> <span class="stat-box-special"> {{ resp_json.wins }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat-box">
|
<div class="stat-box">
|
||||||
<p>Remisy:</p> <span class="stat-box-special"> {{ stats.draws }}</span>
|
<p>Remisy:</p> <span class="stat-box-special"> {{ resp_json.draws }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat-box">
|
<div class="stat-box">
|
||||||
<p>Porażki:</p> <span class="stat-box-special"> {{ stats.lost }}</span>
|
<p>Porażki:</p> <span class="stat-box-special"> {{ resp_json.lost }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
{% endif %}
|
{#{% endif %}#}
|
||||||
{% endfor %}
|
{#{% endfor %}#}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block footer %}
|
{% block footer %}
|
||||||
|
|||||||
@@ -36,7 +36,6 @@
|
|||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for match in matches %}
|
{% for match in matches %}
|
||||||
{% if match.data[:4] == selected_date %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ match.data }}</td>
|
<td>{{ match.data }}</td>
|
||||||
|
|
||||||
@@ -49,7 +48,6 @@
|
|||||||
<td>{{ match.minutes }}</td>
|
<td>{{ match.minutes }}</td>
|
||||||
-->
|
-->
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<p>Gole:</p> <span class="stat-box-special"> {{ nation_stats.goals }} </span>
|
<p>Gole:</p> <span class="stat-box-special"> {{ nation_stats.goals }} </span>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat-box">
|
<div class="stat-box">
|
||||||
<p>Asysty:</p> <span class="stat-box-special"> {{ nation_stats.assists }} </span>
|
<p>Asysty:</p> <span class="stat-box-special"> {{ nation_stats.assist }} </span>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat-box">
|
<div class="stat-box">
|
||||||
<p>Występy:</p> <span class="stat-box-special"> {{ nation_stats.matches }} </span>
|
<p>Występy:</p> <span class="stat-box-special"> {{ nation_stats.matches }} </span>
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section class="section-stats">
|
<section class="section-stats">
|
||||||
<h2>Puchary międzynarodowe</h2>
|
<h2>(!) Puchary międzynarodowe</h2>
|
||||||
<div class="stats">
|
<div class="stats">
|
||||||
<div class="stat-box">
|
<div class="stat-box">
|
||||||
<h3>{{ international_cups.goals }}</h3>
|
<h3>{{ international_cups.goals }}</h3>
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section class="section-stats">
|
<section class="section-stats">
|
||||||
<h2>Puchary krajowe</h2>
|
<h2>(!) Puchary krajowe</h2>
|
||||||
<div class="stats">
|
<div class="stats">
|
||||||
<div class="stat-box">
|
<div class="stat-box">
|
||||||
<h3>{{ national_cups.goals }}</h3>
|
<h3>{{ national_cups.goals }}</h3>
|
||||||
@@ -103,4 +103,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
<section class="section-stats">
|
||||||
|
<h2>Wygrane, remisy i przegrane</h2>
|
||||||
|
<div class="stats">
|
||||||
|
<div class="stat-box">
|
||||||
|
<h3>{{ wins_losses.wins }}</h3>
|
||||||
|
<p>Wygrane</p>
|
||||||
|
</div>
|
||||||
|
<div class="stat-box">
|
||||||
|
<h3>{{ wins_losses.draws }}</h3>
|
||||||
|
<p>Remisy</p>
|
||||||
|
</div>
|
||||||
|
<div class="stat-box">
|
||||||
|
<h3>{{ wins_losses.losses }}</h3>
|
||||||
|
<p>Przegrane</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user