|
@@ -0,0 +1,449 @@
|
|
1
|
+import React, {useState} from 'react';
|
|
2
|
+import { View, Text, Pressable, StyleSheet, Alert} from 'react-native';
|
|
3
|
+import DropDownPicker from 'react-native-dropdown-picker';
|
|
4
|
+import { Table, TableWrapper, Row, Rows, Col, Cols, Cell } from 'react-native-table-component';
|
|
5
|
+import { parse } from 'json2csv'
|
|
6
|
+//import {styles} from "./styles"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+var allData
|
|
10
|
+var allTitle
|
|
11
|
+
|
|
12
|
+const styles = StyleSheet.create({
|
|
13
|
+
|
|
14
|
+ buttons: {
|
|
15
|
+ flexDirection: 'row',
|
|
16
|
+ justifyContent: 'center',
|
|
17
|
+ marginTop: 40,
|
|
18
|
+ marginBottom: 30,
|
|
19
|
+ margin: 30,
|
|
20
|
+ borderColor: "grey",
|
|
21
|
+ borderRadius: 8,
|
|
22
|
+ padding: (30, 16),
|
|
23
|
+ backgroundColor: "black",
|
|
24
|
+ marginTop: 0,
|
|
25
|
+ },
|
|
26
|
+ navContainer: {
|
|
27
|
+ flexDirection: 'row',
|
|
28
|
+ justifyContent: "space-evenly",
|
|
29
|
+ borderColor: "black",
|
|
30
|
+ borderWidth: 5,
|
|
31
|
+ borderRadius: 8,
|
|
32
|
+ paddingTop: 20,
|
|
33
|
+ backgroundColor: "gray",
|
|
34
|
+ marginTop: 5,
|
|
35
|
+ },
|
|
36
|
+ buttonContainer: {
|
|
37
|
+ flexDirection: 'column',
|
|
38
|
+ backgroundColor: '#f0f8ff',
|
|
39
|
+ alignItems: 'center',
|
|
40
|
+ justifyContent: 'center',
|
|
41
|
+ paddingTop:100,
|
|
42
|
+ marginTop: 40,
|
|
43
|
+ },
|
|
44
|
+ container: {
|
|
45
|
+ flexDirection: 'column',
|
|
46
|
+ justifyContent: 'center',
|
|
47
|
+ backgroundColor: '#f0f8ff',
|
|
48
|
+ alignItems: 'center',
|
|
49
|
+ justifyContent: 'center',
|
|
50
|
+ paddingTop:20,
|
|
51
|
+ marginTop: 20,
|
|
52
|
+ },
|
|
53
|
+ containerbackground:{
|
|
54
|
+
|
|
55
|
+ backgroundColor: '#f0f8ff'
|
|
56
|
+ },
|
|
57
|
+ intro: {
|
|
58
|
+ fontWeight: "bold",
|
|
59
|
+ color:"#black",
|
|
60
|
+ fontSize: 30,
|
|
61
|
+ },
|
|
62
|
+
|
|
63
|
+ sub: {
|
|
64
|
+ color:"#black",
|
|
65
|
+ fontWeight: "bold",
|
|
66
|
+ fontSize: 15,
|
|
67
|
+ paddingBottom:10,
|
|
68
|
+ },
|
|
69
|
+
|
|
70
|
+ Navsub: {
|
|
71
|
+ color:"#black",
|
|
72
|
+ fontWeight: "bold",
|
|
73
|
+ fontSize: 30,
|
|
74
|
+ paddingBottom:10,
|
|
75
|
+ },
|
|
76
|
+ scrollView:{
|
|
77
|
+ marginHorizontal: 20
|
|
78
|
+ },
|
|
79
|
+ listItem:{
|
|
80
|
+ fontSize: 30,
|
|
81
|
+ color: "white",
|
|
82
|
+ textDecorationLines: "underline"
|
|
83
|
+ },
|
|
84
|
+ listButtons:{
|
|
85
|
+ fontSize: 15,
|
|
86
|
+ color: "white",
|
|
87
|
+ textDecorationLines: "underline"
|
|
88
|
+ },
|
|
89
|
+ buttonsVer: {
|
|
90
|
+ flexDirection: 'column',
|
|
91
|
+ justifyContent: 'center',
|
|
92
|
+ marginTop: 40,
|
|
93
|
+ marginBottom: 30,
|
|
94
|
+ margin: 30,
|
|
95
|
+ borderColor: "grey",
|
|
96
|
+ },
|
|
97
|
+ bottom: {
|
|
98
|
+ flex: 0.3,
|
|
99
|
+ backgroundColor: "gray",
|
|
100
|
+ borderWidth: 5,
|
|
101
|
+ alignItems: 'center',
|
|
102
|
+ borderBottomLeftRadius: 20,
|
|
103
|
+ borderBottomRightRadius: 20,
|
|
104
|
+
|
|
105
|
+ },text: {
|
|
106
|
+ fontSize: 16,
|
|
107
|
+ lineHeight: 21,
|
|
108
|
+ fontWeight: 'bold',
|
|
109
|
+ letterSpacing: 0.25,
|
|
110
|
+ color: 'white',
|
|
111
|
+ },
|
|
112
|
+ tablecontainer: { flex: 1, padding: 16, paddingTop: 30, backgroundColor: '#fff' },
|
|
113
|
+ head: { height: 40, backgroundColor: '#f1f8ff' },
|
|
114
|
+ wrapper: { flexDirection: 'row' },
|
|
115
|
+ title: { flex: 1, backgroundColor: '#f6f8fa' },
|
|
116
|
+ row: { height: 28 },
|
|
117
|
+ tabletext: { textAlign: 'center' }
|
|
118
|
+ });
|
|
119
|
+var table = ""
|
|
120
|
+var pueblo = ""
|
|
121
|
+
|
|
122
|
+//where data will be stored
|
|
123
|
+var information
|
|
124
|
+
|
|
125
|
+function Picker() {
|
|
126
|
+
|
|
127
|
+ //table to pick from
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+ const [openTable, setOpenTable] = useState(false);
|
|
131
|
+ const [valueTable, setValueTable] = useState(null);
|
|
132
|
+ const [table, setTable] = useState([
|
|
133
|
+ {label:'DP02PR', value: 'DP02PR'},
|
|
134
|
+ {label:'DP03', value: 'DP03'},
|
|
135
|
+ {label:'DP04', value: 'DP04'},
|
|
136
|
+ {label:'DP05', value: 'DP05'},
|
|
137
|
+ ]);
|
|
138
|
+
|
|
139
|
+ //cambiar pueblo
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+ //pueblo
|
|
143
|
+ const [openPueblo, setOpenPueblo] = useState(false);
|
|
144
|
+ const [valuePueblo, setValuePueblo] = useState(null);
|
|
145
|
+ const [pueblo, setPueblo] = useState([
|
|
146
|
+ {label: 'Adjuntas', value: '001'},
|
|
147
|
+ {label: 'Aguada', value: '003'},
|
|
148
|
+ {label: 'Aguadillas', value: '005'},
|
|
149
|
+ {label: 'Aguas Buenas', value: '007'},
|
|
150
|
+ {label: 'Aibonito', value: '009'},
|
|
151
|
+ {label: 'Añasco', value: '011'},
|
|
152
|
+ {label: 'Arecibo', value: '013'},
|
|
153
|
+ {label: 'Arroyo', value: '015'},
|
|
154
|
+ {label: 'Barceloneta', value: '017'},
|
|
155
|
+ {label: 'Barranquitas', value: '019'},
|
|
156
|
+ {label: 'Bayamón', value: '021'},
|
|
157
|
+ {label: 'Cabo Rojo', value: '023'},
|
|
158
|
+ {label: 'Caguas', value: '025'},
|
|
159
|
+ {label: 'Camuy', value: '027'},
|
|
160
|
+ {label: 'Canóvanas', value: '029'},
|
|
161
|
+ {label: 'Carolina', value: '031'},
|
|
162
|
+ {label: 'Cataño', value: '033'},
|
|
163
|
+ {label: 'Cayey', value: '035'},
|
|
164
|
+ {label: 'Ceiba', value: '037'},
|
|
165
|
+ {label: 'Ciales', value: '039'},
|
|
166
|
+ {label: 'Cidra', value: '041'},
|
|
167
|
+ {label: 'Coamo', value: '043'},
|
|
168
|
+ {label: 'Comerío', value: '045'},
|
|
169
|
+ {label: 'Corozal', value: '047'},
|
|
170
|
+ {label: 'Culebra', value: '049'},
|
|
171
|
+ {label: 'Dorado', value: '051'},
|
|
172
|
+ {label: 'Fajardo', value: '053'},
|
|
173
|
+ {label: 'Florida', value: '054'},
|
|
174
|
+ {label: 'Guánica', value: '055'},
|
|
175
|
+ {label: 'Guayama', value: '057'},
|
|
176
|
+ {label: 'Guayanilla', value: '059'},
|
|
177
|
+ {label: 'Guaynabo', value: '061'},
|
|
178
|
+ {label: 'Gurabo', value: '063'},
|
|
179
|
+ {label: 'Hatillo', value: '065'},
|
|
180
|
+ {label: 'Hormigueros', value: '067'},
|
|
181
|
+ {label: 'Humacao', value: '069'},
|
|
182
|
+ {label: 'Isabela', value: '071'},
|
|
183
|
+ {label: 'Jayuya', value: '073'},
|
|
184
|
+ {label: 'Juana Díaz', value: '075'},
|
|
185
|
+ {label: 'Juncos', value: '077'},
|
|
186
|
+ {label: 'Lajas', value: '079'},
|
|
187
|
+ {label: 'Lares', value: '081'},
|
|
188
|
+ {label: 'Las Marías', value: '083'},
|
|
189
|
+ {label: 'Las Piedras', value: '085'},
|
|
190
|
+ {label: 'Loíza', value: '087'},
|
|
191
|
+ {label: 'Luquillo', value: '089'},
|
|
192
|
+ {label: 'Manatí', value: '091'},
|
|
193
|
+ {label: 'Maricao', value: '093'},
|
|
194
|
+ {label: 'Maunabo', value: '095'},
|
|
195
|
+ {label: 'Mayagüez', value: '097'},
|
|
196
|
+ {label: 'Moca', value: '099'},
|
|
197
|
+ {label: 'Morovis', value: '101'},
|
|
198
|
+ {label: 'Naguabo', value: '103'},
|
|
199
|
+ {label: 'Naranjito', value: '105'},
|
|
200
|
+ {label: 'Orocovis', value: '107'},
|
|
201
|
+ {label: 'Patillas', value: '109'},
|
|
202
|
+ {label: 'Peñuelas', value: '111'},
|
|
203
|
+ {label: 'Ponce', value: '113'},
|
|
204
|
+ {label: 'Quebradillas', value: '115'},
|
|
205
|
+ {label: 'Rincón', value: '117'},
|
|
206
|
+ {label: 'Río Grande', value: '119'},
|
|
207
|
+ {label: 'Sabana Grande', value: '121'},
|
|
208
|
+ {label: 'Salinas', value: '123'},
|
|
209
|
+ {label: 'San Germán', value: '125'},
|
|
210
|
+ {label: 'San Juan', value: '127'},
|
|
211
|
+ {label: 'San Lorenzo', value: '129'},
|
|
212
|
+ {label: 'San Sebastián', value: '131'},
|
|
213
|
+ {label: 'Santa Isabel', value: '133'},
|
|
214
|
+ {label: 'Toa Alta', value: '135'},
|
|
215
|
+ {label: 'Toa Baja', value: '137'},
|
|
216
|
+ {label: 'Trujillo Alto', value: '139'},
|
|
217
|
+ {label: 'Utuado', value: '141'},
|
|
218
|
+ {label: 'Vega Alta', value: '143'},
|
|
219
|
+ {label: 'Vega Baja', value: '145'},
|
|
220
|
+ {label: 'Vieques', value: '147'},
|
|
221
|
+ {label: 'Villalba', value: '149'},
|
|
222
|
+ {label: 'Yabucoa', value: '151'},
|
|
223
|
+ {label: 'Yauco', value: '153'}
|
|
224
|
+ ]);
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+ return (
|
|
228
|
+ <View>
|
|
229
|
+ <DropDownPicker
|
|
230
|
+ open={openTable}
|
|
231
|
+ value={valueTable}
|
|
232
|
+ items={table}
|
|
233
|
+ setOpen={setOpenTable}
|
|
234
|
+ setValue={setValueTable}
|
|
235
|
+ setItems={setTable}
|
|
236
|
+ onChangeValue = {(valueTable) => {
|
|
237
|
+ updateTable(valueTable);
|
|
238
|
+ }}
|
|
239
|
+ onOpen = {() => {setOpenPueblo(false)}}
|
|
240
|
+ zIndex={3000}
|
|
241
|
+ zIndexInverse={1000}
|
|
242
|
+ placeholder="Tabla de Datos"
|
|
243
|
+ />
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+ <DropDownPicker
|
|
247
|
+ searchable={true}
|
|
248
|
+ open={openPueblo}
|
|
249
|
+ value={valuePueblo}
|
|
250
|
+ items={pueblo}
|
|
251
|
+ setOpen={setOpenPueblo}
|
|
252
|
+ setValue={setValuePueblo}
|
|
253
|
+ setItems={setPueblo}
|
|
254
|
+ onChangeValue = {(valuePueblo) => {
|
|
255
|
+ updatePueblo(valuePueblo);
|
|
256
|
+ }}
|
|
257
|
+ onOpen = {() => {setOpenTable(false)}}
|
|
258
|
+ zIndex={1000}
|
|
259
|
+ zIndexInverse={3000}
|
|
260
|
+ placeholder="Pueblo"
|
|
261
|
+ searchPlaceholder="Busqueda..."
|
|
262
|
+ />
|
|
263
|
+
|
|
264
|
+ </View>
|
|
265
|
+
|
|
266
|
+ );
|
|
267
|
+}
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+function updateTable(value){
|
|
272
|
+ table = value
|
|
273
|
+}
|
|
274
|
+
|
|
275
|
+function updatePueblo(value){
|
|
276
|
+ pueblo = value
|
|
277
|
+}
|
|
278
|
+
|
|
279
|
+//calls data query
|
|
280
|
+function loadDoc(query) {
|
|
281
|
+ console.log("load")
|
|
282
|
+ var xhttp = new XMLHttpRequest();
|
|
283
|
+ xhttp.onreadystatechange = function() {
|
|
284
|
+ if (this.readyState == 4) {
|
|
285
|
+ information = this.responseText;
|
|
286
|
+
|
|
287
|
+ if(this.status == 200){console.log("received response");organize()}
|
|
288
|
+ }
|
|
289
|
+ }
|
|
290
|
+ xhttp.open("GET", query, true);
|
|
291
|
+ xhttp.send(null);
|
|
292
|
+ }
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+function fetchData() {
|
|
296
|
+
|
|
297
|
+ var query = "https://api.census.gov/data/2020/acs/acs5/profile?get=group" + "(" + table + ")&for=county:" + pueblo + "&in=state:72"
|
|
298
|
+ if(pueblo && table)
|
|
299
|
+ {loadDoc(query)}
|
|
300
|
+
|
|
301
|
+ else
|
|
302
|
+ {Alert.alert("Please fill every parameter before calling!")}
|
|
303
|
+
|
|
304
|
+ }
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+function DataTable() {
|
|
309
|
+ let tableHead = ['Variable', 'Estimate', 'MoE']
|
|
310
|
+ let tableTitle = allTitle
|
|
311
|
+ let tableData = allData
|
|
312
|
+ return (
|
|
313
|
+ <View style={styles.tablecontainer}>
|
|
314
|
+ <Table borderStyle={{borderWidth: 1}}>
|
|
315
|
+ <Row data={tableHead} flexArr={[1, 2, 1, 1]} style={styles.head} textStyle={styles.tabletext}/>
|
|
316
|
+ <TableWrapper style={styles.wrapper}>
|
|
317
|
+ <Col data={tableTitle} style={styles.title} heightArr={[28,28]} textStyle={styles.tabletext}/>
|
|
318
|
+ <Rows data={tableData} flexArr={[2, 1, 1]} style={styles.row} textStyle={styles.tabletext}/>
|
|
319
|
+ </TableWrapper>
|
|
320
|
+ </Table>
|
|
321
|
+ </View>
|
|
322
|
+ )
|
|
323
|
+}
|
|
324
|
+
|
|
325
|
+//organize data make it pretty
|
|
326
|
+//add loading thing while this organizes all the data !!!
|
|
327
|
+
|
|
328
|
+function organize(){
|
|
329
|
+
|
|
330
|
+ let bigData = JSON.parse(information)
|
|
331
|
+ bigData = parse(bigData)
|
|
332
|
+ var variables = []
|
|
333
|
+ var estimates = []
|
|
334
|
+ var moe = []
|
|
335
|
+
|
|
336
|
+ let divData = bigData.split(",")
|
|
337
|
+ let num = Math.floor(divData.length/3) + 1
|
|
338
|
+ for(let i = num; i < Math.floor(divData.length/3*2); i++){
|
|
339
|
+ variables.push(divData[i])
|
|
340
|
+ estimates.push(divData[i+num])
|
|
341
|
+ moe.push(divData[i+num*1.5])
|
|
342
|
+
|
|
343
|
+ }
|
|
344
|
+
|
|
345
|
+ //console.log(variables)
|
|
346
|
+ //console.log(estimates)
|
|
347
|
+ //console.log(moe)
|
|
348
|
+ let tableContents = []
|
|
349
|
+ for(let i = 0; i < estimates.length; i++)
|
|
350
|
+ {
|
|
351
|
+ tableContents.push([estimates[i],moe[i]])
|
|
352
|
+ }
|
|
353
|
+
|
|
354
|
+ allTitle = variables
|
|
355
|
+ allData = tableContents
|
|
356
|
+
|
|
357
|
+ information = <DataTable />
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+ /*
|
|
361
|
+ var stringDiv = JSON.stringify(information)
|
|
362
|
+ stringDiv = stringDiv.replace('[[', '');
|
|
363
|
+ stringDiv = stringDiv.replace(']]', '');
|
|
364
|
+ stringDiv = stringDiv.split(',')
|
|
365
|
+ //create smaller array variables
|
|
366
|
+ let variables = []
|
|
367
|
+ let value = []
|
|
368
|
+ let est = []
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+ //theres a better way to do this but im not fixing it rn
|
|
372
|
+ for(let i = 0; i<stringDiv.length; i++){
|
|
373
|
+
|
|
374
|
+ if(i<stringDiv.length/3)
|
|
375
|
+ {variables.push(stringDiv[i])}
|
|
376
|
+ else if(i<stringDiv.length/3*2)
|
|
377
|
+ {value.push(stringDiv[i])}
|
|
378
|
+ else
|
|
379
|
+ {est.push(stringDiv[i])}
|
|
380
|
+ }
|
|
381
|
+
|
|
382
|
+ //anyways this to format it
|
|
383
|
+
|
|
384
|
+ console.log("vars:",variables)
|
|
385
|
+ console.log("val:",value)
|
|
386
|
+ console.log("est:",est)
|
|
387
|
+ */
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+}
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+function json_2_csv(information){
|
|
396
|
+
|
|
397
|
+ const csv = parse(obj);
|
|
398
|
+ console.log(csv);
|
|
399
|
+}
|
|
400
|
+
|
|
401
|
+//fix
|
|
402
|
+
|
|
403
|
+DropDownPicker.setListMode("SCROLLVIEW")
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+//data parsing goes here
|
|
407
|
+function getInfo(){
|
|
408
|
+ return information
|
|
409
|
+}
|
|
410
|
+
|
|
411
|
+//data display
|
|
412
|
+
|
|
413
|
+class DataButton extends React.Component{
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+ state = {
|
|
417
|
+ updated: 1,
|
|
418
|
+ notUpdated: 0
|
|
419
|
+ }
|
|
420
|
+
|
|
421
|
+ pullData = () => {fetchData(); this.setState({current: 1})}
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+ //the reason you need to press the button twice is bc the http request doesnt finish in time
|
|
425
|
+ //for information to be updated before its rerendered
|
|
426
|
+ componentDidUpdate(){
|
|
427
|
+ if(this.state.current == 1){
|
|
428
|
+ this.setState({current: 0})
|
|
429
|
+ }
|
|
430
|
+ }
|
|
431
|
+
|
|
432
|
+ state = {current: 0}
|
|
433
|
+
|
|
434
|
+ render() {
|
|
435
|
+ return(
|
|
436
|
+ <View style = {styles.container}>
|
|
437
|
+
|
|
438
|
+ <Pressable style={styles.buttons} onPress = {this.pullData}>
|
|
439
|
+ <Text style={styles.text}> Fetch Data</Text>
|
|
440
|
+ </Pressable>
|
|
441
|
+
|
|
442
|
+ <Text style={styles.sub}>{information}</Text>
|
|
443
|
+
|
|
444
|
+ </View>
|
|
445
|
+ );
|
|
446
|
+ }
|
|
447
|
+}
|
|
448
|
+
|
|
449
|
+export { Picker, updateTable, updatePueblo,loadDoc,fetchData,DataButton};
|