|
|
@@ -2,8 +2,9 @@ import redis
|
|
|
from datetime import datetime
|
|
|
|
|
|
class RedisHandler:
|
|
|
- def __init__(self, host='localhost', port=6379, db=0):
|
|
|
+ def __init__(self, host='localhost', port=6379, db=0, expire_time=60 * 60 * 24 * 30): # Keep data for 30 days
|
|
|
self.client = redis.Redis(host=host, port=port, db=db)
|
|
|
+ self.expire_time = expire_time
|
|
|
|
|
|
def save_measurement(self, cell_id, voltage, current, temperature):
|
|
|
"""Save cell measurements with timestamp"""
|
|
|
@@ -14,7 +15,7 @@ class RedisHandler:
|
|
|
'current': current,
|
|
|
'temperature': temperature
|
|
|
})
|
|
|
- self.client.expire(key, 60 * 60 * 24 * 30) # Keep data for 30 days
|
|
|
+ self.client.expire(key, self.expire_time)
|
|
|
|
|
|
def get_capacity_estimate(self, cell_id):
|
|
|
"""Calculate estimated capacity based on historical data"""
|
|
|
@@ -22,7 +23,6 @@ class RedisHandler:
|
|
|
if not measurements:
|
|
|
return None
|
|
|
|
|
|
- # Here you would implement your capacity estimation algorithm
|
|
|
+ # TODO: Put the capacity estimation algorithm
|
|
|
# based on voltage curves, current integration, etc.
|
|
|
- # This is a simplified example
|
|
|
return float(self.client.get(f"cell:{cell_id}:estimated_capacity") or 0)
|