Dooders / Pyology

A metaphorical model of a biological cell
MIT License
0 stars 0 forks source link

Generic Function for Executing Commands with Attribute Tracking and Validation #22

Closed csmangum closed 1 month ago

csmangum commented 1 month ago

Create Generic Function for Executing Commands with Attribute Tracking and Validation

Description

We need a generic function that can execute a command on a provided object, track specified attributes before and after execution, log the results, and perform optional validations or checks. This function will be used throughout our simulation to monitor changes in metabolite levels and ensure conservation laws are respected.

Requirements

  1. The function should accept the following parameters:

    • obj: The object on which to execute the command
    • command: The method of the object to be called
    • tracked_attributes: List of attribute names to track
    • args: Positional arguments to pass to the command (optional)
    • kwargs: Keyword arguments to pass to the command (optional)
    • validations: List of validation functions to run after execution (optional)
  2. The function should:

    • Log initial values of tracked attributes
    • Execute the specified command
    • Log final values of tracked attributes
    • Calculate and log changes in tracked attributes
    • Perform any specified validations
    • Return a dictionary containing the results and tracked attribute values
  3. The function should use Python's logging module for all logging operations

  4. The function should handle both numeric and non-numeric attributes

  5. The function should be type-hinted for better code readability and IDE support

Acceptance Criteria

  1. The function is implemented as specified in the requirements
  2. The function is well-documented with docstrings explaining its purpose, parameters, and return value
  3. The function handles errors gracefully, logging warnings for failed validations rather than raising exceptions
  4. The function is tested thoroughly (see Test Cases section)
  5. The function is integrated into at least one existing part of the simulation (e.g., the Glycolysis class) as a proof of concept

Test Cases

  1. Test with a simple object and command, tracking numeric attributes
  2. Test with a complex object (e.g., Organelle) and command, tracking both numeric and non-numeric attributes
  3. Test with no tracked attributes (should not raise an error)
  4. Test with invalid tracked attributes (should log a warning and continue)
  5. Test with a validation function that passes
  6. Test with a validation function that fails (should log a warning)
  7. Test with multiple validation functions
  8. Test error handling when the command raises an exception

Implementation Details

Related Issues

Estimated Time

4-6 hours

Priority

High

Assigned To

[Your Name]

Labels

enhancement, simulation, testing