|
|
|
|
@ -6,6 +6,7 @@ from typing import Dict
|
|
|
|
|
|
|
|
|
|
from mongoengine import connect
|
|
|
|
|
from mongoengine import Document, StringField, DictField, ListField
|
|
|
|
|
#import folium
|
|
|
|
|
|
|
|
|
|
from kedro.framework.session import KedroSession
|
|
|
|
|
from kedro.extras.datasets.yaml import YAMLDataSet
|
|
|
|
|
@ -17,10 +18,15 @@ from actesdataset import JSONDataSetCollection
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#class FoliumMap(Document):
|
|
|
|
|
# globalmap = StringField(required=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Helpers(Document):
|
|
|
|
|
house_trigram = DictField()
|
|
|
|
|
prince_bigram = DictField()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Database schemas
|
|
|
|
|
class House(Document):
|
|
|
|
|
"_id is the name"
|
|
|
|
|
@ -42,7 +48,7 @@ class Acte(Document):
|
|
|
|
|
date_time = StringField(required=True, max_length=15)
|
|
|
|
|
filename = StringField(required=True, max_length=100)
|
|
|
|
|
ref_acte = StringField(required=True, max_length=100)
|
|
|
|
|
xmlcontent = StringField(required=True) # no max_length
|
|
|
|
|
xmlcontent = StringField(required=True) # no max_length
|
|
|
|
|
place = DictField()
|
|
|
|
|
folium = StringField(required=False) # no max_length
|
|
|
|
|
|
|
|
|
|
@ -61,26 +67,45 @@ def db_connect(storage_ip, db_name, mongodb_admin, mongodb_password):
|
|
|
|
|
|
|
|
|
|
# pipeline functions
|
|
|
|
|
def populate_mongo(jsondoc: JSONDataSetCollection, storage_ip: str, db_name: str, db_collection_name: str, mongodb_admin: str, mongodb_password: str) -> None:
|
|
|
|
|
|
|
|
|
|
"loads the json for an acte"
|
|
|
|
|
jsondatasets = jsondoc.datasets
|
|
|
|
|
housename = jsondoc._housename
|
|
|
|
|
|
|
|
|
|
db_connect(storage_ip, db_name, mongodb_admin, mongodb_password)
|
|
|
|
|
|
|
|
|
|
#places = []
|
|
|
|
|
|
|
|
|
|
for dataset_filenamestem, dataset in jsondatasets.items():
|
|
|
|
|
# a manual load is required here, because
|
|
|
|
|
# the dataset **is not** registered in kedro's catalog
|
|
|
|
|
json_document = dataset._load()
|
|
|
|
|
json_document["_id"] = json_document["filename"]
|
|
|
|
|
acte_entry = Acte(**json_document)
|
|
|
|
|
#logger.info("adding entry: " + json_document["filename"])
|
|
|
|
|
logger.info("... adding entry: " + json_document["filename"])
|
|
|
|
|
acte_entry.save()
|
|
|
|
|
#res = actes_collection.insert_one(document)
|
|
|
|
|
#logger.info(res.inserted_id)
|
|
|
|
|
# properly closes the db connection
|
|
|
|
|
# myclient.close()
|
|
|
|
|
|
|
|
|
|
## place location in the folium global map
|
|
|
|
|
#if json_document['place'].get('latitude') is not None:
|
|
|
|
|
# places.append(json_document['place'])
|
|
|
|
|
|
|
|
|
|
# folium global map
|
|
|
|
|
# add to mongo db
|
|
|
|
|
#m = folium.Map(location=[46.603354, 1.888334], zoom_start=6)
|
|
|
|
|
#folium.TileLayer(name="Géolocalisation des actes",control=False).add_to(m)
|
|
|
|
|
#for place in places:
|
|
|
|
|
# folium.Marker(
|
|
|
|
|
# location=[float(place['latitude']), float(place['longitude'])],
|
|
|
|
|
# popup=place['name']
|
|
|
|
|
# #icon=folium.Icon(icon="cloud")
|
|
|
|
|
# #icon=folium.Icon(color='lightgray', icon='home', prefix='fa')
|
|
|
|
|
# ).add_to(m)
|
|
|
|
|
#globalmap = m.get_root()._repr_html_()
|
|
|
|
|
##globalmap = m._repr_html_()
|
|
|
|
|
#folium_map = FoliumMap(globalmap=globalmap)
|
|
|
|
|
#folium_map.save()
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_houses(yamldoc: YAMLDataSet, storage_ip: str, db_name: str, mongodb_admin: str, mongodb_password: str) -> None:
|
|
|
|
|
|
|
|
|
|
@ -93,16 +118,13 @@ def load_houses(yamldoc: YAMLDataSet, storage_ip: str, db_name: str, mongodb_adm
|
|
|
|
|
house_entry = House(**house_dict)
|
|
|
|
|
house_entry.save()
|
|
|
|
|
|
|
|
|
|
# properly closes the db connection
|
|
|
|
|
# FIXME with MongoClient() as client
|
|
|
|
|
#myclient.close()
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
def load_helpers(house_trigram: JSONDataSet, prince_bigram: JSONDataSet,
|
|
|
|
|
|
|
|
|
|
def load_helpers(house_trigram: JSONDataSet, prince_bigram: JSONDataSet,
|
|
|
|
|
storage_ip: str, db_name: str, mongodb_admin: str, mongodb_password: str) -> None:
|
|
|
|
|
|
|
|
|
|
db_connect(storage_ip, db_name, mongodb_admin, mongodb_password)
|
|
|
|
|
|
|
|
|
|
helper_entry = Helpers(house_trigram=house_trigram, prince_bigram=prince_bigram)
|
|
|
|
|
helper_entry.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|