Skip to content
Snippets Groups Projects
Commit 1810676c authored by Duchateau Fabien's avatar Duchateau Fabien
Browse files

[M] added coll_indic to constructor signature

parent 2a63a2c7
No related branches found
No related tags found
No related merge requests found
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment