No Description

App.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. import React, {useState, useEffect, Component} from 'react';
  2. import { View, Image, StyleSheet, Text, Button, ScrollView, Pressable, Linking} from 'react-native';
  3. import DropDownPicker from 'react-native-dropdown-picker';
  4. import { parse } from 'json2csv';
  5. import { Table, TableWrapper, Row, Rows, Col, Cols, Cell } from 'react-native-table-component';
  6. //import JSON;
  7. //import { Dataframe, readJSON } from "danfojs";
  8. //where data will be put
  9. var organizedData
  10. //where data will be stored
  11. var information = "data goes here"
  12. //organize data make it pretty
  13. //add loading thing while this organizes all the data !!!
  14. function organize(){
  15. var stringDiv = JSON.parse(information)
  16. var csv = parse(stringDiv)
  17. console.log(csv)
  18. //var csv is the variable with the thing you just pulled
  19. //put function and data cleaning here
  20. //just make sure you change the return value in 'getInfo()'
  21. //so it returns the actual organized table
  22. //or make getInfo() organize the table as well
  23. //and return that organized table
  24. //i leave this to you
  25. }
  26. //fix
  27. DropDownPicker.setListMode("SCROLLVIEW")
  28. //data query variables (global)
  29. const queryBase = "https://api.census.gov/data/2020/acs/acs5/profile?get=group"
  30. const queryEnd = "&in=state:72"
  31. var table = ""
  32. var pueblo = ""
  33. function updateTable(value){
  34. table = value
  35. }
  36. function updatePueblo(value){
  37. pueblo = value
  38. }
  39. //calls data query
  40. function loadDoc(query) {
  41. var xhttp = new XMLHttpRequest();
  42. xhttp.onreadystatechange = function() {
  43. if (this.readyState == 4 && this.status == 200) {
  44. information = this.responseText;
  45. organize()
  46. }
  47. };
  48. xhttp.open("GET", query, true);
  49. xhttp.send();
  50. }
  51. //"https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP02PR)&for=county:127&in=state:72"
  52. function fetchData() {
  53. console.log("fetching data")
  54. var query = queryBase + "(" + table + ")&for=county:" + pueblo + queryEnd
  55. if(pueblo && table)
  56. {loadDoc(query)}
  57. else
  58. {Alert.alert("Please fill every parameter before calling!")}
  59. }
  60. //change this to an external css file later
  61. const styles = StyleSheet.create({
  62. buttons: {
  63. flexDirection: 'row',
  64. justifyContent: 'center',
  65. marginTop: 40,
  66. marginBottom: 30,
  67. margin: 30,
  68. borderColor: "white",
  69. borderRadius: 8,
  70. paddingVertical: 15,
  71. paddingHorizontal: 30,
  72. backgroundColor: "#008CBA",
  73. marginTop: 0
  74. },
  75. buttonContainer: {
  76. flexDirection: 'column',
  77. backgroundColor: 'black',
  78. // alignItems: 'center',
  79. justifyContent: 'center',
  80. paddingTop:5,
  81. marginTop: 30,
  82. },
  83. container: {
  84. flexDirection: 'column',
  85. justifyContent: 'center',
  86. backgroundColor: 'black',
  87. alignItems: 'center',
  88. justifyContent: 'center',
  89. paddingTop:20,
  90. marginTop: 20,
  91. },
  92. containerbackground:{
  93. backgroundColor: '#063970'
  94. },
  95. intro: {
  96. fontWeight: "bold",
  97. color:"#beb2c8",
  98. fontSize: 30,
  99. },
  100. intro2: {
  101. fontWeight: "bold",
  102. color:"#beb2c8",
  103. fontSize: 20,
  104. },
  105. sub: {
  106. color:"#beb2c8",
  107. fontWeight: "bold",
  108. fontSize: 15,
  109. paddingBottom:10,
  110. },
  111. Navsub: {
  112. color:"#beb2c8",
  113. fontWeight: "bold",
  114. fontSize: 30,
  115. paddingBottom:10,
  116. alignItems: 'center',
  117. },
  118. scrollView:{
  119. marginHorizontal: 20
  120. },
  121. listItem:{
  122. fontSize: 30,
  123. color: "white",
  124. textDecorationLines: "underline"
  125. },
  126. listButtons:{
  127. fontSize: 15,
  128. color: "white",
  129. textDecorationLines: "underline"
  130. },
  131. buttonsVer: {
  132. flexDirection: 'column',
  133. justifyContent: 'center',
  134. marginTop: 40,
  135. marginBottom: 30,
  136. margin: 30,
  137. borderColor: "grey",
  138. }
  139. });
  140. //default button press
  141. const handlePress = () => false
  142. //data parsing goes here
  143. function getInfo(){
  144. //console.log(information[6])
  145. if(!information)
  146. {Alert.alert("Please try again later! Error retriving data")}
  147. else
  148. {return information}
  149. }
  150. //data display
  151. class DataButton extends React.Component{
  152. state = {
  153. click: false
  154. }
  155. pullData = () => {fetchData(); this.setState({click: true})}
  156. render() {
  157. return(
  158. <View>
  159. <Button
  160. onPress = {this.pullData}
  161. title = "Fetch Data"
  162. color = "black"
  163. />
  164. <Text style={styles.sub}>{getInfo()}</Text>
  165. </View>
  166. );}
  167. }
  168. //picker test
  169. function Picker() {
  170. //table to pick from
  171. const [openTable, setOpenTable] = useState(false);
  172. const [valueTable, setValueTable] = useState(null);
  173. const [table, setTable] = useState([
  174. {label:'DP02PR', value: 'DP02PR'},
  175. {label:'DP03', value: 'DP03'},
  176. {label:'DP04', value: 'DP04'},
  177. {label:'DP05', value: 'DP05'},
  178. ]);
  179. //cambiar pueblo
  180. //pueblo
  181. const [openPueblo, setOpenPueblo] = useState(false);
  182. const [valuePueblo, setValuePueblo] = useState(null);
  183. const [pueblo, setPueblo] = useState([
  184. {label: 'Adjuntas', value: '001'},
  185. {label: 'Aguada', value: '003'},
  186. {label: 'Aguadillas', value: '005'},
  187. {label: 'Aguas Buenas', value: '007'},
  188. {label: 'Aibonito', value: '009'},
  189. {label: 'Añasco', value: '011'},
  190. {label: 'Arecibo', value: '013'},
  191. {label: 'Arroyo', value: '015'},
  192. {label: 'Barceloneta', value: '017'},
  193. {label: 'Barranquitas', value: '019'},
  194. {label: 'Bayamón', value: '021'},
  195. {label: 'Cabo Rojo', value: '023'},
  196. {label: 'Caguas', value: '025'},
  197. {label: 'Camuy', value: '027'},
  198. {label: 'Canóvanas', value: '029'},
  199. {label: 'Carolina', value: '031'},
  200. {label: 'Cataño', value: '033'},
  201. {label: 'Cayey', value: '035'},
  202. {label: 'Ceiba', value: '037'},
  203. {label: 'Ciales', value: '039'},
  204. {label: 'Cidra', value: '041'},
  205. {label: 'Coamo', value: '043'},
  206. {label: 'Comerío', value: '045'},
  207. {label: 'Corozal', value: '047'},
  208. {label: 'Culebra', value: '049'},
  209. {label: 'Dorado', value: '051'},
  210. {label: 'Fajardo', value: '053'},
  211. {label: 'Florida', value: '054'},
  212. {label: 'Guánica', value: '055'},
  213. {label: 'Guayama', value: '057'},
  214. {label: 'Guayanilla', value: '059'},
  215. {label: 'Guaynabo', value: '061'},
  216. {label: 'Gurabo', value: '063'},
  217. {label: 'Hatillo', value: '065'},
  218. {label: 'Hormigueros', value: '067'},
  219. {label: 'Humacao', value: '069'},
  220. {label: 'Isabela', value: '071'},
  221. {label: 'Jayuya', value: '073'},
  222. {label: 'Juana Díaz', value: '075'},
  223. {label: 'Juncos', value: '077'},
  224. {label: 'Lajas', value: '079'},
  225. {label: 'Lares', value: '081'},
  226. {label: 'Las Marías', value: '083'},
  227. {label: 'Las Piedras', value: '085'},
  228. {label: 'Loíza', value: '087'},
  229. {label: 'Luquillo', value: '089'},
  230. {label: 'Manatí', value: '091'},
  231. {label: 'Maricao', value: '093'},
  232. {label: 'Maunabo', value: '095'},
  233. {label: 'Mayagüez', value: '097'},
  234. {label: 'Moca', value: '099'},
  235. {label: 'Morovis', value: '101'},
  236. {label: 'Naguabo', value: '103'},
  237. {label: 'Naranjito', value: '105'},
  238. {label: 'Orocovis', value: '107'},
  239. {label: 'Patillas', value: '109'},
  240. {label: 'Peñuelas', value: '111'},
  241. {label: 'Ponce', value: '113'},
  242. {label: 'Quebradillas', value: '115'},
  243. {label: 'Rincón', value: '117'},
  244. {label: 'Río Grande', value: '119'},
  245. {label: 'Sabana Grande', value: '121'},
  246. {label: 'Salinas', value: '123'},
  247. {label: 'San Germán', value: '125'},
  248. {label: 'San Juan', value: '127'},
  249. {label: 'San Lorenzo', value: '129'},
  250. {label: 'San Sebastián', value: '131'},
  251. {label: 'Santa Isabel', value: '133'},
  252. {label: 'Toa Alta', value: '135'},
  253. {label: 'Toa Baja', value: '137'},
  254. {label: 'Trujillo Alto', value: '139'},
  255. {label: 'Utuado', value: '141'},
  256. {label: 'Vega Alta', value: '143'},
  257. {label: 'Vega Baja', value: '145'},
  258. {label: 'Vieques', value: '147'},
  259. {label: 'Villalba', value: '149'},
  260. {label: 'Yabucoa', value: '151'},
  261. {label: 'Yauco', value: '153'}
  262. ]);
  263. //add a thing here to select year to take info from
  264. //add a dropdown in here
  265. return (
  266. <View>
  267. <DropDownPicker
  268. open={openTable}
  269. value={valueTable}
  270. items={table}
  271. setOpen={setOpenTable}
  272. setValue={setValueTable}
  273. setItems={setTable}
  274. onChangeValue = {(valueTable) => {
  275. updateTable(valueTable);
  276. }}
  277. onOpen = {() => {setOpenPueblo(false)}}
  278. zIndex={3000}
  279. zIndexInverse={1000}
  280. placeholder="Tabla de Datos"
  281. />
  282. <DropDownPicker
  283. searchable={true}
  284. open={openPueblo}
  285. value={valuePueblo}
  286. items={pueblo}
  287. setOpen={setOpenPueblo}
  288. setValue={setValuePueblo}
  289. setItems={setPueblo}
  290. onChangeValue = {(valuePueblo) => {
  291. updatePueblo(valuePueblo);
  292. }}
  293. onOpen = {() => {setOpenTable(false)}}
  294. zIndex={1000}
  295. zIndexInverse={3000}
  296. placeholder="Pueblo"
  297. searchPlaceholder="Busqueda..."
  298. />
  299. </View>
  300. );
  301. }
  302. //actual application
  303. class App extends React.Component {
  304. //Note: if prop-types could not be found within the project
  305. //run on terminal "npm install --save proptypes"
  306. // constructor(props) {
  307. // super(props);
  308. // this.setData = {
  309. // HeadTable: ['Head1', 'Head2', 'Head3', 'Head4', 'Head5'],
  310. // DataTable: [
  311. // ['1', '2', '3', '4', '5'],
  312. // ['a', 'b', 'c', 'd', 'e'],
  313. // ['1', '2', '3', '4', '5'],
  314. // ['a', 'b', 'c', 'd', 'e'],
  315. // ['1', '2', '3', '4', '5']
  316. // ]
  317. // }
  318. // }
  319. //the text at the end of a page gets cut off if anyone knows how to fix that?
  320. vars = {
  321. welcome:
  322. <View style = {styles.containerbackground}>
  323. <View style = {styles.container}>
  324. <Text style={styles.intro}>BIENVENIDO!!!!</Text>
  325. <Image source={require('./Logo.jpeg')} />
  326. </View>
  327. <View style = {styles.container}>
  328. <Text style={styles.sub}>Aqui podra mantenerse al tanto con las
  329. ultimas noticias relacionadas al censo y tambien verificar
  330. las tablas por municipio.</Text>
  331. </View>
  332. <View style = {styles.container}>
  333. <Text style={styles.intro2}>Contactenos:</Text>
  334. <Text style={styles.sub}>Prof: Hernando Mattei Torres
  335. <Button onPress={() => Linking.openURL('mailto:hernando.mattei@upr.edu') }
  336. title="e-mail" /></Text>
  337. <Text style={styles.sub}>Angelica Rosario Santos
  338. <Button onPress={() => Linking.openURL('mailto:angelica.rosario2@upr.edu') }
  339. title="e-mail" /></Text>
  340. <Text style={styles.sub}>Data from:</Text>
  341. <Image source={require('./census-logos.png')} />
  342. <Button onPress={() => Linking.openURL('https://data.census.gov/profile?q=United+States&g=0100000US') }
  343. title="United States Census page" />
  344. </View>
  345. </View>
  346. ,
  347. newsView:
  348. <View style = {styles.containerbackground}>
  349. <ScrollView style={styles.scrollView}>
  350. <View style = {styles.container}>
  351. <Text style={styles.intro}>Noticias</Text>
  352. <Image source={require('./Logo.jpeg')} />
  353. </View>
  354. </ScrollView>
  355. </View>,
  356. dataOp:
  357. <View style = {styles.containerbackground}>
  358. <ScrollView nestedScrollEnabled = {true} style={styles.scrollView}>
  359. <View style = {styles.container}>
  360. <Text style={styles.intro}>DATA VIEWING PROJECT</Text>
  361. <Picker />
  362. <Image source={require('./testimg.gif')} />
  363. <DataButton />
  364. <Text style={styles.sub}>blehhhhhh bleh bleh bleh bleh bleh blehhhhhhhhhhhhhhhhh </Text>
  365. <View style={styles.container}>
  366. {/* <Table borderStyle={{borderWidth: 1, borderColor: '#ffa1d2'}}>
  367. <Row data={state.HeadTable} style={styles.HeadStyle} textStyle={styles.TableText}/>
  368. <Rows data={state.DataTable} textStyle={styles.TableText}/>
  369. </Table> */}
  370. </View>
  371. </View>
  372. </ScrollView></View>
  373. }
  374. //current state
  375. state = {current: this.vars.welcome}
  376. //state changing functions
  377. setHome = () => this.setState({ current: this.vars.welcome })
  378. setData = () => this.setState({current: this.vars.dataOp})
  379. setNews = () => this.setState({ current: this.vars.newsView })
  380. //render app
  381. render() {
  382. return (
  383. <View>
  384. <View style = {styles.containerbackground}>
  385. <ScrollView style={styles.scrollView}>
  386. <View style = {styles.buttonContainer}>
  387. <Text style={styles.Navsub}> Demographic Data Viewer</Text>
  388. <Text style={styles.sub}> Navegador</Text>
  389. <Pressable style = {styles.buttons} onPress={this.setNews}>
  390. <Button
  391. title = "Noticias"
  392. color = "white"
  393. />
  394. </Pressable>
  395. <Pressable style = {styles.buttons} onPress={this.setData}>
  396. <Button
  397. title = "Datos"
  398. color = "white"
  399. />
  400. </Pressable>
  401. {this.state.current}
  402. </View>
  403. </ScrollView>
  404. </View>
  405. </View>
  406. );
  407. }
  408. }
  409. export default App