From 1810676cf2b160f724d5379ff544df0b81babe19 Mon Sep 17 00:00:00 2001 From: Duchateau Fabien <fabien.duchateau@univ-lyon1.fr> Date: Mon, 4 Jan 2021 22:48:50 +0100 Subject: [PATCH] [M] added coll_indic to constructor signature --- mongiris/api.py | 16 +++++++++------- ...mple-iris.json => example-neighbourhood.json} | 0 2 files changed, 9 insertions(+), 7 deletions(-) rename mongiris/data/{example-iris.json => example-neighbourhood.json} (100%) diff --git a/mongiris/api.py b/mongiris/api.py index cfc70b8..e1ca9c2 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 -- GitLab