Skip to content

Commit

Permalink
Merge pull request #1140 from Vizzuality/fix/minor-changes-in-legacy-…
Browse files Browse the repository at this point in the history
…piece-importers

fix solutions legacy piece importer and input-dat reader
  • Loading branch information
angelhigueraacid authored Jun 17, 2022
2 parents 35e9672 + 9799dd8 commit c4db4ee
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,26 @@ const getFixtures = async () => {
const sut = sandbox.get(InputDatReader);
const fakeMarxanInput: FakeMarxanInput = sandbox.get(MarxanInput);

const inputDatVariables: MarxanParameters = { BLM: 1, BESTSCORE: 2 };
const file = { ...inputDatVariables, RandomName: 2, blm: 4 };
const inputDatVariables: MarxanParameters = {
BLM: 1,
BESTSCORE: 2,
THRESHPEN1: 14.5,
};
const file = {
...inputDatVariables,
RandomName: 2,
blm: 4,
VARIABLE1: 'invalid',
};

return {
GivenAValidInputDatFile: () =>
Readable.from(
'Skip comments in input/n' +
'.dat file/n' +
'Skip comments in input\n' +
'.dat file\n' +
Object.entries(file)
.map(([key, value]) => `${key} ${value}`)
.join('/n'),
.join('\n'),
),
GivenAnInvalidInputDatFile: () => {
fakeMarxanInput.failFromOperation = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class InputDatReader {
private filterCommentsInInputFile(words: string[]) {
//valid line must only have 2 words separated by one space and
//variable name must be in capital letters
return words.length === 2 && /^[A-Z]*$/.test(words[0]);
return words.length === 2 && /^[A-Z0-9]*$/.test(words[0]);
}

private isKeyInInputDatFile(
Expand Down Expand Up @@ -80,7 +80,8 @@ export class InputDatReader {
const stringInputDatFile = buffer.toString();

const inputLines = stringInputDatFile
.split('/n')
.split('\n')
.filter((line) => line !== '')
.map((inputLine) => inputLine.split(' '));

const possibleInputLineVariables = inputLines.filter((wordsInLine) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class SolutionsLegacyProjectPieceImporter
);
const outputSumPath = `${outputFolder}/${outputSumFileName}.${outputSumFileNameExtension}`;

this.geoEntityManager.transaction(async (em) => {
await this.geoEntityManager.transaction(async (em) => {
await this.insertOutputScenarioFeaturesData(em, scenarioFeatureRunData);
await this.insertOutputScenariosPuData(em, planningUnitsState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const getFixtures = async () => {
...validVariableValues,
};

return saveFile('BESTSCORE 100/nBLM 200');
return saveFile('BESTSCORE 100\nBLM 200');
},
GivenInvalidInputDatFile: () => {
const invalidVariableValues = 'BESTSCORE invalidBestScore';
Expand Down

0 comments on commit c4db4ee

Please sign in to comment.