diff --git a/mongiris/api.py b/mongiris/api.py index cfc70b8792819b5dc0ddca1304131589bf0d1428..e1ca9c2aa2830f3124522ee276a1aa15747c761f 100755 --- a/mongiris/api.py +++ b/mongiris/api.py @@ -15,10 +15,10 @@ max_timeout = 3 # delay before connection timeout class Mongiris: """ - The Mongiris class is an API to manipulate data from the MongoDB `dbinsee` datatase. + The Mongiris class is an API to manipulate data from a MongoDB database containing neighbourhoods (GeoJSON format). Several methods accepts a 'collection' parameter for flexibility (i.e., be able to query other collections than the - iris collection). + neighbourhoods collection). Most methods convert resulting documents from the BSON format (MongoDB) to JSON. This mainly avoids the issue of ObjectId type (for MongoDB '_id' field). @@ -29,11 +29,12 @@ class Mongiris: Examples of usages, including testing geospatial queries, are available in `tests/api_tests.py`. - An example of IRIS following the GeoJSON format is provided in `data/example-iris.json`. + An example of neighbourhood following the GeoJSON format is provided in `data/example-neighbourhood.json`. Args: - db: the database name to connect to (string) - collection: the collection name containing neighbourhoods (string) + db: the MongoDB database name to connect to (string) + coll_neighbourhoods: the name of the neighbourhoods collection, inside database db (string) + coll_indic: the name of the indicators collection, inside database db (string) Additional resources: @@ -45,13 +46,14 @@ class Mongiris: """ - def __init__(self, db, collection): + def __init__(self, db, coll_neighbourhoods, coll_indic='collindic'): logging.basicConfig(format='[%(levelname)s] - %(name)s - %(asctime)s : %(message)s') self.logger = logging.getLogger() self.logger.setLevel(logging.INFO) self.connection, self.connection_status = self.init_connection() # default connection on 'localhost', 27017 self.database = self.connection[db] # link to database - self.collection_neighbourhoods = self.database[collection] # link to collection + self.collection_neighbourhoods = self.database[coll_neighbourhoods] # link to neighbourhoods collection + self.collection_indicators = self.database[coll_indic] # link to indicators collection (used for prediction) @staticmethod def bson_to_json(doc_bson): diff --git a/mongiris/data/example-iris.json b/mongiris/data/example-neighbourhood.json similarity index 100% rename from mongiris/data/example-iris.json rename to mongiris/data/example-neighbourhood.json