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(api, robot-server): allow setting CSV param files via protocols & analyses endpoints #15686

Merged
merged 10 commits into from
Jul 29, 2024

Conversation

sanni-t
Copy link
Member

@sanni-t sanni-t commented Jul 16, 2024

Closes AUTH-416

Overview

This PR adds the capability of setting the CSV run time parameter with a CSV file. Features added:

  • POST /protocols and POST /analyses now accept runTimeParameterFiles data in addition to the existing runTimeParameterValues data
  • Adds a table to save the CSV file IDs used in analyses
  • The CSV param is updated with the file ID mentioned

Test Plan

  • Upload the protocol in feat(api): add csv parameter definitions #15332 without supplying a csv file ID in the request. Test that:
    • the protocol upload response contains the full run time parameters, including CSV parameter without any file info
    • the protocol's analysis eventually completes with a status of ok and the run time parameters are present in the full completed analysis
  • Upload a CSV file to the /dataFiles endpoint, get its ID.
  • Upload the above protocol again, and provide the above CSV file ID with it using runTimeParameterFiles. Test that:
    • the protocol upload response contains the full run time parameters, including CSV parameter and the file ID
    • the protocol's analysis eventually completes with a status of ok and the CSV parameters with file ID are present in the full analysis
  • Test both points (1) & (3) using the POST /protocols/protocolId/analyses endpoint
  • Test that if you send the same protocol with the same RTP values and files, a new analysis is not started

Changelog

API:

  • updated the CSV param engine type to include file name in file property
  • updated PythonProtocolRunner.load & supporting functions to accept CSV file ID overrides and use them to validate and set CSV parameters.
  • added a function to initialize the CSV parameter with the file and file info (right now only sets the file ID)

Robot-server:

  • added analysis csv params DB table
  • updated POST /protocols and POST /analyses to accept runTimeParameterFiles in their form-data & request body, respectively.
  • updated analysis stores to update the csv table with CSV file IDs

Review requests

  • Test with the app and make sure the app requirements are fulfilled.
  • Usual code sanity checks.

Risk assessment

None- low. Adds a new capability to the protocols endpoints and doesn't change existing code much.

Copy link
Contributor

A PR has been opened to address analyses snapshot changes. Please review the changes here: https://github.com/Opentrons/opentrons/pull/

@sanni-t sanni-t marked this pull request as ready for review July 18, 2024 22:41
@sanni-t sanni-t requested review from a team as code owners July 18, 2024 22:42
Comment on lines +1058 to +1061
file: Optional[FileInfo] = Field(
default=None,
description="ID of the CSV file stored on the robot; to be used for fetching the CSV file."
" For local analysis this will most likely be empty.",
Copy link
Member Author

Choose a reason for hiding this comment

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

@ncdiehl @koji : reverted this to be a nested file property and added name field to the data type.

Comment on lines 97 to 99
file:
- id: '{csv_file_id}'
name: ''
Copy link
Member Author

Choose a reason for hiding this comment

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

@ncdiehl @koji see this for example CSV param in analysis response

Copy link
Contributor

A PR has been opened to address analyses snapshot changes. Please review the changes here: https://github.com/Opentrons/opentrons/pull/

from opentrons.protocol_engine.types import (
RunTimeParameter,
PrimitiveRunTimeParamValuesType,
CsvRunTimeParamFilesType,
Copy link
Contributor

Choose a reason for hiding this comment

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

Little nitpick, I think we should always capitalize CSV if we're doing camelcase, it makes it stand out more.

with self._sql_engine.begin() as transaction:
results = transaction.execute(statement).all()

csv_rtps: Dict[str, Union[str, None]] = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
csv_rtps: Dict[str, Union[str, None]] = {}
csv_rtps: Dict[str, Optional[str]] = {}

Copy link
Contributor

@jbleon95 jbleon95 left a comment

Choose a reason for hiding this comment

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

Some minor nitpicks with style and the like, but this is looking good!


with self._sql_engine.begin() as transaction:
transaction.execute(delete_primitive_rtp_statement)
transaction.execute(delete_csv_rtp_statement)
transaction.execute(delete_csv_rtp_statement)
Copy link
Contributor

Choose a reason for hiding this comment

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

Line repeated, unless we want to make sure the file is really deleted 😛

Copy link
Member Author

Choose a reason for hiding this comment

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

😆


analysis_id: str
parameter_variable_name: str
file_id: Union[str, None]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
file_id: Union[str, None]
file_id: Optional[str]

@sanni-t sanni-t force-pushed the AUTH-416-accept-csv-file-ids-and-save-to-csv-table branch from 5282993 to c7fff38 Compare July 23, 2024 18:41
Copy link
Contributor

@jbleon95 jbleon95 left a comment

Choose a reason for hiding this comment

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

Besides one more teensy nitpick this looks great.



@dataclass
class CsvParameterResource:
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to be nitpicky on this but for style consistency lets also have this be CSVParameterResource

@sanni-t sanni-t force-pushed the AUTH-416-accept-csv-file-ids-and-save-to-csv-table branch 2 times, most recently from cd06d7d to a252211 Compare July 26, 2024 21:35
@sanni-t sanni-t changed the base branch from AUTH-527-move-rtps-to-their-own-table to edge July 29, 2024 19:21
@sanni-t sanni-t force-pushed the AUTH-416-accept-csv-file-ids-and-save-to-csv-table branch from a252211 to c927ebd Compare July 29, 2024 19:45
@sanni-t sanni-t merged commit 800ce4d into edge Jul 29, 2024
39 checks passed
@sanni-t sanni-t deleted the AUTH-416-accept-csv-file-ids-and-save-to-csv-table branch August 6, 2024 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants