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

[MD] update documentation

parent e2cf5f70
No related branches found
No related tags found
No related merge requests found
source diff could not be displayed: it is too large. Options to address this: view the blob.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.6.3" />
<title>Package mongiris documentation</title>
<meta name="description" content="" />
<link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'>
<link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'>
<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet">
<style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase;cursor:pointer}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Package <code>mongiris</code></h1>
</header>
<section id="section-intro">
The package <code>mongiris</code> consists of two modules:
<ul>
<li><a href="api.html">api</a>, for manipulating IRIS data.</li>
<li><a href="integrator.html">integrator</a>, for integrating data sources. There should be no need to run this module since the MongoDB dumps are provided.</li>
</ul>
</section>
</article>
<nav id="sidebar">
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3><a href="#header-modules">Modules</a></h3>
<ul>
<li>
<h4><code><a title="api" href="api.html">api</a></code></h4>
</li>
<li><h4><code><a title="integrator" href="integrator.html">integrator</a></code></h4>
</li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.6.3</a>.</p>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad()</script>
</main>
</body>
</html>
\ No newline at end of file
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.6.3" />
<title>integrator API documentation</title>
<meta name="description" content="" />
<link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'>
<link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'>
<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet">
<style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase;cursor:pointer}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>integrator</code></h1>
</header>
<section id="section-intro">
<details class="source">
<summary>Source code</summary>
<pre><code class="python">#!/usr/bin/env python
# encoding: utf-8
# =============================================================================
# Integrator: perform the integration of different data sources to produce MongoDB documents (GeoJSON format) containing
# IRIS information (~640 or ~350 INSEE indicators, depending on the IRIS).
# This file does not need to be run because the MongoDB dump is provided (unless for integrating new data sources).
# =============================================================================
# Path to MongoDB tools (under MacOS): /Applications/MongoDB.app/Contents/Resources/Vendor/mongodb/bin/
# Export and import a local database (metadata/indexes included, option dryRun for testing, several files):
# mongodump --db dbinsee --verbose -o dump/
# mongorestore --db dbinsee --dir dump/dbinsee --verbose --dryRun
# Export and import a local database (metadata/indexes included, option dryRun for testing, single binary file):
# mongodump --db dbinsee --verbose --archive=dbinsee.bin
# mongorestore --archive=dbinsee.bin --verbose
# Export and import in JSON:
# ./mongoexport --db dbinsee --out ~/dump-iris.json
# ./mongoimport --db dbinsee --file ~/dump-iris.json
# =============================================================================
import os
import logging
from mongiris import config
from mongiris import xls_utils
from mongiris import api
def get_all_xlsx_files(dir_sources):
&#34;&#34;&#34;
Returns a list of spreadsheets files to be integrated.
Args:
dir_sources: path to a directory containing data sources (spreadsheets from INSEE)
Returns:
insee_files: a list of filepaths (to xls files)
&#34;&#34;&#34;
insee_files = list()
for file in os.listdir(dir_sources):
filepath = os.path.join(config.insee_dir, file)
if os.path.isfile(filepath) and filepath.endswith(&#34;.xls&#34;):
insee_files.append(filepath)
return insee_files
def integrate_xls_file(connection, xls_file):
&#34;&#34;&#34;
Integrates data from an xsl file : the 3 collections may be updated. First, extracts information about the source
(e.g., title, date) and inserts a document for that source in &#39;collsources&#39;. Next extracts information about the
indicators (e.g., short name, long name) and updates/inserts a document in &#39;collindic&#39;. Finally for each line (IRIS)
in the spreadsheet, updates corresponding document with new indicators.
Args:
connection: an object representing the database connection
xls_file: a csv file path containing INSEE indicators
&#34;&#34;&#34;
indicator_metadata, indicators, source_metadata = xls_utils.parse_xls_to_dict(xls_file)
# add the source metadata into collection_sources
doc = connection.find_one_document(connection.collection_sources, {&#34;filename&#34;: xls_file})
if doc is None:
connection.insert_one_document(connection.collection_sources, source_metadata)
# add the indicators information into collection_indic
for ind in indicator_metadata:
short_name = ind[config.geojson_shortname_label]
doc = connection.find_one_document(connection.collection_indic, {config.geojson_shortname_label: short_name})
if doc is not None: # only update field from_insee_files, $addToSet does not add duplicate values
connection.update_one_document(connection.collection_indic, {config.geojson_shortname_label: short_name},
{&#34;$addToSet&#34;: {config.geojson_from_files_label: xls_file}})
else: # add the document
connection.insert_one_document(connection.collection_indic, ind)
# add the indicators values into collection_iris
not_found_iris = found_iris = nb_replacements = 0
for code_iris, indics in indicators.items():
doc = connection.get_iris_from_code(code_iris)
if doc is None:
not_found_iris += 1
else:
doc_id = doc[&#39;properties&#39;][&#39;CODE_IRIS&#39;]
found_iris += 1
need_replacement = False
doc_changes = {&#34;$set&#34;: dict()} # an update document containing the new fields
for ind, value in indics.items():
if ind in config.labels_dictionary_init: # main indicator, do not replace it if already there
if ind not in doc[&#39;properties&#39;]: # general information (code iris, city name, etc.)
doc_changes[&#34;$set&#34;][&#34;properties.&#34; + ind] = value
need_replacement = True
else: # raw indicator
if ind not in doc[&#39;properties&#39;][config.geojson_raw_indicators_label]: # add this value
doc_changes[&#34;$set&#34;][&#34;properties.&#34; + config.geojson_raw_indicators_label + &#34;.&#34; + ind] = value
need_replacement = True
if need_replacement: # replace the old doc by new doc
res = connection.update_one_document(connection.collection_iris, {&#39;properties.CODE_IRIS&#39;: doc_id}, doc_changes)
nb_replacements += res.modified_count
logger.info(f&#34;\t\t{xls_file}: {found_iris} found iris, {not_found_iris} not found iris, {nb_replacements} updates&#34;)
return True
def integrate(connection, dir_sources):
&#34;&#34;&#34;
Main integration method: parses a directory of data sources, and call the `integrate_xls_file` function for each
data source.
Args:
connection: an object representing the database connection
dir_sources: path to a directory containing data sources (spreadsheets from INSEE)
&#34;&#34;&#34;
logger.info(&#34;Searching xlsx files...&#34;)
insee_files = get_all_xlsx_files(dir_sources) # get the list of all xlsx files to be integrated
logger.info(f&#34;Found a total of {len(insee_files)} xlsx files to be integrated.&#34;)
# insee_files = [] # roughly 10-20 mins execution time for one data source
logger.info(f&#39;Selected {len(insee_files)} xlsx files to be integrated.&#39;)
logger.info(&#34;Integrating sources files (metadata for source and indicators, data for iris)&#34;)
for file in insee_files: # integrate each xlsx INSEE file (both indicators in IRIS and indicators dict)
logger.info(f&#34;\t- INSEE xlsx file: {file}&#34;)
integrate_xls_file(connection, file)
logger.info(&#34;Done !&#34;)
def check_properties(connection):
&#34;&#34;&#34;
Computes and prints statistics on the IRIS collection, mainly the number of indicators per document.
Args:
connection: an object representing the database connection
&#34;&#34;&#34;
docs = connection.find_documents(connection.collection_iris, {}, )
counts = dict()
for doc in docs:
nb = len(doc[&#39;properties&#39;][config.geojson_raw_indicators_label])
if nb not in counts:
counts[nb] = 0
counts[nb] += 1
print(counts)
#########################
# main integration script
#########################
if __name__ == &#39;__main__&#39;:
logging.basicConfig(format=&#39;[%(levelname)s] - %(name)s - %(asctime)s : %(message)s&#39;)
logger = logging.getLogger()
logger.setLevel(logging.INFO)
connection = api.Mongiris() # database connection
integrate(connection, config.insee_dir) # integrating data sources
check_properties(connection) # stats about properties 5min execution {350: 36530, 638: 11738, 615: 1057, 373: 79}</code></pre>
</details>
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="integrator.check_properties"><code class="name flex">
<span>def <span class="ident">check_properties</span></span>(<span>connection)</span>
</code></dt>
<dd>
<section class="desc"><p>Computes and prints statistics on the IRIS collection, mainly the number of indicators per document.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>connection</code></strong></dt>
<dd>an object representing the database connection</dd>
</dl></section>
<details class="source">
<summary>Source code</summary>
<pre><code class="python">def check_properties(connection):
&#34;&#34;&#34;
Computes and prints statistics on the IRIS collection, mainly the number of indicators per document.
Args:
connection: an object representing the database connection
&#34;&#34;&#34;
docs = connection.find_documents(connection.collection_iris, {}, )
counts = dict()
for doc in docs:
nb = len(doc[&#39;properties&#39;][config.geojson_raw_indicators_label])
if nb not in counts:
counts[nb] = 0
counts[nb] += 1
print(counts)</code></pre>
</details>
</dd>
<dt id="integrator.get_all_xlsx_files"><code class="name flex">
<span>def <span class="ident">get_all_xlsx_files</span></span>(<span>dir_sources)</span>
</code></dt>
<dd>
<section class="desc"><p>Returns a list of spreadsheets files to be integrated.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>dir_sources</code></strong></dt>
<dd>path to a directory containing data sources (spreadsheets from INSEE)</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><strong><code>insee_files</code></strong></dt>
<dd>a list of filepaths (to xls files)</dd>
</dl></section>
<details class="source">
<summary>Source code</summary>
<pre><code class="python">def get_all_xlsx_files(dir_sources):
&#34;&#34;&#34;
Returns a list of spreadsheets files to be integrated.
Args:
dir_sources: path to a directory containing data sources (spreadsheets from INSEE)
Returns:
insee_files: a list of filepaths (to xls files)
&#34;&#34;&#34;
insee_files = list()
for file in os.listdir(dir_sources):
filepath = os.path.join(config.insee_dir, file)
if os.path.isfile(filepath) and filepath.endswith(&#34;.xls&#34;):
insee_files.append(filepath)
return insee_files</code></pre>
</details>
</dd>
<dt id="integrator.integrate"><code class="name flex">
<span>def <span class="ident">integrate</span></span>(<span>connection, dir_sources)</span>
</code></dt>
<dd>
<section class="desc"><p>Main integration method: parses a directory of data sources, and call the <a title="integrator.integrate_xls_file" href="#integrator.integrate_xls_file"><code>integrate_xls_file()</code></a> function for each
data source.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>connection</code></strong></dt>
<dd>an object representing the database connection</dd>
<dt><strong><code>dir_sources</code></strong></dt>
<dd>path to a directory containing data sources (spreadsheets from INSEE)</dd>
</dl></section>
<details class="source">
<summary>Source code</summary>
<pre><code class="python">def integrate(connection, dir_sources):
&#34;&#34;&#34;
Main integration method: parses a directory of data sources, and call the `integrate_xls_file` function for each
data source.
Args:
connection: an object representing the database connection
dir_sources: path to a directory containing data sources (spreadsheets from INSEE)
&#34;&#34;&#34;
logger.info(&#34;Searching xlsx files...&#34;)
insee_files = get_all_xlsx_files(dir_sources) # get the list of all xlsx files to be integrated
logger.info(f&#34;Found a total of {len(insee_files)} xlsx files to be integrated.&#34;)
# insee_files = [] # roughly 10-20 mins execution time for one data source
logger.info(f&#39;Selected {len(insee_files)} xlsx files to be integrated.&#39;)
logger.info(&#34;Integrating sources files (metadata for source and indicators, data for iris)&#34;)
for file in insee_files: # integrate each xlsx INSEE file (both indicators in IRIS and indicators dict)
logger.info(f&#34;\t- INSEE xlsx file: {file}&#34;)
integrate_xls_file(connection, file)
logger.info(&#34;Done !&#34;)</code></pre>
</details>
</dd>
<dt id="integrator.integrate_xls_file"><code class="name flex">
<span>def <span class="ident">integrate_xls_file</span></span>(<span>connection, xls_file)</span>
</code></dt>
<dd>
<section class="desc"><p>Integrates data from an xsl file : the 3 collections may be updated. First, extracts information about the source
(e.g., title, date) and inserts a document for that source in 'collsources'. Next extracts information about the
indicators (e.g., short name, long name) and updates/inserts a document in 'collindic'. Finally for each line (IRIS)
in the spreadsheet, updates corresponding document with new indicators.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>connection</code></strong></dt>
<dd>an object representing the database connection</dd>
<dt><strong><code>xls_file</code></strong></dt>
<dd>a csv file path containing INSEE indicators</dd>
</dl></section>
<details class="source">
<summary>Source code</summary>
<pre><code class="python">def integrate_xls_file(connection, xls_file):
&#34;&#34;&#34;
Integrates data from an xsl file : the 3 collections may be updated. First, extracts information about the source
(e.g., title, date) and inserts a document for that source in &#39;collsources&#39;. Next extracts information about the
indicators (e.g., short name, long name) and updates/inserts a document in &#39;collindic&#39;. Finally for each line (IRIS)
in the spreadsheet, updates corresponding document with new indicators.
Args:
connection: an object representing the database connection
xls_file: a csv file path containing INSEE indicators
&#34;&#34;&#34;
indicator_metadata, indicators, source_metadata = xls_utils.parse_xls_to_dict(xls_file)
# add the source metadata into collection_sources
doc = connection.find_one_document(connection.collection_sources, {&#34;filename&#34;: xls_file})
if doc is None:
connection.insert_one_document(connection.collection_sources, source_metadata)
# add the indicators information into collection_indic
for ind in indicator_metadata:
short_name = ind[config.geojson_shortname_label]
doc = connection.find_one_document(connection.collection_indic, {config.geojson_shortname_label: short_name})
if doc is not None: # only update field from_insee_files, $addToSet does not add duplicate values
connection.update_one_document(connection.collection_indic, {config.geojson_shortname_label: short_name},
{&#34;$addToSet&#34;: {config.geojson_from_files_label: xls_file}})
else: # add the document
connection.insert_one_document(connection.collection_indic, ind)
# add the indicators values into collection_iris
not_found_iris = found_iris = nb_replacements = 0
for code_iris, indics in indicators.items():
doc = connection.get_iris_from_code(code_iris)
if doc is None:
not_found_iris += 1
else:
doc_id = doc[&#39;properties&#39;][&#39;CODE_IRIS&#39;]
found_iris += 1
need_replacement = False
doc_changes = {&#34;$set&#34;: dict()} # an update document containing the new fields
for ind, value in indics.items():
if ind in config.labels_dictionary_init: # main indicator, do not replace it if already there
if ind not in doc[&#39;properties&#39;]: # general information (code iris, city name, etc.)
doc_changes[&#34;$set&#34;][&#34;properties.&#34; + ind] = value
need_replacement = True
else: # raw indicator
if ind not in doc[&#39;properties&#39;][config.geojson_raw_indicators_label]: # add this value
doc_changes[&#34;$set&#34;][&#34;properties.&#34; + config.geojson_raw_indicators_label + &#34;.&#34; + ind] = value
need_replacement = True
if need_replacement: # replace the old doc by new doc
res = connection.update_one_document(connection.collection_iris, {&#39;properties.CODE_IRIS&#39;: doc_id}, doc_changes)
nb_replacements += res.modified_count
logger.info(f&#34;\t\t{xls_file}: {found_iris} found iris, {not_found_iris} not found iris, {nb_replacements} updates&#34;)
return True</code></pre>
</details>
</dd>
</dl>
</section>
<section>
</section>
</article>
<nav id="sidebar">
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="">
<li><code><a title="integrator.check_properties" href="#integrator.check_properties">check_properties</a></code></li>
<li><code><a title="integrator.get_all_xlsx_files" href="#integrator.get_all_xlsx_files">get_all_xlsx_files</a></code></li>
<li><code><a title="integrator.integrate" href="#integrator.integrate">integrate</a></code></li>
<li><code><a title="integrator.integrate_xls_file" href="#integrator.integrate_xls_file">integrate_xls_file</a></code></li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.6.3</a>.</p>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad()</script>
</body>
</html>
\ No newline at end of file
#!/usr/bin/env python
# mongiris setup.py (uses setup.cfg)
# pdoc --force --html mongiris/main.py mongiris/integrator.py
# pdoc mongiris/api.py -o doc
# pandoc paper.md --filter pandoc-citeproc -o paper.pdf
# python3 -m setup bdist_wheel sdist
# python3 -m pip install -e mongiris/
......
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