Skip to content

CProgramming_FormulaGenerator is a python based tool which helps to generate the excel logical formula

Notifications You must be signed in to change notification settings

SRMTestingServices/CProgramming_FormulaGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Formula Generator

A web-based application for extracting C code from Excel files and generating Excel formulas from control logic. This is a multi-phase system that analyzes C code, extracts parameters, identifies outputs, and prepares for automatic Excel formula generation.

Current Features

✅ Phase 1: C Code Extraction (Completed)

  • Excel File Reader: Read .xlsx and .xlsb files containing C code
  • C Code Parser: Extract C functions from Excel cells with column-by-column scanning
  • Batch Processing: Process single files or entire folders recursively
  • AUTOSAR Support: Handles FUNC() macro patterns
  • Web Interface: Modern UI with drag-and-drop file upload

✅ Phase 2: Parameter Extraction (Completed)

  • Template Support: Multiple extraction templates (TOCHIGI, PADAS)
  • PADAS Template:
    • Sheet-specific processing with SheetJS integration
    • Multi-marker support: "変数名", "DefineVariable", "Input", and "Expected Value" markers
    • Processes ALL marker locations found in same sheet
    • Horizontal parameter layout extraction (変数名, DefineVariable, Expected Value)
    • Vertical parameter layout extraction (Input)
    • Robust empty cell detection (stops after 5 consecutive empty columns)
    • Input/Output Classification: Automatic parameter type detection
  • TOCHIGI Template: Vertical layout with section-based extraction
  • Stub File Auto-Detection: Automatically finds and uploads matching .txt stub files

✅ Phase 4: Output Parameter Identification (Completed - PADAS Only)

  • Expected Value Marker: Extracts output parameters from "Expected Value" marker in PADAS templates
  • Horizontal Layout: Parameter names in row+1, values in row+2 (same as 変数名/DefineVariable)
  • Automatic Classification: All parameters tagged as "input" or "output" type
  • Separate Counting: API returns input_count and output_count separately
  • UI Display: Input parameters (blue) and output parameters (orange) shown in separate sections
  • Template Support: PADAS only (TOCHIGI and ADAS5 output extraction not implemented)

✅ Phase 6: Report Generation (Completed)

  • HTML Report: Generate downloadable reports with all extraction results
  • Backend Logs: Includes execution logs from c_parser_history.log
  • Comprehensive Data: C code, parameters, stub files, processing timestamps
  • Clear Functionality: Reset UI and start fresh processing

🔄 Phase 5: Formula Generation (Implemented - Needs Enhancement)

  • Rule-Based Pattern Translation: 5 core rules for common C patterns
  • Rules Implemented:
    1. Direct Assignment: output = input=input
    2. If/Else Selection: Conditional assignments → =IF(condition, value_a, value_b)
    3. Set-Only Latch: Sticky fault pattern → =OR(fault=1, PREV_output=1)
    4. Rising-Edge Hold: HoldEdge pattern → Multi-formula (edge, counter, output)
    5. Up-Counter: Counter with enable/reset → =IF(reset, 0, IF(enable, PREV+1, PREV))
  • Function Bundler: Groups Phase 1-4 data by function
  • Formula Output: Shows formulas with rule names, dependencies, and warnings
  • Current Limitation: Basic rules need enhancement to match more PADAS code patterns
  • Status: Working for simple patterns (HoldEdge), needs improvement for complex logic

⏳ Upcoming Phases

  • Phase 3: Stub file content extraction and mapping (partially complete - auto-detection done)
  • Phase 5 Enhancement: Improve pattern matching rules for real PADAS C code structures

Installation

pip install -r requirements.txt

Usage

Web Interface (Recommended)

  1. Start the server:
python run.py
  1. Open browser to http://localhost:8000

  2. Select template type (TOCHIGI or PADAS)

  3. Upload files:

    • Single file: Click "Select File"
    • Batch processing: Click "Select Folder" (includes all subfolders)
  4. Click "Generate Formula" to process

  5. View results in the table and download HTML report

API Usage

# Upload single file with PADAS template
curl -X POST "http://localhost:8000/api/upload" \
  -F "file=@example.xlsx" \
  -F "template=padas" \
  -F "sheet_name=SheetName" \
  -F "first_in_batch=true"

# Get recent logs
curl "http://localhost:8000/api/logs?lines=500"

Project Structure

formula_generator/
├── src/
│   └── formula_generator/
│       ├── __init__.py
│       ├── excel_reader.py           # Excel file handling
│       ├── c_parser.py               # C code extraction and parsing
│       ├── parameter_parser.py       # Parameter extraction (Phase 2 & 4)
│       ├── function_bundler.py       # Combine Phase 1-4 data (Phase 5)
│       └── formula_generator.py      # Rule-based formula generation (Phase 5)
├── tests/
│   ├── __init__.py
│   └── test_analyzer.py
├── examples/
│   └── sample_usage.py
├── requirements.txt
├── pyproject.toml
└── README.md

Development

Run tests:

pytest tests/

License

MIT

About

CProgramming_FormulaGenerator is a python based tool which helps to generate the excel logical formula

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •