-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctional-programming.js
More file actions
221 lines (176 loc) Β· 6.7 KB
/
functional-programming.js
File metadata and controls
221 lines (176 loc) Β· 6.7 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// // 1 Haal de RDW data op 3
// // 2 Selecteer de kolom in de dataset die ik wil onderzoeken/visualiseren
// // 3 Schoon deze data op
// const endpoint =
// 'https://raw.githubusercontent.com/SharonV33/frontend-data/main/data/parkeergarages_1000.json'
// const areaIdColumn = getData
// const selectedColumn = 'parkingFacilityInformation'
// async function getData(url) {
// const response = await fetch(url)
// const data = await response.json()
// return data
// }
// getData(endpoint).then((RDWData) => {
// //get data all data
// const allData = filterAccesspoint(RDWData, selectedColumn)
// console.log(allData)
// // removes all the arrays around the objects
// const removeArrays = removeArray(allData)
// //replace undifined values with null
// const emptyFixed = fixEmptyKeys(removeArrays)
// //filter out the long lat
// const longLatArray = getLocationArray(emptyFixed)
// //Alle null waardes weghalen
// const removeNullValues = removeNulls(longLatArray)
// //Weer een een array om object weghalen
// const removeArrayLonLat = removeArray(removeNullValues)
// // //make array of the long lat of every object
// // const geoArray = createLongLatArray(removeArrayLonLat)
// // console.log(JSON.stringify(geoArray))
// //Get disabled Data
// const disabledArray = filterDisabled(RDWData, selectedColumn)
// const removeArrayDisabled = removeArray(disabledArray)
// // const removeObjectsDisabled = removeObjects(removeArrayDisabled)
// //Calls the function that replaces undefined for {} so i can add and id to the object
// const objectArray = addObjectUndef(removeArrays)
// //adds id's to the lonlat data objects so I can combine it with the other data variable
// const addIdToLonLat = addIds(objectArray)
// //adds id's to the disabled data objects so I can combine it with the other data variable
// const addIdToDisabled = addIds(removeArrayDisabled)
// const combineJSON = addIdToLonLat.map((item) => {
// // console.log('dit is t item: ', item)
// return {
// ...item,
// ...addIdToDisabled.filter((data) => data.id === item.id)[0],
// //https://flaviocopes.com/how-to-merge-objects-javascript/
// }
// })
// // console.log('volledige JSON: ', combineJSON)
// //and than as last we filter out the not usable parking spots
// const filterUselessData = filterData(combineJSON)
// // console.log(filterUselessData)
// //Aantal loops om classes toe te voegen aan de dataset
// const addsClassesNone = addClassesNone(filterUselessData)
// const addsClassesDisabled = addClassesDisabled(addsClassesNone)
// const addsClassesCharging = addClassesCharging(addsClassesDisabled)
// const addsClassesBoth = addClassesBoth(addsClassesCharging)
// // console.log('both: ', JSON.stringify((addsClassesBoth)))
// })
// //FUNCTION PART
// //remove data that cant be used
// function filterData(data) {
// return data.filter((result) => result.accessPointLocation)
// }
// function addObjectUndef(data) {
// return data.map((result) => {
// if (result == undefined) {
// return (result = {})
// } else {
// return result
// }
// })
// }
// function addIds(data) {
// return data.map((item, index) => {
// if (index !== undefined) {
// return { ...item, id: index + 1 }
// } else {
// return { id: index + 1 }
// }
// //https://stackoverflow.com/questions/50023291/add-id-to-array-of-objects-javascript
// })
// }
// function addClassesNone(data) {
// return data.map((item) => {
// // console.log('item', item)
// if (item.chargingPointCapacity == 0 && item.disabledAccess == false) {
// return { ...item, id: 'none' }
// } else {
// return item
// }
// })
// }
// function addClassesDisabled(data) {
// return data.map((item) => {
// if (item.chargingPointCapacity == 0 && item.disabledAccess == true) {
// return { ...item, id: 'disabled' }
// } else {
// return item
// }
// })
// }
// function addClassesCharging(data) {
// return data.map((item) => {
// if (item.chargingPointCapacity > 0 && item.disabledAccess == false) {
// return { ...item, id: 'charging' }
// } else {
// return item
// }
// })
// }
// function addClassesBoth(data) {
// return data.map((item) => {
// // console.log('item', item)
// if (item.chargingPointCapacity > 0 && item.disabledAccess == true) {
// return { ...item, id: 'both' }
// } else {
// return item
// }
// })
// }
// //get disbaled data
// function filterDisabled(dataArray, index) {
// return dataArray.map((item) => item[index].specifications)
// }
// function removeObjects(data){
// return data.filter(result => result.chargingPointCapacity !== undefined);
// }
// function filterAccesspoint(dataArray, index) {
// return dataArray.map((item) => item[index].accessPoints)
// }
// function getLocationArray(data) {
// return data.map((item) => item.accessPointLocation)
// }
// function removeArray(data) {
// return data.map((result) => result[0])
// }
// function removeNulls(data) {
// return data.filter((result) => result !== null)
// }
// // function createLongLatArray(data){
// // let lat = data.map(result => result.latitude )
// // let long = data.map(result => result.longitude)
// // return lat.map((latitude, index) =>{
// // return [latitude, long[index]]})
// // }
// function fixEmptyKeys(data) {
// // Create an object with all the keys in it
// // This will return one object containing all keys the items
// let obj = data.reduce((res, item) => ({ ...res, ...item }))
// // Get those keys as an array
// let keys = Object.keys(obj)
// // Create an object with all keys set to the default value null
// let def = keys.reduce((result, key) => {
// result[key] = null
// return result
// }, {})
// // Use object destrucuring to replace all default values with the ones we have
// return data.map((item) => ({ ...def, ...item }))
// //source: https://stackoverflow.com/questions/47870887/how-to-fill-in-missing-keys-in-an-array-of-objects/47871014#47871014?newreg=7adc7a5e48b7436d99619b4aad68d8f8
// }
// cleaning ROUTEDATA
// const deData = routeData[0]
// // console.log(deData)
// const filteredData = filterData(deData)
// // console.log(filteredData)
// const multiLineString = getMultiLineString(filteredData)
// // console.log(multiLineString)
// const multilineString2 = getMultiLineString(multiLineString)
// console.log('multilinestring 2', multilineString2)
// function filterData(data, i) {
// return data.map((result) => result.wkb_geometry.coordinates)
// }
// function getMultiLineString(data) {
// return data.map((result) => result[0])
// }
// console.log(getMultiLineString)