I have a model Service to save data from ping probes, so i ping at the IP address, i must enter the result value in a list "history" of 30 values, delete the oldest value in that list and calculate the average to save the list and the average in the database.
class Service(peewee.Model):
identifier = peewee.CharField(max_length=30, primary_key=True)
ip = peewee.CharField(max_length=15)
latency = peewee.CharField(max_length=10)
history = peewee.CharField(max_length=1000)
device = peewee.ForeignKeyField(Core, on_delete='CASCADE')
I could create the functions to calculate and average, do the round robin and then save the results to the database, or I could try to serialize the model in a dataclass and implement the necessary functions. Which would be the best option? what would be the best practice?.
To keep in mind, I must iterate this procedure in several services.