File tree Expand file tree Collapse file tree 4 files changed +53
-15
lines changed Expand file tree Collapse file tree 4 files changed +53
-15
lines changed Original file line number Diff line number Diff line change @@ -12,3 +12,4 @@ coverage
12
12
.github
13
13
14
14
/temp
15
+ * /output
Original file line number Diff line number Diff line change 1
1
import path from 'path' ;
2
2
import { readDataset } from '../utils/dataset-reader.js' ;
3
+ import { writeSubmission } from '../utils/subsmission_writer.js' ;
4
+ import { Submission } from '../utils/subsmission_writer' ;
5
+ import { Dataset , Ingredient } from '../models/models' ;
3
6
4
- readDataset ( path . resolve ( process . cwd ( ) , './practice_round/datasets/a_an_example.in.txt' ) ) . then (
5
- ( dataset ) => console . log ( dataset ) ,
7
+ export const datasetsPath = './practice_round/datasets/' ;
8
+ export const outputFilesPath = './practice_round/output/' ;
9
+
10
+ const datasets = {
11
+ a : 'a_an_example.in.txt' ,
12
+ b : 'b_basic.in.txt' ,
13
+ c : 'c_coarse.in.txt' ,
14
+ d : 'd_difficult.in.txt' ,
15
+ e : 'e_elaborate.in.txt' ,
16
+ } ;
17
+
18
+ readDataset ( path . resolve ( process . cwd ( ) , `${ datasetsPath } ${ datasets . a } ` ) ) . then (
19
+ ( dataset : Dataset ) => {
20
+ const submission : Submission = {
21
+ name : dataset . name ,
22
+ total_ingredients : dataset . clients [ 0 ] . likedIngredients . length ,
23
+ ingredients : dataset . clients [ 0 ] . likedIngredients ,
24
+ } ;
25
+ // Escribimos output en fichero
26
+ writeSubmission ( path . resolve ( process . cwd ( ) , outputFilesPath ) , submission ) ;
27
+ } ,
6
28
) ;
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { once } from 'events';
5
5
6
6
export function readDataset ( inputFilePath : string ) : Promise < Dataset > {
7
7
const dataset : Dataset = {
8
- name : inputFilePath . split ( '/' ) . pop ( ) || '' ,
8
+ name : inputFilePath . split ( '/' ) . pop ( ) . split ( '.' ) [ 0 ] || '' ,
9
9
totalClients : 0 ,
10
10
clients : [ ] ,
11
11
} ;
@@ -31,22 +31,10 @@ export function readDataset(inputFilePath: string): Promise<Dataset> {
31
31
} ) ;
32
32
33
33
return once ( rl , 'close' ) . then ( ( ) => dataset ) ;
34
-
35
- //return parseDataset(name, fileContent);
36
34
}
37
35
38
36
const parseIngredientsLint = ( line : string ) : Ingredient [ ] =>
39
37
line
40
38
. split ( ' ' )
41
39
. slice ( 1 )
42
40
. map ( ( ingredient ) => ( { name : ingredient } ) ) ;
43
-
44
- // export function parseDataset(name: string, fileContent: string): Dataset {
45
- // const [teamsLine, ...pizzaLines] = trimLines(fileContent.split('\n'));
46
- // ingredientMap.clear();
47
- // return {
48
- // name,
49
- // teams: parseTeams(teamsLine),
50
- // pizzas: pizzaLines.map(parsePizza),
51
- // };
52
- //}
Original file line number Diff line number Diff line change
1
+ import { Ingredient } from '../models/models' ;
2
+ import * as fs from 'fs' ;
3
+
4
+ export type Submission = {
5
+ name : string ;
6
+ total_ingredients : number ;
7
+ ingredients : Ingredient [ ] ;
8
+ } ;
9
+
10
+ export async function writeSubmission ( filePath : string , submission : Submission ) {
11
+ try {
12
+ fs . mkdirSync ( filePath , { recursive : true } ) ;
13
+ } catch {
14
+ // Submission directory already exists
15
+ }
16
+ const fileName = `${ submission . name } -${ getCurrentTime ( ) } .out` ;
17
+ const lines = [
18
+ `${ submission . total_ingredients } ` ,
19
+ ...submission . ingredients . map ( ( ingredient ) => ingredient . name ) ,
20
+ ] ;
21
+ fs . writeFileSync ( `${ filePath } /${ fileName } ` , lines . join ( ' ' ) ) ;
22
+ }
23
+
24
+ function getCurrentTime ( ) : string {
25
+ const today = new Date ( ) ;
26
+ return today . toTimeString ( ) . slice ( 0 , 8 ) ;
27
+ }
You can’t perform that action at this time.
0 commit comments