@bytebrand/export-cars 1.26.24 → 1.26.25
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/package.json
CHANGED
|
@@ -51,41 +51,51 @@ export function googleElectricRange(car: DataSchemes.Car): string | undefined {
|
|
|
51
51
|
// electricity and CO2, and the fuel consumption with a DISCHARGED battery separately. In CBD those
|
|
52
52
|
// are wltpWeightedCombined, wltpWeightedPowerCombined, wltpCo2 (weighted for a plug-in) and
|
|
53
53
|
// wltpCombined (discharged for a plug-in); the legacy consumptionCombined / co2 are only a fallback.
|
|
54
|
+
//
|
|
55
|
+
// engineData.hybridPlugin alone does not prove a plug-in: since ADV-124 every hybrid carries it, and
|
|
56
|
+
// the weighted fields of hybrids without an electric range are enrichment-sheet templates
|
|
57
|
+
// (prod 07.10: 4,178 of 5,576 flagged cars, e.g. 2.3 l + 21.5 kWh + 195 g). Only a hybrid with an
|
|
58
|
+
// electric range counts as a confirmed plug-in; the others keep the values sent before.
|
|
59
|
+
const isConfirmedPlugIn = (car: DataSchemes.Car): boolean => isPlugIn(car) && !!googleElectricRange(car);
|
|
54
60
|
|
|
55
61
|
// Missing or 0 is omitted instead of sending "0l/100km". BEVs carry no fuel consumption
|
|
56
62
|
// (CBD mirrors kWh into consumptionCombined for them).
|
|
57
63
|
export function googleFuelConsumption(car: DataSchemes.Car): string | undefined {
|
|
58
64
|
if (isBev(car)) return undefined;
|
|
59
|
-
const value =
|
|
65
|
+
const value = isConfirmedPlugIn(car)
|
|
60
66
|
? positive(get(car, 'consumption.wltpWeightedCombined')) ?? positive(get(car, 'consumption.consumptionCombined'))
|
|
61
67
|
: positive(get(car, 'consumption.consumptionCombined'));
|
|
62
68
|
return value ? `${value}l/100km` : undefined;
|
|
63
69
|
}
|
|
64
70
|
|
|
65
|
-
//
|
|
66
|
-
// here would repeat the weighted figure
|
|
71
|
+
// Confirmed plug-in: wltpCombined, no fallback (the legacy combined value is close to the weighted
|
|
72
|
+
// one, sending it here would repeat the weighted figure). Unconfirmed plug-in: the stored combined
|
|
73
|
+
// value, as before.
|
|
67
74
|
export function googleFuelConsumptionDischarged(car: DataSchemes.Car): string | undefined {
|
|
68
75
|
if (!isPlugIn(car)) return undefined;
|
|
69
|
-
const value =
|
|
76
|
+
const value = isConfirmedPlugIn(car)
|
|
77
|
+
? positive(get(car, 'consumption.wltpCombined'))
|
|
78
|
+
: positive(get(car, 'consumption.consumptionCombined')) ?? positive(get(car, 'consumption.wltpCombined'));
|
|
70
79
|
return value ? `${value}l/100km` : undefined;
|
|
71
80
|
}
|
|
72
81
|
|
|
73
|
-
// BEV: combined consumption.
|
|
82
|
+
// BEV: combined consumption. Confirmed plug-in: weighted combined. Unconfirmed plug-in: the stored
|
|
83
|
+
// electric value, as before. Nothing for other cars.
|
|
74
84
|
export function googleEnergyConsumption(car: DataSchemes.Car): string | undefined {
|
|
75
85
|
let value: number | undefined;
|
|
76
|
-
if (
|
|
77
|
-
value = positive(get(car, 'consumption.wltpPowerCombined')) ?? positive(get(car, 'consumption.consumptionPowerCombined'));
|
|
78
|
-
} else if (isPlugIn(car)) {
|
|
86
|
+
if (isConfirmedPlugIn(car)) {
|
|
79
87
|
value = positive(get(car, 'consumption.wltpWeightedPowerCombined'));
|
|
88
|
+
} else if (isBev(car) || isPlugIn(car)) {
|
|
89
|
+
value = positive(get(car, 'consumption.wltpPowerCombined')) ?? positive(get(car, 'consumption.consumptionPowerCombined'));
|
|
80
90
|
}
|
|
81
91
|
return value ? `${value}kWh/100km` : undefined;
|
|
82
92
|
}
|
|
83
93
|
|
|
84
|
-
// A BEV emits 0 g/km by definition; a plug-in sends the weighted WLTP CO2;
|
|
85
|
-
// stored value. A missing or 0 value is omitted.
|
|
94
|
+
// A BEV emits 0 g/km by definition; a confirmed plug-in sends the weighted WLTP CO2; every other car
|
|
95
|
+
// the stored value. A missing or 0 value is omitted.
|
|
86
96
|
export function googleCo2(car: DataSchemes.Car): string | undefined {
|
|
87
97
|
if (isBev(car)) return '0g/km';
|
|
88
|
-
const value =
|
|
98
|
+
const value = isConfirmedPlugIn(car)
|
|
89
99
|
? positive(get(car, 'environmentEmissions.wltpCo2')) ?? positive(get(car, 'environmentEmissions.co2'))
|
|
90
100
|
: positive(get(car, 'environmentEmissions.co2'));
|
|
91
101
|
return value ? `${value}g/km` : undefined;
|
|
@@ -66,6 +66,7 @@ const cases: Array<[string, () => void]> = [
|
|
|
66
66
|
['plug-in: weighted fuel, discharged fuel, weighted electricity and weighted CO2', () => {
|
|
67
67
|
const phev = car('selector_fuel_hybridElectricalPetrol', {
|
|
68
68
|
hybridPlugin: true,
|
|
69
|
+
battery: { wltpTotalRange: 62 },
|
|
69
70
|
consumption: { consumptionCombined: 1.4, wltpCombined: 6.3, wltpWeightedCombined: 1.2, wltpPowerCombined: 19.3, wltpWeightedPowerCombined: 17.3 },
|
|
70
71
|
environmentEmissions: { co2: 121, wltpCo2: 28 },
|
|
71
72
|
});
|
|
@@ -77,6 +78,7 @@ const cases: Array<[string, () => void]> = [
|
|
|
77
78
|
['plug-in without weighted values falls back to the legacy combined ones, never the pure-electric value', () => {
|
|
78
79
|
const phev = car('selector_fuel_hybridElectricalPetrol', {
|
|
79
80
|
hybridPlugin: true,
|
|
81
|
+
battery: { wltpRange: 59 },
|
|
80
82
|
consumption: { consumptionCombined: 1.4, wltpPowerCombined: 19.3 },
|
|
81
83
|
environmentEmissions: { co2: 32 },
|
|
82
84
|
});
|
|
@@ -95,6 +97,17 @@ const cases: Array<[string, () => void]> = [
|
|
|
95
97
|
assert.equal(googleEnergyConsumption(hev), undefined);
|
|
96
98
|
assert.equal(googleCo2(hev), '116g/km');
|
|
97
99
|
}],
|
|
100
|
+
['a plug-in flag without an electric range keeps the stored values (ADV-124 flags every hybrid)', () => {
|
|
101
|
+
const flagged = car('selector_fuel_hybridElectricalPetrol', {
|
|
102
|
+
hybridPlugin: true,
|
|
103
|
+
consumption: { consumptionCombined: 5.1, wltpCombined: 5.3, wltpWeightedCombined: 2.3, wltpPowerCombined: 21.5, wltpWeightedPowerCombined: 21.5 },
|
|
104
|
+
environmentEmissions: { co2: 116, wltpCo2: 116, wltpCo2Discharged: 195 },
|
|
105
|
+
});
|
|
106
|
+
assert.equal(googleFuelConsumption(flagged), '5.1l/100km');
|
|
107
|
+
assert.equal(googleFuelConsumptionDischarged(flagged), '5.1l/100km');
|
|
108
|
+
assert.equal(googleEnergyConsumption(flagged), '21.5kWh/100km');
|
|
109
|
+
assert.equal(googleCo2(flagged), '116g/km');
|
|
110
|
+
}],
|
|
98
111
|
['BEV energy consumption is the combined value', () => {
|
|
99
112
|
assert.equal(googleEnergyConsumption(car('selector_fuel_electrical', { consumption: { wltpPowerCombined: 16.5 } })), '16.5kWh/100km');
|
|
100
113
|
assert.equal(googleEnergyConsumption(car('selector_fuel_electrical', { consumption: { consumptionPowerCombined: 18 } })), '18kWh/100km');
|