Exemple #1
0
def do_import_reco(file_path) -> Recommendation:
    reco_dataframe = pd.read_csv(file_path)
    total_reco = new_reco = 0

    for row in reco_dataframe.itertuples():
        if str(row.benefit) == 'nan':
            continue
        reco = Recommendation.query.get(row.id)
        if not reco:
            reco = Recommendation()
            reco.id = row.id
            new_reco += 1

        reco.title = row.title
        if str(row.content) != 'nan':
            reco.content = row.content
        # TODO: temporary with set a default value
        else:
            reco.content = "Contenu non défini"
        if str(row.benefit) != 'nan':
            reco.benefit = row.benefit
        else:
            reco.benefit = 0.0
        if str(row.benefit_description) != 'nan':
            reco.benefit_description = row.benefit_description
        if str(row.how_to) != 'nan':
            reco.how_to = row.how_to
        reco.type = FootprintType({'label': row.category})
        total_reco += 1
        BaseObject.check_and_save(reco)

    print('Recommendations updated : %s' % str(total_reco - new_reco))
    print('Recommendations created : %s' % new_reco)
Exemple #2
0
    def execute(self, user: User, data) -> Recommendation:
        if user is None:
            raise BadUserException()

        if data is None:
            raise BadArgException

        recommendation = Recommendation()
        recommendation.user_id = user.id
        recommendation.title = data.get('title')
        recommendation.content = data.get('content')
        recommendation.estimated_success_time = data.get(
            'estimated_success_time')
        recommendation.difficulty_level = data.get('difficulty_level')
        recommendation.benefit = data.get('benefit')
        recommendation.type = data.get('type')

        BaseObject.check_and_save(recommendation)

        return recommendation