# app/models/statistics.py
class Statistics:
def __init__(self):
self.energy = 100 # 100 is full, 0 is exhausted
self.hunger = 100 # 100 is full, 0 is starving
self.intelligence = 50
self.strength = 50
self.mental_health = 70 # 100 is optimal, 0 is critical
self.physical_health = 70 # 100 is optimal, 0 is critical
self.social_skills = 50
self.job_performance = 50
def update_stat(self, stat_name, value):
if hasattr(self, stat_name):
new_value = getattr(self, stat_name) + value
setattr(self, stat_name, max(0, min(new_value, 100))) # Keeps stats within 0 to 100 range
else:
raise ValueError(f"Statistic '{stat_name}' does not exist.")
def __repr__get_json(self):
return self.__dict__
def __repr__(f"Energyself):
{ return str(self.energy},get_json())
Alguien podria decirme que puedo hacer en el método get_json de person para poder retornar un Json interno de todo lo que hay en statistics.py
El problema consiste en que viene por parte de una respuesta de una API: Este es el link del controlador:
https://github.com/felipedelosh/API-LifeInstructions/blob/main/app/controllers/player_controller.py
Lo que estoy tratando de hacer es imprimir el player que es un hijo de Persona:
# Hungerapp/models/player.py
from app.models.person import Person
class Player(Person):
{ def __init__(self.hunger}, Intelligenceid):
{ super().__init__(id)
self.intelligence},_father "= None
self._mother = None
@property
f"Strengthdef father(self):
{ return self.strength},_father
Mental Health @father.setter
def father(self, value):
{ self.mental_health},_father Physical= Healthvalue
@property
def mother(self):
{ return self.physical_health},_mother
" @mother.setter
def mother(self, value):
self._mother = value
f"Socialdef Skillsget_json(self):
{ return self.social_skills},__dict__
Job Performance def __repr__(self):
attributes = ', '.join(f'{key}={value}' for key, value in self.job_performance__dict__.items())
return f'Player({attributes}")'
Alguien podria decirme que puedo hacer en el método get_json de person para poder retornar un Json interno de todo lo que hay en statistics.py