Code Monkey home page Code Monkey logo

run-detection's Introduction

run-detection

License: GPL-3.0 Build: passing Code style: black linting: pylint

Running and Testing

To run:

  • pip install .
  • run-detection

To install when developing:

  • pip install .[dev]
    Note: you may need to escape the square brackets. This will also install pytest, pylint, mypy etc.

To demo and test. The easiest way to test the whole run detection currently:

  • docker run -p 61613:61613 -p 61616:61616 -p 8161:8161 rmohr/activemq
  • Login to the webgui at http://localhost:8161
  • Create a new queue called "Interactive-Reduction"
  • Send messages via the webgui to that queue
  • Verify they are printed.

How to container

docker build . -f ./container/rundetection.D -t ghcr.io/interactivereduction/rundetection
  • Run the container by running:
docker run -it --rm --mount source=/archive,target=/archive --name rundetection ghcr.io/interactivereduction/rundetection
  • To push containers you will need to setup the correct access for it, you can follow this guide.
  • Upload the container by running (should be handled by CI, but this can be done manually if needed):
docker push ghcr.io/interactivereduction/rundetection -a
  • To pull containers you will also need the permissions set above in the guide.
  • Pull the container by running:
docker pull ghcr.io/interactivereduction/rundetection:latest

Running tests

To run the unit tests only run: pytest . --ignore test/test_e2e.py

To run the e2e tests:

cd test 
docker-compose up -d
cd ..
pytest test/test_e2e.py

This will pull the kafka/activemq containers and build the run detection container. Any code changes made after starting run detection will require the run detection container to be rebuilt.

Adding to Instrument Specifications

For a run to be sent downstream the metadata of the recieved file must meet the specification for that instrument. The specifications for each instrument are found in rundetection/specifications/<instrument>_specification.json

An example specification file:

{
  "enabled": true
}

Within the json file each field is considered to be a Rule and has a class associated with it. e.g. the EnabledRule class.

Example of Adding a new Rule

Below is an example of adding a new rule. The example is unrealistic, but it shows how much flexibility there is.

  1. Update the specification file:
    {
     "enabled": true,
     "skipTitlesIncluding": ["foo", "bar", "baz"] 
    }
  2. Create the Rule implementation:
    class SkipTitlesIncludingRule(Rule[List[str]]):
    
      def verify(self, metadata: NexusMetadata):
          return any(word in metadata.experiment_title for word in self._value)
  3. Update the RuleFactory:
    def rule_factory(key: str, value: T) -> Rule[T]:
        """
        Given the rule key, and rule value, return the rule implementation
        :param key: The key of the rule
        :param value: The value of the rule
        :return: The Rule implementation
        """
        match key.lower():
            case "enabled":
                if isinstance(value, bool):
                    return EnabledRule(value)
                else:
                    raise ValueError(f"Bad value: {value} in rule: {key}")
            case "skiptitlesincluding":
                if isinstance(value, list):
                    return SkipTitlesIncludingRule(value)
                else:
                    raise ValueError(f"Bad value: {value} in rule: {key}")
            case _:
                raise MissingRuleError(f"Implementation of Rule: {key} does not exist.")

run-detection's People

Contributors

keiranjprice101 avatar pasarus avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.