Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue 110 - read merge cells from xlsx files + use sync assets scripts #114

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}

- name: Generate assets
run: npm run assets:sync

- name: Run unit tests
run: npm run test

Expand Down
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const config = {
// Automatically clear mock calls, instances, contexts and results before every test
clearMocks: true,
// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,
collectCoverage: false,
// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',
// Indicates which provider should be used to instrument code for coverage
coverageProvider: 'v8',
// Do not fail for the moment (time to make all the tests operational)
testFailureExitCode: 0,
// Add extra jest configuration
//setupFilesAfterEnv: ['<rootDir>/test/setup-jest.js'],
setupFilesAfterEnv: ['<rootDir>/test/setup-jest.js'],
transform: {}
};

Expand Down
4,307 changes: 2,347 additions & 1,960 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"qa:format": "prettier --plugin-search-dir . --write .",
"release": "semantic-release",
"release:dry": "semantic-release --dry-run",
"prepare": "husky install",
"prepare": "husky install && npm run assets:sync",
"assets:sync": "node scripts/synchronize_assets.js"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/assets/domain/synchronize-enum-tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class SynchronizeEnumTables {
// Overwrite the enums.js file in filesystem
return this.#fileStore.writeFileToLocalSystem(
`${this.#appConfig.assetsOutputFolder}/enums.js`,
`/** @type {TableEnum} **/\nexport default ${JSON.stringify(enumsOutput, null, 2)}`
`/** @type {TableEnum} **/\nconst enums = ${JSON.stringify(enumsOutput, null, 2)};\n export default enums;`
);
}
);
Expand Down
6 changes: 4 additions & 2 deletions src/core/assets/domain/synchronize-valeur-tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,22 @@ export class SynchronizeValeurTables {
this.#synchronizeC1Tables.execute()
]).then((tablesValues) => {
const solicitationsTablesValues = tablesValues[0];
const c1TablesValues = tablesValues[1];
const dpeGesLimitTablesValues = tablesValues[1];
const c1TablesValues = tablesValues[2];

// Merge content from "valeur_tables.xlsx" file with "18.2_sollicitations_ext.ods" file
const tableValues = Object.assign(
{},
valeurTablesValues,
solicitationsTablesValues,
dpeGesLimitTablesValues,
c1TablesValues
);

// Overwrite the enum.js file in filesystem
return this.#fileStore.writeFileToLocalSystem(
`${this.#appConfig.assetsOutputFolder}/tv.js`,
`/** @type {TableValeur} **/\nexport const tvs = ${JSON.stringify(tableValues, null, 2)}`
`/** @type {TableValeur} **/\nexport const tvs = ${JSON.stringify(tableValues, null, 2)};\n export default tvs;`
);
});
});
Expand Down
9 changes: 6 additions & 3 deletions src/core/assets/domain/synchronize-valeur-tables.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ describe('SynchronizeValeurTables unit tests', () => {
it('should download, parse and convert valeur_tables.xlsx file', () => {
const fileStore = new FileStore();
const appConfig = new ApplicationConfig();
const synchronizeC1Tables = new SynchronizeC1Tables(null, null);
const synchronizeSolicitationTables = new SynchronizeSolicitationsTables(null, null);
const synchronizeDpeGesLimitValuesTables = new SynchronizeDpeGesLimitValuesTables(null, null);
const synchronizeC1Tables = new SynchronizeC1Tables(fileStore, appConfig);
const synchronizeSolicitationTables = new SynchronizeSolicitationsTables(fileStore, appConfig);
const synchronizeDpeGesLimitValuesTables = new SynchronizeDpeGesLimitValuesTables(
fileStore,
appConfig
);
const synchronizeValeurTables = new SynchronizeValeurTables(
fileStore,
appConfig,
Expand Down
8 changes: 4 additions & 4 deletions src/core/conf/infrastructure/application.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
export class ApplicationConfig {
get ademeRepositoryVersion() {
return 'dpe-2.4-audit-2.2';
return 'dpe-mdd-v8.2.1-controle-1.21.8-audit-mdd-v4.4.0-controle-1.9.9-ajout-nom-organisme-qualification';
}

get ademeRepositoryUrl() {
return 'https://gitlab.com/observatoire-dpe/observatoire-dpe';
}

get ademeEnumTablesFileUrl() {
return `${this.ademeRepositoryUrl}/-/raw/${this.ademeRepositoryVersion}/modele_donnee/enum_tables.xlsx?ref_type=heads&inline=false`;
return `${this.ademeRepositoryUrl}/-/raw/${this.ademeRepositoryVersion}/modele_donnee/enum_tables.xlsx?ref_type=tags&inline=false`;
}

get ademeValeurTablesFileUrl() {
return `${this.ademeRepositoryUrl}/-/raw/${this.ademeRepositoryVersion}/modele_donnee/valeur_tables.xlsx?ref_type=heads&inline=false`;
return `${this.ademeRepositoryUrl}/-/raw/${this.ademeRepositoryVersion}/modele_donnee/valeur_tables.xlsx?ref_type=tags&inline=false`;
}

get solicitationsExtFilePath() {
Expand All @@ -28,6 +28,6 @@ export class ApplicationConfig {
}

get assetsOutputFolder() {
return 'scripts/assets';
return 'src';
}
}
19 changes: 18 additions & 1 deletion src/core/file/infrastructure/adapter/file.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,24 @@ export class FileStore {
#excelWorkBookToJson(workBook) {
const jsonOutput = {};
workBook.SheetNames.forEach((sheetName) => {
jsonOutput[sheetName] = XLSX.utils.sheet_to_json(workBook.Sheets[sheetName], { raw: false });
/**
* @type {import('xlsx').WorkSheet}
*/
const sheet = workBook.Sheets[sheetName];
if (sheet['!merges']) {
sheet['!merges'].forEach((merge) => {
const columnStart = XLSX.utils.encode_col(merge.s.c);
const rowStart = XLSX.utils.encode_row(merge.s.r);

const nbMergedRows = merge.e.r - merge.s.r;
const firstCell = sheet[`${columnStart}${rowStart}`];
for (let i = 0; i < nbMergedRows; i++) {
const newRowStart = XLSX.utils.encode_row(merge.s.r + i + 1);
sheet[`${columnStart}${newRowStart}`] = firstCell;
}
});
}
jsonOutput[sheetName] = XLSX.utils.sheet_to_json(sheet, { raw: false });
});
return jsonOutput;
}
Expand Down
13 changes: 10 additions & 3 deletions src/enums.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/** @type {TableEnum} **/
const enums = {
version: {
1: 'version du 1er juillet 2021',
1.1: 'version corrective du 1er novembre',
2: 'version avec modèle complet sans contrôle de cohérence',
1.1: 'version corrective du 1er novembre',
2.1: 'version de fin de validation incluant les contrôles de cohérences',
2.2: 'version de préparation de compatibilité audit/dpe',
2.3: 'version corrective de janvier 2023'
2.3: 'version corrective de janvier 2023',
2.4: "version correspondant à l'arrêté des seuils pour les petites surfaces"
},
modele_dpe: {
1: 'dpe 3cl 2021 méthode logement',
Expand Down Expand Up @@ -106,6 +108,12 @@ const enums = {
7: 'dpe tertiaire vierge dans un bâtiment de logement',
8: 'dpe tertiaire vierge neuf dans un bâtiment de logement'
},
sous_modele_dpe_ter: {
1: 'bureaux, services administratifs, enseignement',
2: 'bâtiments à occupation continue',
3: 'autres',
4: 'centre commercial'
},
calcul_echantillonnage: {
1: 'absence de méthode d’échantillonnage',
2: 'calcul de l’échantillonnage effectué par un logiciel validé',
Expand Down Expand Up @@ -1144,5 +1152,4 @@ const enums = {
3: 'bon'
}
};

export default enums;
Loading