Exemplo n.º 1
0
    def test_get_departement_name(self) -> None:
        """Point checks for the get_departement_name func."""

        self.assertEqual('Guadeloupe',
                         geo.get_departement_name(self._db, '971'))
        self.assertEqual('Nièvre', geo.get_departement_name(self._db, '58'))
        self.assertEqual('La Réunion',
                         geo.get_departement_name(self._db, '974'))
Exemplo n.º 2
0
def _find_best_departements(unused_, project):
    """Find which are the best departement to relocate for a given job group."""

    job_group = project.details.target_job.job_group.rome_id

    local_stats_ids = {
        ('{}:{}'.format(departement_id, job_group)): departement_id
        for departement_id in geo.list_all_departements(project.database)
    }

    local_stats = project.database.local_diagnosis.find(
        {'_id': {
            '$in': list(local_stats_ids)
        }})

    departement_to_offers = {}
    for departement_local_stats in local_stats:
        departement_id = local_stats_ids[departement_local_stats['_id']]
        departement_to_offers[departement_id] = \
            departement_local_stats.get('imt', {}).get('yearlyAvgOffersPer10Candidates', 0) or 0

    # If we do not have data about our own departement, we chose not to say anything.
    own_departement = project.details.mobility.city.departement_id
    if own_departement:
        try:
            geo.get_departement_name(project.database, own_departement)
        except KeyError:
            logging.warning(
                'We cannot find the name of the French département "%s"',
                own_departement)

    # We only advice departements that are better than own departement.
    min_offers = departement_to_offers.get(own_departement, 0)

    if not min_offers:
        return []

    # Compute the score for each departement.
    sorted_departements = sorted(departement_to_offers.items(),
                                 key=lambda x: x[1],
                                 reverse=True)

    # Get only departements that are strictly better than own departement.
    top_departements = [
        project_pb2.DepartementScore(name=geo.get_departement_name(
            project.database, dep[0]),
                                     offer_ratio=dep[1] / min_offers)
        for dep in sorted_departements if dep[1] > min_offers
    ]

    return top_departements
Exemplo n.º 3
0
def _find_best_departements(unused_: Any, project: scoring_base.ScoringProject) \
        -> list[project_pb2.DepartementScore]:
    """Find which are the best departement to relocate for a given job group."""

    own_departement_offers = project.imt_proto(
    ).yearly_avg_offers_per_10_candidates

    # If we do not have data about our own departement, we choose not to say anything.
    if not own_departement_offers:
        return []

    best_departements = project.job_group_info().departement_scores

    result: list[project_pb2.DepartementScore] = []
    for dep in itertools.islice(best_departements, 10):
        if dep.local_stats.imt.yearly_avg_offers_per_10_candidates <= own_departement_offers:
            return result
        offer_ratio = \
            dep.local_stats.imt.yearly_avg_offers_per_10_candidates / own_departement_offers
        result.append(
            project_pb2.DepartementScore(name=project.translate_string(
                geo.get_departement_name(project.database,
                                         dep.departement_id)),
                                         offer_ratio=offer_ratio))

    return result
Exemplo n.º 4
0
def _make_departements_section(user_departement_id, best_departements,
                               area_type, database):
    if area_type < geo_pb2.COUNTRY or not best_departements:
        return None
    best_departements_title = '<br />'.join(
        geo.get_departement_name(database, dep) for dep in best_departements)
    try:
        best_departements.remove(user_departement_id)
        is_best_departement = True
    except ValueError:
        is_best_departement = False
    best_departements_sentence = ' et '.join(
        geo.get_in_a_departement_text(database, dep)
        for dep in best_departements)
    return {
        'count': str(len(best_departements)),
        'isInBest': campaign.as_template_boolean(is_best_departement),
        'title': best_departements_title,
        'sentence': best_departements_sentence,
    }
Exemplo n.º 5
0
def _make_departements_section(
        user_departement_id: str, best_departements: list[str],
        area_type: 'geo_pb2.AreaType.V', database: mongo.NoPiiMongoDatabase,
        scoring_project: scoring.ScoringProject) -> Optional[dict[str, str]]:
    if area_type < geo_pb2.COUNTRY or not best_departements:
        return None
    best_departements_title = '<br />'.join(
        geo.get_departement_name(database, dep) for dep in best_departements)
    try:
        best_departements.remove(user_departement_id)
        is_best_departement = True
    except ValueError:
        is_best_departement = False
    best_departements_sentence = scoring_project.translate_static_string(' et ').join(
        geo.get_in_a_departement_text(database, dep) for dep in best_departements)
    return {
        'count': str(len(best_departements)),
        'isInBest': campaign.as_template_boolean(is_best_departement),
        'title': best_departements_title,
        'sentence': best_departements_sentence,
    }
Exemplo n.º 6
0
    def test_get_departement_name_unknown_id(self):
        """Check get_departement_name on an unknown département."""

        with self.assertRaises(KeyError):
            geo.get_departement_name(self._db, 'xxx')