Skip to main content

Mold

Architecture Overview / Data Flow

Mold Machine
↓ (exports to file)
C:\WINCC\dati\YYYYMM.dat
↓ (monitored by)
Python Script (main.py)
↓ (detects changes via hash)
Parse CSV → JSON
↓ (POST request)
API: /api/mold/import_mold_data
↓ (validates & processes)
Database: block table
↓ (fetched by)
API: /api/block/get
↓ (displays in)
Mold In Progress Page (Tabulator table)
↓ (operator edits)
API: /api/block/save
↓ (updates)
Database: block table

Python Monitoring Script

Location: C:\Users\jmess\PycharmProjects\shelter-ent-mold-app\main.py

The Python script runs continuously on the mold machine computer, monitoring changes to the monthly mold data file.

Configuration (settings.json):

{
"site_url": "https://dev.shelter-ent.app/index.php/",
"file_path": ".\\",
"mold_file_path": ".\\",
"controller": "api/mold",
"function": "import_mold_data",
"api_key": "YOUR_API_KEY",
"sleep_time": 30,
"headers": [
"date", "time", "block_num", "density", "height", "depth",
"load_weight", "weight", "req_density", "regrind", "silo_density",
"block_density", "stab_t", "cycle_time", "steam_time",
"raw_silo", "raw_code", "ground_silo", "ground_code"
]
}

Key Functions

  • File Monitoring (handle_file_change): Computes the SHA3-512 hash of the mold file every 30 seconds. When the hash changes, it waits for the file to stop changing, parses the file, and exports it to the web application.
  • Data Parsing (process_block_data): Reads the tab-separated .dat file, structures data as JSON, and stores a local backup in json_files\YYYYMM.json.
  • API Communication (post_data): Posts the JSON array to {site_url}/api/mold/import_mold_data using Bearer token authentication.
  • Startup Behavior: Runs an immediate export on script start, begins monitoring for file changes, and outputs: "DO NOT CLOSE THIS WINDOW (minimize it)".

Web Application Backend

API Controller: App\Controllers\Api\Mold

import_data() Method (/api/mold/import_mold_data):

  • Combines date + time into the created timestamp.
  • Maps density string to database ID using parse_density_string() helper (falls back to "Custom" density if no match found).
  • Checks for existing block via get_block(created, block_num).
  • If a block doesn't exist, creates a new Block_model record.
  • If it exists, updates the existing record.
  • Links block to lots from raw and ground silos intelligently using FIFO consumption tracking (calculate_block_material_consumption).

API Controller: App\Controllers\Api\Block

  • get() (/api/block/get): Fetches paginated unused blocks (date_used IS NULL).
  • save() (/api/block/save): Updates block properties from inline editing via Tabulator.
  • flag() (/api/block/flag): Updates flagged status and comments. Requires a comment even if an empty string.

Model: App\Models\Block_model

Table: block

Fillable Fields:

  • density_id, block_num, created, height, regrind, weight, depth, load_weight, raw_silo, ground_silo

Relationships:

  • density(): BelongsTo Density_model
  • cut_job(): BelongsTo Job_model
  • eifs_blocks(): HasMany Eifs_block_model
  • used_eifs_blocks(): HasMany Eifs_block_model

Important Considerations

  • Duplicate Prevention: The get_block() helper checks for existing blocks by date + block_num. Import always updates existing blocks rather than creating duplicates.
  • Density Matching: parse_density_string() uses fuzzy matching for density labels.
  • Silo/Lot Linking: Blocks are automatically linked to lots in the silos they were created from in the block_lots junction table.

Validation Rules

Import Validation:

  • Dates must be valid m/d/Y format
  • Times must be valid H:i:s format
  • Block numbers: 1-99998
  • Regrind: 0-100%
  • Heights, weights must be > 0
  • Silo numbers within acceptable ranges

Troubleshooting

Problem: Block appears in mold file but not in web application.

Solution:

  1. Check Python script console for errors.
  2. Verify script is running (should show "Waiting for file changes...").
  3. Check logs/log-YYYY-MM-DD.txt for error messages.
  4. Verify API key in settings.json is valid.
  5. Check network connectivity between mold computer and web server.
  6. Review web application logs for validation errors.

Problem: Density shows as "Custom" when it should be specific type.

Solution:

  1. Check exact density string in .dat file.
  2. Add new variation to parse_density_string() function in block_helper.php.
  3. Or update density label in database to match mold machine output.
  • Python Scripts - Detailed documentation on the overall architecture of Python scripts integrating with the factory hardware.