-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
78 lines (64 loc) · 1.66 KB
/
script.js
File metadata and controls
78 lines (64 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import fs from "fs";
import csv from "csv-parser";
const INPUT_CSV_FILE = "input.csv";
const OUTPUT_JSON_FILE = "output.json";
const COLORS = [
"#2ecc71",
"#3498db",
"#9b59b6",
"#f1c40f",
"#e67e22",
"#e74c3c",
];
const slugify = (text) =>
text
.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
.replace(/(^-|-$)/g, "");
const randomPolygon = () => {
const baseLat = 28 + Math.random(); // arbitrary region
const baseLng = 77 + Math.random();
return [
[baseLat, baseLng],
[baseLat + 0.001, baseLng],
[baseLat + 0.001, baseLng + 0.001],
[baseLat, baseLng + 0.001],
];
};
const sectorsMap = new Map();
const startups = [];
let colorIndex = 0;
fs.createReadStream(INPUT_CSV_FILE)
.pipe(csv())
.on("data", (row) => {
const stallNo = row["Stall No."];
const sectorName = row["Sector"];
const startupName = row["Startup Name"];
if (!sectorName || !startupName) return;
// Create sector if not exists
if (!sectorsMap.has(sectorName)) {
const sectorId = slugify(sectorName);
sectorsMap.set(sectorName, {
id: sectorId,
name: sectorName,
color: COLORS[colorIndex % COLORS.length],
coords: randomPolygon(),
});
colorIndex++;
}
// Create startup entry
startups.push({
id: Number(stallNo),
name: startupName,
sectorId: sectorsMap.get(sectorName).id,
bio: "", // placeholder
});
})
.on("end", () => {
const output = {
sectors: Array.from(sectorsMap.values()),
startups,
};
fs.writeFileSync(OUTPUT_JSON_FILE, JSON.stringify(output, null, 2));
console.log(`✅ JSON generated: ${OUTPUT_JSON_FILE}`);
});