def main(): """Run the main script.""" parser, inspect_parser, query_parser = make_parser() args = parser.parse_args() # Extract data from the data files into structured Python objects. database = NEODatabase(load_neos(args.neofile), load_approaches(args.cadfile)) # Run the chosen subcommand. try: if args.cmd == 'inspect': inspect(database, pdes=args.pdes, name=args.name, verbose=args.verbose) elif args.cmd == 'query': query(database, args) elif args.cmd == 'interactive': NEOShell(database, inspect_parser, query_parser, aggressive=args.aggressive).cmdloop() except UnboundLocalError: print("Supplied bad name or designation. Please check your inputs.")
def __init__(self, neos=load_neos(), approaches=load_approaches()): """Create a new `NEODatabase`. As a precondition, this constructor assumes that the collections of NEOs and close approaches haven't yet been linked - that is, the `.approaches` attribute of each `NearEarthObject` resolves to an empty collection, and the `.neo` attribute of each `CloseApproach` is None. However, each `CloseApproach` has an attribute (`._designation`) that matches the `.designation` attribute of the corresponding NEO. This constructor modifies the supplied NEOs and close approaches to link them together - after it's done, the `.approaches` attribute of each NEO has a collection of that NEO's close approaches, and the `.neo` attribute of each close approach references the appropriate NEO. :param neos: A collection of `NearEarthObject`s. :param approaches: A collection of `CloseApproach`es. """ self._neos = neos self._approaches = approaches self._designation_neo_dict = {} self._name_neo_dict = {} for neo in self._neos: self._designation_neo_dict[neo.designation] = neo if neo.name: self._name_neo_dict[neo.name] = neo for approach in self._approaches: neo = self._designation_neo_dict[approach._designation] approach.neo = neo neo.approaches.append(approach)
def build_results(n): neos = tuple(load_neos(TEST_NEO_FILE)) approaches = tuple(load_approaches(TEST_CAD_FILE)) # Only needed to link together these objects. NEODatabase(neos, approaches) return approaches[:n]
def build_results(n): neos = load_neos(TEST_NEO_FILE) approaches = load_approaches(TEST_CAD_FILE) # Only needed to link together these objects. db = NEODatabase(neos, approaches) return db.get_approaches_list()[:n]
def main(): """Run the main script.""" parser, inspect_parser, query_parser = make_parser() args = parser.parse_args() # Extract data from the data files into structured Python objects. database = NEODatabase(load_neos(args.neofile), load_approaches(args.cadfile)) # Run the chosen subcommand. if args.cmd == 'inspect': inspect(database, pdes=args.pdes, name=args.name, verbose=args.verbose) elif args.cmd == 'query': query(database, args) elif args.cmd == 'interactive': NEOShell(database, inspect_parser, query_parser, aggressive=args.aggressive).cmdloop()
def setUpClass(cls): cls.neos = load_neos(TEST_NEO_FILE) cls.approaches = load_approaches(TEST_CAD_FILE) cls.db = NEODatabase(cls.neos, cls.approaches)
provided filters. If no arguments are provided, generate all known close approaches. The `CloseApproach` objects are generated in internal order, which isn't guaranteed to be sorted meaninfully, although is often sorted by time. :param filters: A collection of filters capturing user-specified criteria. :return: A stream of matching `CloseApproach` objects. """ # TODO: Generate `CloseApproach` objects that match all of the filters. for approach in self.approaches_dict: mapped = map(lambda x: x(approach), filters) if all(flag is True for flag in mapped): yield approach # Testing neos_dict = load_neos() print(len(neos_dict)) cads_dict = load_approaches() print(len(cads_dict)) neo_db = NEODatabase(neos_dict, cads_dict) neo_db.get_neo_by_designation('433') neo_db.get_neo_by_name('Eros').approaches
def setUpClass(cls): cls.neos = load_neos(TEST_NEO_FILE) cls.approaches = load_approaches(TEST_CAD_FILE)
def setUpClass(cls): cls.neos = load_neos(TEST_NEO_FILE) cls.neos_by_designation = {neo.designation: neo for neo in cls.neos}
def memoize(function): """Create cache file for expedited retrieval in interactive mode.""" function._cache = {} @functools.wraps(function) def wrapper(*args, **kwargs): key = (args, tuple(kwargs.items())) if key not in function._cache: function._cache[key] = function(*args, **kwargs) return function._cache[key] return function._cache[key] return wrapper neos = load_neos() approaches = load_approaches() class NEODatabase: """Sets up Database of Near Earth Object classes. Connects them with their close approach classes. """ def __init__(self, neos, approaches): """Define neo based on specified attributes.""" self._neos = neos self._approaches = approaches self.designation_neo_dict = {} self.name_neo_dict = {}
def setUpClass(cls): cls.neos = load_neos(TEST_NEO_FILE) cls.neos_by_designation = {des: neo for des, neo in cls.neos.items()}
from extract import load_neos, load_approaches from database import NEODatabase from filters import valid_attribute, limit import operator import math import datetime import operator neos = load_neos('./tests/test-neos-2020.csv') cads = load_approaches('./tests/test-cad-2020.json') neo_database = NEODatabase(neos, cads) result = neo_database.get_neo_by_designation('1865') #print(result) #print(get_attribute(an_approach, operator.eq, value, attribute)) #print(neo_1036.approaches) #print(neo_database.get_neo_by_name('Ganymed'))