-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] ~minor ✨ Añado escritura en fichero del output
[Link a la tarea ](https://apps.edicomgroup.com/JDev/#idstask|) /label ~"status::needs triage" ~type::feat ~minor /assign me
- Loading branch information
jsan
committed
Feb 24, 2022
1 parent
1e58a88
commit cc17fc1
Showing
4 changed files
with
53 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ coverage | |
.github | ||
|
||
/temp | ||
*/output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,28 @@ | ||
import path from 'path'; | ||
import { readDataset } from '../utils/dataset-reader.js'; | ||
import { writeSubmission } from '../utils/subsmission_writer.js'; | ||
import { Submission } from '../utils/subsmission_writer'; | ||
import { Dataset, Ingredient } from '../models/models'; | ||
|
||
readDataset(path.resolve(process.cwd(), './practice_round/datasets/a_an_example.in.txt')).then( | ||
(dataset) => console.log(dataset), | ||
export const datasetsPath = './practice_round/datasets/'; | ||
export const outputFilesPath = './practice_round/output/'; | ||
|
||
const datasets = { | ||
a: 'a_an_example.in.txt', | ||
b: 'b_basic.in.txt', | ||
c: 'c_coarse.in.txt', | ||
d: 'd_difficult.in.txt', | ||
e: 'e_elaborate.in.txt', | ||
}; | ||
|
||
readDataset(path.resolve(process.cwd(), `${datasetsPath}${datasets.a}`)).then( | ||
(dataset: Dataset) => { | ||
const submission: Submission = { | ||
name: dataset.name, | ||
total_ingredients: dataset.clients[0].likedIngredients.length, | ||
ingredients: dataset.clients[0].likedIngredients, | ||
}; | ||
// Escribimos output en fichero | ||
writeSubmission(path.resolve(process.cwd(), outputFilesPath), submission); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Ingredient } from '../models/models'; | ||
import * as fs from 'fs'; | ||
|
||
export type Submission = { | ||
name: string; | ||
total_ingredients: number; | ||
ingredients: Ingredient[]; | ||
}; | ||
|
||
export async function writeSubmission(filePath: string, submission: Submission) { | ||
try { | ||
fs.mkdirSync(filePath, { recursive: true }); | ||
} catch { | ||
// Submission directory already exists | ||
} | ||
const fileName = `${submission.name}-${getCurrentTime()}.out`; | ||
const lines = [ | ||
`${submission.total_ingredients}`, | ||
...submission.ingredients.map((ingredient) => ingredient.name), | ||
]; | ||
fs.writeFileSync(`${filePath}/${fileName}`, lines.join(' ')); | ||
} | ||
|
||
function getCurrentTime(): string { | ||
const today = new Date(); | ||
return today.toTimeString().slice(0, 8); | ||
} |