@bytebrand/export-cars 1.26.27 → 1.26.28

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.
Files changed (32) hide show
  1. package/README.md +28 -0
  2. package/dist/configs/config.d.ts +2 -1
  3. package/dist/configs/config.js +1 -0
  4. package/dist/configs/config.js.map +1 -1
  5. package/dist/configs/google.config.js +16 -0
  6. package/dist/configs/google.config.js.map +1 -1
  7. package/dist/exporters/google.exporter.js +12 -2
  8. package/dist/exporters/google.exporter.js.map +1 -1
  9. package/dist/interfaces/params.interface.d.ts +10 -0
  10. package/dist/services/publication-gate.d.ts +15 -0
  11. package/dist/services/publication-gate.js +107 -0
  12. package/dist/services/publication-gate.js.map +1 -0
  13. package/dist/transformers/google-feed-envkv.d.ts +2 -0
  14. package/dist/transformers/google-feed-envkv.js +62 -31
  15. package/dist/transformers/google-feed-envkv.js.map +1 -1
  16. package/dist/transformers/google-feed-item-row.d.ts +6 -1
  17. package/dist/transformers/google-feed-item-row.js +3 -1
  18. package/dist/transformers/google-feed-item-row.js.map +1 -1
  19. package/dist/tsconfig.build.tsbuildinfo +1 -1
  20. package/package.json +2 -2
  21. package/schema/feed-items.json +12 -0
  22. package/src/configs/config.ts +3 -1
  23. package/src/configs/google.config.ts +41 -26
  24. package/src/export.command.ts +38 -38
  25. package/src/exporters/google.exporter.ts +67 -56
  26. package/src/interfaces/params.interface.ts +43 -29
  27. package/src/services/feed-items-bigquery.writer.ts +101 -101
  28. package/src/services/publication-gate.ts +119 -0
  29. package/src/transformers/google-feed-envkv.ts +81 -33
  30. package/src/transformers/google-feed-item-row.ts +78 -71
  31. package/test/google-feed-item-row.test.ts +135 -121
  32. package/test/publication-gate.test.ts +86 -0
package/README.md CHANGED
@@ -45,6 +45,34 @@ bq mk --table \
45
45
  schema/feed-items.json
46
46
  ```
47
47
 
48
+ Tables created before 1.26.28 need the two gate columns: `bq update <table> schema/feed-items.json`.
49
+
50
+ ## Publication gate for estimated EnVKV values (EnVKV C8)
51
+
52
+ car-basic-data fills missing or implausible consumption / CO2 values from the CO2 estimator, the
53
+ make-model template sheet or global defaults, and logs each such change to its enrichment log in
54
+ BigQuery. The car itself does not say which of its values are estimates, so the Google export reads
55
+ the log: a field counts as estimated when its latest log row has `finalValueSource` `co2-estimate`,
56
+ `mmm` or `globalDefault` and that row's final value is still the value stored on the car.
57
+
58
+ | Param | Example |
59
+ |----------------------------|----------------------------|
60
+ | `publicationGate` | `off` (default) / `audit` / `enforce` |
61
+ | `publicationGateBqProject` | `auto-de-not-production` |
62
+ | `publicationGateBqDataset` | `develop_auto_de` |
63
+ | `publicationGateBqTable` | `develop_cbd_enrichment_log` |
64
+
65
+ - `audit`: the feed is unchanged; the estimated attributes of each item go to the feed items table
66
+ (`estimatedAttributes`, with `publicationGate`). If the log cannot be read the gate is off for the run.
67
+ - `enforce`: estimated `fuel_consumption`, `fuel_consumption_discharged_battery`,
68
+ `energy_consumption`, `co2_emissions` (and `electric_range`, which CBD never estimates) are left out
69
+ of the item. If the log cannot be read the export fails before the output is touched, so the last
70
+ published feed stays.
71
+
72
+ Only the field an attribute was actually taken from counts (e.g. `wltpCombined` for an ICE car, the
73
+ legacy `consumptionCombined` only when it was the fallback). Values set before the enrichment log
74
+ existed are not covered.
75
+
48
76
  ## Description
49
77
 
50
78
  [Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
@@ -1,5 +1,5 @@
1
1
  import { ExportType, ImageType } from '../enums';
2
- import { FeedItemsBigQueryTarget, Params } from '../interfaces/params.interface';
2
+ import { FeedItemsBigQueryTarget, Params, PublicationGateConfig } from '../interfaces/params.interface';
3
3
  export declare class Config {
4
4
  apikey: string;
5
5
  campaign: string;
@@ -37,6 +37,7 @@ export declare class Config {
37
37
  metaPushPriorityCsvUrl: string;
38
38
  runId?: string;
39
39
  feedItemsBigQuery?: FeedItemsBigQueryTarget;
40
+ publicationGate?: PublicationGateConfig;
40
41
  protected environmentConfig: {
41
42
  develop: {
42
43
  domain: string;
@@ -31,6 +31,7 @@ class Config {
31
31
  metaPushPriorityCsvUrl;
32
32
  runId;
33
33
  feedItemsBigQuery;
34
+ publicationGate;
34
35
  environmentConfig = {
35
36
  [enums_1.Environment.DEVELOP]: {
36
37
  domain: 'autode-dev.de',
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/configs/config.ts"],"names":[],"mappings":";;;AAAA,oCAA8D;AAG9D,MAAa,MAAM;IACjB,MAAM,CAAS;IACf,QAAQ,CAAS;IACjB,cAAc,CAAS;IACvB,sBAAsB,CAAS;IAC/B,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,QAAQ,CAAS;IACjB,YAAY,CAAS;IACrB,iBAAiB,CAAS;IAC1B,eAAe,CAAS;IACxB,SAAS,CAAY;IACrB,aAAa,CAAU;IACvB,QAAQ,CAAU;IAClB,QAAQ,CAAU;IAClB,UAAU,CAAa;IACvB,MAAM,CAAS;IACf,KAAK,CAIH;IAIF,oBAAoB,CAAU;IAC9B,YAAY,CAIV;IACF,WAAW,CAAW;IACtB,GAAG,CAAS;IACZ,oBAAoB,CAAS;IAC7B,uBAAuB,CAAS;IAChC,oBAAoB,CAAS;IAC7B,uBAAuB,CAAS;IAChC,sBAAsB,CAAS;IAE/B,KAAK,CAAU;IAEf,iBAAiB,CAA2B;IAElC,iBAAiB,GAAG;QAC5B,CAAC,mBAAW,CAAC,OAAO,CAAC,EAAE;YACrB,MAAM,EAAE,eAAe;YACvB,kBAAkB,EAAE,CAAC;YACrB,6BAA6B,EAAE,EAAE;YACjC,uBAAuB,EAAE,mBAAmB;YAC5C,eAAe,EAAE,YAAY;YAC7B,QAAQ,EAAE,yCAAyC;YACnD,YAAY,EAAE,8BAA8B;SAC7C;QACD,CAAC,mBAAW,CAAC,UAAU,CAAC,EAAE;YACxB,MAAM,EAAE,SAAS;YACjB,kBAAkB,EAAE,CAAC;YACrB,6BAA6B,EAAE,CAAC;YAChC,uBAAuB,EAAE,oBAAoB;YA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,MAAM;YACvB,QAAQ,EAAE,MAAM,CAAC,MAAM;YACvB,MAAM,EAAE,MAAM,CAAC,IAAI;SACpB,CAAC;QACF,IAAI,CAAC,YAAY,GAAG;YAClB,cAAc,EAAE,uBAAuB;YACvC,uBAAuB,EAAE,0BAA0B;YACnD,YAAY,EAAE,MAAM;SACrB,CAAC;IACJ,CAAC;CACF;AA/FD,wBA+FC"}
@@ -19,6 +19,22 @@ class GoogleConfig extends config_1.Config {
19
19
  if (feedItemsBigQuery.project && feedItemsBigQuery.dataset && feedItemsBigQuery.table) {
20
20
  this.feedItemsBigQuery = feedItemsBigQuery;
21
21
  }
22
+ const gateMode = trimmed(params.publicationGate).toLowerCase();
23
+ if (gateMode === 'audit' || gateMode === 'enforce') {
24
+ const gate = {
25
+ mode: gateMode,
26
+ project: trimmed(params.publicationGateBqProject),
27
+ dataset: trimmed(params.publicationGateBqDataset),
28
+ table: trimmed(params.publicationGateBqTable),
29
+ };
30
+ if (!gate.project || !gate.dataset || !gate.table) {
31
+ throw new Error(`publicationGate=${gateMode} needs publicationGateBqProject, publicationGateBqDataset and publicationGateBqTable`);
32
+ }
33
+ this.publicationGate = gate;
34
+ }
35
+ else if (gateMode && gateMode !== 'off') {
36
+ throw new Error(`publicationGate must be off, audit or enforce, got "${gateMode}"`);
37
+ }
22
38
  this.outputFiles = [
23
39
  `${this.pathesConfig.localConvertedDirectory}/api_export_cars_${enums_1.ExportType.GOOGLE}.${enums_1.FileType.XML}`,
24
40
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"google.config.js","sourceRoot":"","sources":["../../src/configs/google.config.ts"],"names":[],"mappings":";;;AAAA,oCAA4D;AAC5D,4EAA6E;AAE7E,qCAAkC;AAElC,MAAM,OAAO,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAE5F,MAAa,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uDAAuD,QAAQ,GAAG,CAAC,CAAC;SACrF;QACD,IAAI,CAAC,WAAW,GAAG;YACjB,GAAG,IAAI,CAAC,YAAY,CAAC,uBAAuB,oBAAoB,kBAAU,CAAC,MAAM,IAAI,gBAAQ,CAAC,GAAG,EAAE;SACpG,CAAC;IACJ,CAAC;CACF;AAjCD,oCAiCC"}
@@ -17,6 +17,7 @@ const services_1 = require("../services");
17
17
  const google_transformer_1 = require("../transformers/google.transformer");
18
18
  const google_feed_item_row_1 = require("../transformers/google-feed-item-row");
19
19
  const feed_items_bigquery_writer_1 = require("../services/feed-items-bigquery.writer");
20
+ const publication_gate_1 = require("../services/publication-gate");
20
21
  const google_xml_builder_1 = require("../formats/google-xml.builder");
21
22
  let GoogleExporter = class GoogleExporter {
22
23
  carService;
@@ -32,6 +33,7 @@ let GoogleExporter = class GoogleExporter {
32
33
  this.moduleRef = moduleRef;
33
34
  }
34
35
  async export() {
36
+ const gate = await (0, publication_gate_1.loadPublicationGate)(this.configService.config.publicationGate);
35
37
  const [fileName] = this.configService.config.outputFiles;
36
38
  await cronicle_helper_1.CronicleUtils.ensureDir(this.configService.config.pathesConfig.localConvertedDirectory);
37
39
  await cronicle_helper_1.CronicleUtils.emptyDir(this.configService.config.pathesConfig.localConvertedDirectory);
@@ -41,18 +43,26 @@ let GoogleExporter = class GoogleExporter {
41
43
  const { feedItemsBigQuery, runId } = this.configService.config;
42
44
  const feedItemsWriter = feedItemsBigQuery ? new feed_items_bigquery_writer_1.FeedItemsBigQueryWriter(feedItemsBigQuery) : null;
43
45
  const exportedAt = new Date();
46
+ let gatedItems = 0;
44
47
  await this.loaderService.process(async (chunk) => {
45
48
  chunk.data = chunk.data.filter(car => this.carService.filterCar(car, this.rulesService.rules));
46
49
  for (const data of chunk.data) {
47
50
  const car = await googleTransformer.transform(data);
48
51
  if (car) {
49
- await googleXmlBuilder.addItem(car);
50
- feedItemsWriter?.add((0, google_feed_item_row_1.buildGoogleFeedItemRow)(data.car, car, runId, exportedAt));
52
+ const estimatedAttributes = gate.estimatedAttributes(data.car);
53
+ if (estimatedAttributes.length)
54
+ gatedItems += 1;
55
+ await googleXmlBuilder.addItem(gate.apply(car, estimatedAttributes));
56
+ const gateInfo = gate.mode === 'off' ? null : { mode: gate.mode, estimatedAttributes };
57
+ feedItemsWriter?.add((0, google_feed_item_row_1.buildGoogleFeedItemRow)(data.car, car, runId, exportedAt, gateInfo));
51
58
  }
52
59
  this.carService.counter.countCar(data.images);
53
60
  }
54
61
  });
55
62
  await googleXmlBuilder.buildEnd();
63
+ if (gate.mode !== 'off') {
64
+ console.log(`Publication gate ${gate.mode}: ${gatedItems} items with estimated EnVKV values${gate.mode === 'enforce' ? ' (attributes left out)' : ''}`);
65
+ }
56
66
  await feedItemsWriter?.close();
57
67
  console.log(this.carService.counter.getCountedCars());
58
68
  }
@@ -1 +1 @@
1
- {"version":3,"file":"google.exporter.js","sourceRoot":"","sources":["../../src/exporters/google.exporter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,uCAAyC;AAEzC,gEAA2D;AAG3D,0CAAqF;AACrF,2EAAuE;AACvE,+EAA8E;AAC9E,uFAAiF;AACjF,sEAAiE;AAI1D,IAAM,cAAc,GAApB,MAAM,cAAc;IAEf;IACA;IACA;IACA;IACA;IALV,YACU,UAAsB,EACtB,aAA4B,EAC5B,YAA0B,EAC1B,aAA4B,EAC5B,SAAoB;QAJpB,eAAU,GAAV,UAAU,CAAY;QACtB,kBAAa,GAAb,aAAa,CAAe;QAC5B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,kBAAa,GAAb,aAAa,CAAe;QAC5B,cAAS,GAAT,SAAS,CAAW;IAC1B,CAAC;IAEL,KAAK,CAAC,MAAM;QACV,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC;QACzD,MAAM,+BAAa,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAA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emsBqProject?: string;
15
15
  feedItemsBqDataset?: string;
16
16
  feedItemsBqTable?: string;
17
+ publicationGate?: string;
18
+ publicationGateBqProject?: string;
19
+ publicationGateBqDataset?: string;
20
+ publicationGateBqTable?: string;
17
21
  }
18
22
  export interface FeedItemsBigQueryTarget {
19
23
  project: string;
20
24
  dataset: string;
21
25
  table: string;
22
26
  }
27
+ export interface PublicationGateConfig {
28
+ mode: 'off' | 'audit' | 'enforce';
29
+ project: string;
30
+ dataset: string;
31
+ table: string;
32
+ }
@@ -0,0 +1,15 @@
1
+ import { DataSchemes } from '@bytebrand/car-schema';
2
+ import { PublicationGateConfig } from '../interfaces/params.interface';
3
+ import { GoogleEnvkvAttribute } from '../transformers/google-feed-envkv';
4
+ export declare const ESTIMATE_SOURCES: string[];
5
+ export declare const GATED_FIELDS: string[];
6
+ export declare class PublicationGate {
7
+ readonly mode: 'off' | 'audit' | 'enforce';
8
+ private estimates;
9
+ constructor(mode: 'off' | 'audit' | 'enforce', estimates: Map<string, string>);
10
+ static off(): PublicationGate;
11
+ get size(): number;
12
+ estimatedAttributes(car: DataSchemes.Car): GoogleEnvkvAttribute[];
13
+ apply<T extends Partial<Record<GoogleEnvkvAttribute, string>>>(item: T, attributes: GoogleEnvkvAttribute[]): T;
14
+ }
15
+ export declare function loadPublicationGate(config: PublicationGateConfig | undefined): Promise<PublicationGate>;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadPublicationGate = exports.PublicationGate = exports.GATED_FIELDS = exports.ESTIMATE_SOURCES = void 0;
4
+ const path_1 = require("path");
5
+ const lodash_1 = require("lodash");
6
+ const bigquery_logger_1 = require("@bytebrand/bigquery-logger");
7
+ const google_feed_envkv_1 = require("../transformers/google-feed-envkv");
8
+ exports.ESTIMATE_SOURCES = ['co2-estimate', 'mmm', 'globalDefault'];
9
+ exports.GATED_FIELDS = [
10
+ 'consumption.wltpWeightedCombined',
11
+ 'consumption.wltpCombined',
12
+ 'consumption.consumptionCombined',
13
+ 'consumption.wltpWeightedPowerCombined',
14
+ 'consumption.wltpPowerCombined',
15
+ 'consumption.consumptionPowerCombined',
16
+ 'environmentEmissions.wltpCo2',
17
+ 'environmentEmissions.co2',
18
+ 'battery.wltpTotalRange',
19
+ 'battery.wltpRange',
20
+ 'battery.batteryRangeElectric',
21
+ ];
22
+ const sameValue = (logged, stored) => {
23
+ if (stored === undefined || stored === null)
24
+ return false;
25
+ const a = Number(logged);
26
+ const b = Number(stored);
27
+ if (Number.isFinite(a) && Number.isFinite(b))
28
+ return Math.abs(a - b) < 1e-9;
29
+ return logged === String(stored);
30
+ };
31
+ class PublicationGate {
32
+ mode;
33
+ estimates;
34
+ constructor(mode, estimates) {
35
+ this.mode = mode;
36
+ this.estimates = estimates;
37
+ }
38
+ static off() {
39
+ return new PublicationGate('off', new Map());
40
+ }
41
+ get size() {
42
+ return this.estimates.size;
43
+ }
44
+ estimatedAttributes(car) {
45
+ if (this.mode === 'off')
46
+ return [];
47
+ const carId = String((0, lodash_1.get)(car, '_id', ''));
48
+ const attributes = [];
49
+ for (const [attribute, field] of Object.entries((0, google_feed_envkv_1.googleEnvkvSourceFields)(car))) {
50
+ const logged = this.estimates.get(`${carId}|${field}`);
51
+ if (logged !== undefined && sameValue(logged, (0, lodash_1.get)(car, field)))
52
+ attributes.push(attribute);
53
+ }
54
+ return attributes;
55
+ }
56
+ apply(item, attributes) {
57
+ if (this.mode !== 'enforce')
58
+ return item;
59
+ for (const attribute of attributes)
60
+ delete item[attribute];
61
+ return item;
62
+ }
63
+ }
64
+ exports.PublicationGate = PublicationGate;
65
+ class EnrichmentLogReader extends bigquery_logger_1.BigQueryLogger {
66
+ async latestEstimates(table) {
67
+ const query = `
68
+ SELECT carId, fieldName, finalValue
69
+ FROM (
70
+ SELECT carId, fieldName, finalValue, finalValueSource,
71
+ ROW_NUMBER() OVER (PARTITION BY carId, fieldName ORDER BY timestamp DESC) AS rn
72
+ FROM \`${table}\`
73
+ WHERE fieldName IN UNNEST(@fields)
74
+ )
75
+ WHERE rn = 1 AND finalValueSource IN UNNEST(@sources) AND finalValue IS NOT NULL`;
76
+ const [rows] = await this.client.query({ query, params: { fields: exports.GATED_FIELDS, sources: exports.ESTIMATE_SOURCES } });
77
+ const estimates = new Map();
78
+ for (const row of rows)
79
+ estimates.set(`${row.carId}|${row.fieldName}`, String(row.finalValue));
80
+ return estimates;
81
+ }
82
+ }
83
+ async function loadPublicationGate(config) {
84
+ if (!config || config.mode === 'off')
85
+ return PublicationGate.off();
86
+ const table = `${config.project}.${config.dataset}.${config.table}`;
87
+ try {
88
+ const credentials = require((0, path_1.join)(process.cwd(), 'credentials/google-cloud-project-id.json'));
89
+ const reader = new EnrichmentLogReader(credentials, {
90
+ BigQueryProject: config.project,
91
+ BigQueryDataset: config.dataset,
92
+ BigQueryLogTable: config.table,
93
+ });
94
+ const estimates = await reader.latestEstimates(table);
95
+ console.log(`Publication gate ${config.mode}: ${estimates.size} estimated car fields from ${table}`);
96
+ return new PublicationGate(config.mode, estimates);
97
+ }
98
+ catch (e) {
99
+ const message = String(e?.message || e).split('\n')[0];
100
+ if (config.mode === 'enforce')
101
+ throw new Error(`Publication gate: cannot read ${table}: ${message}`);
102
+ console.error(`Publication gate disabled for this run: cannot read ${table}: ${message}`);
103
+ return PublicationGate.off();
104
+ }
105
+ }
106
+ exports.loadPublicationGate = loadPublicationGate;
107
+ //# sourceMappingURL=publication-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publication-gate.js","sourceRoot":"","sources":["../../src/services/publication-gate.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAC5B,mCAA6B;AAC7B,gEAA4D;AAG5D,yEAAkG;AAgBrF,QAAA,gBAAgB,GAAG,CAAC,cAAc,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;AAG5D,QAAA,YAAY,GAAG;IAC1B,kCAAkC;IAClC,0BAA0B;IAC1B,iCAAiC;IACjC,uCAAuC;IACvC,+B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: DataSchemes.Car): string | un
6
6
  export declare function googleFuelConsumptionDischarged(car: DataSchemes.Car): string | undefined;
7
7
  export declare function googleEnergyConsumption(car: DataSchemes.Car): string | undefined;
8
8
  export declare function googleCo2(car: DataSchemes.Car): string | undefined;
9
+ export type GoogleEnvkvAttribute = 'fuel_consumption' | 'fuel_consumption_discharged_battery' | 'energy_consumption' | 'electric_range' | 'co2_emissions';
10
+ export declare function googleEnvkvSourceFields(car: DataSchemes.Car): Partial<Record<GoogleEnvkvAttribute, string>>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.googleCo2 = exports.googleEnergyConsumption = exports.googleFuelConsumptionDischarged = exports.googleFuelConsumption = exports.googleElectricRangeSource = exports.googleElectricRange = exports.googleEngine = void 0;
3
+ exports.googleEnvkvSourceFields = exports.googleCo2 = exports.googleEnergyConsumption = exports.googleFuelConsumptionDischarged = exports.googleFuelConsumption = exports.googleElectricRangeSource = exports.googleElectricRange = exports.googleEngine = void 0;
4
4
  const lodash_1 = require("lodash");
5
5
  const GOOGLE_ENGINE = {
6
6
  selector_fuel_petrol: 'Gasoline',
@@ -47,49 +47,80 @@ function googleElectricRangeSource(car) {
47
47
  }
48
48
  exports.googleElectricRangeSource = googleElectricRangeSource;
49
49
  const isConfirmedPlugIn = (car) => isPlugIn(car) && !!googleElectricRange(car);
50
- function googleFuelConsumption(car) {
50
+ const firstPositive = (car, fields) => {
51
+ for (const field of fields) {
52
+ const value = positive((0, lodash_1.get)(car, field));
53
+ if (value)
54
+ return { field, value };
55
+ }
56
+ return undefined;
57
+ };
58
+ const pickFuelConsumption = (car) => {
51
59
  if (isBev(car))
52
60
  return undefined;
53
- let value;
54
- if (isConfirmedPlugIn(car)) {
55
- value = positive((0, lodash_1.get)(car, 'consumption.wltpWeightedCombined')) ?? positive((0, lodash_1.get)(car, 'consumption.consumptionCombined'));
56
- }
57
- else if (isPlugIn(car)) {
58
- value = positive((0, lodash_1.get)(car, 'consumption.consumptionCombined'));
59
- }
60
- else {
61
- value = positive((0, lodash_1.get)(car, 'consumption.wltpCombined')) ?? positive((0, lodash_1.get)(car, 'consumption.consumptionCombined'));
62
- }
63
- return value ? `${value}l/100km` : undefined;
61
+ if (isConfirmedPlugIn(car))
62
+ return firstPositive(car, ['consumption.wltpWeightedCombined', 'consumption.consumptionCombined']);
63
+ if (isPlugIn(car))
64
+ return firstPositive(car, ['consumption.consumptionCombined']);
65
+ return firstPositive(car, ['consumption.wltpCombined', 'consumption.consumptionCombined']);
66
+ };
67
+ const pickFuelConsumptionDischarged = (car) => {
68
+ if (!isPlugIn(car))
69
+ return undefined;
70
+ return isConfirmedPlugIn(car)
71
+ ? firstPositive(car, ['consumption.wltpCombined'])
72
+ : firstPositive(car, ['consumption.consumptionCombined', 'consumption.wltpCombined']);
73
+ };
74
+ const pickEnergyConsumption = (car) => {
75
+ if (isConfirmedPlugIn(car))
76
+ return firstPositive(car, ['consumption.wltpWeightedPowerCombined']);
77
+ if (isBev(car) || isPlugIn(car))
78
+ return firstPositive(car, ['consumption.wltpPowerCombined', 'consumption.consumptionPowerCombined']);
79
+ return undefined;
80
+ };
81
+ const pickCo2 = (car) => {
82
+ if (isBev(car))
83
+ return undefined;
84
+ return isPlugIn(car) && !isConfirmedPlugIn(car)
85
+ ? firstPositive(car, ['environmentEmissions.co2'])
86
+ : firstPositive(car, ['environmentEmissions.wltpCo2', 'environmentEmissions.co2']);
87
+ };
88
+ function googleFuelConsumption(car) {
89
+ const picked = pickFuelConsumption(car);
90
+ return picked ? `${picked.value}l/100km` : undefined;
64
91
  }
65
92
  exports.googleFuelConsumption = googleFuelConsumption;
66
93
  function googleFuelConsumptionDischarged(car) {
67
- if (!isPlugIn(car))
68
- return undefined;
69
- const value = isConfirmedPlugIn(car)
70
- ? positive((0, lodash_1.get)(car, 'consumption.wltpCombined'))
71
- : positive((0, lodash_1.get)(car, 'consumption.consumptionCombined')) ?? positive((0, lodash_1.get)(car, 'consumption.wltpCombined'));
72
- return value ? `${value}l/100km` : undefined;
94
+ const picked = pickFuelConsumptionDischarged(car);
95
+ return picked ? `${picked.value}l/100km` : undefined;
73
96
  }
74
97
  exports.googleFuelConsumptionDischarged = googleFuelConsumptionDischarged;
75
98
  function googleEnergyConsumption(car) {
76
- let value;
77
- if (isConfirmedPlugIn(car)) {
78
- value = positive((0, lodash_1.get)(car, 'consumption.wltpWeightedPowerCombined'));
79
- }
80
- else if (isBev(car) || isPlugIn(car)) {
81
- value = positive((0, lodash_1.get)(car, 'consumption.wltpPowerCombined')) ?? positive((0, lodash_1.get)(car, 'consumption.consumptionPowerCombined'));
82
- }
83
- return value ? `${value}kWh/100km` : undefined;
99
+ const picked = pickEnergyConsumption(car);
100
+ return picked ? `${picked.value}kWh/100km` : undefined;
84
101
  }
85
102
  exports.googleEnergyConsumption = googleEnergyConsumption;
86
103
  function googleCo2(car) {
87
104
  if (isBev(car))
88
105
  return '0g/km';
89
- const value = isPlugIn(car) && !isConfirmedPlugIn(car)
90
- ? positive((0, lodash_1.get)(car, 'environmentEmissions.co2'))
91
- : positive((0, lodash_1.get)(car, 'environmentEmissions.wltpCo2')) ?? positive((0, lodash_1.get)(car, 'environmentEmissions.co2'));
92
- return value ? `${value}g/km` : undefined;
106
+ const picked = pickCo2(car);
107
+ return picked ? `${picked.value}g/km` : undefined;
93
108
  }
94
109
  exports.googleCo2 = googleCo2;
110
+ function googleEnvkvSourceFields(car) {
111
+ const picks = {
112
+ fuel_consumption: pickFuelConsumption(car),
113
+ fuel_consumption_discharged_battery: pickFuelConsumptionDischarged(car),
114
+ energy_consumption: pickEnergyConsumption(car),
115
+ electric_range: pickElectricRange(car),
116
+ co2_emissions: pickCo2(car),
117
+ };
118
+ const fields = {};
119
+ for (const [attribute, picked] of Object.entries(picks)) {
120
+ if (picked)
121
+ fields[attribute] = picked.field;
122
+ }
123
+ return fields;
124
+ }
125
+ exports.googleEnvkvSourceFields = googleEnvkvSourceFields;
95
126
  //# sourceMapping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AAO,CAAC;IAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACpD,CAAC;AAJD,8BAIC;AAWD,SAAgB,uBAAuB,CAAC,GAAoB;IAC1D,MAAM,KAAK,GAAgE;QACzE,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,CAAC;QAC1C,mCAAmC,EAAE,6BAA6B,CAAC,GAAG,CAAC;QACvE,kBAAkB,EAAE,qBAAqB,CAAC,GAAG,CAAC;QAC9C,cAAc,EAAE,iBAAiB,CAAC,GAAG,CAAC;QACtC,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC;KAC5B,CAAC;IACF,MAAM,MAAM,GAAkD,EAAE,CAAC;IACjE,KAAK,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACvD,IAAI,MAAM;YAAE,MAAM,CAAC,SAAiC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;KACtE;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAbD,0DAaC"}
@@ -21,5 +21,10 @@ export interface FeedItemRow {
21
21
  rangeSourceField: string | null;
22
22
  price: number | null;
23
23
  availability: string | null;
24
+ publicationGate: string | null;
25
+ estimatedAttributes: string | null;
24
26
  }
25
- export declare function buildGoogleFeedItemRow(car: DataSchemes.Car, item: GoogleXmlItem, runId: string | null, exportedAt: Date): FeedItemRow;
27
+ export declare function buildGoogleFeedItemRow(car: DataSchemes.Car, item: GoogleXmlItem, runId: string | null, exportedAt: Date, gate?: {
28
+ mode: string;
29
+ estimatedAttributes: string[];
30
+ } | null): FeedItemRow;
@@ -8,7 +8,7 @@ const sentPrice = (price) => {
8
8
  const n = parseFloat(price);
9
9
  return Number.isFinite(n) ? n : null;
10
10
  };
11
- function buildGoogleFeedItemRow(car, item, runId, exportedAt) {
11
+ function buildGoogleFeedItemRow(car, item, runId, exportedAt, gate = null) {
12
12
  const hybridPlugin = (0, lodash_1.get)(car, 'engineData.hybridPlugin');
13
13
  return {
14
14
  partitionDay: exportedAt.toISOString().slice(0, 10),
@@ -31,6 +31,8 @@ function buildGoogleFeedItemRow(car, item, runId, exportedAt) {
31
31
  rangeSourceField: item.electric_range ? (0, google_feed_envkv_1.googleElectricRangeSource)(car) : null,
32
32
  price: sentPrice(item.price),
33
33
  availability: orNull(item.availability),
34
+ publicationGate: gate ? gate.mode : null,
35
+ estimatedAttributes: gate && gate.estimatedAttributes.length ? gate.estimatedAttributes.join(',') : null,
34
36
  };
35
37
  }
36
38
  exports.buildGoogleFeedItemRow = buildGoogleFeedItemRow;
@@ -1 +1 @@
1
- {"version":3,"file":"google-feed-item-row.js","sourceRoot":"","sources":["../../src/transformers/google-feed-item-row.ts"],"names":[],"mappings":";;;AAAA,mCAAwC;AAGxC,2DAAgE;AA4BhE,MAAM,MAAM,GAAG,CAAC,KAAc,EAAiB,EAAE,CAC/C,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAG/E,MAAM,SAAS,GAAG,CAAC,KAAyB,EAAiB,EAAE;IAC7D,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAC5B,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACvC,CAAC,CAAC;AAGF,SAAgB,sBAAsB,CACpC,GAAoB,EACpB,IAAmB,EACnB,KAAoB,EACpB,UAAgB;IAEhB,MAAM,YAAY,GAAG,IAAA,YAAG,EAAC,GAAG,EAAE,yBAAyB,CAAC,CAAC;IACzD,OAAO;QACL,YAAY,EAAE,UAAU,CAAC,WAAW,EAAE,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