indexing-preprod.ts.snap 13.9 KB
Newer Older
Julien Bouquillon's avatar
Julien Bouquillon committed
1 2 3 4 5 6 7 8 9 10
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`kosko generate --dev 1`] = `
"---
apiVersion: bitnami.com/v1alpha1
kind: SealedSecret
metadata:
  name: elastic-recherche-entreprises-write
  annotations:
    app.gitlab.com/app: socialgouv-recherche-entreprises
11 12
    app.gitlab.com/env: preprod-dev42
    app.gitlab.com/env.name: preprod-dev42
Julien Bouquillon's avatar
Julien Bouquillon committed
13 14
  labels:
    application: v1-2-3-recherche-entreprises
15
    component: v1-2-3-recherche-entreprises
Julien Bouquillon's avatar
Julien Bouquillon committed
16 17 18
    owner: recherche-entreprises
    team: recherche-entreprises
    cert: wildcard
19
  namespace: recherche-entreprises-85-preprod-dev42
Julien Bouquillon's avatar
Julien Bouquillon committed
20 21 22
spec:
  encryptedData:
    ELASTICSEARCH_URL: >-
23
      AgB82d7LnDA/6RxRlks/7cRtmWuz6Ql1p4gCwdghu3X85Ek4FqSL6ui1tIBiuM1pZcaiwM6ZizsKA0ofq5iBafUwRQOzTFc3XAMy7XltrymG/QwBRmYKS4w4Ub1DPuYpVxEUC6Jngyex7OvhCKUK7pugjG6Q8FXO6i9iyVVEpKnAcSVLaUe+olmlOrO2RMjIK3mgKX/xOFT+2FYiN5/LJob+w/+p0hPlZaMsLrLOl/i5N4LuI5ckg+FawifD2MnN057fsLbwt0m63g7ZHvXtGT66tbTcQgpWfy5kLe2m7oIbzdk+oPoh4FS8PnyU6nMC8sOkC3v/GUMK91qCas01RBoyPRTTs11yX3gbYHti5Nc3zDt36YHPhrqfRQHQ8xONYkx5SkAylnDr1JoXyfrKDwZUBvLQ6Xh3gGI7qu909LxZ2ryWd9WRslpB1+8bOLN0tV20slAesGYFC/W6e5GT0AhwWqwJ9usGLf0dM7GE+IXJegIlconcM+2x/FW3RQ5XnK5kI/coiha5pxBkK0p8pbwmLnOwH5c2QoBD5xgLCZ3wleMcbTW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5LSsGxP1KICJ0J1MMSL8=
Julien Bouquillon's avatar
Julien Bouquillon committed
26 27 28 29
  template:
    metadata:
      annotations:
        app.gitlab.com/app: socialgouv-recherche-entreprises
30 31
        app.gitlab.com/env: preprod-dev42
        app.gitlab.com/env.name: preprod-dev42
Julien Bouquillon's avatar
Julien Bouquillon committed
32 33 34
      name: elastic-recherche-entreprises-write
      labels:
        application: v1-2-3-recherche-entreprises
35
        component: v1-2-3-recherche-entreprises
Julien Bouquillon's avatar
Julien Bouquillon committed
36 37 38 39 40 41 42 43
        owner: recherche-entreprises
        team: recherche-entreprises
        cert: wildcard
    type: Opaque
---
apiVersion: v1
kind: ConfigMap
data:
44
  get-data.sh: >
Julien Bouquillon's avatar
Julien Bouquillon committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    #!/bin/bash


    # borrowed from annuaire entreprise  :

    # https://github.com/etalab/api-annuaire-entreprises/tree/master/db/init


    geodir=\${DATA_DIR}/geo


    mkdir -p $geodir


    echo \\"-- Download datasets\\"


    for d in \`seq -w 1 19\` 2A 2B \`seq 21 74\` \`seq 76 95\` 98 \\"\\"; do
      wget --progress=bar:force:noscroll -q --show-progress https://files.data.gouv.fr/geo-sirene/last/dep/geo_siret_$d.csv.gz --directory-prefix=$geodir
      gunzip \${geodir}/geo_siret_$d.csv.gz
    done


    #Cas particulier Paris

    for d in \`seq -w 1 20\`; do
      wget --progress=bar:force:noscroll -q --show-progress https://files.data.gouv.fr/geo-sirene/last/dep/geo_siret_751$d.csv.gz --directory-prefix=$geodir
      gunzip \${geodir}/geo_siret_751$d.csv.gz
    done


    #Cas particulier DOM

    for d in \`seq -w 1 8\`; do
      wget --progress=bar:force:noscroll -q --show-progress https://files.data.gouv.fr/geo-sirene/last/dep/geo_siret_97$d.csv.gz --directory-prefix=$geodir
      gunzip \${geodir}/geo_siret_97$d.csv.gz
    done


    # SIRET data

    wget --progress=bar:force:noscroll -q --show-progress
    https://files.data.gouv.fr/insee-sirene/StockUniteLegale_utf8.zip
    --directory-prefix=$DATA_DIR


    # WEEZ data

    wget --progress=bar:force:noscroll -q --show-progress
94
    https://www.data.gouv.fr/fr/datasets/r/a785345a-6e8c-4961-ae0a-bc00878e4f2e
Julien Bouquillon's avatar
Julien Bouquillon committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
    -O \${DATA_DIR}/WEEZ.csv
  assemble_data.py: |
    \\"\\"\\"CDTN Entreprises data assembler

    This script assembles data from different places and creates a new file that
    will be used as source for our search index.

    \\"\\"\\"
    import argparse
    import pandas as pd
    import numpy as np
    from os import listdir
    from os.path import isfile, join


    def read_siren(stock_unite_legale_file):
        \\"\\"\\" Read SIREN Stock Unite Legale

        Parameters
        ----------
        stock_unite_legale_file: str
            The location of the CSV or ZIP file

        Returns
        -------
        employeurs
            a Pandas dataframe containing the list of all companies that are still open
            and employ people
        \\"\\"\\"
124 125 126 127 128 129 130 131 132 133 134
        trancheEffectifsUniteLegale = \\"trancheEffectifsUniteLegale\\"
        categorieJuridiqueUniteLegale = \\"categorieJuridiqueUniteLegale\\"
        nomenclatureActivitePrincipaleUniteLegale = \\"nomenclatureActivitePrincipaleUniteLegale\\"
        categorieEntreprise = \\"categorieEntreprise\\"
        activitePrincipaleUniteLegale = \\"activitePrincipaleUniteLegale\\"

        selection = [\\"siren\\", \\"sigleUniteLegale\\", \\"nomUniteLegale\\", \\"nomUsageUniteLegale\\",
                     'denominationUniteLegale', \\"denominationUsuelle1UniteLegale\\", \\"denominationUsuelle2UniteLegale\\",
                     \\"denominationUsuelle3UniteLegale\\", activitePrincipaleUniteLegale,
                     trancheEffectifsUniteLegale, categorieJuridiqueUniteLegale,
                     nomenclatureActivitePrincipaleUniteLegale, categorieEntreprise]
Julien Bouquillon's avatar
Julien Bouquillon committed
135 136 137

        etatAdmin = \\"etatAdministratifUniteLegale\\"
        caractereEmployeur = \\"caractereEmployeurUniteLegale\\"
138 139 140

        # we only select columns in use and convert to categorical dtype
        # in order to decrease the dataframe memory footprint
Julien Bouquillon's avatar
Julien Bouquillon committed
141
        cols = selection + [etatAdmin, caractereEmployeur]
142
        raw = pd.read_csv(stock_unite_legale_file, usecols=cols,
Lionel's avatar
Lionel committed
143
                          dtype={ \\"siren\\": np.dtype(str), etatAdmin: \\"category\\", caractereEmployeur: \\"category\\",
144 145 146 147 148 149
                                 trancheEffectifsUniteLegale: \\"category\\",
                                 categorieJuridiqueUniteLegale: \\"category\\",
                                 nomenclatureActivitePrincipaleUniteLegale: \\"category\\",
                                 activitePrincipaleUniteLegale: \\"category\\",
                                 categorieEntreprise: \\"category\\"}, )

Julien Bouquillon's avatar
Julien Bouquillon committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
        is_ouvert = raw[etatAdmin] == \\"A\\"
        is_employeur = raw[caractereEmployeur] == \\"O\\"
        is_admin = raw[etatAdmin] == \\"A\\"

        employeurs = raw[is_ouvert & is_employeur & is_admin]

        return employeurs[selection]


    def read_geo(geo_directory):
        \\"\\"\\" Read GEO data

        Parameters
        ----------
        geo_directory: str
            The directory containing geo data for all regions

        Returns
        -------
        all_geo
            a Pandas dataframe containing geo information for all open companies
        \\"\\"\\"
        geo_files = [f for f in listdir(
            geo_directory) if isfile(join(geo_directory, f))]
        geo_selection = [\\"enseigne1Etablissement\\", \\"enseigne2Etablissement\\", \\"enseigne3Etablissement\\", \\"denominationUsuelleEtablissement\\", \\"activitePrincipaleEtablissement\\",
                         'siren', 'siret', 'codePostalEtablissement', 'libelleCommuneEtablissement', \\"etatAdministratifEtablissement\\", \\"geo_adresse\\"]
        geo = {}
        for file in geo_files:
            geo[file] = pd.read_csv(
179 180
                geo_directory + file, dtype={\\"codePostalEtablissement\\": np.dtype(str),
                                             \\"etatAdministratifEtablissement\\": \\"category\\",
Lionel's avatar
Lionel committed
181 182 183
                                             \\"activitePrincipaleEtablissement\\": \\"category\\",
                                             \\"siret\\": np.dtype(str),
                                             \\"siren\\": np.dtype(str),
184
                                             }, usecols=geo_selection
Julien Bouquillon's avatar
Julien Bouquillon committed
185 186 187 188
            )

        all_geo = pd.concat(geo.values(), ignore_index=True).dropna(
            subset=['siret'])
189 190 191 192

        all_geo = all_geo.astype(dtype={\\"codePostalEtablissement\\": np.dtype(str),
                                        \\"etatAdministratifEtablissement\\": \\"category\\",
                                        \\"activitePrincipaleEtablissement\\": \\"category\\",
Lionel's avatar
Lionel committed
193 194
                                        \\"siret\\": np.dtype(str),
                                        \\"siren\\": np.dtype(str),
195 196
                                        })

Julien Bouquillon's avatar
Julien Bouquillon committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
        all_geo = all_geo[all_geo[\\"etatAdministratifEtablissement\\"] == \\"A\\"]

        return all_geo


    def read_idcc(idcc_file):
        \\"\\"\\" Read IDCC data

        Parameters
        ----------
        idcc_file: str
            The location of the CSV file containing associations between companies and their \\"convention collectives\\", (aka WEEZ)

        Returns
        -------
        idccs
            a Pandas dataframe containing siret / idcc associations
        \\"\\"\\"
Lionel's avatar
Lionel committed
215
        idccs = pd.read_csv(idcc_file, dtype={\\"SIRET\\": np.dtype(str)}, usecols=[\\"SIRET\\", \\"IDCC\\"]).rename(
Julien Bouquillon's avatar
Julien Bouquillon committed
216
            columns={\\"SIRET\\": \\"siret\\", \\"IDCC\\": \\"idcc\\"})
217
      
Julien Bouquillon's avatar
Julien Bouquillon committed
218 219 220 221
        return idccs


    def assemble(siren, geo, idcc, output):
Lionel's avatar
Lionel committed
222 223
        sirenGeo = pd.merge(siren, geo, on='siren') 
        merged = pd.merge(sirenGeo, idcc, how='left', on='siret') 
Julien Bouquillon's avatar
Julien Bouquillon committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277

        # add etablissement counts
        etsCounts = merged.siren.value_counts().rename_axis(
            'siren').reset_index(name='etablissements')
        withEts = pd.merge(merged, etsCounts, on='siren')

        # persits as CSV file
        withEts.astype({'idcc': 'Int64'}).to_csv(output)


    def main():
        parser = argparse.ArgumentParser(description=__doc__)
        parser.add_argument(
            'siren_file',
            type=str,
            help=\\"Location of the StockUniteLegale CSV or ZIP file\\"
        )
        parser.add_argument(
            'geo_directory',
            type=str,
            help=\\"Location of the directory containing all the Geo CSV files\\"
        )
        parser.add_argument(
            'idcc_file',
            type=str,
            help=\\"Location of the siret/idcc CSV file (aka WEEZ)\\"
        )
        parser.add_argument(
            'output_file',
            type=str,
            help=\\"Location of the output file\\"
        )

        args = parser.parse_args()

        print(\\"Read SIREN data\\")
        siren = read_siren(args.siren_file)

        print(\\"Read GEO data\\")
        geo = read_geo(args.geo_directory)

        print(\\"Read IDCC data\\")
        idcc = read_idcc(args.idcc_file)

        print(\\"Assemble datasets\\")
        assemble(siren, geo, idcc, args.output_file)


    if __name__ == \\"__main__\\":
        main()
  requirements.txt: |
    numpy
    pandas
metadata:
278
  name: config-map-files-0123456
Julien Bouquillon's avatar
Julien Bouquillon committed
279 280
  annotations:
    app.gitlab.com/app: socialgouv-recherche-entreprises
281 282
    app.gitlab.com/env: preprod-dev42
    app.gitlab.com/env.name: preprod-dev42
Julien Bouquillon's avatar
Julien Bouquillon committed
283 284
  labels:
    application: v1-2-3-recherche-entreprises
285
    component: v1-2-3-recherche-entreprises
Julien Bouquillon's avatar
Julien Bouquillon committed
286 287 288
    owner: recherche-entreprises
    team: recherche-entreprises
    cert: wildcard
289
  namespace: recherche-entreprises-85-preprod-dev42
Julien Bouquillon's avatar
Julien Bouquillon committed
290 291 292 293
---
apiVersion: batch/v1
kind: Job
metadata:
294
  name: update-index-0123456
Julien Bouquillon's avatar
Julien Bouquillon committed
295 296
  annotations:
    app.gitlab.com/app: socialgouv-recherche-entreprises
297 298
    app.gitlab.com/env: preprod-dev42
    app.gitlab.com/env.name: preprod-dev42
Julien Bouquillon's avatar
Julien Bouquillon committed
299 300
  labels:
    application: v1-2-3-recherche-entreprises
301
    component: v1-2-3-recherche-entreprises
Julien Bouquillon's avatar
Julien Bouquillon committed
302 303 304
    owner: recherche-entreprises
    team: recherche-entreprises
    cert: wildcard
305
  namespace: recherche-entreprises-85-preprod-dev42
Julien Bouquillon's avatar
Julien Bouquillon committed
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
spec:
  backoffLimit: 3
  template:
    spec:
      containers:
        - name: update-index
          image: >-
            harbor.fabrique.social.gouv.fr/cdtn/recherche-entreprises-index:1.2.3
          volumeMounts:
            - name: data
              mountPath: /data
          env:
            - name: ASSEMBLY_FILE
              value: /data/assembly.csv
          envFrom:
            - secretRef:
                name: elastic-recherche-entreprises-write
323 324 325 326
          resources:
            requests:
              cpu: '1'
              memory: 14Gi
Julien Bouquillon's avatar
Julien Bouquillon committed
327 328 329 330 331
      restartPolicy: Never
      volumes:
        - name: data
          emptyDir: {}
        - configMap:
332
            name: config-map-files-0123456
Julien Bouquillon's avatar
Julien Bouquillon committed
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
            defaultMode: 511
          name: local-files
      initContainers:
        - args:
            - '-c'
            - >

              apt-get update -y && apt-get install -y wget 


              export DATA_DIR=\\"/data\\"


              cd /data


              echo \\"running get-data.sh...\\"


              /mnt/scripts/get-data.sh


              pip3 install -r /mnt/scripts/requirements.txt


              echo \\"running assemble_data.py...\\"


              python3 /mnt/scripts/assemble_data.py
              $DATA_DIR/StockUniteLegale_utf8.zip  $DATA_DIR/geo/
              $DATA_DIR/WEEZ.csv $DATA_DIR/assembly.csv
          command:
            - sh
          image: python:3.9.4
          imagePullPolicy: Always
          name: download-data
          volumeMounts:
            - name: data
              mountPath: /data
            - mountPath: /mnt/scripts
              name: local-files
    metadata:
      annotations:
        app.gitlab.com/app: socialgouv-recherche-entreprises
377 378
        app.gitlab.com/env: preprod-dev42
        app.gitlab.com/env.name: preprod-dev42
Julien Bouquillon's avatar
Julien Bouquillon committed
379 380
      labels:
        application: v1-2-3-recherche-entreprises
381
        component: v1-2-3-recherche-entreprises
Julien Bouquillon's avatar
Julien Bouquillon committed
382 383 384 385 386
        owner: recherche-entreprises
        team: recherche-entreprises
        cert: wildcard
"
`;