mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
feat(bikeshare): render GBFS stations on Navara
This commit is contained in:
1 parent
1a694baf5a
commit
d82a6f1550
32 files changed
+1394
-278
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import {
|
||||
DEFAULT_CAPACITY,
|
||||
POINT_SIZE_MIN,
|
||||
POINT_SIZE_MAX,
|
||||
COLOR_NEUTRAL,
|
||||
COLOR_MUTED,
|
||||
COLOR_GREEN,
|
||||
COLOR_YELLOW,
|
||||
COLOR_RED,
|
||||
} from './policy.js';
|
||||
|
||||
export function resolveCapacity(model, capacityFromInfo, status) {
|
||||
const fromInfo = model.toNonNegativeInteger(capacityFromInfo);
|
||||
if (fromInfo && fromInfo > 0) return fromInfo;
|
||||
const bikes = model.toNonNegativeInteger(status?.bikesAvailable, 0);
|
||||
const docks = model.toNonNegativeInteger(status?.docksAvailable, 0);
|
||||
return bikes + docks || DEFAULT_CAPACITY;
|
||||
}
|
||||
|
||||
export function capacityToPixelSize(capacity) {
|
||||
const value = Math.max(1, Math.min(80, Number(capacity) || DEFAULT_CAPACITY));
|
||||
const normalized = Math.sqrt(value) / Math.sqrt(80);
|
||||
const size = POINT_SIZE_MIN + normalized * (POINT_SIZE_MAX - POINT_SIZE_MIN);
|
||||
return Math.max(POINT_SIZE_MIN, Math.min(POINT_SIZE_MAX, size));
|
||||
}
|
||||
|
||||
export function statusToColor(model, status, capacity) {
|
||||
if (!status) return COLOR_NEUTRAL;
|
||||
if (!status.isInstalled || !status.isRenting || !status.isReturning)
|
||||
return COLOR_MUTED;
|
||||
const bikes = model.toNonNegativeInteger(status.bikesAvailable);
|
||||
if (!Number.isFinite(bikes)) return COLOR_NEUTRAL;
|
||||
const resolvedCapacity = Math.max(1, Number(capacity) || DEFAULT_CAPACITY);
|
||||
const ratio = bikes / resolvedCapacity;
|
||||
if (ratio > 0.6) return COLOR_GREEN;
|
||||
if (ratio >= 0.3) return COLOR_YELLOW;
|
||||
return COLOR_RED;
|
||||
}
|
||||
Reference in new issue
Block a user