Coder Social home page Coder Social logo

phe-sto / enthic Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 1.0 45.88 MB

French societies accountability extraction and treatment by PapIT

Home Page: https://api.enthic.fr/

License: Do What The F*ck You Want To Public License

Python 95.16% HTML 1.54% Shell 3.06% Io 0.24%
techforgood opendata inpi transparency bigdata

enthic's Introduction

EOL, l'INPI supprime le FTP du RNCS et remplace tout par le RNE

L'INPI a communiqué cela le 03/04/2023:

Madame, Monsieur,

En tant que licencié aux données du RNE nous vous informons de la fermeture des anciennes applications de diffusion des données du RNCS le 30 juin 2023.

Les API et le serveur FTP RNCS ne seront plus accessibles, les données étant désormais disponibles sur les nouvelles applications API et SFTP du RNE au format JSON et PDF.

Nous vous rappelons par ailleurs que les quotas de téléchargement sont de 10 Go ou 10 000 appels par jour.

Vous pouvez retrouver l’ensemble des documentations techniques dans l’onglet « espace open data » du portail DATA INPI.

Qui est partant pour faire une version de Enthic avec le FTP du RNE?

Projet en pause

Ce projet est en pause faute de temps et d'énergie. Je me concentre maintenant sur un projet similaire, IN FRANCE, plus complet qui utilise ces mêmes données pour étudier l'économie Française. Merci à tous ceux qui ont collaboré. N'hésitez pas à me [email protected] pour toute question.

Project on hold

This projet is on hold due to a lack of time and energy. I am focusing on IN FRANCE project, a similar one, more complete, studying the French economy. Thank you all contributor. Don't hesitate to contact me at [email protected].

French societies accountability extraction and treatment by PapIT

Project that treats data from opendata-rncs.inpi.fr. They contain xml files of the account declaration of all french societies. The overall project is meant to be low-code and open source. Aim to provide ethical indicators on companies. Information media is a MySQL database, CSV files, web visualisation and a swagger API. The search engine endpoint return a JSON-LD (Hydra) compliant JSON. Company JSON cannot conform to JSON-LD Organization type due to lack of data (contact for instance). Score and indicators are calculated by batch, sql and why not using fancy libraries. Help in data treatment to improve scoring would be appreciated. Scoring, AI, data scrapping for segmentation. Shell and python must be launched from their corresponding directory ./sh and ./py.

Install dependencies and python package

Synaptic packages have to be installed libxml2-utils mysql-server tree python3. Pip packages as well have to be installed for development purpose.

$ sh ./install-dependencies.sh

To install the enthic python package only.

$ sh ./install-wheel.sh

Run an instance

Extract data from zip

Data are stored in zip files on opendata-rncs.inpi.fr, group by day. Each XML is in a zip. The first step is then to read the XML files and convert data into "bundle.tmp" and "identity.tmp" You must create folders 'input' and 'output' at the root of the project, and put some daily zipfile named like "bilans_saisis_<date>.zip" in 'input' folder.

$ sh ./clear-data.sh

Check the XML format

An XSD is provided by the INPI. This step verify all the XML are following this XSD. XML not following this XSD have their filename printed out.

$ sh ./check-data.sh

Format XML

Create two CSV based on the output generated by clear-data.sh. One for each table, identity and bundle.

$ sh ./csv-table.sh

Create MySQL database

Create database, tables and indexes. The content of the two tables come from the previously generated CSV files.

$ sh ./database-creation.sh --password=<your mysql password>

Run API

A flask REST API can distribute data over the web. Following Swagger standard.

$ python3 ./app.py

Development and contribution

License

Do What The Fuck You Want To Public License (WTFPL)

Development and Coding Rules

  • snake_case for variables, definition and CamelCase for classes.
  • Only argument is configuration file for python.
  • No output or print information (just raw results authorized), just log and files.
  • Sonar Qube integration.
  • Pytest python and API testing.
  • Autodocumentation using Sphinx 1.8.5.
  • Benchmark of CPython VS Pypy.
  • Common sens and clean code.

Build and install python enthic package

$ sh ./install-wheel.sh

Testing

Only python package is tested. Used test framework is pytest. Tests can be run via pytest in the python/enthic/ directory.

Generate documentation

Generate HTML documentation via Sphinx documentation framework. Sphinx is called programmatically at the beginning of setup.py. Therefore the above installation build the doc at the same time.

Library structure

./enthic
├── account-ontology.csv
├── bilans-saisis-v1.1.xsd
├── .gitignore
├── enthic.dbdiagram.io
├── input
├── LICENSE.md
├── output
│   ├── bundle.csv
│   └── identity.csv
├── python
│   ├── doc
│   │   ├── conf.py
│   │   ├── index.rst
│   │   └── papit.png
│   ├── enthic
│   │   ├── app.py
│   │   ├── company
│   │   │   ├── company.py
│   │   │   ├── denomination_company.py
│   │   │   ├── __init__.py
│   │   │   └── siren_company.py
│   │   ├── database
│   │   │   ├── mysql.py
│   │   │   ├── mysql_data.py
│   │   │   ├── fetchall.py
│   │   │   └── __init__.py
│   │   ├── configuration.json
│   │   ├── conftest.py
│   │   ├── decorator
│   │   │   ├── check_sql_injection.py
│   │   │   ├── __init__.py
│   │   │   └── insert_request.py
│   │   ├── extract_bundle.py
│   │   ├── __init__.py
│   │   ├── ontology.py
│   │   ├── static
│   │   │   ├── 404.html
│   │   │   ├── 500.html
│   │   │   ├── bootstrap.min.css
│   │   │   ├── documentation
│   │   │   │   ├── .buildinfo
│   │   │   │   ├── doctrees
│   │   │   │   │   ├── environment.pickle
│   │   │   │   │   └── index.doctree
│   │   │   │   ├── genindex.html
│   │   │   │   ├── index.html
│   │   │   │   ├── _modules
│   │   │   │   │   ├── company
│   │   │   │   │   │   ├── company.html
│   │   │   │   │   │   ├── denomination_company.html
│   │   │   │   │   │   └── siren_company.html
│   │   │   │   │   ├── decorator
│   │   │   │   │   │   ├── check_sql_injection.html
│   │   │   │   │   │   └── insert_request.html
│   │   │   │   │   ├── index.html
│   │   │   │   │   └── utils
│   │   │   │   │       ├── error_json_response.html
│   │   │   │   │       ├── json_response.html
│   │   │   │   │       ├── not_found_response.html
│   │   │   │   │       └── ok_json_response.html
│   │   │   │   ├── .nojekyll
│   │   │   │   ├── objects.inv
│   │   │   │   ├── py-modindex.html
│   │   │   │   ├── search.html
│   │   │   │   ├── searchindex.js
│   │   │   │   ├── _sources
│   │   │   │   │   └── index.rst.txt
│   │   │   │   └── _static
│   │   │   │       ├── ajax-loader.gif
│   │   │   │       ├── alabaster.css
│   │   │   │       ├── basic.css
│   │   │   │       ├── comment-bright.png
│   │   │   │       ├── comment-close.png
│   │   │   │       ├── comment.png
│   │   │   │       ├── custom.css
│   │   │   │       ├── doctools.js
│   │   │   │       ├── documentation_options.js
│   │   │   │       ├── down.png
│   │   │   │       ├── down-pressed.png
│   │   │   │       ├── file.png
│   │   │   │       ├── jquery-3.2.1.js
│   │   │   │       ├── jquery.js
│   │   │   │       ├── language_data.js
│   │   │   │       ├── minus.png
│   │   │   │       ├── papit.png
│   │   │   │       ├── plus.png
│   │   │   │       ├── pygments.css
│   │   │   │       ├── searchtools.js
│   │   │   │       ├── underscore-1.3.1.js
│   │   │   │       ├── underscore.js
│   │   │   │       ├── up.png
│   │   │   │       ├── up-pressed.png
│   │   │   │       └── websupport.js
│   │   │   ├── favicon.ico
│   │   │   ├── google7775f38904c3d3fc.html
│   │   │   ├── index.html
│   │   │   ├── jquery.min.js
│   │   │   ├── robot.txt
│   │   │   ├── sitemap.xml
│   │   │   ├── swagger.json
│   │   │   ├── swagger-ui-bundle.js
│   │   │   ├── swagger-ui-bundle.js.map
│   │   │   ├── swagger-ui.css
│   │   │   ├── swagger-ui.css.map
│   │   │   ├── swagger-ui.js
│   │   │   ├── swagger-ui.js.map
│   │   │   ├── swagger-ui-standalone-preset.js
│   │   │   └── swagger-ui-standalone-preset.js.map
│   │   ├── test_app.py
│   │   ├── test_extract_bundle.py
│   │   ├── test_treat_bundle.py
│   │   ├── treat_bundle.py
│   │   └── utils
│   │       ├── error_json_response.py
│   │       ├── conversion.py
│   │       ├── __init__.py
│   │       ├── json_response.py
│   │       ├── not_found_response.py
│   │       └── ok_json_response.py
│   ├── __init__.py
│   ├── MANIFEST.in
│   ├── setup.cfg
│   └── setup.py
├── README.rst
├── sh
│   ├── check-data.sh
│   ├── clear-data.sh
│   ├── csv-table.sh
│   ├── database-creation.sh
│   ├── install-dependencies.sh
│   └── install-wheel.sh
├── sonar-project.properties
└── sql
    ├── create-database-enthic.sql
    ├── create-index-bundle.sql
    ├── create-index-identity.sql
    ├── create-table-bundle.sql
    ├── create-table-identity.sql
    ├── create-table-request.sql
    ├── insert-bundle.sql
    └── insert-identity.sql

Donation

You can donate to support Python and Open Source development.

BTC 32JSkGXcBK2dirP6U4vCx9YHHjV5iSYb1G

ETH 0xF556505d13aC9a820116d43c29dc61417d3aB2F8

enthic's People

Contributors

foundkim avatar phe-sto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

enthic's Issues

New metadata file make the `clear_data.sh` script crash

Launching clear_data.sh I get the following error message:
[sudo] password for chrichri: STEP 1: REMOVE UNNECESSARY MD5 FILES IN ../input STEP 2: UNZIPING IN ../input Traceback (most recent call last): File "../python/enthic/extract_bundle.py", line 229, in <module> main() # ONLY IF EXECUTED NOT WHEN IMPORTED File "../python/enthic/extract_bundle.py", line 182, in main "\t".join( TypeError: sequence item 4: expected str instance, NoneType found
This ouput is self explanatory I guess.

Failed to insert data in bundle and accountability metadata

Running the following script failed to insert all the INPI data in enthic database:

chrichri@chrichri-x470aorusultragaming:~/enthic-all/enthic/sh$ sudo sh database-creation.sh enthic
[sudo] password for chrichri: 
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1265 (01000) at line 1: Data truncated for column 'siren' at row 1
error when filling table bundle
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1406 (22001) at line 1: Data too long for column 'info_traitement' at row 825317
mysql: [Warning] Using a password on the command line interface can be insecure.

Could we check if test_extract_bundle.py is up to date is running?

Ajouter un point d'API permettant de télécharger du csv

Il faudrait ajouter un point d'api permettant de télécharger les données sous la forme d'un tableau csv en 2 dimensions : chaque ligne correspondant à une année d'une entreprise, et chaque colonne correspondant à un type de donnée (Chiffre d'affaire, Impôt, Salaire, etc...).
Comme la base de donnée est vraiment grosse, il faudrait pouvoir passer des arguments à l'API pour sélectionner les données demandées. Je propose de commencer simple, avec un seul argument : une liste de siren.

Dans un deuxième temps je propose le couple d'argument code APE + année pour permettre de récupérer toutes les données d'une année pour un secteur (en limitant les code APE valide au niveau le plus détaillé, c'est à dire un code APE avec 4 chiffres)

Is sh/database-creations.sh still compatible with recent MySQL 8 versions

I had to replace all "$1" by --password="$1"; on my machine that as a quite recent version of MySQL 8.
Version is:
mysql Ver 8.0.23-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
Is it more safe in all case to have --password="$1" in sql commands?
I cannot recall why we just had "$1" do you? I just guess it was working fine older version of MySQL 8.

Choix du compte pour chiffre d'affaire: consolidé vs. complet

L'API requeté avec un SIREN donné renvoie parfois plusieurs comptes annuels: N complet et parfois 1 consolidé.

Pour TOTAL SA (SIREN 542051180), le CA "compte annuel consolidé" vaut bien 209.4 milliards comme attendu. Un CA "Compte annuel complet" est aussi renvoyé, qui vaut 7.377 milliards d'euros.

Pour ORAN (SIREN 330956871), seul une valeur de "Compte annuel complet" est renvoyée, qui ne correspond pas au chiffre d'affaire attendu de 3.623 pour l'année 2017 (source).

Données pour ORANO:

import requests
from pprint import pprint

response = requests.get("http://api.enthic.fr/company/siren/330956871/2018/").json()
pprint(response["financial_data"][21])
print("{} is {} billions € instead of 3.623 \n ".format(121086000.0, 121086000.0/(10**9)))
pprint(response)

Qui donne pour résultat:

image

Quelle valeur accorder au CA du "Compte annuel complet" quand un CA pour le "Compte annuel consolidé" n'est pas présent ?

Wrong parsing of identity data for company 434805644

the line corresponding to siren 434805644 in enthic production database is :

siren denomination ape postal_code town
434805644 SERVICES TERTIAIRES AUX ENTREPRISES DES PYRENEES - STEP : ;1431 32767 PAU

So ape seems to be at the end of denomination, postal code is in APE and town in postal code. Then nothing in town

Compute annual statistics test fail

 FAILED [ 38%]
AssertionError: WRONG HTTP RETURN CODE 500 INSTEAD OF 200
500 != 200
Expected :
200
Actual :
500
host = '127.0.0.1:5000', first_letters = 'aa'
@pytest.mark.parametrize("first_letters", LETTERS_COUPLE_LIST)
def test_compute_annual_statistics(host, first_letters):
"""
Test the /compute/ endpoint. Should return a JSON and RC 200.

:param host: Fixture of the API host.
:param first_letters: Filter to compute only on companies whose denomination begin with these letters.
"""
response = get("http://" + host + "/compute/" + first_letters)
>       assert response.status_code == 200, "WRONG HTTP RETURN CODE %s INSTEAD OF 200" % response.status_code
E AssertionError: WRONG HTTP RETURN CODE 500 INSTEAD OF 200
E assert 500 == 200
test_app.py:438: AssertionError

See complete test report attached
Test Results — pytest in test_app.py.pdf

.

L'entreprise 538348525 a ses chiffres multipliés par 2 en 2018

Si on compare, par exemple, le chiffre d'affaire de cette entreprise dans Enthic (https://enthic-dataviz.netlify.app/entreprises/538348525) et sur LegalTile (https://www.legaltile.com/entreprise/beausejour-538348525/bilans/2199685), on voit que le notre est doublé.
Je pense que c'est parce que cette entreprise a livré ses comptes de 2018 deux fois, et donc ils apparaissent 2 fois dans les données brutes de l'INPI et qu'Enthic additionne les valeurs dans ce cas-là, ce qui est une erreur. Il faudrait prendre la 2ème version, ou ne garder que la première, ou encore faire une vérification plus compliquée, mais surtout pas additionner les valeurs, car on se retrouve avec des chiffres faux dans la base.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.