fix
Former-commit-id: e60e29fb767ab2b7d8152eced7a50255ce6b06ad
This commit is contained in:
8
utils.py
8
utils.py
@ -11,13 +11,15 @@ from typing import List, Literal, Optional
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
stateType = Literal["transport", "middle", "about", "colored"]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class HistoryRecord:
|
class HistoryRecord:
|
||||||
"""历史记录的单个条目"""
|
"""历史记录的单个条目"""
|
||||||
|
|
||||||
timestamp: float
|
timestamp: float
|
||||||
state: Literal["transport", "middle", "about", "colored"]
|
state: stateType
|
||||||
rate: float
|
rate: float
|
||||||
volume: float
|
volume: float
|
||||||
image: np.ndarray
|
image: np.ndarray
|
||||||
@ -51,7 +53,7 @@ class History:
|
|||||||
def add_record(
|
def add_record(
|
||||||
self,
|
self,
|
||||||
timestamp: float,
|
timestamp: float,
|
||||||
state: str,
|
state: stateType,
|
||||||
rate: float,
|
rate: float,
|
||||||
volume: float,
|
volume: float,
|
||||||
image: np.ndarray,
|
image: np.ndarray,
|
||||||
@ -69,7 +71,7 @@ class History:
|
|||||||
return
|
return
|
||||||
base_records = self.get_recent_records(self._base_time, timestamp)
|
base_records = self.get_recent_records(self._base_time, timestamp)
|
||||||
self.base = sum([rec.rate for rec in base_records]) / len(base_records)
|
self.base = sum([rec.rate for rec in base_records]) / len(base_records)
|
||||||
get_endpoint_logger().info("Base rate calculated: %.2f", self.base)
|
logging.getLogger("Endpoint").info("Base rate calculated: %.2f", self.base)
|
||||||
|
|
||||||
def _cleanup_old_records(self, current_time: float):
|
def _cleanup_old_records(self, current_time: float):
|
||||||
"""清理过期的历史记录"""
|
"""清理过期的历史记录"""
|
||||||
|
Reference in New Issue
Block a user