Skip to main content

mxbiflow is a toolkit based on pygame and pymxbi

Project description

TODO

  • session should be managed automatically

Table of Contents

Get Started 🚀

I typically use uv to manage a Python project, and I highly recommend you use uv to start the mxbi code as well.

cd # Go back to home

cd /path/your_favorite # Choose your favorite directory

git clone https://github.com/Ccccraz/mxbi.git # Clone the mxbi repository

cd mxbi # Enter the mxbi directory

uv sync # Install required dependencies

uv run mxbi # Start mxbi

Current architecture

Currently, the entire code structure is divided into five main parts:

  • User GUI: used for manually adjusting experiment settings
  • Task scheduler: used for adjusting task difficulty and switching between tasks
  • Task: used for executing specific tasks
  • Theater: serves as the environment for task execution
  • Detector: Detector, used to detect RFID tags
flowchart LR
    user_gui -->|create theater| theater
    theater -->|create scheduler| scheduler
    scheduler -->|create task| task
    task -->|adjust level| scheduler
    scheduler -->|check rfid| detector
    detector -->|control| scheduler

Task Scheduler

There were too many different states in the original code, which made the code branch paths overly complex. Therefore, I decided to separate the task scheduler, ensuring that the tasks themselves are stateless and that their inputs and outputs are deterministic. The task scheduler will ensure that its initial state is correct.

Moreover, the Protocol is used to define the interface of Task, which enables the scheduler not only to adjust the difficulty but also to switch between tasks.

Detector

Overview

The RFID module should run in an independent thread, performing detection every 100 ms and triggering corresponding callbacks based on the detection results.

Detector States

  • NO_ANIMAL: No animal detected
  • ANIMAL_PRESENT: One animal detected
  • MORE_THAN_ONE_ANIMAL: Multiple animals detected (defined as error behavior)

Data Maintenance

  • current_animal: Currently detected animal
  • history_animal: Historical animal record

State Transition Events

  • NO_ANIMAL → ANIMAL_PRESENT and current_animal != history_animal: New animal appears
  • NO_ANIMAL → ANIMAL_PRESENT and current_animal == history_animal: Animal returns
  • ANIMAL_PRESENT → NO_ANIMAL: Animal leaves
  • ANIMAL_PRESENT → ANIMAL_PRESENT and current_animal != history_animal: New animal appears
  • ANIMAL_PRESENT → MORE_THAN_ONE_ANIMAL: Multiple animals detected (error behavior)
  • MORE_THAN_ONE_ANIMAL → ANIMAL_PRESENT: Recovery
  • MORE_THAN_ONE_ANIMAL → NO_ANIMAL: Recovery

Scheduler State Regulation

  • ANIMAL_ENTERED → Scheduler in SCHEDULE
  • ANIMAL_RETURNED → Scheduler in SCHEDULE
  • ANIMAL_CHANGED → Scheduler in SCHEDULE
  • ANIMAL_LEFT → Scheduler in IDLE
  • ERROR_DETECTED → Scheduler in ERROR
sequenceDiagram
    participant RFID_Thread
    participant Detector
    participant Scheduler

    loop Every 100 ms
        RFID_Thread->>Detector: Perform detection
        activate Detector

        alt NO_ANIMAL → ANIMAL_PRESENT (current ≠ history)
            Detector->>Detector: State transition
            Detector->>Scheduler: ANIMAL_ENTERED
            Scheduler->>Scheduler: Set to SCHEDULE
        else NO_ANIMAL → ANIMAL_PRESENT (current = history)
            Detector->>Detector: State transition
            Detector->>Scheduler: ANIMAL_RETURNED
            Scheduler->>Scheduler: Set to SCHEDULE
        else ANIMAL_PRESENT → NO_ANIMAL
            Detector->>Detector: State transition
            Detector->>Scheduler: ANIMAL_LEFT
            Scheduler->>Scheduler: Set to IDLE
        else ANIMAL_PRESENT → ANIMAL_PRESENT (current ≠ history)
            Detector->>Detector: State transition
            Detector->>Scheduler: ANIMAL_CHANGED
            Scheduler->>Scheduler: Set to SCHEDULE
        else ANIMAL_PRESENT → MORE_THAN_ONE_ANIMAL
            Detector->>Detector: State transition
            Detector->>Scheduler: ERROR_DETECTED
            Scheduler->>Scheduler: Set to ERROR
        else MORE_THAN_ONE_ANIMAL → ANIMAL_PRESENT
            Detector->>Detector: State transition
            Detector->>Scheduler: Recovery event
            Scheduler->>Scheduler: Set to SCHEDULE
        else MORE_THAN_ONE_ANIMAL → NO_ANIMAL
            Detector->>Detector: State transition
            Detector->>Scheduler: Recovery event
            Scheduler->>Scheduler: Set to IDLE
        end

        deactivate Detector
    end

Extract data model

The states in the original code were scattered across a large number of variables, so I tried to extract all the data models for unified management. You can find most of the data models under src/mxbi/models.

TODO:

  • More tasks
  • More detailed instruction documents

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

mxbiflow-0.1.1.tar.gz (4.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mxbiflow-0.1.1-py3-none-any.whl (4.5 MB view details)

Uploaded Python 3

File details

Details for the file mxbiflow-0.1.1.tar.gz.

File metadata

  • Download URL: mxbiflow-0.1.1.tar.gz
  • Upload date:
  • Size: 4.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mxbiflow-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fc0d6eed2d0675f670cc2073b35e33a9862597f4be92f3dfd5f5edadcd184497
MD5 bac4f448805d771ae069d87bafebc42d
BLAKE2b-256 8fa42fa13f012735e28bd53332c4560335770b97e94cb84c58f9ae4c4634b386

See more details on using hashes here.

File details

Details for the file mxbiflow-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mxbiflow-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mxbiflow-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2f68bbba6a9d4c491afe6f07667de006ca83a3b9d47ce8ee0c1428ef5ebeb1c1
MD5 2272a5de840e161d9e9c95143a029398
BLAKE2b-256 e8fb8b34d09c2df5fed8e3eb53f86eac26b632a3ba0a54e1d1ce628cbf9933f9

See more details on using hashes here.

Supported by

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