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.2.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.2-py3-none-any.whl (4.5 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mxbiflow-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 b4fdd1e1d107d914ba1dfa9c7efd9e0cb23fd8824c558e2f6a905057ddaeb6ab
MD5 553f241a1476631cce776e577f16b50c
BLAKE2b-256 67e875e48ba89135ff5af44990fa24ba532102376612ea1bb38744cc782e5363

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mxbiflow-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7e67ced89a344dc257a584e3d7e80f18a92761496db54d95f7c36f9ed1f7440a
MD5 a25c744948df89cbb1f035516cd1fc3c
BLAKE2b-256 50f052caa7e3080c2a59941fa7f69834a3aa13e4210d68dfd9ebd1a8ff803587

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