Skip to content

v5.2.0 #220

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

v5.2.0 #220

wants to merge 9 commits into from

Conversation

Frix-x
Copy link
Owner

@Frix-x Frix-x commented May 25, 2025

  • Big refactor of the graph_creators for easier maintenance and extensibility
  • Fixed CLI mode for CSV(s) files and added documentation for this CLI mode
  • Added ACCEL_CHIP parameter to axes and belts macros. This allow to manually specify and force a chip for the measurements. If nothing is set, S&T will continue to use its default behavior where it try to find the best accel chip for each measurement based on what is found in [resonance_tester].
  • Added a 5 seconds dwell time between belt measurements in order to help mitigate futhermore errors and failures on printer having low powered host computers with CANbus, etc...

Summary by Sourcery

Refactor graph creation architecture for better modularity and extensibility, fix CLI CSV handling, add manual accelerometer chip selection, and improve belt test reliability.

New Features:

  • Implement composition-based graph creators by separating computation logic and plotting into dedicated modules
  • Enable CSV file support in CLI mode with proper loading logic and include a new CLI usage guide
  • Add ACCEL_CHIP parameter to axes and belts macros to allow explicit accelerometer chip selection
  • Increase belt measurement dwell time to 5 seconds to improve stability on low-power hosts

Bug Fixes:

  • Fix CSV loading in CLI mode to correctly append measurements without relying on temporary files

Enhancements:

  • Organize graph_creators code into computations and plotters packages
  • Introduce an abstract GraphCreator base class to standardize graph creation workflows

Documentation:

  • Add a CLI usage guide and update main documentation to cover CLI mode
  • Document the new ACCEL_CHIP parameter in macro reference and dummy macros configuration

Frix-x added 7 commits May 25, 2025 17:08
Better separation of concerns between computations and plotting logic,
and switch to composition instead of inheritance for the graph creators.
Also added better type safety using Protocols, better abstract base classes
and data transfer objects.
this will allow to manually specify a specific chip for the measurement
and override the default behavior where S&T usually try to find the best
suited chip based on what is found in `[resonance_tester]` config section
Refactor graph creators
And fix CLI mode
in order to help mitigate error and  failures on printer having
low pewer host computer with CANbus, etc...
Copy link
Contributor

sourcery-ai bot commented May 25, 2025

Reviewer's Guide

This PR overhauls the graph creation subsystem into a composition-based architecture—decoupling computation and plotting logic into dedicated modules—while enhancing CLI support, adding an ACCEL_CHIP override to relevant macros, and improving belt measurement robustness with an extended dwell time.

Sequence Diagram: Graph Creation Process with New Architecture

sequenceDiagram
    actor ClientCode
    participant GCF as GraphCreatorFactory
    participant SGC as SpecificGraphCreator
    participant SC as SpecificComputation
    participant SP as SpecificPlotter # Instance
    participant MM as MeasurementsManager

    ClientCode ->> GCF: create_graph_creator(type, config)
    GCF -->> SGC: new SpecificGraphCreator(config, SpecificComputationClass, SpecificPlotterClass)
    note right of SGC: SGC holds SpecificComputationClass and an instance of SpecificPlotter (SP)
    GCF -->> ClientCode: specificGraphCreator

    ClientCode ->> SGC: configure(...)

    ClientCode ->> SGC: create_graph(measurementsManager)
    activate SGC
        SGC ->> SGC: computation_instance = _create_computation(measurementsManager)
        activate SGC
            SGC ->> SC: new SpecificComputation(measurementsManager, config_from_SGC)
            SC -->> SGC: computation_instance
        deactivate SGC

        SGC ->> SC: computationResult = compute()
        activate SC
        SC -->> SGC: computationResult
        deactivate SC

        SGC ->> SP: figure = plot(computationResult)
        activate SP
        SP -->> SGC: figure
        deactivate SP

        SGC ->> SGC: _save_figure(figure)
    deactivate SGC
Loading

Sequence Diagram: ACCEL_CHIP Parameter Handling in Macros

sequenceDiagram
    actor User
    participant Macro as axes_shaper_calibration
    participant Printer
    participant AccelHelper as Accelerometer

    User ->> Macro: AXES_SHAPER_CALIBRATION(..., ACCEL_CHIP=chip_name_or_None)
    Macro ->> Macro: current_accel_chip = Get ACCEL_CHIP param
    alt current_accel_chip is None (not provided by user)
        Macro ->> AccelHelper: find_axis_accelerometer(printer, axis)
        AccelHelper -->> Macro: found_chip_name
        Macro ->> Macro: current_accel_chip = found_chip_name
    end
    alt current_accel_chip is None (still not found)
        Macro -->> User: Error: No suitable accelerometer found
    else chip found or provided
        Macro ->> Printer: k_accelerometer = lookup_object(current_accel_chip)
        alt k_accelerometer is None (chip not valid)
            Macro -->> User: Error: Accelerometer chip not found
        else chip valid
            Macro ->> AccelHelper: new Accelerometer(k_accelerometer, reactor)
            AccelHelper -->> Macro: accelerometer_instance
            Macro ->> Macro: Proceed with measurements using accelerometer_instance
        end
    end
Loading

Class Diagram: GraphCreator Factory and Registration

classDiagram
class GraphCreator {
    <<Abstract>>
    +registry: dict
    +graph_type: str
    +register(graph_type: str) classmethod
    +__init__(config, computation_class, plotter_class)
}

class GraphCreatorFactory {
    +create_graph_creator(graph_type: str, config: ShakeTuneConfig) GraphCreator
}
GraphCreatorFactory ..> GraphCreator : creates

VibrationsGraphCreator --|> GraphCreator
class VibrationsGraphCreator {
    +graph_type: "vibrations profile"
}

ShaperGraphCreator --|> GraphCreator
class ShaperGraphCreator {
    +graph_type: "input shaper"
}

AxesMapGraphCreator --|> GraphCreator
class AxesMapGraphCreator{
    +graph_type: "axes map"
}

BeltsGraphCreator --|> GraphCreator
class BeltsGraphCreator{
    +graph_type: "belts comparison"
}

StaticGraphCreator --|> GraphCreator
class StaticGraphCreator{
    +graph_type: "static frequency"
}

note for GraphCreatorFactory "Uses GraphCreator.registry to find and instantiate the correct GraphCreator subclass"
Loading

File-Level Changes

Change Details Files
Refactor graph_creators to composition-based architecture
  • Introduce GraphCreator base class with computation and plotter class injection
  • Extract per-tool computation logic into graph_creators/computations/
  • Move plotting routines into graph_creators/plotters/ and unify via PlotterStrategy
  • Define common data models in base_models, computation_results and plotting_utils
shaketune/graph_creators/graph_creator.py
shaketune/graph_creators/graph_creator_factory.py
shaketune/graph_creators/base_models.py
shaketune/graph_creators/computations/*
shaketune/graph_creators/plotters/*
shaketune/graph_creators/computation_results.py
shaketune/graph_creators/plotting_utils.py
Enable CLI mode for CSV input and add documentation
  • Handle CSV loading under SHAKE_TUNE CLI by appending samples directly
  • Return measurements list from load_from_stdata
  • Add a new CLI usage guide in docs/cli_usage.md
  • Mention CLI mode in top-level docs/README.md
shaketune/helpers/accelerometer.py
docs/README.md
docs/cli_usage.md
Add ACCEL_CHIP parameter to axes and belts macros
  • Accept ACCEL_CHIP override in axes_shaper_calibration and compare_belts_responses
  • Fallback to automatic chip discovery when unset
  • Propagate ACCEL_CHIP through dummy_macros.cfg
  • Document ACCEL_CHIP in macros reference pages
shaketune/commands/axes_shaper_calibration.py
shaketune/commands/compare_belts_responses.py
shaketune/dummy_macros.cfg
docs/macros/axes_shaper_calibrations.md
docs/macros/compare_belts_responses.md
Increase dwell time between belt measurements
  • Change toolhead.dwell from 0.5 to 5 seconds to improve stability on low-powered hosts
shaketune/commands/compare_belts_responses.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Frix-x - I've reviewed your changes - here's some feedback:

  • The accelerometer lookup and validation logic in both axes_shaper_calibration and compare_belts_responses is duplicated—consider extracting it into a shared helper function to reduce code repetition and keep behavior consistent.
  • After the refactor to a composition-based GraphCreator, double-check that all CLI and plugin flows still call define_output_target() before create_graph() to avoid the “Output target not defined” error.
  • The updated __all__ in graph_creators/__init__.py now exposes many classes—verify that only intended public APIs are exported, and move any internal helpers out of the public interface if needed.
Here's what I looked at during the review
  • 🟡 General issues: 5 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant