andrea.nieves7 1 year ago
parent
commit
eed927458e
1 changed files with 61 additions and 5 deletions
  1. 61
    5
      Datos.js

+ 61
- 5
Datos.js View File

@@ -1,8 +1,14 @@
1 1
 import React, {useState} from 'react';
2 2
 import { View, Text, Pressable, StyleSheet, Alert} from 'react-native';
3 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'
4 6
 //import {styles} from "./styles"
5 7
   
8
+  
9
+var allData
10
+var allTitle
11
+  
6 12
 const styles = StyleSheet.create({
7 13
 	
8 14
 	buttons: {
@@ -103,6 +109,12 @@ const styles = StyleSheet.create({
103 109
 	  letterSpacing: 0.25,
104 110
 	  color: 'white',
105 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' }
106 118
   });  
107 119
 var table = ""
108 120
 var pueblo = ""
@@ -282,7 +294,7 @@ function loadDoc(query) {
282 294
 		
283 295
 function fetchData() {
284 296
             
285
-        var query = "http://127.0.0.1:5378/table?table=" + table + "&municipality=" + pueblo 
297
+        var query = "https://api.census.gov/data/2020/acs/acs5/profile?get=group" + "(" + table + ")&for=county:" + pueblo + "&in=state:72"
286 298
         if(pueblo && table)
287 299
         {loadDoc(query)}
288 300
 
@@ -293,14 +305,57 @@ function fetchData() {
293 305
 
294 306
 
295 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
+
296 325
 //organize data make it pretty
297 326
 //add loading thing while this organizes all the data !!!
298 327
 
299 328
 function organize(){
300 329
 	
301
-	console.log(information)
302
-	
303 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
+	
304 359
 	
305 360
 	/*
306 361
 	var stringDiv = JSON.stringify(information)
@@ -334,6 +389,9 @@ function organize(){
334 389
 	
335 390
 }
336 391
 
392
+
393
+
394
+
337 395
 function json_2_csv(information){
338 396
 
339 397
 	const csv = parse(obj);
@@ -366,9 +424,7 @@ class DataButton extends React.Component{
366 424
 	//the reason you need to press the button twice is bc the http request doesnt finish in time
367 425
 	//for information to be updated before its rerendered
368 426
 	componentDidUpdate(){
369
-		console.log(this.state)
370 427
 		if(this.state.current == 1){
371
-			console.log("updating")
372 428
 			this.setState({current: 0})
373 429
 		}
374 430
 	}