Skip to content

Commit

Permalink
Merge branch 'main' into add-lodash-types
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienheureux authored Aug 19, 2024
2 parents 7b274ab + c41aabe commit 7da5f77
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 16 deletions.
46 changes: 46 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Description succincte du problème résolu

Carte Notion : [Titre de la carte](https://notion.so/...)

Description plus détaillée de l'intention, l'approche ou de l'implémentation (ce qui n’est pas visible directement en lisant le code)

<!-- Cocher la/les case.s appropriée.s -->
**Type de changement** :
- [ ] Bug fix
- [ ] Nouvelle fonctionnalité
- [ ] Mise à jour de données / DAG
- [ ] Les changements nécessitent une mise à jour de documentation
- [ ] Refactoring de code (explication à retrouver dans la description)

## Auto-review

Les trucs à faire avant de demander une review :
- [ ] J'ai bien relu mon code
- [ ] La CI passe bien
- [ ] En cas d'ajout de variable d'environnement, j'ai bien mis à jour le `.env.template`
- [ ] J'ai ajouté des tests qui couvrent le nouveau code

## Comment tester

En local / staging :
- Récupérer la base de production
- Aller sur http://localhost:8000
- Cliquer sur ABC
-

## Développement local

<!-- Dans le cas où il y a des instructions spécifiques pour garantir un local fonctionnel pour le reste de l'équipe -->
- Mettre à jour le `.env`
- Réinstaller les dépendances Python avec `pip install -r requirements.txt -r dev-requirements.txt`
- Réinstaller les dépendances node avec `npm install`
- Rebuild la stack docker avec `docker compose build`
- ...

## Déploiement

<!-- Dans le cas où il y a des instructions spécifiques de déploiement -->

- Exécuter les migrations
- Exécuter la commande `rf -rf /`
- ...
2 changes: 2 additions & 0 deletions dags/cma.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"email": "email",
"phone": "telephone",
"siret": "siret",
"longitude": "location",
"latitude": "location",
"id": "identifiant_externe",
"is_enabled": "statut",
"other_info": "commentaires",
Expand Down
5 changes: 3 additions & 2 deletions dags/config/db_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"déchets phytosanitaires ménagers": "Déchets phytosanitaires ménagers - Produits chimiques",
"outillage du peintre": "ABJ_Outillage du peintre usagé",
"panneaux photovoltaïques": "Panneaux photovoltaïques",
"déchets dangereux de pmcb": "Déchets dangereux de PMCB",
"déchets dangereux de pmcb": "Déchets dangereux de PMCB (produits et matériaux de construction du bâtiment)",
"décoration textile": "Décoration textile - Éléments d'ameublement",
"huisseries": "Huisseries (produits et matériaux de construction du bâtiment)",
"laine de roche": "Laine de roche (produits et matériaux de construction du bâtiment)",
Expand All @@ -38,7 +38,8 @@
"rembourrés d'assise ou de couchage": "Rembourrés d'assise ou de couchage - Éléments d'ameublement",
"sièges": "Sièges - Éléments d'ameublement",
"produits pyrotechniques": "produits pyrotechniques",
"pneu": "pneu"
"pneu": "pneu",
"béton": "Béton - PMCB (produits et matériaux de construction du bâtiment)"
},
"sous_categories_cma":{
"articles d’ameublement (meubles, chaises, fauteuils, canapés, tapis, etc)": ["meuble"],
Expand Down
7 changes: 6 additions & 1 deletion dags/utils/dag_eo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def create_actors(**kwargs):
]:
df[new_col] = df.apply(
lambda row: utils.transform_location(
row["latitude"], row["longitude"]
row["longitude"], row["latitude"]
),
axis=1,
)
Expand Down Expand Up @@ -473,6 +473,11 @@ def create_actors(**kwargs):
df["cree_le"] = datetime.now()
df["statut"] = "ACTIF"
df["modifie_le"] = df["cree_le"]
if "siret" in df.columns:
df["siret"] = df["siret"].apply(mapping_utils.process_siret)
if "telephone" in df.columns:
df["telephone"] = df["telephone"].apply(mapping_utils.process_phone_number)

df = df.replace({np.nan: None})

duplicates_mask = df.duplicated("identifiant_unique", keep=False)
Expand Down
18 changes: 18 additions & 0 deletions dags/utils/mapping_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@
utils = import_module(f"{env}.utils.utils")


def process_siret(siret):
if pd.isna(siret):
return None
siret = str(siret).strip()
if len(siret) == 13 and siret.isdigit():
siret = "0" + siret
return siret[:14]


def process_phone_number(number):
if pd.isna(number):
return number
number = number.replace(" ", "")
if number.startswith("33"):
number = "0" + number[2:]
return number


def transform_acteur_type_id(value, df_acteurtype):
mapping_dict = {
"solution en ligne (site web, app. mobile)": "en ligne (web, mobile)",
Expand Down
5 changes: 4 additions & 1 deletion jinja2/layout/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
{% endif %}
</head>

<body class="qfdmo-flex qfdmo-flex-col">
<body
class="qfdmo-flex qfdmo-flex-col"
data-controller="analytics"
>
{% if not is_embedded(request) %}
{% block header %}
{% include "layout/header.html" %}
Expand Down
6 changes: 4 additions & 2 deletions jinja2/qfdmo/_addresses_partials/map_and_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
<div
class="qfdmo-flex-grow qfdmo-relative qfdmo-shadow"
data-controller="map"
data-action="map:captureInteraction->analytics#captureInteractionWithMap"
data-map-location-value="{{ location }}"
>
>
{{ form.bounding_box }}
<div id="map" class="qfdmo-absolute qfdmo-inset-0">
</div>
Expand Down Expand Up @@ -161,7 +162,8 @@ <h3 class="qfdmo-text-2xl sm:qfdmo-text-4xl qfdmo-text-center text-black qfdmo-m
</button>
<button class="fr-btn fr-btn--sm fr-btn--tertiary-no-outline fr-btn--icon-left fr-icon-arrow-up-s-line sm:qfdmo-hidden"
type='button'
data-action="click -> search-solution-form#displayFullDetails"
data-action="click -> search-solution-form#displayFullDetails
click -> analytics#captureInteractionWithSolutionDetails"
data-search-solution-form-target="expandDetailsButton"
>
Ouvrir
Expand Down
33 changes: 24 additions & 9 deletions jinja2/qfdmo/adresse/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ <h4 class='fr-my-1v fr-h6'>
target="_blank"
title="itinéraire"
rel='noopener'
>
data-action="click -> analytics#captureInteractionWithSolutionDetails"
>
<span class="fr-btn fr-icon-send-plane-line qfdmo-rounded-full"
></span>
<span class="fr-text--xs fr-mb-0">Itinéraire</span>
Expand All @@ -63,7 +64,8 @@ <h4 class='fr-my-1v fr-h6'>
{% if adresse.url %}
<a class="qfdmo-flex qfdmo-flex-col qfdmo-items-center qfdmo-no-underline qfdmo-bg-none qfdmo-no-external-link-icon"
href="{{ adresse.url }}" target="_blank" title="Site Internet" rel='noopener'
>
data-action="click -> analytics#captureInteractionWithSolutionDetails"
>
<span class="fr-btn fr-btn--secondary-light fr-icon-global-line qfdmo-rounded-full">
</span>
<span class="fr-text--xs fr-mb-0">Site web</span>
Expand All @@ -81,15 +83,22 @@ <h4 class='fr-my-1v fr-h6'>
{% if adresse.telephone %}
<a class="qfdmo-flex qfdmo-flex-col qfdmo-items-center qfdmo-bg-none qfdmo-no-external-link-icon"
href="tel:{{ adresse.telephone }}" title="Téléphone" rel='noopener'
>
data-action="click -> analytics#captureInteractionWithSolutionDetails"
>
<span class="fr-btn fr-btn--secondary-light fr-icon-phone-line qfdmo-rounded-full"
></span>
<span class="fr-text--xs fr-mb-0">Téléphone</span>
</a>
{% endif %}

<div class="qfdmo-flex qfdmo-flex-col qfdmo-items-center">
<button class="fr-btn fr-btn--secondary-light fr-icon-share-line qfdmo-rounded-full" type="button" aria-describedby="shareTooltip" aria-labelledby="detail-share-tooltip-label">
<button
class="fr-btn fr-btn--secondary-light fr-icon-share-line qfdmo-rounded-full"
type="button"
aria-describedby="shareTooltip"
aria-labelledby="detail-share-tooltip-label"
data-action="click -> analytics#captureInteractionWithSolutionDetails"
>
</button>
<span class="fr-tooltip fr-placement" id="shareTooltip" role="tooltip" aria-hidden="true">
<span class="fr-share">
Expand Down Expand Up @@ -177,7 +186,8 @@ <h4 class='fr-my-1v fr-h6'>
aria-selected="false"
aria-controls="infosPanel"
type="button"
>
data-action="click -> analytics#captureInteractionWithSolutionDetails"
>
Adresse
</button>
</li>
Expand All @@ -190,7 +200,8 @@ <h4 class='fr-my-1v fr-h6'>
aria-selected="false"
aria-controls="labelsPanel"
type="button"
>
data-action="click -> analytics#captureInteractionWithSolutionDetails"
>
Labels
</button>
</li>
Expand All @@ -203,7 +214,8 @@ <h4 class='fr-my-1v fr-h6'>
aria-selected="false"
aria-controls="sourcesPanel"
type="button"
>
data-action="click -> analytics#captureInteractionWithSolutionDetails"
>
Sources
</button>
</li>
Expand Down Expand Up @@ -351,7 +363,10 @@ <h3 class="fr-text--sm fr-m-0 qfdmo-text-grey-425">Type d'enseigne</h3>

<a class="fr-my-1w fr-btn fr-btn--tertiary qfdmo-whitespace-nowrap qfdmo-w-full qfdmo-justify-center"
href="https://tally.so/r/3xMqd9?Nom={{adresse.nom}}&Ville={{adresse.ville}}&Adresse={{adresse.adresse}}"
target="_blank" rel="noopener" title="Proposer une modification - Nouvelle fenêtre"
>
target="_blank"
rel="noopener"
title="Proposer une modification - Nouvelle fenêtre"
data-action="click -> analytics#captureInteractionWithSolutionDetails"
>
Proposer une modification
</a>
2 changes: 1 addition & 1 deletion qfdmo/fixtures/actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"fields": {
"code": "acheter",
"libelle": "acheter de seconde main",
"libelle_groupe": "J'achête",
"libelle_groupe": "J'achète",
"afficher": true,
"description": "acheter d'occasion",
"order": 8,
Expand Down
2 changes: 2 additions & 0 deletions static/to_compile/entrypoints/qfdmo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Turbo from "@hotwired/turbo"

import AddressAutocompleteController from "../src/address_autocomplete_controller"
import MapController from "../src/map_controller"
import AnalyticsController from "../src/analytics_controller"
import SearchSolutionFormController from "../src/search_solution_form_controller"
import SsCatObjectAutocompleteController from "../src/ss_cat_object_autocomplete_controller"

Expand All @@ -15,5 +16,6 @@ stimulus.register("map", MapController)
stimulus.register("ss-cat-object-autocomplete", SsCatObjectAutocompleteController)
stimulus.register("address-autocomplete", AddressAutocompleteController)
stimulus.register("search-solution-form", SearchSolutionFormController)
stimulus.register("analytics", AnalyticsController)

Turbo.session.drive = false
4 changes: 4 additions & 0 deletions static/to_compile/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const posthogConfig = {

if (process.env.NODE_ENV !== "development") {
posthog.init("phc_SGbYOrenShCMKJOQYyl62se9ZqCHntjTlzgKNhrKnzm", posthogConfig)
posthog.debug()
} else {
// TODO : ce serait bien qu'on définisse ces variables dans l'environnement de build,
// pour qu'elles soient écrites durant cette phase et
// avoir un environnement PostHog dédié en staging
posthog.init("phc_SwcKewoXg9MZyAIdl8qsyvwz3Vij8Vlrbr2SjEeN3u9", posthogConfig)
}

Expand Down
26 changes: 26 additions & 0 deletions static/to_compile/src/analytics_controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Controller } from "@hotwired/stimulus"
import { InteractionType as PosthogUIInteractionType, PosthogEventType } from "./types"
import posthog from "posthog-js"

export default class extends Controller<HTMLElement> {
// Sert principalement à type les appels à la méthode capture de Posthog.
// Ça évite d'appeler un événement indéfini, ce qui peut rapidement polluer
// les données stockées côtés PostHog.
capture(posthogEvent: PosthogEventType, details: object) {
posthog.capture(posthogEvent, details)
}

captureUIInteraction(UIInteractionType: PosthogUIInteractionType) {
this.capture("ui_interaction", {
ui_interaction_type: UIInteractionType,
})
}

captureInteractionWithSolutionDetails() {
this.captureUIInteraction("solution_details")
}

captureInteractionWithMap() {
this.captureUIInteraction("map")
}
}
1 change: 1 addition & 0 deletions static/to_compile/src/map_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ export default class extends Controller<HTMLElement> {
this.dispatch("setSrcDetailsAddress", {
detail: { identifiantUnique: identifiantUnique },
})
this.dispatch("captureInteraction")
}
}
3 changes: 3 additions & 0 deletions static/to_compile/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ export class SSCatObject {
sub_label: string
identifier: int
}

export type InteractionType = "map" | "solution_details"
export type PosthogEventType = "ui_interaction"
21 changes: 21 additions & 0 deletions unit_tests/dags/utils/mapping_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pandas as pd

from dags.utils import mapping_utils
import numpy as np


class TestDataTransformations(unittest.TestCase):
Expand Down Expand Up @@ -49,6 +50,26 @@ def test_without_service_a_domicile_only(self):
}
self.assertEqual(mapping_utils.create_identifiant_unique(row), "ecoorg_123AbC")

def test_process_siret_value(self):
self.assertEqual(
mapping_utils.process_siret("123456789012345"), "12345678901234"
)
self.assertEqual(mapping_utils.process_siret(np.nan), None)
self.assertEqual(
mapping_utils.process_siret("98765432109876"), "98765432109876"
)
self.assertEqual(mapping_utils.process_siret("8765432109876"), "08765432109876")

def test_process_telephone_value(self):
self.assertEqual(
mapping_utils.process_phone_number("33 1 23 45 67 89"), "0123456789"
)
self.assertEqual(mapping_utils.process_phone_number("0612345678"), "0612345678")
self.assertEqual(mapping_utils.process_phone_number(None), None)
self.assertEqual(
mapping_utils.process_phone_number("+33612345678"), "+33612345678"
)


class TestTransformFloat(unittest.TestCase):
def test_float(self):
Expand Down

0 comments on commit 7da5f77

Please sign in to comment.