| 12345678910111213141516171819202122232425262728 |
- import redis
- from datetime import datetime
- class RedisHandler:
- 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"""
- timestamp = datetime.now().isoformat()
- key = f"cell:{cell_id}:measurements:{timestamp}"
- self.client.hmset(key, {
- 'voltage': voltage,
- 'current': current,
- 'temperature': temperature
- })
- self.client.expire(key, self.expire_time)
- def get_capacity_estimate(self, cell_id):
- """Calculate estimated capacity based on historical data"""
- measurements = self.client.keys(f"cell:{cell_id}:measurements:*")
- if not measurements:
- return None
-
- # TODO: Put the capacity estimation algorithm
- # based on voltage curves, current integration, etc.
- return float(self.client.get(f"cell:{cell_id}:estimated_capacity") or 0)
|