Compare commits
4 Commits
frontend
...
cf46fdfbb7
| Author | SHA1 | Date | |
|---|---|---|---|
| cf46fdfbb7 | |||
| 791d20139d | |||
| c3a6626d6f | |||
| 5960e44b17 |
@@ -58,6 +58,8 @@ def setup():
|
||||
sanity_string += f" If you're running a reverse proxy, set {c.OKCYAN}is_proxied{c.ENDC} to true to silence this message.\n"
|
||||
print(sanity_string)
|
||||
|
||||
# Should fix disconnects: https://stackoverflow.com/a/61739721
|
||||
app.config['SQLALCHEMY_ENGINE_OPTIONS'] = {"pool_pre_ping": True}
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = f"{config['general']['db_path_url']}"
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
|
||||
|
||||
@@ -36,6 +36,9 @@ class baza():
|
||||
self.db = self.initDB(self.app, config)
|
||||
self.refresh_session()
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Obiekt bazodanowy baza ({len(self.entities)} encji)>"
|
||||
|
||||
def initDB(self, app, config):
|
||||
global sportowcy, trofea, sportowcy_w_meczach, statystyki_sportowcow, kluby, mecze
|
||||
tnp = config['general']['db_prefix'] + "_lewangoalski_"
|
||||
@@ -201,8 +204,10 @@ class baza():
|
||||
:param string: Zapis tekstowy
|
||||
:type string: str
|
||||
"""
|
||||
table_str = string[:string.find('.')]
|
||||
column_str = string[string.find('.') + 1:]
|
||||
try:
|
||||
table_str, column_str = string.split('.')
|
||||
except:
|
||||
raise ValueError("Nieprawidłowe dane - podaj zarówno tabelę, jak i kolumnę, np.: \"kluby.id_klubu\".")
|
||||
if hasattr(self.entities[table_str], column_str):
|
||||
return getattr(self.entities[table_str], column_str)
|
||||
return None
|
||||
@@ -222,28 +227,61 @@ class baza():
|
||||
if not isinstance(entity_type, str):
|
||||
entity_type = entity_type.__name__
|
||||
|
||||
# Save special arguments received with kwargs,
|
||||
# that are meant for SQL operations to special_args,
|
||||
# and delete from the rest, that will be passed
|
||||
# directly to filter_by().
|
||||
# They will not be passed as search query, but serve
|
||||
# as an additional search parameter.
|
||||
special_keywords = ("ORDER_BY", "ORDER_BY_DESC", "LIMIT")
|
||||
special_args = {}
|
||||
|
||||
for arg in special_keywords:
|
||||
if arg in kwargs:
|
||||
special_args[arg] = kwargs[arg]
|
||||
del kwargs[arg]
|
||||
query_params, special_args = self.extract_special_args(kwargs)
|
||||
|
||||
print(f"[{round(time.time())}] SELECT")
|
||||
|
||||
results = (
|
||||
self.session.
|
||||
query(self.entities[entity_type]).
|
||||
filter_by(**kwargs)
|
||||
filter_by(**query_params)
|
||||
)
|
||||
|
||||
# Obsługuje "ORDER_BY", "LIMIT", itp. itd.
|
||||
results = self.manipulate_results(results, special_args)
|
||||
|
||||
results_objs = results.all()
|
||||
print(f"[{round(time.time())}] SELECT RESULTS: {results_objs}")
|
||||
|
||||
return results_objs
|
||||
|
||||
def extract_special_args(self, dictionary: dict):
|
||||
"""
|
||||
Zwraca krotkę składającą się ze słowników z:
|
||||
- parametrami wyszukiwania
|
||||
- specjalnymi argumentami
|
||||
|
||||
:param dictionary: Słownik wejściowy
|
||||
:type dictionary: dict
|
||||
"""
|
||||
|
||||
# Save special arguments received with kwargs,
|
||||
# that are meant for SQL operations to special_args,
|
||||
# and delete from the rest, that will be passed
|
||||
# directly to filter_by().
|
||||
# They will not be passed as search query, but serve
|
||||
# as an additional search parameter.
|
||||
dictionary = dictionary.copy()
|
||||
|
||||
special_keywords = ("ORDER_BY", "ORDER_BY_DESC", "LIMIT")
|
||||
special_args = {}
|
||||
|
||||
for arg in special_keywords:
|
||||
if arg in dictionary:
|
||||
special_args[arg] = dictionary[arg]
|
||||
del dictionary[arg]
|
||||
|
||||
return dictionary, special_args
|
||||
|
||||
def manipulate_results(self, results, special_args: dict):
|
||||
"""
|
||||
Wykonuje specjalne operacje na rezultatach wyszukiwania.
|
||||
|
||||
:param results: Wyniki wyszukiwania (ORM)
|
||||
:param special_args: Specjalne operacje
|
||||
:type special_args: dict
|
||||
"""
|
||||
|
||||
if "ORDER_BY" in special_args:
|
||||
column = self.str_to_column(special_args["ORDER_BY"])
|
||||
if column is not None:
|
||||
@@ -257,10 +295,7 @@ class baza():
|
||||
if "LIMIT" in special_args:
|
||||
results = results.limit(special_args["LIMIT"])
|
||||
|
||||
results_objs = results.all()
|
||||
print(f"[{round(time.time())}] SELECT RESULTS: {results_objs}")
|
||||
|
||||
return results_objs
|
||||
return results
|
||||
|
||||
@exit_gracefully
|
||||
def simple_insert_one(self, entity_type, **kwargs):
|
||||
|
||||
@@ -36,11 +36,11 @@ def getCommit() -> str | None:
|
||||
return None
|
||||
|
||||
def getCommitInFormattedHTML():
|
||||
repo = "<p>Brak informacji o wersji skryptu</p>"
|
||||
repo = "<center><p style=\"color: white;\">Brak informacji o wersji skryptu</p></center>"
|
||||
commit = getCommit()
|
||||
|
||||
if commit is not None:
|
||||
repo = f"<p>Commit: <a href='https://gitea.7o7.cx/roberteam/lewangoalski/commit/{commit}'>{commit[:11]}</a></p>"
|
||||
repo = f"<center><p style=\"color: white;\">Commit: <a href='https://gitea.7o7.cx/roberteam/lewangoalski/commit/{commit}'>{commit[:11]}</a></p></center>"
|
||||
|
||||
return repo
|
||||
|
||||
|
||||
@@ -6,33 +6,33 @@ import lewy_globals
|
||||
def get_lewy_stats():
|
||||
return {
|
||||
'all_time_stats': {
|
||||
'goals': 380,
|
||||
'assists': 120,
|
||||
'matches': 450,
|
||||
'goals': 589+78,
|
||||
'assists':154+21,
|
||||
'matches': 791+136,
|
||||
},
|
||||
'club_stats': {
|
||||
'goals': 132,
|
||||
'assists': 112,
|
||||
'matches': 245,
|
||||
'goals': 589,
|
||||
'assists': 154,
|
||||
'matches': 791,
|
||||
},
|
||||
'nation_stats': {
|
||||
'goals': 86,
|
||||
'assists': 52,
|
||||
'matches': 158,
|
||||
'goals': 78,
|
||||
'assists': 21,
|
||||
'matches': 136,
|
||||
},
|
||||
'worldcup': {
|
||||
'goals': 7,
|
||||
'assists': 2,
|
||||
'matches': 11,
|
||||
'international_cups': {
|
||||
'goals': 110,
|
||||
'assists': 19,
|
||||
'matches': 152,
|
||||
},
|
||||
'euro': {
|
||||
'goals': 6,
|
||||
'assists': 2,
|
||||
'matches': 18,
|
||||
'national_cups': {
|
||||
'goals': 58,
|
||||
'assists': 4,
|
||||
'matches': 74,
|
||||
},
|
||||
'cards': {
|
||||
'yellow': 24,
|
||||
'red': 4,
|
||||
'yellow': 86,
|
||||
'red': 2,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,9 +58,28 @@ def index():
|
||||
|
||||
def mecze():
|
||||
# Możesz dostarczyć szczegóły dotyczące meczów
|
||||
selected_date = request.args.get("date", 2024)
|
||||
matches = [
|
||||
{'date': '2024-10-12', 'opponent': 'Real Madrid', 'goals': 2, 'assists': 1, 'minutes': 90},
|
||||
{'date': '2024-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2023-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2023-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2023-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2022-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2022-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2022-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2022-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2021-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2021-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2021-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2021-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2020-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2020-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2020-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2019-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2019-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2019-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
|
||||
]
|
||||
return render_template('matches.html', matches=matches)
|
||||
|
||||
@@ -71,18 +90,24 @@ def statystyki():
|
||||
def clubs():
|
||||
selected_club = request.args.get("club","FC Barcelona")
|
||||
clubs = [
|
||||
{'club': 'FC Barcelona', 'goals': 22,'assist':12},
|
||||
{'club': 'Bayern Monachium', 'goals': 132,'assist':12},
|
||||
{'club': 'Borussia Dortmund', 'goals': 132,'assist':12},
|
||||
{'club': 'Lech Poznan', 'goals': 132,'assist':12},
|
||||
{'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': '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': '-'},
|
||||
]
|
||||
return render_template('club.html', clubs=clubs, selected_club=selected_club)
|
||||
|
||||
def representation():
|
||||
nation_stats = {
|
||||
'goals': 86,
|
||||
'assists': 52,
|
||||
'goals': 85,
|
||||
'assists': 35,
|
||||
'matches': 158,
|
||||
'minutes_played': 12108,
|
||||
'yellow_card':10,
|
||||
'red_card': 0,
|
||||
'wins':75,
|
||||
'draws': 35,
|
||||
'lost': 48
|
||||
}
|
||||
return render_template('representation.html', nation_stats=nation_stats)
|
||||
def compare():
|
||||
|
||||
@@ -33,25 +33,25 @@
|
||||
<p>Asysty:</p> <span class="stat-box-special"> {{ stats.assist }} </span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Występy:</p> <span class="stat-box-special"> {{ stats.goals }} </span>
|
||||
<p>Występy:</p> <span class="stat-box-special"> {{ stats.matches }} </span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Łączny czas gry:</p> <span class="stat-box-special"> {{ stats.goals }}</span>
|
||||
<p>Łączny czas gry:</p> <span class="stat-box-special"> {{ stats.minutes_played }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Hat-tricki:</p> <span class="stat-box-special"> {{ stats.goals }}</span>
|
||||
<p>Żółte kartki:</p> <span class="stat-box-special"> {{ stats.yellow_card }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Zwycięstwa:</p> <span class="stat-box-special"> {{ stats.goals }}</span>
|
||||
<p>Czerwone kartki:</p> <span class="stat-box-special"> {{ stats.red_card }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Porażki:</p> <span class="stat-box-special"> {{ stats.goals }}</span>
|
||||
<p>Zwycięstwa:</p> <span class="stat-box-special"> {{ stats.wins }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Żółte kartki:</p> <span class="stat-box-special"> {{ stats.goals }}</span>
|
||||
<p>Remisy:</p> <span class="stat-box-special"> {{ stats.draws }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Czerwone kartki:</p> <span class="stat-box-special"> {{ stats.goals }}</span>
|
||||
<p>Porażki:</p> <span class="stat-box-special"> {{ stats.lost }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -11,28 +11,28 @@
|
||||
<p>Gole:</p> <span class="stat-box-special"> {{ nation_stats.goals }} </span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Asysty:</p> <span class="stat-box-special"> {{ nation_stats.assist }} </span>
|
||||
<p>Asysty:</p> <span class="stat-box-special"> {{ nation_stats.assists }} </span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Występy:</p> <span class="stat-box-special"> {{ nation_stats.goals }} </span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Łączny czas gry:</p> <span class="stat-box-special"> {{ nation_stats.goals }}</span>
|
||||
<p>Łączny czas gry:</p> <span class="stat-box-special"> {{ nation_stats.minutes_played }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Hat-tricki:</p> <span class="stat-box-special"> {{ nation_stats.goals }}</span>
|
||||
<p>Żółte kartki:</p> <span class="stat-box-special"> {{ nation_stats.yellow_card }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Zwycięstwa:</p> <span class="stat-box-special"> {{ nation_stats.goals }}</span>
|
||||
<p>Czerwone kartki:</p> <span class="stat-box-special"> {{ nation_stats.red_card }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Porażki:</p> <span class="stat-box-special"> {{ nation_stats.goals }}</span>
|
||||
<p>Zwycięstwa:</p> <span class="stat-box-special"> {{ nation_stats.wins }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Żółte kartki:</p> <span class="stat-box-special"> {{ nation_stats.goals }}</span>
|
||||
<p>Remisy:</p> <span class="stat-box-special"> {{ nation_stats.draws }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Czerwone kartki:</p> <span class="stat-box-special"> {{ nation_stats.goals }}</span>
|
||||
<p>Porażki:</p> <span class="stat-box-special"> {{ nation_stats.lost }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -56,35 +56,35 @@
|
||||
</div>
|
||||
</section>
|
||||
<section class="section-stats">
|
||||
<h2>Mistrzostwa świata</h2>
|
||||
<h2>Puchary międzynarodowe</h2>
|
||||
<div class="stats">
|
||||
<div class="stat-box">
|
||||
<h3>{{ worldcup.goals }}</h3>
|
||||
<h3>{{ international_cups.goals }}</h3>
|
||||
<p>Gole</p>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<h3>{{ worldcup.assists }}</h3>
|
||||
<h3>{{ international_cups.assists }}</h3>
|
||||
<p>Asysty</p>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<h3>{{ worldcup.matches }}</h3>
|
||||
<h3>{{ international_cups.matches }}</h3>
|
||||
<p>Występy</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="section-stats">
|
||||
<h2>EURO</h2>
|
||||
<h2>Puchary krajowe</h2>
|
||||
<div class="stats">
|
||||
<div class="stat-box">
|
||||
<h3>{{ euro.goals }}</h3>
|
||||
<h3>{{ national_cups.goals }}</h3>
|
||||
<p>Gole</p>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<h3>{{ euro.assists }}</h3>
|
||||
<h3>{{ national_cups.assists }}</h3>
|
||||
<p>Asysty</p>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<h3>{{ euro.matches }}</h3>
|
||||
<h3>{{ national_cups.matches }}</h3>
|
||||
<p>Występy</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user