Browse Source

Cambios en la pantalla de Datos

juan.hernandez41 1 year ago
parent
commit
800ce1413b
1 changed files with 55 additions and 9 deletions
  1. 55
    9
      Datos.js

+ 55
- 9
Datos.js View File

@@ -1,8 +1,13 @@
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
6 11
 
7 12
 var table = ""
8 13
 var pueblo = ""
@@ -182,7 +187,7 @@ function loadDoc(query) {
182 187
 		
183 188
 function fetchData() {
184 189
             
185
-        var query = "http://127.0.0.1:5378/table?table=" + table + "&municipality=" + pueblo 
190
+        var query = "https://api.census.gov/data/2020/acs/acs5/profile?get=group" + "(" + table + ")&for=county:" + pueblo + "&in=state:72"
186 191
         if(pueblo && table)
187 192
         {loadDoc(query)}
188 193
 
@@ -193,14 +198,57 @@ function fetchData() {
193 198
 
194 199
 
195 200
 
201
+function DataTable() {
202
+    let tableHead = ['Variable', 'Estimate', 'MoE']
203
+    let tableTitle = allTitle
204
+    let tableData = allData
205
+    return (
206
+      <View style={styles.tablecontainer}>
207
+        <Table borderStyle={{borderWidth: 1}}>
208
+          <Row data={tableHead} flexArr={[1, 2, 1, 1]} style={styles.head} textStyle={styles.tabletext}/>
209
+          <TableWrapper style={styles.wrapper}>
210
+            <Col data={tableTitle} style={styles.title} heightArr={[28,28]} textStyle={styles.tabletext}/>
211
+            <Rows data={tableData} flexArr={[2, 1, 1]} style={styles.row} textStyle={styles.tabletext}/>
212
+          </TableWrapper>
213
+        </Table>
214
+      </View>
215
+    )
216
+}
217
+
196 218
 //organize data make it pretty
197 219
 //add loading thing while this organizes all the data !!!
198 220
 
199 221
 function organize(){
200
-
201
-	console.log(information)
202 222
 	
203 223
 	let bigData = JSON.parse(information)
224
+	bigData = parse(bigData)
225
+	var variables = []
226
+	var estimates = []
227
+	var moe = []
228
+	
229
+	let divData = bigData.split(",")
230
+	let num = Math.floor(divData.length/3) + 1
231
+	for(let i = num; i < Math.floor(divData.length/3*2); i++){
232
+		variables.push(divData[i])
233
+		estimates.push(divData[i+num])
234
+		moe.push(divData[i+num*1.5])
235
+		
236
+	}
237
+	
238
+	//console.log(variables)
239
+	//console.log(estimates)
240
+	//console.log(moe)
241
+	let tableContents = []
242
+	for(let i = 0; i < estimates.length; i++)
243
+	{
244
+		tableContents.push([estimates[i],moe[i]])
245
+	}
246
+	
247
+	allTitle = variables
248
+	allData = tableContents
249
+	
250
+	information = <DataTable />
251
+	
204 252
 	
205 253
 	/*
206 254
 	var stringDiv = JSON.stringify(information)
@@ -234,6 +282,9 @@ function organize(){
234 282
 	
235 283
 }
236 284
 
285
+
286
+
287
+
237 288
 function json_2_csv(information){
238 289
 
239 290
 	const csv = parse(obj);
@@ -247,10 +298,7 @@ DropDownPicker.setListMode("SCROLLVIEW")
247 298
 
248 299
 //data parsing goes here
249 300
 function getInfo(){
250
-	if(!information)
251
-	{Alert.alert("Please try again later! Error retriving data")}
252
-	else
253
-	{return information}
301
+	return information
254 302
 }
255 303
 
256 304
 //data display
@@ -269,9 +317,7 @@ class DataButton extends React.Component{
269 317
 	//the reason you need to press the button twice is bc the http request doesnt finish in time
270 318
 	//for information to be updated before its rerendered
271 319
 	componentDidUpdate(){
272
-		console.log(this.state)
273 320
 		if(this.state.current == 1){
274
-			console.log("updating")
275 321
 			this.setState({current: 0})
276 322
 		}
277 323
 	}