generation du html folium

develop
gwen 2 years ago
parent 33bdbab985
commit 6ff8ec6b74

@ -44,6 +44,7 @@ class Acte(Document):
ref_acte = StringField(required=True, max_length=100)
xmlcontent = StringField(required=True) # no max_length
place = DictField()
folium = StringField(required=False) # no max_length
def db_connect(storage_ip, db_name, mongodb_admin, mongodb_password):
@ -52,7 +53,7 @@ def db_connect(storage_ip, db_name, mongodb_admin, mongodb_password):
password = urllib.parse.quote_plus(mongodb_password)
mongodb_url = f"mongodb://{username}:{password}@{storage_ip}:27017/"
#mongodb_url = "mongodb://{}:27017/".format(storage_ip)
logger.info("connection to the mongodb server")
#logger.info("connection to the mongodb server")
# pymongo settings
# myclient = pymongo.MongoClient(mongodb_url)
myclient = connect(db=db_name, host=mongodb_url, authentication_source='admin', alias="default")
@ -61,15 +62,10 @@ 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:
#logger.info(storage_ip)
#logger.info(db_name)
#logger.info(db_collection_name)
jsondatasets = jsondoc.datasets
housename = jsondoc._housename
db_connect(storage_ip, db_name, mongodb_admin, mongodb_password)
#actesdb = myclient[db_name]
#actes_collection = actesdb[db_collection_name]
for dataset_filenamestem, dataset in jsondatasets.items():
# a manual load is required here, because
@ -77,7 +73,7 @@ def populate_mongo(jsondoc: JSONDataSetCollection, storage_ip: str, db_name: str
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)
@ -92,7 +88,7 @@ def load_houses(yamldoc: YAMLDataSet, storage_ip: str, db_name: str, mongodb_adm
for house_dict in yamldoc['houses'].values():
house_dict['_id'] = house_dict['name']
logger.info("inserting: " + str(house_dict))
#logger.info("inserting: " + str(house_dict))
#houses_col.insert_one(house_dict)
house_entry = House(**house_dict)
house_entry.save()

@ -2,6 +2,7 @@ import logging
from pathlib import Path
from typing import Dict
import folium
from kedro.framework.session import KedroSession
from actesdataset import EtreeXMLDataSet, BsXMLDataSet, JSONDataSet
@ -63,6 +64,18 @@ def make_json_collection(datasetcol: BsXMLDataSetCollection) -> JSONDataSetColle
output_datasets.datasets[dataset_filenamestem] = output_xmldataset
return output_datasets
def _make_map(latitude, longitude, popup):
m = folium.Map(location=[latitude, longitude], zoom_start=12,
width=800,
height=600,
)
folium.Marker(
location=[latitude, longitude],
popup=popup,
icon=folium.Icon(icon="cloud"),
).add_to(m)
return m.get_root()._repr_html_()
def add_xmlcontent_tojson(jsondoc: JSONDataSetCollection, xmlcontent: TextDataSetCollection) -> JSONDataSetCollection:
"adds xmlcontent to the json"
@ -81,7 +94,9 @@ def add_xmlcontent_tojson(jsondoc: JSONDataSetCollection, xmlcontent: TextDataSe
# xmlds._load()
document['xmlcontent'] = xmldatasets[dataset_filenamestem]._load()
if document['place']['latitude'] is not None:
document['folium'] = "FIXME"
document['folium'] = _make_map(document['place']['latitude'],
document['place']['longitude'],
document['place']['name'])
else:
document['folium'] = None
else:

@ -10,3 +10,4 @@ lxml~=4.9.3
nbstripout~=0.4
pymongo~=4.5.0
mongoengine~=0.27.0
folium~=0.14.0

Loading…
Cancel
Save