Updating matches
Updating players stats(not finished) Not tested
This commit is contained in:
@@ -307,6 +307,72 @@ class baza():
|
||||
return 0
|
||||
#return 1
|
||||
|
||||
@exit_gracefully
|
||||
def increment_fields(self, entity_type, record_id, **increments):
|
||||
"""
|
||||
Dodaje wartości do istniejących pól (np. goli_sum += 2).
|
||||
|
||||
Użycie:
|
||||
increment_fields(ldb.statystyki_sportowcow, 123, goli_sum=2, asyst_sum=1)
|
||||
"""
|
||||
if not isinstance(entity_type, str):
|
||||
entity_type = entity_type.__name__
|
||||
|
||||
if entity_type not in self.entities:
|
||||
print(f"Nieznany typ encji: {entity_type}")
|
||||
return -1
|
||||
|
||||
model_class = self.entities[entity_type]
|
||||
|
||||
print(f"[{round(time.time())}] INCREMENT")
|
||||
|
||||
record = self.session.get(model_class, record_id)
|
||||
if not record:
|
||||
print(f"Rekord z ID {record_id} nie istnieje w tabeli {entity_type}")
|
||||
return -1
|
||||
|
||||
for key, increment_value in increments.items():
|
||||
if hasattr(record, key):
|
||||
current_value = getattr(record, key, 0)
|
||||
setattr(record, key, current_value + increment_value)
|
||||
else:
|
||||
print(f"⚠️ Pole '{key}' nie istnieje w modelu '{entity_type}' – pomijam.")
|
||||
|
||||
self.session.commit()
|
||||
return 0
|
||||
@exit_gracefully
|
||||
def simple_update_one(self, entity_type, record_id, **kwargs):
|
||||
"""
|
||||
Użycie:
|
||||
simple_update_one(ldb.kluby, "polska", pelna_nazwa="Nowa Nazwa", skrocona_nazwa="NN")
|
||||
|
||||
Aktualizuje pojedynczy rekord w bazie danych na podstawie ID.
|
||||
"""
|
||||
if not isinstance(entity_type, str):
|
||||
entity_type = entity_type.__name__
|
||||
|
||||
if entity_type not in self.entities:
|
||||
print(f"Nieznany typ encji: {entity_type}")
|
||||
return -1
|
||||
|
||||
model_class = self.entities[entity_type]
|
||||
|
||||
print(f"[{round(time.time())}] UPDATE")
|
||||
|
||||
record = self.session.get(model_class, record_id)
|
||||
if not record:
|
||||
print(f"Rekord z ID {record_id} nie istnieje w tabeli {entity_type}")
|
||||
return -1
|
||||
|
||||
for key, value in kwargs.items():
|
||||
if hasattr(record, key):
|
||||
setattr(record, key, value)
|
||||
else:
|
||||
print(f"⚠️ Pole '{key}' nie istnieje w modelu '{entity_type}' – pomijam.")
|
||||
|
||||
self.session.commit()
|
||||
return 0
|
||||
|
||||
@exit_gracefully
|
||||
def sample_data_init(self, override_safety_check=False):
|
||||
"""
|
||||
@@ -388,4 +454,5 @@ class baza():
|
||||
|
||||
session.commit()
|
||||
return 0
|
||||
return 1
|
||||
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user