feat: implement billing, usage tracking, and administrative geocoding features in API with infrastructure updates
This commit is contained in:
+41
-8
@@ -270,17 +270,50 @@ let TelemetryAnalyzerService = TelemetryAnalyzerService_1 = class TelemetryAnaly
|
||||
FROM cluster_stats s
|
||||
JOIN cluster_path p ON s.cid = p.cid
|
||||
GROUP BY s.cid, s.drv_count, s.pt_count, s.avg_spd
|
||||
),
|
||||
oneway_detect AS (
|
||||
-- 4. Detect one-way direction from telemetry heading data
|
||||
SELECT
|
||||
fc.cid,
|
||||
DEGREES(ST_Azimuth(
|
||||
ST_StartPoint(fc.geom::geometry),
|
||||
ST_EndPoint(fc.geom::geometry)
|
||||
)) AS geom_bearing,
|
||||
AVG(tl.heading) AS avg_heading,
|
||||
COUNT(*) AS heading_samples
|
||||
FROM final_candidates fc
|
||||
JOIN telemetry_logs tl ON ST_DWithin(
|
||||
tl.location::geometry,
|
||||
fc.geom::geometry,
|
||||
30
|
||||
)
|
||||
WHERE tl.speed > 3
|
||||
GROUP BY fc.cid, fc.geom
|
||||
HAVING COUNT(*) >= 5
|
||||
),
|
||||
oneway_scored AS (
|
||||
SELECT
|
||||
od.cid,
|
||||
CASE
|
||||
WHEN LEAST(ABS(od.avg_heading - od.geom_bearing), 360 - ABS(od.avg_heading - od.geom_bearing)) < 45
|
||||
AND od.heading_samples >= 10 THEN 1
|
||||
WHEN LEAST(ABS(od.avg_heading - (od.geom_bearing + 180) % 360), 360 - ABS(od.avg_heading - (od.geom_bearing + 180) % 360)) < 45
|
||||
AND od.heading_samples >= 10 THEN -1
|
||||
ELSE 0
|
||||
END AS oneway_val
|
||||
FROM oneway_detect od
|
||||
)
|
||||
INSERT INTO candidate_roads (geometry, "uniqueDriverCount", "totalPoints", "averageSpeed", "lengthMeters", confidence, status)
|
||||
SELECT geom, drv_count, pt_count, avg_spd, len,
|
||||
-- SQL port of calculateConfidence logic
|
||||
INSERT INTO candidate_roads (geometry, "uniqueDriverCount", "totalPoints", "averageSpeed", "lengthMeters", confidence, status, oneway)
|
||||
SELECT fc.geom, fc.drv_count, fc.pt_count, fc.avg_spd, fc.len,
|
||||
ROUND((
|
||||
LEAST(drv_count::float / 5, 1.0) * 0.4 +
|
||||
LEAST(pt_count::float / 50, 1.0) * 0.3 +
|
||||
CASE WHEN len BETWEEN 50 AND 2000 THEN 0.3 ELSE 0.1 END
|
||||
LEAST(fc.drv_count::float / 5, 1.0) * 0.4 +
|
||||
LEAST(fc.pt_count::float / 50, 1.0) * 0.3 +
|
||||
CASE WHEN fc.len BETWEEN 50 AND 2000 THEN 0.3 ELSE 0.1 END
|
||||
)::numeric, 2) as conf,
|
||||
'pending'
|
||||
FROM final_candidates
|
||||
'pending',
|
||||
COALESCE(os.oneway_val, 0)
|
||||
FROM final_candidates fc
|
||||
LEFT JOIN oneway_scored os ON os.cid = fc.cid
|
||||
RETURNING id;
|
||||
`;
|
||||
const result = await this.dataSource.query(query);
|
||||
|
||||
Reference in New Issue
Block a user