暫無描述

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. import React, {useState, useEffect, Component} from 'react';
  2. import { View, Image, StyleSheet, Text, Button, ScrollView, Pressable, Linking} from 'react-native';
  3. import DropDownPicker from 'react-native-dropdown-picker';
  4. import { parse } from 'json2csv';
  5. //import { Table, TableWrapper, Row, Rows, Col, Cols, Cell } from 'react-native-table-component';
  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. if(information == ""){Alert.alert("No data response found.")}}
  74. else
  75. {Alert.alert("Please fill every parameter before calling!")}
  76. }
  77. //change this to an external css file later
  78. const styles = StyleSheet.create({
  79. buttons: {
  80. flexDirection: 'row',
  81. justifyContent: 'center',
  82. marginTop: 40,
  83. marginBottom: 30,
  84. margin: 30,
  85. borderColor: "white",
  86. borderRadius: 8,
  87. padding: (30, 16),
  88. backgroundColor: "black",
  89. marginTop: 0
  90. },
  91. buttonContainer: {
  92. flexDirection: 'column',
  93. backgroundColor: 'black',
  94. alignItems: 'center',
  95. justifyContent: 'center',
  96. paddingTop:5,
  97. marginTop: 30,
  98. },
  99. container: {
  100. flexDirection: 'column',
  101. justifyContent: 'center',
  102. backgroundColor: '#f0f8ff',
  103. alignItems: 'center',
  104. justifyContent: 'center',
  105. paddingTop:20,
  106. marginTop: 20,
  107. },
  108. containerbackground:{
  109. backgroundColor: '#f0f8ff'
  110. },
  111. intro: {
  112. fontWeight: "bold",
  113. color:"#black",
  114. fontSize: 30,
  115. },
  116. intro2: {
  117. fontWeight: "bold",
  118. color:"#beb2c8",
  119. fontSize: 20,
  120. },
  121. sub: {
  122. color:"#black",
  123. fontWeight: "bold",
  124. fontSize: 15,
  125. paddingBottom:10,
  126. },
  127. Navsub: {
  128. color:"#black",
  129. fontWeight: "bold",
  130. fontSize: 30,
  131. paddingBottom:10,
  132. alignItems: 'center',
  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. //Note: if prop-types could not be found within the project
  319. //run on terminal "npm install --save proptypes"
  320. // constructor(props) {
  321. // super(props);
  322. // this.setData = {
  323. // HeadTable: ['Head1', 'Head2', 'Head3', 'Head4', 'Head5'],
  324. // DataTable: [
  325. // ['1', '2', '3', '4', '5'],
  326. // ['a', 'b', 'c', 'd', 'e'],
  327. // ['1', '2', '3', '4', '5'],
  328. // ['a', 'b', 'c', 'd', 'e'],
  329. // ['1', '2', '3', '4', '5']
  330. // ]
  331. // }
  332. // }
  333. //the text at the end of a page gets cut off if anyone knows how to fix that?
  334. vars = {
  335. welcome:
  336. <View style = {styles.containerbackground}>
  337. <ScrollView style={styles.scrollView}>
  338. <View style = {styles.containerbackground}>
  339. <View style = {styles.container}>
  340. <Text style={styles.intro}>Bienvenido!</Text>
  341. </View>
  342. <View style = {styles.container}>
  343. <Text style={styles.sub}>Aqui podra mantenerse al tanto con las
  344. ultimas noticias relacionadas al censo y tambien verificar
  345. las tablas por municipio.</Text>
  346. </View>
  347. </ScrollView>
  348. </View>,
  349. newsView:
  350. <View style = {styles.containerbackground}>
  351. <ScrollView style={styles.scrollView}>
  352. <View style = {styles.container}>
  353. <Text style={styles.intro}>Noticias</Text>
  354. <Image source={require('./Logo.jpeg')} />
  355. </View>
  356. </ScrollView>
  357. </View>,
  358. dataOp:
  359. <View style = {styles.containerbackground}>
  360. <ScrollView nestedScrollEnabled = {true} style={styles.scrollView}>
  361. <View style = {styles.container}>
  362. <Text style={styles.intro}>DATA VIEWING PROJECT</Text>
  363. <Picker />
  364. <DataButton />
  365. <Text style={styles.sub}>blehhhhhh bleh bleh bleh bleh bleh blehhhhhhhhhhhhhhhhh </Text>
  366. <View style={styles.container}>
  367. {/* <Table borderStyle={{borderWidth: 1, borderColor: '#ffa1d2'}}>
  368. <Row data={state.HeadTable} style={styles.HeadStyle} textStyle={styles.TableText}/>
  369. <Rows data={state.DataTable} textStyle={styles.TableText}/>
  370. </Table> */}
  371. </View>
  372. </View>
  373. </ScrollView></View>
  374. }
  375. //current state
  376. state = {current: this.vars.welcome}
  377. //state changing functions
  378. setHome = () => this.setState({ current: this.vars.welcome })
  379. setData = () => this.setState({current: this.vars.dataOp})
  380. setNews = () => this.setState({ current: this.vars.newsView })
  381. //render app
  382. render() {
  383. return (
  384. <View>
  385. <View style = {styles.containerbackground}>
  386. <ScrollView style={styles.scrollView}>
  387. <View style = {styles.buttonContainer}>
  388. <Text style={styles.Navsub}> Demographic Data Viewer</Text>
  389. <Text style={styles.sub}> Navegador</Text>
  390. <Pressable style = {styles.buttons} onPress={this.setNews}>
  391. <Button
  392. title = "Noticias"
  393. color = "white"
  394. />
  395. </Pressable>
  396. <Pressable style = {styles.buttons} onPress={this.setData}>
  397. <Button
  398. title = "Datos"
  399. color = "white"
  400. />
  401. </Pressable>
  402. {this.state.current}
  403. </View>
  404. </ScrollView>
  405. </View>
  406. </View>
  407. );
  408. }
  409. }
  410. export default App