Update Exploring Near Earth Objects project and add Meme Generator project
This commit is contained in:
@@ -21,6 +21,7 @@ class NEODatabase:
|
||||
help fetch NEOs by primary designation or by name and to help speed up
|
||||
querying for close approaches that match criteria.
|
||||
"""
|
||||
|
||||
def __init__(self, neos, approaches):
|
||||
"""Create a new `NEODatabase`.
|
||||
|
||||
@@ -42,9 +43,16 @@ class NEODatabase:
|
||||
self._neos = neos
|
||||
self._approaches = approaches
|
||||
|
||||
# TODO: What additional auxiliary data structures will be useful?
|
||||
self._neo_by_designation = {neo.designation: neo for neo in self._neos}
|
||||
self._neo_by_name = {neo.name: neo for neo in self._neos}
|
||||
|
||||
# TODO: Link together the NEOs and their close approaches.
|
||||
for approach in self._approaches:
|
||||
# Link approach.neo to the corresponding NearEarthObject, namely
|
||||
# the one whose designation matches approach._designation.
|
||||
approach.neo = self._neo_by_designation[approach._designation]
|
||||
# Add this approach to the corresponding NearEarthObject's
|
||||
# .approaches collection.
|
||||
self._neo_by_designation[approach._designation].approaches.append(approach)
|
||||
|
||||
def get_neo_by_designation(self, designation):
|
||||
"""Find and return an NEO by its primary designation.
|
||||
@@ -59,8 +67,7 @@ class NEODatabase:
|
||||
:param designation: The primary designation of the NEO to search for.
|
||||
:return: The `NearEarthObject` with the desired primary designation, or `None`.
|
||||
"""
|
||||
# TODO: Fetch an NEO by its primary designation.
|
||||
return None
|
||||
return self._neo_by_designation.get(designation, None)
|
||||
|
||||
def get_neo_by_name(self, name):
|
||||
"""Find and return an NEO by its name.
|
||||
@@ -76,8 +83,7 @@ class NEODatabase:
|
||||
:param name: The name, as a string, of the NEO to search for.
|
||||
:return: The `NearEarthObject` with the desired name, or `None`.
|
||||
"""
|
||||
# TODO: Fetch an NEO by its name.
|
||||
return None
|
||||
return self._neo_by_name.get(name, None)
|
||||
|
||||
def query(self, filters=()):
|
||||
"""Query close approaches to generate those that match a collection of filters.
|
||||
@@ -93,6 +99,7 @@ class NEODatabase:
|
||||
: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:
|
||||
yield approach
|
||||
cases = [filter_i(approach) for filter_i in filters]
|
||||
if all(cases):
|
||||
yield approach
|
||||
|
||||
Reference in New Issue
Block a user