@mxpicture/tesla-superchargers-mate 0.1.59 → 0.1.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/db/schema.sql +50 -26
- package/package.json +2 -2
- package/sql/views.sql +12 -0
package/db/schema.sql
CHANGED
|
@@ -18,8 +18,6 @@ CREATE TYPE public.pic_ref_type AS ENUM ('drive', 'charge', 'idle');
|
|
|
18
18
|
--
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
-- Dumped from database version 18.4 (Debian 18.4-1.pgdg13+1)
|
|
22
|
-
-- Dumped by pg_dump version 18.4
|
|
23
21
|
|
|
24
22
|
SET statement_timeout = 0;
|
|
25
23
|
SET lock_timeout = 0;
|
|
@@ -1004,10 +1002,19 @@ DECLARE
|
|
|
1004
1002
|
-- pic_energy_ledger_v's cfg used the same constant for a car that had never
|
|
1005
1003
|
-- charged.
|
|
1006
1004
|
_base_price CONSTANT NUMERIC := 0.40;
|
|
1007
|
-
-- Rated range
|
|
1008
|
-
--
|
|
1009
|
-
--
|
|
1010
|
-
--
|
|
1005
|
+
-- Rated range rebounds a little after a drive. An idle gain below this is
|
|
1006
|
+
-- that artefact; a gain above it is energy that really arrived and TeslaMate
|
|
1007
|
+
-- never logged. Same threshold the retired pic_energy_ledger_v used for its
|
|
1008
|
+
-- rebound_km.
|
|
1009
|
+
--
|
|
1010
|
+
-- The +16.72 km within 1.3 min this constant was once justified by was NOT a
|
|
1011
|
+
-- rebound: it was cp 18's pre-charge gap, which pic_refs_prep_v now adopts
|
|
1012
|
+
-- into the charge, and measuring the rest of production put the true
|
|
1013
|
+
-- post-drive rebound at 1.29 km or less. So the threshold is uncalibrated
|
|
1014
|
+
-- between roughly 1.3 km and 20 km -- production holds no observation in
|
|
1015
|
+
-- that band. It still earns its keep at the top of the range, where it
|
|
1016
|
+
-- catches the 218.76 km home session TeslaMate slept through, and lowering
|
|
1017
|
+
-- it would only start guessing in the empty middle.
|
|
1011
1018
|
_rebound_km CONSTANT NUMERIC := 20.0;
|
|
1012
1019
|
BEGIN
|
|
1013
1020
|
-- Same lock as pic_build_refs_car: this procedure rewrites cost and
|
|
@@ -1624,8 +1631,6 @@ $function$
|
|
|
1624
1631
|
--
|
|
1625
1632
|
|
|
1626
1633
|
|
|
1627
|
-
-- Dumped from database version 18.4 (Debian 18.4-1.pgdg13+1)
|
|
1628
|
-
-- Dumped by pg_dump version 18.4
|
|
1629
1634
|
|
|
1630
1635
|
SET statement_timeout = 0;
|
|
1631
1636
|
SET lock_timeout = 0;
|
|
@@ -2547,29 +2552,38 @@ CREATE VIEW public.pic_refs_prep_v AS
|
|
|
2547
2552
|
chain.next_id,
|
|
2548
2553
|
chain.end_date,
|
|
2549
2554
|
chain.end_range_km,
|
|
2550
|
-
chain.sec_to_next
|
|
2555
|
+
chain.sec_to_next,
|
|
2556
|
+
((chain.next_type = 'charge'::public.pic_ref_type) AND (chain.end_range_km > chain.start_range_km) AND (chain.sec_to_next <= (600)::numeric)) AS adopted
|
|
2551
2557
|
FROM chain
|
|
2552
|
-
WHERE (chain.sec_to_next > (
|
|
2558
|
+
WHERE (chain.sec_to_next > (0)::numeric)
|
|
2559
|
+
), adoption AS (
|
|
2560
|
+
SELECT idle.car_id,
|
|
2561
|
+
idle.next_id,
|
|
2562
|
+
idle.start_date,
|
|
2563
|
+
idle.start_range_km
|
|
2564
|
+
FROM idle
|
|
2565
|
+
WHERE idle.adopted
|
|
2553
2566
|
), collection AS (
|
|
2554
|
-
SELECT
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2567
|
+
SELECT b.t AS ref_type,
|
|
2568
|
+
b.id AS ref_id,
|
|
2569
|
+
b.car_id,
|
|
2570
|
+
COALESCE(a.start_date, b.start_date) AS start_date,
|
|
2571
|
+
b.end_date,
|
|
2572
|
+
COALESCE(a.start_range_km, b.start_range_km) AS start_range_km,
|
|
2573
|
+
b.end_range_km,
|
|
2561
2574
|
NULL::public.pic_ref_type AS prev_type,
|
|
2562
2575
|
NULL::integer AS prev_id,
|
|
2563
2576
|
NULL::public.pic_ref_type AS next_type,
|
|
2564
2577
|
NULL::integer AS next_id,
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
FROM public.pic_refs_base_v
|
|
2578
|
+
b.start_position_id,
|
|
2579
|
+
b.end_position_id,
|
|
2580
|
+
b.start_address_id,
|
|
2581
|
+
b.end_address_id,
|
|
2582
|
+
b.start_geofence_id,
|
|
2583
|
+
b.end_geofence_id,
|
|
2584
|
+
b.real_km
|
|
2585
|
+
FROM (public.pic_refs_base_v b
|
|
2586
|
+
LEFT JOIN adoption a ON (((a.car_id = b.car_id) AND (a.next_id = b.id) AND (b.t = 'charge'::public.pic_ref_type))))
|
|
2573
2587
|
UNION ALL
|
|
2574
2588
|
SELECT 'idle'::public.pic_ref_type AS ref_type,
|
|
2575
2589
|
NULL::integer AS ref_id,
|
|
@@ -2590,6 +2604,7 @@ CREATE VIEW public.pic_refs_prep_v AS
|
|
|
2590
2604
|
idle.at_geofence_id AS end_geofence_id,
|
|
2591
2605
|
NULL::numeric AS real_km
|
|
2592
2606
|
FROM idle
|
|
2607
|
+
WHERE ((NOT idle.adopted) AND (idle.sec_to_next > (60)::numeric))
|
|
2593
2608
|
)
|
|
2594
2609
|
SELECT c.ref_type,
|
|
2595
2610
|
c.ref_id,
|
|
@@ -2649,6 +2664,14 @@ CREATE VIEW public.pic_refs_v AS
|
|
|
2649
2664
|
r.kwh_per_real_1km,
|
|
2650
2665
|
r.cost_per_real_100km,
|
|
2651
2666
|
r.cost_per_kwh,
|
|
2667
|
+
(r.cost + COALESCE(i.cost, 0.0)) AS gross_cost,
|
|
2668
|
+
(r.hours + COALESCE(i.hours, 0.0)) AS gross_hours,
|
|
2669
|
+
(r.mean_draw_kw + COALESCE(i.mean_draw_kw, 0.0)) AS gross_mean_draw_kw,
|
|
2670
|
+
(r.dropped_km + COALESCE(i.dropped_km, 0.0)) AS gross_dropped_km,
|
|
2671
|
+
(r.dropped_kwh + COALESCE(i.dropped_kwh, 0.0)) AS gross_dropped_kwh,
|
|
2672
|
+
(r.kwh_per_real_1km + COALESCE(i.kwh_per_real_1km, 0.0)) AS gross_kwh_per_real_1km,
|
|
2673
|
+
(r.cost_per_real_100km + COALESCE(i.cost_per_real_100km, 0.0)) AS gross_cost_per_real_100km,
|
|
2674
|
+
(r.cost_per_kwh + COALESCE(i.cost_per_kwh, 0.0)) AS gross_cost_per_kwh,
|
|
2652
2675
|
sm.seed_address_id AS start_seed_address_id,
|
|
2653
2676
|
em.seed_address_id AS end_seed_address_id,
|
|
2654
2677
|
sm.cluster_id AS start_cluster_id,
|
|
@@ -2669,7 +2692,8 @@ CREATE VIEW public.pic_refs_v AS
|
|
|
2669
2692
|
END AS end_address_type,
|
|
2670
2693
|
COALESCE(sg.name, (sa.address)::character varying, (sa_fallback.address)::character varying) AS start_address,
|
|
2671
2694
|
COALESCE(eg.name, (ea.address)::character varying, (ea_fallback.address)::character varying) AS end_address
|
|
2672
|
-
FROM ((((((((public.pic_refs r
|
|
2695
|
+
FROM (((((((((public.pic_refs r
|
|
2696
|
+
LEFT JOIN public.pic_refs i ON (((i.ref_type = 'idle'::public.pic_ref_type) AND (r.ref_type = 'drive'::public.pic_ref_type) AND (i.next_type = r.ref_type) AND (i.next_id = r.ref_id))))
|
|
2673
2697
|
LEFT JOIN public.pic_cluster_map_v sm ON ((sm.address_id = r.start_address_id)))
|
|
2674
2698
|
LEFT JOIN public.pic_cluster_map_v em ON ((em.address_id = r.end_address_id)))
|
|
2675
2699
|
LEFT JOIN public.pic_addresses_v sa ON ((sa.id = sm.seed_address_id)))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mxpicture/tesla-superchargers-mate",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.60",
|
|
4
4
|
"description": "TeslaMate integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "MXPicture",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@mxpicture/tesla-superchargers-generated": "^0.1.
|
|
53
|
+
"@mxpicture/tesla-superchargers-generated": "^0.1.60",
|
|
54
54
|
"dbmate": "2.35.1",
|
|
55
55
|
"postgres": "^3.4.9",
|
|
56
56
|
"short-uuid": "^6.0.3",
|
package/sql/views.sql
CHANGED
|
@@ -1036,6 +1036,14 @@ FROM
|
|
|
1036
1036
|
CREATE OR REPLACE VIEW pic_refs_v AS
|
|
1037
1037
|
SELECT
|
|
1038
1038
|
r.*,
|
|
1039
|
+
r.cost + COALESCE(i.cost, 0.0) AS gross_cost,
|
|
1040
|
+
r.hours + COALESCE(i.hours, 0.0) AS gross_hours,
|
|
1041
|
+
r.mean_draw_kw + COALESCE(i.mean_draw_kw, 0.0) AS gross_mean_draw_kw,
|
|
1042
|
+
r.dropped_km + COALESCE(i.dropped_km, 0.0) AS gross_dropped_km,
|
|
1043
|
+
r.dropped_kwh + COALESCE(i.dropped_kwh, 0.0) AS gross_dropped_kwh,
|
|
1044
|
+
r.kwh_per_real_1km + COALESCE(i.kwh_per_real_1km, 0.0) AS gross_kwh_per_real_1km,
|
|
1045
|
+
r.cost_per_real_100km + COALESCE(i.cost_per_real_100km, 0.0) AS gross_cost_per_real_100km,
|
|
1046
|
+
r.cost_per_kwh + COALESCE(i.cost_per_kwh, 0.0) AS gross_cost_per_kwh,
|
|
1039
1047
|
sm.seed_address_id AS start_seed_address_id,
|
|
1040
1048
|
em.seed_address_id AS end_seed_address_id,
|
|
1041
1049
|
sm.cluster_id AS start_cluster_id,
|
|
@@ -1058,6 +1066,10 @@ SELECT
|
|
|
1058
1066
|
COALESCE(eg.name, ea.address, ea_fallback.address) AS end_address
|
|
1059
1067
|
FROM
|
|
1060
1068
|
pic_refs r
|
|
1069
|
+
LEFT JOIN pic_refs i ON i.ref_type = 'idle'::pic_ref_type
|
|
1070
|
+
AND r.ref_type = 'drive'::pic_ref_type
|
|
1071
|
+
AND i.next_type = r.ref_type
|
|
1072
|
+
AND i.next_id = r.ref_id
|
|
1061
1073
|
LEFT JOIN pic_cluster_map_v sm ON sm.address_id = r.start_address_id
|
|
1062
1074
|
LEFT JOIN pic_cluster_map_v em ON em.address_id = r.end_address_id
|
|
1063
1075
|
LEFT JOIN pic_addresses_v sa ON sa.id = sm.seed_address_id
|