|
| 1 | +NASA Exoplanet Query App Solution |
| 2 | + |
| 3 | +To address the requirements and constraints of the NASA Exoplanet Query app, I propose the following solution: |
| 4 | + |
| 5 | +Data Loading and Storage |
| 6 | + |
| 7 | +To efficiently load the exoplanet CSV data, we can use the following approach: |
| 8 | + |
| 9 | +Use a library like pandas in Python to read the CSV file into a DataFrame. |
| 10 | +Convert the DataFrame into a JSON object using a library like csv2json. |
| 11 | +Store the JSON object in a data structure like a dictionary or a hash table for fast lookups. |
| 12 | +Data Structure and Search Mechanism |
| 13 | + |
| 14 | +To minimize the time required to query the exoplanet data, we can use the following approach: |
| 15 | + |
| 16 | +Use a data structure like a hash table or a trie to store the exoplanet data. |
| 17 | +Implement a search mechanism that uses the hash table or trie to quickly find matching exoplanets based on the selected query values. |
| 18 | +User Interface and Query Panel |
| 19 | + |
| 20 | +To implement the user interface and query panel, we can use the following approach: |
| 21 | + |
| 22 | +Use a web framework like React or Angular to create a user-friendly interface. |
| 23 | +Create a query panel with dropdowns for year of discovery, discovery method, host name, and discovery facility. |
| 24 | +Add 'Clear' and 'Search' buttons to the query panel. |
| 25 | +Use JavaScript events to handle user input and search queries. |
| 26 | +Results Panel and Data Display |
| 27 | + |
| 28 | +To display the matching exoplanet data in a tabular format, we can use the following approach: |
| 29 | + |
| 30 | +Use a library like react-table or angular-material-table to create a table component. |
| 31 | +Display only the queriable fields in the table. |
| 32 | +Use JavaScript events to handle user input and update the table data. |
| 33 | +Bonus Features |
| 34 | + |
| 35 | +To implement the bonus features, we can use the following approach: |
| 36 | + |
| 37 | +Use a library like react-router or angular-router to create hyperlinks to NASA's Confirmed Planet Overview Page. |
| 38 | +Use JavaScript events to handle user input and open the hyperlinks in a new browser tab. |
| 39 | +Use a library like react-sortable-table or angular-sortable-table to add icons and sorting functionality to the table. |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +example code |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +# ExoplanetQueryApp.js |
| 48 | +import React, { useState, useEffect } from 'react'; |
| 49 | +import axios from 'axios'; |
| 50 | + |
| 51 | +function ExoplanetQueryApp() { |
| 52 | + const [exoplanetData, setExoplanetData] = useState([]); |
| 53 | + const [queryValues, setQueryValues] = useState({ |
| 54 | + yearOfDiscovery: '', |
| 55 | + discoveryMethod: '', |
| 56 | + hostName: '', |
| 57 | + discoveryFacility: '', |
| 58 | + }); |
| 59 | + const [searchResults, setSearchResults] = useState([]); |
| 60 | + |
| 61 | + useEffect(() => { |
| 62 | + axios.get('https://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI') |
| 63 | + .then(response => { |
| 64 | + setExoplanetData(response.data); |
| 65 | + }) |
| 66 | + .catch(error => { |
| 67 | + console.error(error); |
| 68 | + }); |
| 69 | + }, []); |
| 70 | + |
| 71 | + const handleSearch = () => { |
| 72 | + const filteredData = exoplanetData.filter(exoplanet => { |
| 73 | + return ( |
| 74 | + (queryValues.yearOfDiscovery === '' || exoplanet.yearOfDiscovery === queryValues.yearOfDiscovery) && |
| 75 | + (queryValues.discoveryMethod === '' || exoplanet.discoveryMethod === queryValues.discoveryMethod) && |
| 76 | + (queryValues.hostName === '' || exoplanet.hostName === queryValues.hostName) && |
| 77 | + (queryValues.discoveryFacility === '' || exoplanet.discoveryFacility === queryValues.discoveryFacility) |
| 78 | + ); |
| 79 | + }); |
| 80 | + setSearchResults(filteredData); |
| 81 | + }; |
| 82 | + |
| 83 | + const handleClear = () => { |
| 84 | + setQueryValues({ |
| 85 | + yearOfDiscovery: '', |
| 86 | + discoveryMethod: '', |
| 87 | + hostName: '', |
| 88 | + discoveryFacility: '', |
| 89 | + }); |
| 90 | + setSearchResults([]); |
| 91 | + }; |
| 92 | + |
| 93 | + return ( |
| 94 | + <div> |
| 95 | + <h1>Exoplanet Query App</h1> |
| 96 | + <form> |
| 97 | + <label>Year of Discovery:</label> |
| 98 | + <select value={queryValues.yearOfDiscovery} onChange={e => setQueryValues({ ...queryValues, yearOfDiscovery: e.target.value })}> |
| 99 | + <option value="">Select a year</option> |
| 100 | + {exoplanetData.map(exoplanet => ( |
| 101 | + <option key={exoplanet.yearOfDiscovery} value={exoplanet.yearOfDiscovery}>{exoplanet.yearOfDiscovery}</option> |
| 102 | + ))} |
| 103 | + </select> |
| 104 | + <br /> |
| 105 | + <label>Discovery Method:</label> |
| 106 | + <select value={queryValues.discoveryMethod} onChange={e => setQueryValues({ ...queryValues, discoveryMethod: e.target.value })}> |
| 107 | + <option value="">Select a method</option> |
| 108 | + {exoplanetData.map(exoplanet => ( |
| 109 | + <option key={exoplanet.discoveryMethod} value={exoplanet |
0 commit comments