Skip to main content

A skeleton template for Python projects.

Project description

Python Simple decision table procesor

CI Codecov Maintainability Code Climate technical debt Read the Docs PyPi

Install

pysidetap is available on PyPI pypi-pysidetap and you can install it using pip:

`sh pip install pysidetap `

Summary

Simple Decision Table Processor

https://en.wikipedia.org/wiki/Decision_table

This function find and return field ‘return’ from Decision Table,

when all operands in row by ‘fields’ are True.

Example:

This example show use case off Traffic lights decisions.

https://en.wikipedia.org/wiki/Traffic_light#Meanings_of_signals

Decision Table:

red

yellow

green

return

==on

==off

==off

stop

==on

==on

==off

ready

==off

==off

==on

go

==off

==on

==off

break

==off

==off

==off

off

from pysidetap.processor import DTProcessor

DTableTL = [
    {
        'fields': {
            'red': {'op':'==', 'value':'on'},
            'yellow': {'op':'==', 'value':'off'},
            'green': {'op':'==', 'value':'off'},
        },
        # Traffic may not proceed beyond the stop line or
        # otherwise enter the intersection
        'return': {'stop'}
    },
    {
        'fields': {
            'red': {'op':'==', 'value':'on'},
            'yellow': {'op':'==', 'value':'on'},
            'green': {'op':'==', 'value':'off'},
        },
        # The signal is about to change, but the red light rules do apply
        'return': {'ready'}
    },
    {
        'fields': {
            'red': {'op':'==', 'value':'off'},
            'yellow': {'op':'==', 'value':'off'},
            'green': {'op':'==', 'value':'on'},
        },
        # Traffic may not pass the stop line or enter the intersection
        # unless it cannot safely stop when the light shows
        'return': {'go'}
    },
    {
        'fields': {
            'red': {'op':'==', 'value':'off'},
            'yellow': {'op':'==', 'value':'on'},
            'green': {'op':'==', 'value':'off'},
        },
        # Traffic may proceed unless it would not clear the intersection
        # before the next change of phase
        'return': {'break'}
    },
    {
        'fields': {
            'red': {'op':'==', 'value':'off'},
            'yellow': {'op':'==', 'value':'off'},
            'green': {'op':'==', 'value':'off'},
        },
        # Traffic lights is off
        'return': {'off'}
    },
]

p = DTProcessor(DTableTL)
for red in ['on','off']:
    for yellow in ['on','off']:
        for green in ['on','off']:
            result = p.process({'red':red, 'yellow':yellow, 'green':green})
            print(f'red: {red}, yellow: {yellow}, green: {green}, result:{result}')

Issues and Discussions

As usual for any GitHub-based project, raise an issue if you find any bug or want to suggest an improvement, or open a discussion if you want to discuss or chat :wink:

Version

v0.0.7

Changelog

v0.0.7 (2023-12-22)

v0.0.6 (2023-12-22)

v0.0.5 (2023-12-22)

v0.0.4 (2023-01-08)

  • documentation update

  • added traffic lights example

v0.0.3 (2023-01-05)

  • documentation update

v0.0.2 (2023-01-05)

  • First release on PyPI.

v0.1.0 (2023-01-05)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysidetap-0.0.7.tar.gz (22.4 kB view hashes)

Uploaded Source

Built Distribution

pysidetap-0.0.7-py3-none-any.whl (6.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page