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

feat: auto_validation function #2768

Merged
merged 14 commits into from
Jan 24, 2024

Conversation

andriacap
Copy link
Contributor

  • create migration alembic to create function auto_validation (gn_profiles.auto_validation)
  • create task celery in validation module
  • add parameters in validation toml config

[Refs_ticket] #2600
Reviewed-by: andriacap

@andriacap
Copy link
Contributor Author

Hello,

J'ai créée cette PR suite aux discussions de l'issue #2600 .

J'ai testé sur des observation en local , la fonction fonnctionne bien .

Si vous avez des retours remarques , que ce soit sur la forme ou sur le fond n'hésitez pas . En tout cas je me suis appuyé sur les idées de l'issue mentionnée plus haut.

@andriacap andriacap force-pushed the feat/auto-validation branch from fec216e to 15751a9 Compare October 26, 2023 09:59
@codecov
Copy link

codecov bot commented Oct 26, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (14ad7c6) 78.43% compared to head (517757c) 78.44%.
Report is 3 commits behind head on develop.

Files Patch % Lines
...e_validation/backend/gn_module_validation/tasks.py 76.19% 5 Missing ⚠️
backend/geonature/core/gn_commons/models/base.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2768   +/-   ##
========================================
  Coverage    78.43%   78.44%           
========================================
  Files           88       89    +1     
  Lines         7183     7213   +30     
========================================
+ Hits          5634     5658   +24     
- Misses        1549     1555    +6     
Flag Coverage Δ
pytest 78.44% <80.64%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andriacap andriacap force-pushed the feat/auto-validation branch from 57d4dd6 to 3297b60 Compare December 12, 2023 10:09
@camillemonchicourt
Copy link
Member

Il manquerait quelques lignes sur la validation automatique et comment elle fonctionne dans la documentation administrateur.
Ici je dirai : https://github.com/PnX-SI/GeoNature/blob/master/docs/admin-manual.rst#L2323 avec quelques lignes sur la possibilité d'activer la validation automatique, son fonctionnement par défaut, et la possibilité de le surcoucher.
Et ici pour mentionner que les profils de taxons peuvent être utilisés pour la validation automatique en activant la fonction dans la conf - https://github.com/PnX-SI/GeoNature/blob/master/docs/admin-manual.rst#L489

@camillemonchicourt
Copy link
Member

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

CodiumAI-Agent commented Jan 19, 2024

PR Analysis

(review updated until commit 3297b60)

  • 🎯 Main theme: Adding an auto-validation feature to the validation module
  • 📝 PR summary: This PR introduces an auto-validation feature to the validation module. It includes a new SQL function for auto-validation, a Celery task to periodically run the auto-validation, and updates to the test suite to cover the new functionality. The auto-validation feature can be enabled or disabled via the configuration file.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: Yes
  • ⏱️ Estimated effort to review [1-5]: 4, because the PR is quite large and involves changes in multiple files including SQL, Python, and configuration files. It also introduces a new feature which requires a good understanding of the existing codebase to review effectively.
  • 🔒 Security concerns: Yes, because the SQL queries in the new auto-validation function in backend/geonature/core/gn_commons/models/base.py are constructed using string formatting, which could potentially lead to SQL injection attacks if the function is not used carefully.

PR Feedback

💡 General suggestions: The PR is well-structured and the changes are logically grouped. The use of Celery for scheduling the auto-validation task is a good choice. However, it would be beneficial to provide more comments in the code to explain the logic, especially in the SQL function and the Celery task. This would make the code easier to maintain and understand for other developers.


✨ Usage guide:

Overview:
The review tool scans the PR code changes, and generates a PR review. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:

/review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...

With a configuration file, use the following template:

[pr_reviewer]
some_config1=...
some_config2=...
Utilizing extra instructions

The review tool can be configured with extra instructions, which can be used to guide the model to a feedback tailored to the needs of your project.

Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify the relevant sub-tool, and the relevant aspects of the PR that you want to emphasize.

Examples for extra instructions:

[pr_reviewer] # /review #
extra_instructions="""
In the code feedback section, emphasize the following:
- Does the code logic cover relevant edge cases?
- Is the code logic clear and easy to understand?
- Is the code logic efficient?
...
"""

Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

How to enable\disable automation
  • When you first install PR-Agent app, the default mode for the review tool is:
pr_commands = ["/review", ...]

meaning the review tool will run automatically on every PR, with the default configuration.
Edit this field to enable/disable the tool, or to change the used configurations

About the 'Code feedback' section

The review tool provides several type of feedbacks, one of them is code suggestions.
If you are interested only in the code suggestions, it is recommended to use the improve feature instead, since it dedicated only to code suggestions, and usually gives better results.
Use the review tool if you want to get a more comprehensive feedback, which includes code suggestions as well.

Auto-labels

The review tool can auto-generate two specific types of labels for a PR:

  • a possible security issue label, that detects possible security issues (enable_review_labels_security flag)
  • a Review effort [1-5]: x label, where x is the estimated effort to review the PR (enable_review_labels_effort flag)
Extra sub-tools

The review tool provides a collection of possible feedbacks about a PR.
It is recommended to review the possible options, and choose the ones relevant for your use case.
Some of the feature that are disabled by default are quite useful, and should be considered for enabling. For example:
require_score_review, require_soc2_review, enable_review_labels_effort, and more.

More PR-Agent commands

To invoke the PR-Agent, add a comment using one of the following commands:

  • /review: Request a review of your Pull Request.
  • /describe: Update the PR title and description based on the contents of the PR.
  • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
  • /ask <QUESTION>: Ask a question about the PR.
  • /update_changelog: Update the changelog based on the PR's contents.
  • /add_docs 💎: Generate docstring for new components introduced in the PR.
  • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
  • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

See the tools guide for more details.
To list the possible configuration parameters, add a /config comment.

See the review usage page for a comprehensive guide on using this tool.

@CodiumAI-Agent
Copy link

Persistent review updated to latest commit 3297b60

@camillemonchicourt
Copy link
Member

@CodiumAI-Agent /improve

Copy link
Contributor

@jacquesfize jacquesfize left a comment

Choose a reason for hiding this comment

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

Il faut encore quelques changements sur les requêtes sur la BD (style SQLA 2.0). De plus, comme l'a dit @camillemonchicourt, il faut absolument faire de la documentation dans la doc GeoNature mais aussi dans le code des nouvelles méthodes/fonctions proposées (docstring).

backend/geonature/tests/fixtures.py Show resolved Hide resolved
backend/geonature/tests/test_validation.py Outdated Show resolved Hide resolved
backend/geonature/tests/test_validation.py Outdated Show resolved Hide resolved
backend/geonature/tests/test_validation.py Outdated Show resolved Hide resolved
backend/geonature/tests/test_validation.py Outdated Show resolved Hide resolved
backend/geonature/tests/test_validation.py Outdated Show resolved Hide resolved
- create migration alembic to create function auto_validation
  (gn_profiles.auto_validation)
- create task celery in validation module
- add parameters in validation toml config

[Refs_ticket] PnX-SI#2600
Reviewed-by: andriacap
Add depends_on gn_commons migration alembic

Reviewed-by: andriacap
Reviewed-by: andriacap
Move migration alembic to validation module

Reviewed-by: andriacap
Test to check changes for "STATUT_VALID" on synthese observation with
score = 3 and auto_validation = True and validation.id_validator is None

Reviewed-by: andriacap
@jacquesfize jacquesfize force-pushed the feat/auto-validation branch 2 times, most recently from 71d563d to f6878a4 Compare January 23, 2024 10:46
@camillemonchicourt
Copy link
Member

A vérifier :

  • Toutes les données ayant le statut "En attente de validation" sont passées dans la validation automatique (pas seulement celles qui ont reçu ce statut de manière automatique
  • Pour les données validées automatiquement, on passe bien le booléen validation_auto à true
  • On n'utilise pas les labels des nomenclatures ("En attente de validation") mais leur code ("0")
  • On passe les données en statut "Probable" seulement si elles elles ont une note de 3/3 au niveau des profils, donc qu'elles répondent aux 3 critères des profils
  • En bonus, passer ce statut attribué par la validation automatique en paramètre si certains préféreraient attribuer le statut "Certain - très probable" ? Pas certain que cela soit utile ? "Probable" est idéal pour la validation automatique ?

@jacquesfize
Copy link
Contributor

A vérifier :

* Toutes les données ayant le statut "En attente de validation" sont passées dans la validation automatique (pas seulement celles qui ont reçu ce statut de manière automatique

Fait

* Pour les données validées automatiquement, on passe bien le booléen `validation_auto` à `true`

Fait

* On n'utilise pas les labels des nomenclatures ("En attente de validation") mais leur code ("0")

Fait

* On passe les données en statut "Probable" seulement si elles elles ont une note de 3/3 au niveau des profils, donc qu'elles répondent aux 3 critères des profils

Fait

* En bonus, passer ce statut attribué par la validation automatique en paramètre si certains préféreraient attribuer le statut "Certain - très probable" ? Pas certain que cela soit utile ? "Probable" est idéal pour la validation automatique ?

@jacquesfize jacquesfize force-pushed the feat/auto-validation branch 2 times, most recently from d539a35 to 40b0e1c Compare January 24, 2024 16:28
@jacquesfize jacquesfize merged commit 4926eee into PnX-SI:develop Jan 24, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants