Нема описа

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. return (
  254. <View>
  255. <DropDownPicker
  256. open={openTable}
  257. value={valueTable}
  258. items={table}
  259. setOpen={setOpenTable}
  260. setValue={setValueTable}
  261. setItems={setTable}
  262. onChangeValue = {(valueTable) => {
  263. updateTable(valueTable);
  264. }}
  265. onOpen = {() => {setOpenPueblo(false)}}
  266. zIndex={3000}
  267. zIndexInverse={1000}
  268. placeholder="Tabla de Datos"
  269. />
  270. <DropDownPicker
  271. searchable={true}
  272. open={openPueblo}
  273. value={valuePueblo}
  274. items={pueblo}
  275. setOpen={setOpenPueblo}
  276. setValue={setValuePueblo}
  277. setItems={setPueblo}
  278. onChangeValue = {(valuePueblo) => {
  279. updatePueblo(valuePueblo);
  280. }}
  281. onOpen = {() => {setOpenTable(false)}}
  282. zIndex={1000}
  283. zIndexInverse={3000}
  284. placeholder="Pueblo"
  285. searchPlaceholder="Busqueda..."
  286. />
  287. </View>
  288. );
  289. }
  290. //actual application
  291. class App extends React.Component {
  292. //the text at the end of a page gets cut off if anyone knows how to fix that?
  293. vars = {
  294. welcome:
  295. <View style = {styles.containerbackground}>
  296. <ScrollView style={styles.scrollView}>
  297. <View style = {styles.container}>
  298. <Text style={styles.intro}>BIENVENIDO!!!!</Text>
  299. <Image source={require('./Logo.jpeg')} />
  300. </View>
  301. <View style = {styles.container}>
  302. <Text style={styles.sub}>Aqui podra mantenerse al tanto con las
  303. ultimas noticias relacionadas al censo y tambien verificar
  304. las tablas por municipio.</Text>
  305. </View>
  306. </ScrollView>
  307. </View>,
  308. newsView:
  309. <View style = {styles.containerbackground}>
  310. <ScrollView style={styles.scrollView}>
  311. <View style = {styles.container}>
  312. <Text style={styles.intro}>Noticias</Text>
  313. <Image source={require('./Logo.jpeg')} />
  314. </View>
  315. </ScrollView></View>,
  316. dataOp:
  317. <View style = {styles.containerbackground}>
  318. <ScrollView nestedScrollEnabled = {true} style={styles.scrollView}>
  319. <View style = {styles.container}>
  320. <Text style={styles.intro}>DATA VIEWING PROJECT</Text>
  321. <Picker />
  322. <Image source={require('./testimg.gif')} />
  323. <DataButton />
  324. <Text style={styles.sub}>blehhhhhh bleh bleh bleh bleh bleh blehhhhhhhhhhhhhhhhh </Text>
  325. </View>
  326. </ScrollView></View>
  327. }
  328. //current state
  329. state = {current: this.vars.welcome}
  330. //state changing functions
  331. setHome = () => this.setState({ current: this.vars.welcome })
  332. setData = () => this.setState({current: this.vars.dataOp})
  333. setNews = () => this.setState({ current: this.vars.newsView })
  334. //render app
  335. render() {
  336. return (
  337. <View>
  338. <View style = {styles.containerbackground}>
  339. <View style = {styles.buttonContainer}>
  340. <Text style={styles.Navsub}> Demographic Data Viewer</Text>
  341. <Text style={styles.sub}> Navegador</Text>
  342. <View style = {styles.buttons}>
  343. <Button
  344. onPress = {this.setNews}
  345. title = "Noticias"
  346. color = "rgba(255, 0, 0, 0)"
  347. />
  348. <Button
  349. onPress = {this.setData}
  350. title = "Datos"
  351. color = "rgba(255, 0, 0, 0)"
  352. />
  353. </View>
  354. {this.state.current}
  355. </View>
  356. </View>
  357. </View>
  358. );
  359. }
  360. }
  361. export default App