Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP : Jimmyd/impact retour emploi #384

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

JimmyDore
Copy link
Member

Ajout des scripts réalisés par Joris, Refacto et industrialisation de ces scripts,
afin de calculer l'impact sur le retour à l'emploi de LBB.

@JimmyDore JimmyDore force-pushed the jimmyd/impact_retour_emploi branch from 8618084 to 8d24c28 Compare July 9, 2019 12:27
Copy link
Contributor

@celine-m-s celine-m-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

De manière générale :

  • c'est vraiment dommage qu'il n'y ait aucune docstring, au moins en haut au niveau du module... Un nouvel arrivant sur le projet aura bien du mal à comprendre ce que fait chaque script.
  • les fonctions sont bien trop grandes à mon goût et ont trop de responsabilités. Les fractionner en petites fonctions qui font moins de choses aiderait à comprendre plus rapidement chaque script (en lisant la fonction principale on devrait comprendre tout de suite chaque étape sans entrer dans le détail).
  • il n'y a aucun test !!! => 😱 Avant d'envisager un refacto il faut surtout faire des tests unitaires à mon humble avis !
  • les requêtes en DB en écriture n'ont pas de rollback en cas de souci. J'imagine que tu as dû tester les cas d'erreur mais ça me semble assez dangereux en l'état, non ?
  • l'historique git contient pas mal de wip, ça ne me semble pas très lisible.

Et sinon, bravo pour le boulot !! 👏

@@ -38,6 +40,14 @@ def create_cursor():
cur = con.cursor()
return con, cur

def create_sqlalchemy_engine():
connexion_url = ('mysql://'+DATABASE['USER']+':%s@'+\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je trouve que ce serait plus lisible d'enlever les "+" et de passer par format. Exemple : f"mysql://{DATABASE['USER']}:%s@".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL nouvelle syntaxe, je connaissais seulement '{} {}'.format('one', 'two')

@@ -0,0 +1,147 @@
from datetime import date
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Une docstring générale ne ferait pas de mal pour expliquer ce que fait le script et comment l'utiliser, toujours dans l'optique de la MCO.

import pandas as pd
from labonneboite.importer import util as import_util
from labonneboite.importer import settings as importer_settings
from labonneboite.importer.jobs.common import logger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ce serait bien de différencier les librairies natives des externes et de celles du projet par un saut de ligne.

def clean_csv_act_dpae_file(existing_sql_table=True):

dpae_folder_path = importer_settings.INPUT_SOURCE_FOLDER + '/'
csv_path = dpae_folder_path+'act_dpae.csv'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A mon humble avis, tu peux supprimer la ligne précédente et écrire csv_path = f"{importer_settings.INPUT_SOURCE_FOLDER}/act_dpae.csv", ça enlève une variable et c'est plus lisible.

inplace=True)


def get_type_contrat(row):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Est-ce que ce ne serait pas plus logique que les fonctions soient réunies au début du script, avant la fonction principale appelée par run_main ? Là ça mélange tout.
D'ailleurs j'ai un peu de mal à saisir pourquoi plusieurs fonctions sont dans "clean_csv_act_dpae_file" alors qu'elles pourraient être définies précédemment et être ainsi indépendantes. Ca aiderait grandement à les tester en tests unitaires.

#We select the last DPAE date that has been used in the last joined dpae
engine = import_util.create_sqlalchemy_engine()

query = "select date_embauche from act_dpae_clean order by date_embauche DESC LIMIT 1 "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ce serait plus lisible si les commandes SQL étaient toutes en majuscules.

chunksize = 10 ** 5
else:
chunksize = 10 ** 6
i = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devrait être juste avant la ligne 77 car est utilisé uniquement dans le cadre de cette boucle for.

from labonneboite.scripts.impact_retour_emploi.scripts_charts import grand_public as gd
from labonneboite.importer import util as import_util
from labonneboite.importer.jobs.common import logger
from labonneboite.scripts.impact_retour_emploi.settings_path_charts import root_path, clean_path, gd_pub_path, images_path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Même remarque que précédemment sur les imports.


ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

# FIXME : Refacto all files about the creation of charts and pasting on sheets (<3 Joris)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -0,0 +1,6 @@
from labonneboite.importer import settings as importer_settings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ces settings ne devraient-ils pas être dans scripts_charts ? Ainsi il n'y aurait pas à l'appeler "settings_path_charts" mais juste "settings.py".
Our bien dans les settings de l'importeur (s'il y en a) de manière générale. Ce serait d'ailleurs mieux car ça centralise toutes les configurations de ce module, non ?

Copy link
Contributor

@dejafait dejafait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quelques points en plus de la review très complète de @celine-m-s

@@ -38,6 +40,14 @@ def create_cursor():
cur = con.cursor()
return con, cur

def create_sqlalchemy_engine():
connexion_url = ('mysql://'+DATABASE['USER']+':%s@'+\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL nouvelle syntaxe, je connaissais seulement '{} {}'.format('one', 'two')

cell_A5.alignment = openpyxl.styles.Alignment(horizontal="center")
DPAE_for_gd_pub = [cell_A4.value, nbre_DPAE] # for grand_public

# Add number of IDPE unique
Copy link
Contributor

@dejafait dejafait Jul 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDPE =?

on utilise PEID partout ailleurs dans le code et avec les autres startups, je conseille de s'aligner

s/idpe/peid/

return [title]+stats


def Graph(ordre, columns_date, df, title, name, time_type='week'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

méthode hyper longue à casser en petits bouts

x = []


def Stacked_Bar(ordre, columns_x, df, titles, name, columns_legend):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

04 Réunion
05 Saint Pierre et Miquelon
06 Mayotte
'''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

à quoi sert cette string? Pourquoi n'est-elle pas stockée dans une variable?

"La plus grande valeur est : "]


def build_grand_public_sheet(nbre_DPAE, nbre_IDPE, nbre_IDPE_sign, all_stats, impact_xlsx):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

à casser en petits bouts

openpyxl
pygal
pygal_maps_fr
matplotlib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate

requirements.in Outdated
matplotlib
imgkit
xlsxwriter
cairosvg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'est chaud d'importer autant de libs (comme matplotlib) en production alors qu'elles sont utiles seulement pour l'IRE

on paye le prix de la non séparation de l'importer vs le frontend/api

j'ai pas de solution mais je veux bien l'avis de @celine-m-s

à noter: Michel pour son projet ROME NAF avait séparé ses requirements dans son dossier spécifique ROME_NAF à la racine du repo, c'était pas mal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est vrai que ce n'est pas très efficace...
Peut-être qu'on peut créer un requirements.in spécifique à l'importer et installer ces dépendances dans chaque commande make qui les nécessite ?
Ou bien, si c'est Ansible qui lance les commandes make et installe l'environnement, on peut les installer à ce moment-là ?

@dejafait
Copy link
Contributor

dejafait commented Jan 2, 2020

Elle a 8 mois cette branche, temps de tourner la page et en fait une nouvelle non? @JimmyDore besoin de review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants