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

Result calculations #9

Open
keeganskeate opened this issue Jun 9, 2021 · 2 comments
Open

Result calculations #9

keeganskeate opened this issue Jun 9, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@keeganskeate
Copy link
Member

User-defined logic for result calculations is needed.

  • User-defined calculations should be able to be applied to any data collected from scientific instruments. See this article for an example of how to save calculations as strings and apply them to Pandas DataFrames.
  • Certain calculations, such as for microbiological, residual solvent, pesticide, and heavy metal screening, will require comparison to a defined limit for each analyte and overall to determine if the analyte and sample passes (status='Pass') or fails (status='Fail') screening. If any analyte in a analyses fails, then status is set to Fail in the sample results. Each failing analyte is recorded with the analyte's results in a metrics field in a sample's results model.
@keeganskeate keeganskeate self-assigned this Jun 9, 2021
@keeganskeate keeganskeate added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Jun 9, 2021
@colman-hartinger
Copy link

@keeganskeate You need help on any of these issues? Don't want to hop on anything that is already in progress

@keeganskeate
Copy link
Member Author

Actually yes @colman-hartinger, help on some of these issues would be awesome.

Some of the issues, such as this one, can be approached piecemeal and utilized later on through the API / user interface.

The functionality needed here is to apply a user-defined formula to measurements recorded for each sample. For example, given the following sample measurements, sample results need to be calculated.

Example measurement data points:

# measurement
measurement = {
    'measurement_id': 'xyz',
    'sample_id': 'abc',
    'mass': 0.5,
    'dilution_factor': 200,
    'metrics': [
        {'analyte': 'thca', 'measurement': 100, 'formula': ''},
        {'analyte': 'cbda', 'measurement': 30, 'formula': ''},
        .
        .
        .
    ]
}

Possible usage:

results = cannlytics.lims.calculations.apply_calculation(measurement)

Desired results:

# results
results = {
    'result_id': 'mnop',
    'measurement_id': 'xyz',
    'sample_id': 'abc',
    'mass': 0.5,
    'dilution_factor': 200,
    'metrics': [
        {'analyte': 'thca', 'measurement': 100, 'formula': '', 'result': 15, 'units': 'percent'},
        {'analyte': 'cbda', 'measurement': 30, 'formula': '', 'result': 3, 'units': 'percent'},
        .
        .
        .
    ]
}

Where the formula calculates the result. In most cases, the formula will be:

(measurement x dilution_factor x 10000) / mass

It would be nice (not necessary) for the formula to be customizable by the user. For example, the formula for total_thc may be:

total_thc = thc + 0.877 * thca

Finally, you can designate result status as pass or fail conditional on the analyte limit (or non-detected if below the lowest order of detected (LOD)).

# measurement
measurement = {
    .
    .
    .
    'metrics': [
            {'analyte': 'butane', 'measurement': 100, 'formula': '', 'limit': 5000, 'lod': 0.01},
            {'analyte': 'heptane', 'measurement': 1, 'formula': '', 'limit': 2, 'lod': 0.01},
            {'analyte': 'pentane', 'measurement': 2000, 'formula': '', 'limit': 5000, 'lod': 0.01},
    ]
}

# results
results= {
    .
    .
    .
    'metrics': [
            {'analyte': 'butane', 'measurement': 100, 'formula': '', 'limit': 5000, 'lod': 0.01, 'result': 0.03, 'status': 'pass'},
            {'analyte': 'heptane', 'measurement': 1, 'formula': '', 'limit': 2, 'lod': 0.01, 'result': nd, 'status': 'pass'},
            {'analyte': 'pentane', 'measurement': 2000, 'formula': '', 'limit': 5000, 'lod': 0.01, 'result': 10000, 'status': 'fail'},
    ],
    'overall_status': 'fail',
}

Thank you for starting your contributions and definitely let me know where you end up diving in.

@keeganskeate keeganskeate removed good first issue Good for newcomers help wanted Extra attention is needed labels Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants