feat: improve campus bike discovery and add independent live preview

This commit is contained in:
zzy
2026-11-04 16:42:47 +08:00
parent f986c8deae
commit b6b7b3dbe5
42 changed files with 5267 additions and 4313 deletions
+31
View File
@@ -0,0 +1,31 @@
"""Vehicle state contract shared by statistics and exports; mirrors BikeData.state."""
import math
def battery(value):
if value is None or isinstance(value, bool) or (isinstance(value, str) and not value.strip()):
return None
try:
n = float(value)
except (TypeError, ValueError):
return None
return n if math.isfinite(n) and 0 <= n <= 100 else None
def classify(state, status, electric):
try:
state, status = int(state), int(status)
except (TypeError, ValueError):
return "unknown"
electric = battery(electric)
if state == 1 and status == 1:
return "used"
if state == 4:
return "locked"
if state == 2:
return "reserved"
if state == 10 or (electric is not None and electric < 20):
return "low"
if state == 1 and status == 0:
return "available"
return "unknown"