-
Notifications
You must be signed in to change notification settings - Fork 0
/
dolmadakia.js
37 lines (31 loc) · 929 Bytes
/
dolmadakia.js
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
const path = require('path')
const fs = require('fs')
const Papa = require('papaparse')
const csvData = fs.readFileSync(path.join(__dirname, 'dolmadakia.csv'), 'utf-8')
const addRow = (from, to) => {
if (to === '-') {
return `"${from}" [fixedsize=true,shape=diamond,fillcolor=aquamarine, style=filled]`
} else {
return `"${from}" -> "${to}";`
}
}
const buildGraph = (array, current) => {
const from = current['From']
Object.keys(current).forEach(key => {
if (key === 'From') { return }
const to = current[key]
if (to !== '') {
array.push(addRow(from, to))
}
})
return array
}
const parseResults = results => {
const lines = results.data
const graphArray = lines.reduce(buildGraph, [])
console.log(`digraph {\n${graphArray.join('\n')}labelloc="t";\nlabel="Τα 88 Ντολμαδάκια";\n}`)
}
const csv = Papa.parse(csvData, {
header: true,
complete: parseResults
})