
.. .. image:: https://readthedocs.org/projects/tt4human/badge/?version=latest
    :target: https://tt4human.readthedocs.io/en/latest/
    :alt: Documentation Status

.. image:: https://github.com/MacHu-GWU/tt4human-project/workflows/CI/badge.svg
    :target: https://github.com/MacHu-GWU/tt4human-project/actions?query=workflow:CI

.. .. image:: https://codecov.io/gh/MacHu-GWU/tt4human-project/branch/main/graph/badge.svg
    :target: https://codecov.io/gh/MacHu-GWU/tt4human-project

.. image:: https://img.shields.io/pypi/v/tt4human.svg
    :target: https://pypi.python.org/pypi/tt4human

.. image:: https://img.shields.io/pypi/l/tt4human.svg
    :target: https://pypi.python.org/pypi/tt4human

.. image:: https://img.shields.io/pypi/pyversions/tt4human.svg
    :target: https://pypi.python.org/pypi/tt4human

.. image:: https://img.shields.io/badge/Release_History!--None.svg?style=social
    :target: https://github.com/MacHu-GWU/tt4human-project/blob/main/release-history.rst

.. image:: https://img.shields.io/badge/STAR_Me_on_GitHub!--None.svg?style=social
    :target: https://github.com/MacHu-GWU/tt4human-project

------

.. .. image:: https://img.shields.io/badge/Link-Document-blue.svg
    :target: https://tt4human.readthedocs.io/en/latest/

.. .. image:: https://img.shields.io/badge/Link-API-blue.svg
    :target: https://tt4human.readthedocs.io/en/latest/py-modindex.html

.. image:: https://img.shields.io/badge/Link-Install-blue.svg
    :target: `install`_

.. image:: https://img.shields.io/badge/Link-GitHub-blue.svg
    :target: https://github.com/MacHu-GWU/tt4human-project

.. image:: https://img.shields.io/badge/Link-Submit_Issue-blue.svg
    :target: https://github.com/MacHu-GWU/tt4human-project/issues

.. image:: https://img.shields.io/badge/Link-Request_Feature-blue.svg
    :target: https://github.com/MacHu-GWU/tt4human-project/issues

.. image:: https://img.shields.io/badge/Link-Download-blue.svg
    :target: https://pypi.org/pypi/tt4human#files


Welcome to ``tt4human`` Documentation
==============================================================================
`Truth Table <https://en.wikipedia.org/wiki/Truth_table>`_ is a lookup table that can return a boolean value by given a set of conditions. A set of conditions is called a **case**.

For example, we have two types of conditions: ``weather`` and ``get_up`` (when you get up). And we want to determine if you will go out. ``weather`` has two possible values: ``is_sunny`` and ``not_sunny``. ``get_up`` has three possible values: ``before_10``, ``10_to_2``, ``after_2``.

Below is the truth table::

    weather	    get_up	    go_out
    is_sunny	before_10	1
    is_sunny	10_to_2	    1
    is_sunny	after_2	    0
    not_sunny	before_10	0
    not_sunny	10_to_2	    0
    not_sunny	after_2	    0

**Feature 1, truth table evaluator**

the ``tt4human`` Python library can read truth table data from csv/tsv file and evaluate the truth table by the given case.

.. code-block:: python

    >>> from tt4human.api import TruthTable
    >>> tt = TruthTable.from_csv(dir_unit_test.joinpath("go_out.tsv"))
    >>> tt.evaluate(case=dict(weather="is_sunny", get_up="before_10"))
    True

**Feature 2, Truth table enum module generator**

You may want to create a Python module that contains all the condition enum and the initialized ``TruthTable`` instance. So that you can drop them to your code base and use them directly.

.. code-block:: python

    >>> from tt4human.api import TruthTable
    >>> from pathlib import Path
    >>> tt = TruthTable.from_csv(dir_unit_test.joinpath("go_out.tsv"))
    >>> tt.generate_module(
    ...     dir_path=Path("/path/to/your/project/folder),
    ...     module_name="do_you_go_out",
    ...     overwrite=False,
    ... )

Then it will create a ``do_you_go_out.tsv`` file::

    weather	    get_up	    go_out
    is_sunny	before_10	1
    is_sunny	10_to_2	    1
    is_sunny	after_2	    0
    not_sunny	before_10	0
    not_sunny	10_to_2	    0
    not_sunny	after_2	    0

And create a ``do_you_go_out.py`` file:

.. code-block:: python

    # -*- coding: utf-8 -*-

    """
    this module is generated by https://pypi.org/project/tt4human = 0.1.1
    """

    from pathlib import Path
    from tt4human.api import BetterStrEnum, TruthTable


    class WeatherEnum(BetterStrEnum):
        is_sunny = "is_sunny"
        not_sunny = "not_sunny"


    class GetUpEnum(BetterStrEnum):
        before_10 = "before_10"
        _10_to_2 = "10_to_2"
        after_2 = "after_2"


    truth_table = TruthTable.from_csv(
        path=Path(__file__).absolute().parent.joinpath("do_you_go_out.tsv"),
    )

    if __name__ == "__main__":
        assert truth_table.evaluate(case={'weather': 'is_sunny', 'get_up': 'before_10'}) is True



.. _install:

Install
------------------------------------------------------------------------------

``tt4human`` is released on PyPI, so all you need is to:

.. code-block:: console

    $ pip install tt4human

To upgrade to latest version:

.. code-block:: console

    $ pip install --upgrade tt4human
