ai-cfia / nachet-backend

A flask-based backend for Nachet to handle Azure endpoint and Azure storage API requests from the frontend.
MIT License
1 stars 4 forks source link

Create an endpoint in the backend to save the data to the database for training and statistics purposes #87

Closed sylvanie85 closed 3 months ago

sylvanie85 commented 4 months ago

To let the users save their inference feedback, the backend needs to have an endpoint where it'll retrieve the feedback and send them to the datastore depends on if the inference is perfect or if the user has made some corrections.

The endpoint need to retrieve the user_id of the user who sends the feedback, the inference_id of the inference in question and, if the inference is not perfect, the inference_feedback as a json, contains the user corrections.

If the inference is perfect :

If there is a correction :

sequenceDiagram;
  actor User
  participant Frontend
  participant Backend
  participant Datastore
  participant Database

    User ->> Frontend: Validate inference
    alt Perfect Inference
    Frontend -) Backend: Inference result positive (user_id,inference_id)
    Backend -) Datastore: Inference result positive (user_id,inference_id)
    Datastore ->> Database: Set each object.verified = True & object.modified=False
    else Annotated Inference
    Frontend -) Backend: Inference feedback (inference_feedback.json,user_id,inference_id)
    Backend ->> Datastore: Inference feedback (inference_feedback.json, user_id, inference_id)
    Datastore -> Database: Get Inference_result(inference_id)
        loop each Boxes
            alt box has an id value
                alt inference_feedback.box.verified= False
                    Datastore --> Datastore: Next box & flag_all_box_verified=False
                else
                    Datastore -) Database: Set object.verified=True & object.verified_by=user_id
                    Datastore -) Datastore: Compare label & box coordinate
                    alt label value empty
                        Datastore -) Database: Set object.top_inference=Null
                        Datastore -) Database: Set object.modified=False                   
                    else label or box coordinate are changed & not empty
                        Datastore -) Database: Update object.top_inference & object.box_metadata
                        Note over Datastore,Database: if the top label is not part of the seed_object guesses, <br>we will need to create a new instance of seed_object.
                        Datastore -) Database: Set object.modified=true
                    else label and box haven't changed
                        Datastore -) Database: Set object.modified=False
                    end
                end
            else box has no id value
                Datastore -) Database: Create new object and seed_object
            end
        end
        alt if flag_all_box_verified=True
            Datastore -) Database: Set Inference.verified=true
        end
    end
sylvanie85 commented 4 months ago

Hi, @Francois-Werbrouck @ChromaticPanic is that ok ?

ChromaticPanic commented 4 months ago

Hi, @Francois-Werbrouck @ChromaticPanic is that ok ?

Looks good to me! (From the front end)

ChromaticPanic commented 4 months ago

I'll send this in post data for positive feedback

export interface FeedbackDataPositive {
  userId: string;
  inferenceId: string;
  boxes: Array<{
    boxId: string;
  }>;
}

const request = {
    method: "post",
    url: `${backendUrl}/feedback-positive`,
    headers: {
      "Content-Type": "application/json",
      "Access-Control-Allow-Origin": "*",
    },
    data: {
      userId: uuid,
      inferenceId: inferenceId,
      boxes: [{
                boxId,
            }]
    },
  };