No Description

App.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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 { parse } from 'json2csv';
  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: "grey",
  69. borderRadius: 8,
  70. padding: (30, 16),
  71. backgroundColor: "#008CBA",
  72. marginTop: 0
  73. },
  74. buttonContainer: {
  75. flexDirection: 'column',
  76. backgroundColor: 'black',
  77. alignItems: 'center',
  78. justifyContent: 'center',
  79. paddingTop:100,
  80. marginTop: 20,
  81. },
  82. container: {
  83. flexDirection: 'column',
  84. justifyContent: 'center',
  85. backgroundColor: 'black',
  86. alignItems: 'center',
  87. justifyContent: 'center',
  88. paddingTop:20,
  89. marginTop: 20,
  90. },
  91. containerbackground:{
  92. backgroundColor: '#063970'
  93. },
  94. intro: {
  95. fontWeight: "bold",
  96. color:"#beb2c8",
  97. fontSize: 30,
  98. },
  99. sub: {
  100. color:"#beb2c8",
  101. fontWeight: "bold",
  102. fontSize: 15,
  103. paddingBottom:10,
  104. },
  105. Navsub: {
  106. color:"#beb2c8",
  107. fontWeight: "bold",
  108. fontSize: 30,
  109. paddingBottom:10,
  110. },
  111. scrollView:{
  112. marginHorizontal: 20
  113. },
  114. listItem:{
  115. fontSize: 30,
  116. color: "white",
  117. textDecorationLines: "underline"
  118. },
  119. listButtons:{
  120. fontSize: 15,
  121. color: "white",
  122. textDecorationLines: "underline"
  123. },
  124. buttonsVer: {
  125. flexDirection: 'column',
  126. justifyContent: 'center',
  127. marginTop: 40,
  128. marginBottom: 30,
  129. margin: 30,
  130. borderColor: "grey",
  131. }
  132. });
  133. //default button press
  134. const handlePress = () => false
  135. //data parsing goes here
  136. function getInfo(){
  137. //console.log(information[6])
  138. return information
  139. }
  140. //data display
  141. class DataButton extends React.Component{
  142. state = {
  143. click: false
  144. }
  145. pullData = () => {fetchData(); this.setState({click: true})}
  146. render() {
  147. return(
  148. <View>
  149. <Button
  150. onPress = {this.pullData}
  151. title = "Fetch Data"
  152. color = "black"
  153. />
  154. <Text style={styles.sub}>{getInfo()}</Text>
  155. </View>
  156. );}
  157. }
  158. //picker test
  159. function Picker() {
  160. //table to pick from
  161. const [openTable, setOpenTable] = useState(false);
  162. const [valueTable, setValueTable] = useState(null);
  163. const [table, setTable] = useState([
  164. {label:'DP02PR', value: 'DP02PR'},
  165. {label:'DP03', value: 'DP03'},
  166. {label:'DP04', value: 'DP04'},
  167. {label:'DP05', value: 'DP05'},
  168. ]);
  169. //cambiar pueblo
  170. //pueblo
  171. const [openPueblo, setOpenPueblo] = useState(false);
  172. const [valuePueblo, setValuePueblo] = useState(null);
  173. const [pueblo, setPueblo] = useState([
  174. {label: 'Adjuntas', value: '001'},
  175. {label: 'Aguada', value: '003'},
  176. {label: 'Aguadillas', value: '005'},
  177. {label: 'Aguas Buenas', value: '007'},
  178. {label: 'Aibonito', value: '009'},
  179. {label: 'Añasco', value: '011'},
  180. {label: 'Arecibo', value: '013'},
  181. {label: 'Arroyo', value: '015'},
  182. {label: 'Barceloneta', value: '017'},
  183. {label: 'Barranquitas', value: '019'},
  184. {label: 'Bayamón', value: '021'},
  185. {label: 'Cabo Rojo', value: '023'},
  186. {label: 'Caguas', value: '025'},
  187. {label: 'Camuy', value: '027'},
  188. {label: 'Canóvanas', value: '029'},
  189. {label: 'Carolina', value: '031'},
  190. {label: 'Cataño', value: '033'},
  191. {label: 'Cayey', value: '035'},
  192. {label: 'Ceiba', value: '037'},
  193. {label: 'Ciales', value: '039'},
  194. {label: 'Cidra', value: '041'},
  195. {label: 'Coamo', value: '043'},
  196. {label: 'Comerío', value: '045'},
  197. {label: 'Corozal', value: '047'},
  198. {label: 'Culebra', value: '049'},
  199. {label: 'Dorado', value: '051'},
  200. {label: 'Fajardo', value: '053'},
  201. {label: 'Florida', value: '054'},
  202. {label: 'Guánica', value: '055'},
  203. {label: 'Guayama', value: '057'},
  204. {label: 'Guayanilla', value: '059'},
  205. {label: 'Guaynabo', value: '061'},
  206. {label: 'Gurabo', value: '063'},
  207. {label: 'Hatillo', value: '065'},
  208. {label: 'Hormigueros', value: '067'},
  209. {label: 'Humacao', value: '069'},
  210. {label: 'Isabela', value: '071'},
  211. {label: 'Jayuya', value: '073'},
  212. {label: 'Juana Díaz', value: '075'},
  213. {label: 'Juncos', value: '077'},
  214. {label: 'Lajas', value: '079'},
  215. {label: 'Lares', value: '081'},
  216. {label: 'Las Marías', value: '083'},
  217. {label: 'Las Piedras', value: '085'},
  218. {label: 'Loíza', value: '087'},
  219. {label: 'Luquillo', value: '089'},
  220. {label: 'Manatí', value: '091'},
  221. {label: 'Maricao', value: '093'},
  222. {label: 'Maunabo', value: '095'},
  223. {label: 'Mayagüez', value: '097'},
  224. {label: 'Moca', value: '099'},
  225. {label: 'Morovis', value: '101'},
  226. {label: 'Naguabo', value: '103'},
  227. {label: 'Naranjito', value: '105'},
  228. {label: 'Orocovis', value: '107'},
  229. {label: 'Patillas', value: '109'},
  230. {label: 'Peñuelas', value: '111'},
  231. {label: 'Ponce', value: '113'},
  232. {label: 'Quebradillas', value: '115'},
  233. {label: 'Rincón', value: '117'},
  234. {label: 'Río Grande', value: '119'},
  235. {label: 'Sabana Grande', value: '121'},
  236. {label: 'Salinas', value: '123'},
  237. {label: 'San Germán', value: '125'},
  238. {label: 'San Juan', value: '127'},
  239. {label: 'San Lorenzo', value: '129'},
  240. {label: 'San Sebastián', value: '131'},
  241. {label: 'Santa Isabel', value: '133'},
  242. {label: 'Toa Alta', value: '135'},
  243. {label: 'Toa Baja', value: '137'},
  244. {label: 'Trujillo Alto', value: '139'},
  245. {label: 'Utuado', value: '141'},
  246. {label: 'Vega Alta', value: '143'},
  247. {label: 'Vega Baja', value: '145'},
  248. {label: 'Vieques', value: '147'},
  249. {label: 'Villalba', value: '149'},
  250. {label: 'Yabucoa', value: '151'},
  251. {label: 'Yauco', value: '153'}
  252. ]);
  253. //add a thing here to select year to take info from
  254. //add a dropdown in here
  255. return (
  256. <View>
  257. <DropDownPicker
  258. open={openTable}
  259. value={valueTable}
  260. items={table}
  261. setOpen={setOpenTable}
  262. setValue={setValueTable}
  263. setItems={setTable}
  264. onChangeValue = {(valueTable) => {
  265. updateTable(valueTable);
  266. }}
  267. onOpen = {() => {setOpenPueblo(false)}}
  268. zIndex={3000}
  269. zIndexInverse={1000}
  270. placeholder="Tabla de Datos"
  271. />
  272. <DropDownPicker
  273. searchable={true}
  274. open={openPueblo}
  275. value={valuePueblo}
  276. items={pueblo}
  277. setOpen={setOpenPueblo}
  278. setValue={setValuePueblo}
  279. setItems={setPueblo}
  280. onChangeValue = {(valuePueblo) => {
  281. updatePueblo(valuePueblo);
  282. }}
  283. onOpen = {() => {setOpenTable(false)}}
  284. zIndex={1000}
  285. zIndexInverse={3000}
  286. placeholder="Pueblo"
  287. searchPlaceholder="Busqueda..."
  288. />
  289. </View>
  290. );
  291. }
  292. //actual application
  293. class App extends React.Component {
  294. //the text at the end of a page gets cut off if anyone knows how to fix that?
  295. vars = {
  296. welcome:
  297. <View style = {styles.containerbackground}>
  298. <ScrollView style={styles.scrollView}>
  299. <View style = {styles.container}>
  300. <Text style={styles.intro}>BIENVENIDO!!!!</Text>
  301. <Image source={require('./Logo.jpeg')} />
  302. </View>
  303. <View style = {styles.container}>
  304. <Text style={styles.sub}>Aqui podra mantenerse al tanto con las
  305. ultimas noticias relacionadas al censo y tambien verificar
  306. las tablas por municipio.</Text>
  307. </View>
  308. </ScrollView>
  309. </View>,
  310. newsView:
  311. <View style = {styles.containerbackground}>
  312. <ScrollView style={styles.scrollView}>
  313. <View style = {styles.container}>
  314. <Text style={styles.intro}>Noticias</Text>
  315. <Image source={require('./Logo.jpeg')} />
  316. </View>
  317. </ScrollView></View>,
  318. dataOp:
  319. <View style = {styles.containerbackground}>
  320. <ScrollView nestedScrollEnabled = {true} style={styles.scrollView}>
  321. <View style = {styles.container}>
  322. <Text style={styles.intro}>DATA VIEWING PROJECT</Text>
  323. <Picker />
  324. <Image source={require('./testimg.gif')} />
  325. <DataButton />
  326. <Text style={styles.sub}>blehhhhhh bleh bleh bleh bleh bleh blehhhhhhhhhhhhhhhhh </Text>
  327. </View>
  328. </ScrollView></View>
  329. }
  330. //current state
  331. state = {current: this.vars.welcome}
  332. //state changing functions
  333. setHome = () => this.setState({ current: this.vars.welcome })
  334. setData = () => this.setState({current: this.vars.dataOp})
  335. setNews = () => this.setState({ current: this.vars.newsView })
  336. //render app
  337. render() {
  338. return (
  339. <View>
  340. <View style = {styles.containerbackground}>
  341. <View style = {styles.buttonContainer}>
  342. <Text style={styles.Navsub}> Demographic Data Viewer</Text>
  343. <Text style={styles.sub}> Navegador</Text>
  344. <View style = {styles.buttons}>
  345. <Button
  346. onPress = {this.setNews}
  347. title = "Noticias"
  348. color = "rgba(255, 0, 0, 0)"
  349. />
  350. <Button
  351. onPress = {this.setData}
  352. title = "Datos"
  353. color = "rgba(255, 0, 0, 0)"
  354. />
  355. </View>
  356. {this.state.current}
  357. </View>
  358. </View>
  359. </View>
  360. );
  361. }
  362. }
  363. export default App