Skip to content

Commit

Permalink
#44: updated the process for calculating advertised counts to include…
Browse files Browse the repository at this point in the history
… expansions (#45)
  • Loading branch information
mohit-s96 authored Dec 14, 2023
1 parent 0d75363 commit c00abe9
Showing 1 changed file with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const fs = require('fs/promises');
const CURRENT_DD_VERSION = '1.7';
const STANDARD_NAME_ANNOTATION_TERM = 'RESO.OData.Metadata.StandardName';
const DD_WIKI_URL_TERM = 'RESO.DDWikiUrl';
const FIELDS = 'fields';
const LOOKUPS = 'lookups';
const EXPANSIONS = 'expansions';

const buildAnnotationMap = (annotations = []) =>
annotations.reduce((acc, { term, value }) => {
Expand Down Expand Up @@ -177,39 +180,66 @@ const getAdvertisedCountPerResourcesByType = ({ fields, lookups }) => {
const idxLookups = getIdxLookups(fields, lookups);
for (const [key, value] of Object.entries(reducedFields)) {
advertisedCount[key] = { fields: {}, lookups: {} };
advertisedCount[key]['fields'] = { total: 0, reso: 0, idx: 0, local: 0 };
advertisedCount[key]['lookups'] = { total: 0, reso: 0, idx: 0, local: 0 };
advertisedCount[key][FIELDS] = { total: 0, reso: 0, idx: 0, local: 0 };
advertisedCount[key][LOOKUPS] = { total: 0, reso: 0, idx: 0, local: 0 };

const lookupsCollection = [];
for (const field of value) {
advertisedCount[key]['fields'].total++;
if (field.isExpansion) {
if (!advertisedCount[key]?.expansions) {
advertisedCount[key][EXPANSIONS] = {};
}
if (!advertisedCount[key]?.expansions?.[field.typeName]) {
advertisedCount[key][EXPANSIONS][field.typeName] = {};
}
if (!advertisedCount[key]?.expansions?.[field.typeName]?.[FIELDS]) {
advertisedCount[key].expansions[field.typeName][FIELDS] = { total: 0, reso: 0, idx: 0, local: 0 };
}
if (!advertisedCount[key]?.expansions?.[field.typeName]?.[LOOKUPS]) {
advertisedCount[key].expansions[field.typeName][LOOKUPS] = { total: 0, reso: 0, idx: 0, local: 0 };
}
}
const advertisedField = field.isExpansion ? advertisedCount[key].expansions[field.typeName][FIELDS] : advertisedCount[key][FIELDS];
advertisedField.total++;
if (field.standardRESO) {
advertisedCount[key]['fields'].reso++;
advertisedField.reso++;
if (field?.payloads?.includes('IDX')) {
advertisedCount[key]['fields'].idx++;
advertisedField.idx++;
}
} else {
advertisedCount[key]['fields'].local++;
advertisedField.local++;
}
//collect lookup on single pass
if (!field?.type.startsWith('Edm.')) {
lookupsCollection.push(...lookups.filter(lookup => lookup.lookupName === field.type));
if (field.isExpansion) {
lookupsCollection.push(
...lookups
.filter(lookup => lookup.lookupName === field.type)
.map(l => ({ ...l, isExpansion: true, resourceName: field.typeName }))
);
} else {
lookupsCollection.push(...lookups.filter(lookup => lookup.lookupName === field.type));
}
}
}
for (const lookup of lookupsCollection) {
advertisedCount[key]['lookups'].total++;
const advertisedLookup = lookup.isExpansion
? advertisedCount[key].expansions[lookup.resourceName][LOOKUPS]
: advertisedCount[key][LOOKUPS];
advertisedLookup.total++;
if (lookup.standardRESO) {
advertisedCount[key]['lookups'].reso++;
advertisedLookup.reso++;
if (
idxLookups.some(
idxLookup =>
idxLookup.lookupName === lookup.lookupName &&
(idxLookup.lookupValue === lookup.lookupValue || idxLookup?.annotations?.[0]?.value === lookup?.annotations?.[0]?.value)
)
) {
advertisedCount[key]['lookups'].idx++;
advertisedLookup.idx++;
}
} else {
advertisedCount[key]['lookups'].local++;
advertisedLookup.local++;
}
}
}
Expand Down

0 comments on commit c00abe9

Please sign in to comment.