@@ -16,14 +16,19 @@ const { containsInvalidCoordinate } = require('./utils');
16
16
async function processChangesets ( changesets , date , hour ) {
17
17
// Array to store the file paths of the processed changesets
18
18
const results = [ ] ;
19
+ const dataPath = `${ config . DATA_PATH } /${ date } T${ hour } ` ;
20
+ // create the directory if it does not exist
21
+ if ( ! fs . existsSync ( dataPath ) ) {
22
+ fs . mkdirSync ( dataPath , { recursive : true } ) ;
23
+ }
19
24
20
25
// Process changesets in batches of 10
21
26
const batchSize = 100 ;
22
27
for ( let i = 0 ; i < changesets . length ; i += batchSize ) {
23
28
const batch = changesets . slice ( i , i + batchSize ) ;
24
29
await Promise . all ( batch . map ( async ( changeset ) => {
25
30
// Process the changeset and get the result
26
- const result = await processChangeset ( changeset ) ;
31
+ const result = await processChangeset ( changeset , dataPath ) ;
27
32
results . push ( result ) ;
28
33
} ) ) ;
29
34
}
@@ -35,9 +40,10 @@ async function processChangesets(changesets, date, hour) {
35
40
/**
36
41
* Processes a single changeset and returns the file path of the processed changeset.
37
42
* @param {string } changeset - The changeset ID.
43
+ * @param {string } dataPath - The path to the directory where the processed changesets will be stored.
38
44
* @returns {Promise<string> } A promise that resolves to the file path of the processed changeset.
39
45
*/
40
- async function processChangeset ( changeset ) {
46
+ async function processChangeset ( changeset , dataPath ) {
41
47
// Process the changeset asynchronously and return the result
42
48
const url = `https://real-changesets.s3.amazonaws.com/${ changeset } .json` ;
43
49
// console.log(`Processing changeset ${changeset}`);
@@ -52,7 +58,7 @@ async function processChangeset(changeset) {
52
58
console . log ( `No features found in changeset ${ changeset } ` ) ;
53
59
return ;
54
60
}
55
- const filePath = `${ config . DATA_PATH } /${ changeset } _features.json` ;
61
+ const filePath = `${ dataPath } /${ changeset } _features.json` ;
56
62
57
63
await Promise . all ( features . map ( async ( feature ) => {
58
64
if ( feature !== null && feature !== undefined ) {
@@ -87,7 +93,8 @@ async function processChangeset(changeset) {
87
93
*/
88
94
async function combineResults ( results , date , hour ) {
89
95
console . log ( `Combining results from ${ results . length } changesets` ) ;
90
- const outputStream = fs . createWriteStream ( `${ config . DATA_PATH } /${ date } T${ hour } :00.geojson` ) ;
96
+ const dataPath = `${ config . DATA_PATH } /${ date } T${ hour } ` ;
97
+ const outputStream = fs . createWriteStream ( `${ dataPath } /${ date } T${ hour } :00.geojson` ) ;
91
98
92
99
outputStream . write ( '{"type":"FeatureCollection","features":[' ) ;
93
100
0 commit comments