No Description

App.js 10KB

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