No Description

App.js 12KB

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