Browse Source

Merge branch 'SomeBranch' of https://git.ccom.uprrp.edu/CCOM4030/AnCaJuLu into SomeBranch

"added noticias code"
Luis Ortiz 1 year ago
parent
commit
8ac943746d
2 changed files with 86 additions and 119 deletions
  1. 1
    1
      App.js
  2. 85
    118
      Datos.js

+ 1
- 1
App.js View File

@@ -143,4 +143,4 @@ vars = {
143 143
 }
144 144
 
145 145
 
146
-export default App
146
+export default App

+ 85
- 118
Datos.js View File

@@ -1,116 +1,19 @@
1 1
 import React, {useState} from 'react';
2
-import { View, Text, Pressable, StyleSheet} from 'react-native';
2
+import { View, Text, Pressable, StyleSheet, Alert} from 'react-native';
3 3
 import DropDownPicker from 'react-native-dropdown-picker';
4
-//import {styles} from "./styles"
4
+import { Table, TableWrapper, Row, Rows, Col, Cols, Cell } from 'react-native-table-component';
5
+import { parse } from 'json2csv'
6
+import {styles} from "./styles"
5 7
   
6
-const styles = StyleSheet.create({
7
-	
8
-	buttons: {
9
-		flexDirection: 'row',
10
-		justifyContent: 'center',
11
-		marginTop: 40,
12
-		marginBottom: 30,
13
-		margin: 30,
14
-		borderColor: "grey",
15
-		borderRadius: 8,
16
-		padding: (30, 16),
17
-		backgroundColor: "black",
18
-		marginTop: 0,
19
-	}, 
20
-	navContainer: {
21
-	  flexDirection: 'row',
22
-	  justifyContent: "space-evenly",
23
-	  borderColor: "black",
24
-	  borderWidth: 5,
25
-	  borderRadius: 8,
26
-	  paddingTop: 20,
27
-	  backgroundColor: "gray",
28
-	  marginTop: 5,
29
-  }, 
30
-	buttonContainer: {
31
-	  flexDirection: 'column',
32
-	  backgroundColor: '#f0f8ff',
33
-	  alignItems: 'center',
34
-	  justifyContent: 'center',
35
-	  paddingTop:100,
36
-	  marginTop: 40,
37
-	},
38
-	container: {
39
-	  flexDirection: 'column',
40
-	  justifyContent: 'center',
41
-	  backgroundColor: '#f0f8ff',
42
-	  alignItems: 'center',
43
-	  justifyContent: 'center',
44
-	  paddingTop:20,
45
-	  marginTop: 20,
46
-	},
47
-	containerbackground:{
48
-	  
49
-	  backgroundColor: '#f0f8ff'
50
-	},
51
-	intro: {
52
-		fontWeight: "bold",
53
-		color:"#black",
54
-		fontSize: 30,
55
-	},
56
-  
57
-	sub: {
58
-	  color:"#black",  
59
-	  fontWeight: "bold",
60
-	  fontSize: 15,
61
-	  paddingBottom:10,
62
-  },
63 8
   
64
-	Navsub: {
65
-		color:"#black",  
66
-		fontWeight: "bold",
67
-		fontSize: 30,
68
-		paddingBottom:10,
69
-	},
70
-	scrollView:{
71
-		marginHorizontal: 20
72
-	},
73
-	listItem:{
74
-		fontSize: 30,
75
-		color: "white",
76
-		textDecorationLines: "underline"
77
-	},
78
-	listButtons:{
79
-		fontSize: 15,
80
-		color: "white",
81
-		textDecorationLines: "underline"  
82
-	},
83
-	buttonsVer: {
84
-		flexDirection: 'column',
85
-		justifyContent: 'center',
86
-		marginTop: 40,
87
-		marginBottom: 30,
88
-		margin: 30,
89
-		borderColor: "grey",
90
-	},
91
-	bottom: {
92
-	  flex: 0.3,
93
-	  backgroundColor: "gray",
94
-	  borderWidth: 5,
95
-	  alignItems: 'center',
96
-	  borderBottomLeftRadius: 20,
97
-	  borderBottomRightRadius: 20,
98
-	
99
-  },text: {
100
-	  fontSize: 16,
101
-	  lineHeight: 21,
102
-	  fontWeight: 'bold',
103
-	  letterSpacing: 0.25,
104
-	  color: 'white',
105
-	},
106
-  });  
107
-const queryBase = "https://api.census.gov/data/2020/acs/acs5/profile?get=group"
108
-const queryEnd = "&in=state:72"
9
+var allData
10
+var allTitle
11
+
109 12
 var table = ""
110 13
 var pueblo = ""
111 14
 
112 15
 //where data will be stored
113
-var information = "data goes here"
16
+var information
114 17
 
115 18
 function Picker() {    
116 19
 
@@ -268,38 +171,86 @@ function updatePueblo(value){
268 171
         
269 172
 //calls data query
270 173
 function loadDoc(query) {
174
+	console.log("load")
271 175
     var xhttp = new XMLHttpRequest();
272 176
     xhttp.onreadystatechange = function() {
273
-        if (this.readyState == 4 && this.status == 200) {
177
+        if (this.readyState == 4) {
274 178
             information = this.responseText;
275
-            organize()
179
+			
180
+			if(this.status == 200){console.log("received response");organize()}
276 181
             }
277
-        };
278
-        
182
+        }
279 183
         xhttp.open("GET", query, true);
280
-        xhttp.send();  
184
+        xhttp.send(null);  
281 185
         }
282 186
         
283
-    function fetchData() {
187
+		
188
+function fetchData() {
284 189
             
285
-        console.log("fetching data")
286
-        var query = queryBase + "(" + table + ")&for=county:" + pueblo + queryEnd 
287
-        
190
+        var query = "https://api.census.gov/data/2020/acs/acs5/profile?get=group" + "(" + table + ")&for=county:" + pueblo + "&in=state:72"
288 191
         if(pueblo && table)
289 192
         {loadDoc(query)}
290 193
 
291 194
         else
292
-            {Alert.alert("Please fill every parameter before calling!")}
195
+        {Alert.alert("Please fill every parameter before calling!")}
293 196
             
294 197
     }
295 198
 
296 199
 
297 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
+
298 218
 //organize data make it pretty
299 219
 //add loading thing while this organizes all the data !!!
300 220
 
301 221
 function organize(){
302 222
 	
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
+	
252
+	
253
+	/*
303 254
 	var stringDiv = JSON.stringify(information)
304 255
 	stringDiv = stringDiv.replace('[[', '');
305 256
 	stringDiv = stringDiv.replace(']]', '');
@@ -326,10 +277,14 @@ function organize(){
326 277
 	console.log("vars:",variables)
327 278
 	console.log("val:",value)
328 279
 	console.log("est:",est)
280
+	*/
329 281
 
330 282
 	
331 283
 }
332 284
 
285
+
286
+
287
+
333 288
 function json_2_csv(information){
334 289
 
335 290
 	const csv = parse(obj);
@@ -350,12 +305,24 @@ function getInfo(){
350 305
 
351 306
 class DataButton extends React.Component{
352 307
 	
308
+	
353 309
 	state = {
354
-		click: false
310
+		updated: 1,
311
+		notUpdated: 0
355 312
 	}
356 313
 	
357
-	pullData = () => {fetchData(); this.setState({click: true})}
314
+	pullData = () => {fetchData(); this.setState({current: 1})}
315
+	
316
+	
317
+	//the reason you need to press the button twice is bc the http request doesnt finish in time
318
+	//for information to be updated before its rerendered
319
+	componentDidUpdate(){
320
+		if(this.state.current == 1){
321
+			this.setState({current: 0})
322
+		}
323
+	}
358 324
 	
325
+	state = {current: 0}
359 326
 	
360 327
 	render() {
361 328
 		return(
@@ -365,7 +332,7 @@ class DataButton extends React.Component{
365 332
                         <Text style={styles.text}> Fetch Data</Text>
366 333
                     </Pressable>
367 334
                    
368
-                        <Text style={styles.sub}>{getInfo()}</Text> 
335
+                        <Text style={styles.sub}>{information}</Text> 
369 336
                     
370 337
             </View>
371 338
 	    );