cwicr-quantity-matcher
Match BIM quantities to CWICR work items. Map element categories to cost codes, validate quantities, and generate cost-linked QTOs.
What this skill does
# CWICR Quantity Matcher
## Business Case
### Problem Statement
BIM exports contain quantities but:
- Element categories don't match cost codes
- Manual mapping is error-prone
- Different naming conventions
- Need consistent code assignment
### Solution
Intelligent matching of BIM element quantities to CWICR work items using category mapping, semantic matching, and rule-based assignment.
### Business Value
- **Automation** - Reduce manual mapping effort
- **Consistency** - Standard code assignment
- **Accuracy** - Validated quantity linkage
- **Integration** - BIM-to-cost data flow
## Technical Implementation
```python
import pandas as pd
import numpy as np
from typing import Dict, Any, List, Optional, Tuple
from dataclasses import dataclass, field
from enum import Enum
import re
from difflib import SequenceMatcher
class MatchMethod(Enum):
"""Methods for matching BIM elements to work items."""
EXACT = "exact"
CATEGORY = "category"
SEMANTIC = "semantic"
RULE_BASED = "rule_based"
MANUAL = "manual"
class MatchConfidence(Enum):
"""Confidence level of match."""
HIGH = "high" # >90% confidence
MEDIUM = "medium" # 70-90%
LOW = "low" # 50-70%
MANUAL = "manual" # <50% - needs review
@dataclass
class QuantityMatch:
"""Single quantity match result."""
bim_element_id: str
bim_category: str
bim_description: str
bim_quantity: float
bim_unit: str
matched_work_item: str
work_item_description: str
work_item_unit: str
match_method: MatchMethod
confidence: MatchConfidence
confidence_score: float
unit_conversion_factor: float = 1.0
@dataclass
class MatchingResult:
"""Complete matching result."""
total_elements: int
matched: int
unmatched: int
high_confidence: int
needs_review: int
matches: List[QuantityMatch]
unmatched_elements: List[Dict[str, Any]]
# Category to work item mapping rules
CATEGORY_MAPPING = {
# Revit categories to CWICR prefixes
'walls': ['WALL', 'MSNR', 'PART'],
'floors': ['CONC', 'FLOOR', 'SLAB'],
'columns': ['CONC', 'STRL', 'COLM'],
'beams': ['CONC', 'STRL', 'BEAM'],
'foundations': ['CONC', 'FNDN', 'EXCV'],
'roofs': ['ROOF', 'INSUL'],
'doors': ['DOOR', 'CARP'],
'windows': ['WIND', 'GLAZ'],
'stairs': ['STAIR', 'CONC'],
'railings': ['RAIL', 'METL'],
'ceilings': ['CEIL', 'FINI'],
'structural framing': ['STRL', 'STEE'],
'structural columns': ['STRL', 'COLM'],
'pipes': ['PLMB', 'PIPE'],
'ducts': ['HVAC', 'DUCT'],
'conduits': ['ELEC', 'COND'],
'cable trays': ['ELEC', 'CABL'],
'concrete': ['CONC'],
'rebar': ['REBAR', 'RENF'],
'formwork': ['FORM', 'CONC'],
}
# Unit conversion mapping
UNIT_CONVERSIONS = {
('sf', 'm2'): 0.092903,
('m2', 'sf'): 10.7639,
('cy', 'm3'): 0.764555,
('m3', 'cy'): 1.30795,
('lf', 'm'): 0.3048,
('m', 'lf'): 3.28084,
('lb', 'kg'): 0.453592,
('kg', 'lb'): 2.20462,
}
class CWICRQuantityMatcher:
"""Match BIM quantities to CWICR work items."""
def __init__(self, cwicr_data: pd.DataFrame):
self.work_items = cwicr_data
self._index_data()
self._build_search_index()
def _index_data(self):
"""Index work items."""
if 'work_item_code' in self.work_items.columns:
self._code_index = self.work_items.set_index('work_item_code')
else:
self._code_index = None
def _build_search_index(self):
"""Build search index for semantic matching."""
self._search_index = {}
if 'description' in self.work_items.columns:
for _, row in self.work_items.iterrows():
code = row.get('work_item_code', '')
desc = str(row.get('description', '')).lower()
# Index by keywords
words = re.findall(r'\w+', desc)
for word in words:
if len(word) > 3:
if word not in self._search_index:
self._search_index[word] = []
self._search_index[word].append(code)
def _get_category_codes(self, category: str) -> List[str]:
"""Get potential work item prefixes for BIM category."""
cat_lower = category.lower().strip()
for key, prefixes in CATEGORY_MAPPING.items():
if key in cat_lower:
return prefixes
return []
def _semantic_match(self, description: str, category: str) -> List[Tuple[str, float]]:
"""Find work items using semantic matching."""
desc_lower = description.lower()
words = re.findall(r'\w+', desc_lower)
# Find candidate codes
candidates = {}
for word in words:
if word in self._search_index:
for code in self._search_index[word]:
if code not in candidates:
candidates[code] = 0
candidates[code] += 1
# Score candidates
scored = []
for code, count in candidates.items():
if self._code_index is not None and code in self._code_index.index:
item_desc = str(self._code_index.loc[code].get('description', ''))
similarity = SequenceMatcher(None, desc_lower, item_desc.lower()).ratio()
score = (count * 0.4) + (similarity * 0.6)
scored.append((code, score))
return sorted(scored, key=lambda x: x[1], reverse=True)[:5]
def _get_confidence(self, score: float) -> MatchConfidence:
"""Determine confidence level from score."""
if score >= 0.9:
return MatchConfidence.HIGH
elif score >= 0.7:
return MatchConfidence.MEDIUM
elif score >= 0.5:
return MatchConfidence.LOW
else:
return MatchConfidence.MANUAL
def _get_unit_conversion(self, from_unit: str, to_unit: str) -> float:
"""Get unit conversion factor."""
from_norm = from_unit.lower().strip()
to_norm = to_unit.lower().strip()
if from_norm == to_norm:
return 1.0
return UNIT_CONVERSIONS.get((from_norm, to_norm), 1.0)
def match_element(self,
element: Dict[str, Any],
element_id_col: str = 'ElementId',
category_col: str = 'Category',
description_col: str = 'Description',
quantity_col: str = 'Quantity',
unit_col: str = 'Unit') -> Optional[QuantityMatch]:
"""Match single BIM element to work item."""
element_id = str(element.get(element_id_col, ''))
category = str(element.get(category_col, ''))
description = str(element.get(description_col, ''))
quantity = float(element.get(quantity_col, 0) or 0)
unit = str(element.get(unit_col, ''))
# Try category-based matching first
category_prefixes = self._get_category_codes(category)
best_match = None
best_score = 0
match_method = MatchMethod.CATEGORY
if category_prefixes:
# Filter work items by prefix
for prefix in category_prefixes:
matches = self.work_items[
self.work_items['work_item_code'].str.startswith(prefix)
]
for _, item in matches.iterrows():
item_desc = str(item.get('description', ''))
similarity = SequenceMatcher(None, description.lower(), item_desc.lower()).ratio()
if similarity > best_score:
best_score = similarity
best_match = item
# If no good match, try semantic matching
if best_score < 0.5:
semantic_matches = self._semantic_match(description, category)
if semantic_matches:
top_code, top_score = sRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.