Aucune description

App.js 12KB

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