Skip to content

Allow labelsGap to be a number (constant) or array (variable gaps)#265

Open
ilizaran wants to merge 3 commits into
Udayraj123:masterfrom
ilizaran:master
Open

Allow labelsGap to be a number (constant) or array (variable gaps)#265
ilizaran wants to merge 3 commits into
Udayraj123:masterfrom
ilizaran:master

Conversation

@ilizaran
Copy link
Copy Markdown

@ilizaran ilizaran commented Jan 30, 2026

User description

This enhancement allows field blocks to have different spacing between
consecutive field labels, providing more flexibility in OMR template
configuration for non-uniform layouts.


PR Type

Enhancement


Description

  • Support labelsGap as number or array for flexible field spacing

  • Normalize single number to repeated list in field block setup

  • Validate array length matches expected gaps count

  • Update dimension calculation to sum variable gaps

  • Modify bubble grid generation to use indexed gaps


Diagram Walkthrough

flowchart LR
  A["labelsGap input<br/>number or array"] --> B["Normalize to list<br/>in setup_field_block"]
  B --> C["Validate array length<br/>matches fieldLabels-1"]
  C --> D["Calculate total gaps<br/>for dimensions"]
  D --> E["Apply indexed gaps<br/>in bubble grid"]
Loading

File Walkthrough

Relevant files
Configuration changes
template_schema.py
Schema support for variable labelsGap                                       

src/schemas/template_schema.py

  • Changed labelsGap schema from single positive_number to oneOf allowing
    both number and array
  • Added array validation requiring length equal to len(fieldLabels) - 1
  • Added descriptive text for both constant and variable gap modes
+11/-1   
Enhancement
template.py
Implement variable gaps logic in field block                         

src/template.py

  • Added normalization logic to convert single number to repeated list in
    setup_field_block
  • Added validation to ensure array length matches expected gaps count
  • Modified calculate_block_dimensions to sum all gaps instead of
    multiplication
  • Updated generate_bubble_grid to use indexed gaps from the list for
    each label transition
+19/-3   

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects Bot commented Jan 30, 2026

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Empty list edge case: When num_labels is 1 or less, labels_gap becomes an empty list which may cause issues in
downstream calculations if not properly handled.

Referred Code
if isinstance(labels_gap, (int, float)):
    # If it's a single number, create a list with that value repeated
    num_labels = len(self.parsed_field_labels)
    labels_gap = [labels_gap] * (num_labels - 1) if num_labels > 1 else []

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status:
Type validation missing: The normalization logic checks isinstance(labels_gap, (int, float)) and
isinstance(labels_gap, list) but does not handle cases where labels_gap might be of an
unexpected type.

Referred Code
if isinstance(labels_gap, (int, float)):
    # If it's a single number, create a list with that value repeated
    num_labels = len(self.parsed_field_labels)
    labels_gap = [labels_gap] * (num_labels - 1) if num_labels > 1 else []
elif isinstance(labels_gap, list):
    # Validate that the list length matches the expected number of gaps
    expected_gaps = len(self.parsed_field_labels) - 1
    if len(labels_gap) != expected_gaps:
        raise Exception(
            f"labelsGap array length ({len(labels_gap)}) must equal len(fieldLabels) - 1 ({expected_gaps}) for field block '{self.name}'"
        )

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects Bot commented Jan 30, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix incorrect block dimension calculation
Suggestion Impact:The commit directly implements the suggested fix by adding the multiplication of len(self.parsed_field_labels) with bubble_dimensions[_v] to correctly account for all bubbles' dimensions

code diff:

         fields_dimension = int(
-            total_labels_gap + bubble_dimensions[_v]
+            total_labels_gap + len(self.parsed_field_labels) * bubble_dimensions[_v]

Correct the fields_dimension calculation to account for the dimensions of all
bubbles, not just one, by multiplying bubble_dimensions[_v] by the number of
field labels.

src/template.py [291-293]

 fields_dimension = int(
-    labels_gap * (len(self.parsed_field_labels) - 1) + bubble_dimensions[_v]
+    total_labels_gap
+    + len(self.parsed_field_labels) * bubble_dimensions[_v]
 )

[Suggestion processed]

Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a bug in the PR's logic for calculating fields_dimension, which only accounts for one bubble's dimension instead of all of them, potentially leading to incorrect block dimension calculations.

High
  • Update

Copy link
Copy Markdown
Owner

@Udayraj123 Udayraj123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make this PR brief and to the point with minimal diffs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants