-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.js
162 lines (148 loc) · 3.08 KB
/
generate.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs')
const path = require('path')
const { parse } = require('csv-parse/sync')
const frequenciesData = parse(
fs.readFileSync(path.join(__dirname, 'airport-frequencies.csv'), 'utf-8')
)
const airportsData = parse(
fs.readFileSync(path.join(__dirname, 'airports.csv'), 'utf-8')
)
const runwaysData = parse(
fs.readFileSync(path.join(__dirname, 'runways.csv'), 'utf-8')
)
frequenciesData.shift()
airportsData.shift()
runwaysData.shift()
const allFrequencies = frequenciesData.map((item) => {
const [
id,
,
identifier,
type,
description,
frequency
] = item
// Mapping of frequency types to friendly frequency type names
// this list is not exhaustive
const types = {
UNIC: 'UNICOM',
APP: 'Approach',
GND: 'Ground',
TWR: 'Tower',
'A/D': 'Approach/departure',
CNTR: 'Center',
CLD: 'Clearance Delivery',
DIR: 'Director',
RAD: 'Radar'
}
return {
id,
identifier,
type: types[type] || type,
description,
// frequencies that end with .00 don't have the .00 included, so we add it
// ourselves
frequency: frequency.includes('.') ? frequency : `${frequency}.00`
}
})
const allRunways = runwaysData.map((item) => {
const [
id,
,
airportIdentifier,
length,
width,
surface,
lighted,
closed,
leIdent,
,
,
,
,
leDisplacedThreshold,
heIdent,
,
,
,
,
heDisplacedThreshold
] = item
// Mapping of surface identifiers to friendly surface names
// this list is not exhaustive
const surfaces = {
'ASPH-G': 'Asphalt/gravel',
ASPH: 'Asphalt',
ASP: 'Asphalt',
CON: 'Concrete',
CONC: 'Concrete',
DIRT: 'Dirt',
GRASS: 'Grass',
GRAVEL: 'Gravel',
TURF: 'Turf',
WATER: 'Water'
}
return {
id,
airportIdentifier,
length: Number(length),
width: Number(width),
surface: surfaces[surface] || surface,
lighted: lighted === '1',
closed: closed === '1',
leIdent,
leDisplacedThreshold,
heIdent,
heDisplacedThreshold
}
})
const airports = airportsData.map((item) => {
const [
id,
identifier,
type,
name,
latitude,
longitude,
elevation,
continent,
country,
region,
municipality,
scheduledService,
gpsCode,
iataCode,
localCode
] = item
const airportFrequencies = allFrequencies.filter((frequency) => {
return frequency.identifier === identifier
})
const airportRunways = allRunways.filter((runway) => {
return runway.airportIdentifier === identifier
})
return {
id,
identifier,
type,
name,
latitude: Number(latitude),
longitude: Number(longitude),
elevation: Number(elevation),
continent,
country,
region,
municipality,
scheduledService: scheduledService === 'yes',
gpsCode,
iataCode,
localCode,
frequencies: airportFrequencies,
runways: airportRunways
}
})
fs.writeFileSync(
path.join(__dirname, '../../', 'data/airfields.json'),
JSON.stringify(airports),
'utf8'
)