Skip to content

wardelljm30/codespaces-blank

Repository files navigation

Account Number Mapping Rules Application

A dynamic, user-friendly application for creating, managing, and applying custom rules to map account numbers to different formats.

Features

Rule Builder - Create rules using multiple strategies:

  • Regex Pattern Matching - Use regular expressions for complex transformations
  • Prefix Replacement - Replace account number prefixes
  • Suffix Replacement - Replace account number suffixes
  • Custom Python Expressions - Write custom logic for transformations

📋 Rule Management

  • Create unlimited mapping rules
  • Enable/disable rules without deleting
  • Edit existing rules
  • Delete rules
  • Persistent storage (JSON format)

🎯 Rule Application

  • Apply single or multiple rules to account numbers
  • Single account processing
  • Batch processing with CSV uploads
  • Step-by-step transformation tracking
  • Download results as CSV

🔧 Tools

  • Export rules as JSON (backup/share)
  • Import rules from JSON files
  • Auto-save functionality

Installation

  1. Clone or download this repository
  2. Install dependencies:
pip install -r requirements.txt

Usage

Running the Application

streamlit run mapping_rules.py

The application will open in your default browser at http://localhost:8501

Creating Rules

  1. Navigate to 📋 Rule Builder
  2. Enter rule details:
    • Rule Name: Descriptive name for the rule
    • Description: What the rule does
    • Rule Type: Choose from 4 rule types
  3. Define the pattern and replacement based on rule type
  4. Test with a sample account number using the preview
  5. Click Save Rule

Rule Types Explained

1. Regex Pattern Matching

Use regular expressions for powerful pattern matching.

Example:

  • Pattern: ^ACC(\d+)$
  • Replacement: ACCOUNT-\1
  • Transforms: ACC123456ACCOUNT-123456

2. Prefix Replacement

Replace the beginning of account numbers.

Example:

  • Prefix to Find: ACC
  • Replacement: ACCOUNT
  • Transforms: ACC123456ACCOUNT123456

3. Suffix Replacement

Replace the end of account numbers.

Example:

  • Suffix to Find: -USD
  • Replacement: -CURR
  • Transforms: ACC123456-USDACC123456-CURR

4. Custom Python Expression

Write custom Python code using the account_number variable.

Example:

  • Expression: account_number.upper() + '-MAPPED'
  • Transforms: acc123456ACC123456-MAPPED

Available in Custom Mode:

  • account_number - The account number as a string
  • re - Python regex module

Applying Rules

  1. Navigate to 🎯 Apply Rules
  2. Select which rules to apply (checkboxes)
  3. Choose input method:
    • Single Account: Enter one account number
    • Batch Upload: Upload CSV file
  4. View results:
    • Original and transformed account numbers
    • Optional: Step-by-step transformation view
  5. Download results if needed (batch mode)

Managing Rules

  1. Navigate to 📂 Manage Rules
  2. View all created rules in expandable sections
  3. For each rule, you can:
    • Toggle: Enable/disable without deleting
    • Delete: Permanently remove the rule

Backing Up and Sharing Rules

Export Rules:

  • Click 📥 Export Rules in the sidebar
  • Download as JSON file for backup

Import Rules:

  • Click 📤 Import Rules in the sidebar
  • Select a previously exported JSON file
  • Rules will be merged with existing ones

Data Storage

Rules are automatically saved to mapping_rules.json in the application directory. This file contains all rule configurations and is created/updated automatically.

Example mapping_rules.json:

[
  {
    "rule_id": "rule_20240215120000",
    "name": "Standardize Account Format",
    "description": "Convert old ACC format to new ACCOUNT format",
    "rule_type": "regex",
    "pattern": "^ACC(\\d+)$",
    "replacement": "ACCOUNT-\\1",
    "enabled": true,
    "created_at": "2024-02-15T12:00:00.000000"
  }
]

Architecture

AccountMappingRule Class

Represents a single mapping rule with:

  • Rule metadata (ID, name, description)
  • Rule type and pattern/replacement
  • Apply method for transformations
  • Enable/disable toggle

RuleManager Class

Handles all rule operations:

  • Load/save rules to JSON
  • Add, update, delete rules
  • Apply rules to account numbers
  • Toggle rule status

Application Functions

  • show_rule_builder() - Rule creation interface
  • show_rule_manager() - Rule management interface
  • show_rule_applicator() - Rule application interface
  • main() - Main application with navigation

Advanced Usage

Batch Processing Workflow

  1. Prepare a CSV file with account numbers (first column)
  2. Use the batch upload feature
  3. Select rules to apply
  4. Download the mapped results
  5. Use the exported CSV in your systems

Complex Transformations

Chain multiple rules to create complex transformations:

Example Chain:

  1. Rule 1 (Regex): ^(\w+)(\d+)$$2-$1 - Reorder parts
  2. Rule 2 (Custom): account_number.upper() - Uppercase
  3. Rule 3 (Suffix Replace): Remove unwanted suffix

Apply all three sequentially for compound transformations.

Tips & Best Practices

  1. Test Before Saving - Always use the preview feature before saving rules
  2. Clear Names - Use descriptive rule names for easy identification
  3. Disable Before Deleting - Disable a rule to test impact before deletion
  4. Backup Rules - Regularly export rules for backup
  5. Order Matters - Rules apply in the order they were created
  6. Documentation - Use descriptions to document transformation logic

Troubleshooting

Rules not saving:

  • Check file permissions in the application directory
  • Ensure mapping_rules.json is writable

CSV upload failing:

  • Verify CSV format (UTF-8 encoding recommended)
  • Ensure first column contains account numbers
  • Check for special characters in data

Regex errors:

  • Test regex patterns in an online regex tester first
  • Use raw strings with proper escape sequences
  • Remember to use proper capture groups with \1, \2, etc.

Custom expression errors:

  • Use valid Python syntax
  • Remember account_number is a string
  • Avoid dangerous operations (file I/O, imports, etc.)

Requirements

  • Python 3.7+
  • Streamlit 1.28.0+
  • Pandas 2.0.0+

License

This application is provided as-is for account mapping purposes.

Support

For issues or feature requests, document and test them thoroughly before reporting.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

Generated from github/codespaces-blank