No Description

App.js 10KB

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