[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6FJNVJWVB0BGFTWKKDNEPKM":3,"skill-same:01M6FJNVJWVB0BGFTWKKDNEPKM":59},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":26,"linkOnly":27,"markdownContent":28,"markdownBody":29,"frontMatter":30,"refName":32,"commitSha":33,"skillDirectory":34,"forksCount":35,"repositoryHtmlUrl":36,"repositoryHomepageUrl":6,"ownerHtmlUrl":37,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":38,"install":39,"resources":52},"01M6FJNVJWVB0BGFTWKKDNEPKM","cwicr-cost-calculator",null,"Calculate construction costs using DDC CWICR resource-based methodology. Break down costs into labor, materials, equipment with transparent pricing.","kbarbel640-del\u002Fskills","kbarbel640-del","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F255315490?v=4","01M6CJPPQGCCESXMG3K7BBGQ5J","01M6CJPPX2PB2BCZERFVM2C2B3",1,"MIT","https:\u002F\u002Fgithub.com\u002Fkbarbel640-del\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fdatadrivenconstruction\u002Fcwicr-cost-calculator\u002FSKILL.md",[],[18,19,20,21,22,23,24,25],"calculator","cost","cwicr cost calculator","pricing","methodology","calculate","break down","with","2026-11-10 10:12:30",false,"---\r\nslug: \"cwicr-cost-calculator\"\r\ndisplay_name: \"CWICR Cost Calculator\"\r\ndescription: \"Calculate construction costs using DDC CWICR resource-based methodology. Break down costs into labor, materials, equipment with transparent pricing.\"\r\n---\r\n\r\n# CWICR Cost Calculator\r\n\r\n## Business Case\r\n\r\n### Problem Statement\r\nTraditional cost estimation often produces \"black box\" estimates with hidden markups. Stakeholders need:\r\n- Transparent cost breakdowns\r\n- Traceable pricing logic\r\n- Auditable calculations\r\n- Resource-level detail\r\n\r\n### Solution\r\nResource-based cost calculation using CWICR methodology that separates physical norms (labor hours, material quantities) from volatile prices, enabling transparent and auditable estimates.\r\n\r\n### Business Value\r\n- **Full transparency** - Every cost component visible\r\n- **Auditable** - Traceable calculation logic\r\n- **Flexible** - Update prices without changing norms\r\n- **Accurate** - Based on 55,000+ validated work items\r\n\r\n## Technical Implementation\r\n\r\n### Prerequisites\r\n```bash\r\npip install pandas numpy\r\n```\r\n\r\n### Python Implementation\r\n\r\n```python\r\nimport pandas as pd\r\nimport numpy as np\r\nfrom typing import Dict, Any, List, Optional, Tuple\r\nfrom dataclasses import dataclass, field\r\nfrom enum import Enum\r\nfrom datetime import datetime\r\n\r\n\r\nclass CostComponent(Enum):\r\n    \"\"\"Cost breakdown components.\"\"\"\r\n    LABOR = \"labor\"\r\n    MATERIAL = \"material\"\r\n    EQUIPMENT = \"equipment\"\r\n    OVERHEAD = \"overhead\"\r\n    PROFIT = \"profit\"\r\n    TOTAL = \"total\"\r\n\r\n\r\nclass CostStatus(Enum):\r\n    \"\"\"Cost calculation status.\"\"\"\r\n    CALCULATED = \"calculated\"\r\n    ESTIMATED = \"estimated\"\r\n    MISSING_DATA = \"missing_data\"\r\n    ERROR = \"error\"\r\n\r\n\r\n@dataclass\r\nclass CostBreakdown:\r\n    \"\"\"Detailed cost breakdown for a work item.\"\"\"\r\n    work_item_code: str\r\n    description: str\r\n    unit: str\r\n    quantity: float\r\n\r\n    labor_cost: float = 0.0\r\n    material_cost: float = 0.0\r\n    equipment_cost: float = 0.0\r\n    overhead_cost: float = 0.0\r\n    profit_cost: float = 0.0\r\n\r\n    unit_price: float = 0.0\r\n    total_cost: float = 0.0\r\n\r\n    labor_hours: float = 0.0\r\n    labor_rate: float = 0.0\r\n\r\n    resources: List[Dict[str, Any]] = field(default_factory=list)\r\n    status: CostStatus = CostStatus.CALCULATED\r\n\r\n    def to_dict(self) -> Dict[str, Any]:\r\n        return {\r\n            'work_item_code': self.work_item_code,\r\n            'description': self.description,\r\n            'unit': self.unit,\r\n            'quantity': self.quantity,\r\n            'labor_cost': self.labor_cost,\r\n            'material_cost': self.material_cost,\r\n            'equipment_cost': self.equipment_cost,\r\n            'overhead_cost': self.overhead_cost,\r\n            'profit_cost': self.profit_cost,\r\n            'total_cost': self.total_cost,\r\n            'status': self.status.value\r\n        }\r\n\r\n\r\n@dataclass\r\nclass CostSummary:\r\n    \"\"\"Summary of cost estimate.\"\"\"\r\n    total_cost: float\r\n    labor_total: float\r\n    material_total: float\r\n    equipment_total: float\r\n    overhead_total: float\r\n    profit_total: float\r\n\r\n    item_count: int\r\n    currency: str\r\n    calculated_at: datetime\r\n\r\n    breakdown_by_category: Dict[str, float] = field(default_factory=dict)\r\n\r\n\r\nclass CWICRCostCalculator:\r\n    \"\"\"Resource-based cost calculator using CWICR methodology.\"\"\"\r\n\r\n    DEFAULT_OVERHEAD_RATE = 0.15  # 15% overhead\r\n    DEFAULT_PROFIT_RATE = 0.10   # 10% profit\r\n\r\n    def __init__(self, cwicr_data: pd.DataFrame,\r\n                 overhead_rate: float = None,\r\n                 profit_rate: float = None,\r\n                 currency: str = \"USD\"):\r\n        \"\"\"Initialize calculator with CWICR data.\"\"\"\r\n        self.data = cwicr_data\r\n        self.overhead_rate = overhead_rate or self.DEFAULT_OVERHEAD_RATE\r\n        self.profit_rate = profit_rate or self.DEFAULT_PROFIT_RATE\r\n        self.currency = currency\r\n\r\n        # Index data for fast lookup\r\n        self._index_data()\r\n\r\n    def _index_data(self):\r\n        \"\"\"Create index for fast work item lookup.\"\"\"\r\n        if 'work_item_code' in self.data.columns:\r\n            self._code_index = self.data.set_index('work_item_code')\r\n        else:\r\n            self._code_index = None\r\n\r\n    def calculate_item_cost(self, work_item_code: str,\r\n                            quantity: float,\r\n                            price_overrides: Dict[str, float] = None) -> CostBreakdown:\r\n        \"\"\"Calculate cost for single work item.\"\"\"\r\n\r\n        # Find work item in database\r\n        if self._code_index is not None and work_item_code in self._code_index.index:\r\n            item = self._code_index.loc[work_item_code]\r\n        else:\r\n            # Try partial match\r\n            matches = self.data[\r\n                self.data['work_item_code'].str.contains(work_item_code, case=False, na=False)\r\n            ]\r\n            if matches.empty:\r\n                return CostBreakdown(\r\n                    work_item_code=work_item_code,\r\n                    description=\"NOT FOUND\",\r\n                    unit=\"\",\r\n                    quantity=quantity,\r\n                    status=CostStatus.MISSING_DATA\r\n                )\r\n            item = matches.iloc[0]\r\n\r\n        # Get base costs\r\n        labor_unit = float(item.get('labor_cost', 0) or 0)\r\n        material_unit = float(item.get('material_cost', 0) or 0)\r\n        equipment_unit = float(item.get('equipment_cost', 0) or 0)\r\n\r\n        # Apply price overrides if provided\r\n        if price_overrides:\r\n            if 'labor_rate' in price_overrides:\r\n                labor_norm = float(item.get('labor_norm', 0) or 0)\r\n                labor_unit = labor_norm * price_overrides['labor_rate']\r\n            if 'material_factor' in price_overrides:\r\n                material_unit *= price_overrides['material_factor']\r\n            if 'equipment_factor' in price_overrides:\r\n                equipment_unit *= price_overrides['equipment_factor']\r\n\r\n        # Calculate component costs\r\n        labor_cost = labor_unit * quantity\r\n        material_cost = material_unit * quantity\r\n        equipment_cost = equipment_unit * quantity\r\n\r\n        # Direct costs\r\n        direct_cost = labor_cost + material_cost + equipment_cost\r\n\r\n        # Overhead and profit\r\n        overhead_cost = direct_cost * self.overhead_rate\r\n        profit_cost = (direct_cost + overhead_cost) * self.profit_rate\r\n\r\n        # Total\r\n        total_cost = direct_cost + overhead_cost + profit_cost\r\n\r\n        # Unit price\r\n        unit_price = total_cost \u002F quantity if quantity > 0 else 0\r\n\r\n        return CostBreakdown(\r\n            work_item_code=work_item_code,\r\n            description=str(item.get('description', '')),\r\n            unit=str(item.get('unit', '')),\r\n            quantity=quantity,\r\n            labor_cost=labor_cost,\r\n            material_cost=material_cost,\r\n            equipment_cost=equipment_cost,\r\n            overhead_cost=overhead_cost,\r\n            profit_cost=profit_cost,\r\n            unit_price=unit_price,\r\n            total_cost=total_cost,\r\n            labor_hours=float(item.get('labor_norm', 0) or 0) * quantity,\r\n            labor_rate=float(item.get('labor_rate', 0) or 0),\r\n            status=CostStatus.CALCULATED\r\n        )\r\n\r\n    def calculate_estimate(self, items: List[Dict[str, Any]],\r\n                          group_by_category: bool = True) -> CostSummary:\r\n        \"\"\"Calculate cost estimate for multiple items.\"\"\"\r\n\r\n        breakdowns = []\r\n        for item in items:\r\n            code = item.get('work_item_code') or item.get('code')\r\n            qty = item.get('quantity', 0)\r\n            overrides = item.get('price_overrides')\r\n\r\n            breakdown = self.calculate_item_cost(code, qty, overrides)\r\n            breakdowns.append(breakdown)\r\n\r\n        # Aggregate totals\r\n        labor_total = sum(b.labor_cost for b in breakdowns)\r\n        material_total = sum(b.material_cost for b in breakdowns)\r\n        equipment_total = sum(b.equipment_cost for b in breakdowns)\r\n        overhead_total = sum(b.overhead_cost for b in breakdowns)\r\n        profit_total = sum(b.profit_cost for b in breakdowns)\r\n        total_cost = sum(b.total_cost for b in breakdowns)\r\n\r\n        # Group by category if requested\r\n        breakdown_by_category = {}\r\n        if group_by_category:\r\n            for b in breakdowns:\r\n                # Extract category from work item code prefix\r\n                category = b.work_item_code.split('-')[0] if '-' in b.work_item_code else 'Other'\r\n                if category not in breakdown_by_category:\r\n                    breakdown_by_category[category] = 0\r\n                breakdown_by_category[category] += b.total_cost\r\n\r\n        return CostSummary(\r\n            total_cost=total_cost,\r\n            labor_total=labor_total,\r\n            material_total=material_total,\r\n            equipment_total=equipment_total,\r\n            overhead_total=overhead_total,\r\n            profit_total=profit_total,\r\n            item_count=len(breakdowns),\r\n            currency=self.currency,\r\n            calculated_at=datetime.now(),\r\n            breakdown_by_category=breakdown_by_category\r\n        )\r\n\r\n    def calculate_from_qto(self, qto_df: pd.DataFrame,\r\n                          code_column: str = 'work_item_code',\r\n                          quantity_column: str = 'quantity') -> pd.DataFrame:\r\n        \"\"\"Calculate costs from Quantity Takeoff DataFrame.\"\"\"\r\n\r\n        results = []\r\n        for _, row in qto_df.iterrows():\r\n            code = row[code_column]\r\n            qty = row[quantity_column]\r\n\r\n            breakdown = self.calculate_item_cost(code, qty)\r\n            result = breakdown.to_dict()\r\n\r\n            # Add original QTO columns\r\n            for col in qto_df.columns:\r\n                if col not in result:\r\n                    result[f'qto_{col}'] = row[col]\r\n\r\n            results.append(result)\r\n\r\n        return pd.DataFrame(results)\r\n\r\n    def apply_regional_factors(self, base_costs: pd.DataFrame,\r\n                               region_factors: Dict[str, float]) -> pd.DataFrame:\r\n        \"\"\"Apply regional adjustment factors.\"\"\"\r\n        adjusted = base_costs.copy()\r\n\r\n        if 'labor_cost' in adjusted.columns and 'labor' in region_factors:\r\n            adjusted['labor_cost'] *= region_factors['labor']\r\n\r\n        if 'material_cost' in adjusted.columns and 'material' in region_factors:\r\n            adjusted['material_cost'] *= region_factors['material']\r\n\r\n        if 'equipment_cost' in adjusted.columns and 'equipment' in region_factors:\r\n            adjusted['equipment_cost'] *= region_factors['equipment']\r\n\r\n        # Recalculate totals\r\n        adjusted['direct_cost'] = (\r\n            adjusted.get('labor_cost', 0) +\r\n            adjusted.get('material_cost', 0) +\r\n            adjusted.get('equipment_cost', 0)\r\n        )\r\n        adjusted['total_cost'] = adjusted['direct_cost'] * (1 + self.overhead_rate) * (1 + self.profit_rate)\r\n\r\n        return adjusted\r\n\r\n    def compare_estimates(self, estimate1: CostSummary,\r\n                         estimate2: CostSummary) -> Dict[str, Any]:\r\n        \"\"\"Compare two cost estimates.\"\"\"\r\n        return {\r\n            'total_difference': estimate2.total_cost - estimate1.total_cost,\r\n            'total_percent_change': (\r\n                (estimate2.total_cost - estimate1.total_cost) \u002F\r\n                estimate1.total_cost * 100 if estimate1.total_cost > 0 else 0\r\n            ),\r\n            'labor_difference': estimate2.labor_total - estimate1.labor_total,\r\n            'material_difference': estimate2.material_total - estimate1.material_total,\r\n            'equipment_difference': estimate2.equipment_total - estimate1.equipment_total,\r\n            'item_count_difference': estimate2.item_count - estimate1.item_count\r\n        }\r\n\r\n\r\nclass CostReportGenerator:\r\n    \"\"\"Generate cost reports from calculations.\"\"\"\r\n\r\n    def __init__(self, calculator: CWICRCostCalculator):\r\n        self.calculator = calculator\r\n\r\n    def generate_summary_report(self, items: List[Dict[str, Any]]) -> Dict[str, Any]:\r\n        \"\"\"Generate summary cost report.\"\"\"\r\n        summary = self.calculator.calculate_estimate(items)\r\n\r\n        return {\r\n            'report_date': datetime.now().isoformat(),\r\n            'currency': summary.currency,\r\n            'total_cost': round(summary.total_cost, 2),\r\n            'breakdown': {\r\n                'labor': round(summary.labor_total, 2),\r\n                'material': round(summary.material_total, 2),\r\n                'equipment': round(summary.equipment_total, 2),\r\n                'overhead': round(summary.overhead_total, 2),\r\n                'profit': round(summary.profit_total, 2)\r\n            },\r\n            'percentages': {\r\n                'labor': round(summary.labor_total \u002F summary.total_cost * 100, 1) if summary.total_cost > 0 else 0,\r\n                'material': round(summary.material_total \u002F summary.total_cost * 100, 1) if summary.total_cost > 0 else 0,\r\n                'equipment': round(summary.equipment_total \u002F summary.total_cost * 100, 1) if summary.total_cost > 0 else 0,\r\n            },\r\n            'item_count': summary.item_count,\r\n            'by_category': summary.breakdown_by_category\r\n        }\r\n\r\n    def generate_detailed_report(self, items: List[Dict[str, Any]]) -> pd.DataFrame:\r\n        \"\"\"Generate detailed line-item report.\"\"\"\r\n        results = []\r\n\r\n        for item in items:\r\n            code = item.get('work_item_code') or item.get('code')\r\n            qty = item.get('quantity', 0)\r\n\r\n            breakdown = self.calculator.calculate_item_cost(code, qty)\r\n            results.append(breakdown.to_dict())\r\n\r\n        df = pd.DataFrame(results)\r\n\r\n        # Add totals row\r\n        totals = df[['labor_cost', 'material_cost', 'equipment_cost',\r\n                     'overhead_cost', 'profit_cost', 'total_cost']].sum()\r\n        totals['description'] = 'TOTAL'\r\n        totals['work_item_code'] = ''\r\n\r\n        df = pd.concat([df, pd.DataFrame([totals])], ignore_index=True)\r\n\r\n        return df\r\n\r\n\r\n# Convenience functions\r\ndef calculate_cost(cwicr_data: pd.DataFrame,\r\n                   work_item_code: str,\r\n                   quantity: float) -> float:\r\n    \"\"\"Quick cost calculation.\"\"\"\r\n    calc = CWICRCostCalculator(cwicr_data)\r\n    breakdown = calc.calculate_item_cost(work_item_code, quantity)\r\n    return breakdown.total_cost\r\n\r\n\r\ndef estimate_project_cost(cwicr_data: pd.DataFrame,\r\n                         items: List[Dict[str, Any]]) -> Dict[str, Any]:\r\n    \"\"\"Quick project cost estimate.\"\"\"\r\n    calc = CWICRCostCalculator(cwicr_data)\r\n    report = CostReportGenerator(calc)\r\n    return report.generate_summary_report(items)\r\n```\r\n\r\n## Quick Start\r\n\r\n```python\r\nimport pandas as pd\r\nfrom cwicr_data_loader import CWICRDataLoader\r\n\r\n# Load CWICR data\r\nloader = CWICRDataLoader()\r\ncwicr = loader.load(\"ddc_cwicr_en.parquet\")\r\n\r\n# Initialize calculator\r\ncalc = CWICRCostCalculator(cwicr)\r\n\r\n# Calculate single item\r\nbreakdown = calc.calculate_item_cost(\"CONC-001\", quantity=150)\r\nprint(f\"Total: ${breakdown.total_cost:,.2f}\")\r\nprint(f\"  Labor: ${breakdown.labor_cost:,.2f}\")\r\nprint(f\"  Material: ${breakdown.material_cost:,.2f}\")\r\nprint(f\"  Equipment: ${breakdown.equipment_cost:,.2f}\")\r\n```\r\n\r\n## Common Use Cases\r\n\r\n### 1. Project Estimate\r\n```python\r\nitems = [\r\n    {'work_item_code': 'CONC-001', 'quantity': 150},\r\n    {'work_item_code': 'EXCV-002', 'quantity': 200},\r\n    {'work_item_code': 'REBAR-003', 'quantity': 15000}  # kg\r\n]\r\n\r\nsummary = calc.calculate_estimate(items)\r\nprint(f\"Project Total: ${summary.total_cost:,.2f}\")\r\n```\r\n\r\n### 2. QTO Integration\r\n```python\r\n# Load BIM quantities\r\nqto = pd.read_excel(\"quantities.xlsx\")\r\n\r\n# Calculate costs\r\ncosts = calc.calculate_from_qto(qto,\r\n    code_column='work_item',\r\n    quantity_column='quantity'\r\n)\r\nprint(costs[['description', 'quantity', 'total_cost']])\r\n```\r\n\r\n### 3. Regional Adjustment\r\n```python\r\n# Apply Berlin pricing\r\nberlin_factors = {\r\n    'labor': 1.15,      # 15% higher labor\r\n    'material': 0.95,   # 5% lower materials\r\n    'equipment': 1.0\r\n}\r\n\r\nadjusted = calc.apply_regional_factors(costs, berlin_factors)\r\n```\r\n\r\n## Resources\r\n\r\n- **GitHub**: [OpenConstructionEstimate-DDC-CWICR](https:\u002F\u002Fgithub.com\u002Fdatadrivenconstruction\u002FOpenConstructionEstimate-DDC-CWICR)\r\n- **DDC Book**: Chapter 3.1 - Construction Cost Estimation\r\n","# CWICR Cost Calculator\r\n\r\n## Business Case\r\n\r\n### Problem Statement\r\nTraditional cost estimation often produces \"black box\" estimates with hidden markups. Stakeholders need:\r\n- Transparent cost breakdowns\r\n- Traceable pricing logic\r\n- Auditable calculations\r\n- Resource-level detail\r\n\r\n### Solution\r\nResource-based cost calculation using CWICR methodology that separates physical norms (labor hours, material quantities) from volatile prices, enabling transparent and auditable estimates.\r\n\r\n### Business Value\r\n- **Full transparency** - Every cost component visible\r\n- **Auditable** - Traceable calculation logic\r\n- **Flexible** - Update prices without changing norms\r\n- **Accurate** - Based on 55,000+ validated work items\r\n\r\n## Technical Implementation\r\n\r\n### Prerequisites\r\n```bash\r\npip install pandas numpy\r\n```\r\n\r\n### Python Implementation\r\n\r\n```python\r\nimport pandas as pd\r\nimport numpy as np\r\nfrom typing import Dict, Any, List, Optional, Tuple\r\nfrom dataclasses import dataclass, field\r\nfrom enum import Enum\r\nfrom datetime import datetime\r\n\r\n\r\nclass CostComponent(Enum):\r\n    \"\"\"Cost breakdown components.\"\"\"\r\n    LABOR = \"labor\"\r\n    MATERIAL = \"material\"\r\n    EQUIPMENT = \"equipment\"\r\n    OVERHEAD = \"overhead\"\r\n    PROFIT = \"profit\"\r\n    TOTAL = \"total\"\r\n\r\n\r\nclass CostStatus(Enum):\r\n    \"\"\"Cost calculation status.\"\"\"\r\n    CALCULATED = \"calculated\"\r\n    ESTIMATED = \"estimated\"\r\n    MISSING_DATA = \"missing_data\"\r\n    ERROR = \"error\"\r\n\r\n\r\n@dataclass\r\nclass CostBreakdown:\r\n    \"\"\"Detailed cost breakdown for a work item.\"\"\"\r\n    work_item_code: str\r\n    description: str\r\n    unit: str\r\n    quantity: float\r\n\r\n    labor_cost: float = 0.0\r\n    material_cost: float = 0.0\r\n    equipment_cost: float = 0.0\r\n    overhead_cost: float = 0.0\r\n    profit_cost: float = 0.0\r\n\r\n    unit_price: float = 0.0\r\n    total_cost: float = 0.0\r\n\r\n    labor_hours: float = 0.0\r\n    labor_rate: float = 0.0\r\n\r\n    resources: List[Dict[str, Any]] = field(default_factory=list)\r\n    status: CostStatus = CostStatus.CALCULATED\r\n\r\n    def to_dict(self) -> Dict[str, Any]:\r\n        return {\r\n            'work_item_code': self.work_item_code,\r\n            'description': self.description,\r\n            'unit': self.unit,\r\n            'quantity': self.quantity,\r\n            'labor_cost': self.labor_cost,\r\n            'material_cost': self.material_cost,\r\n            'equipment_cost': self.equipment_cost,\r\n            'overhead_cost': self.overhead_cost,\r\n            'profit_cost': self.profit_cost,\r\n            'total_cost': self.total_cost,\r\n            'status': self.status.value\r\n        }\r\n\r\n\r\n@dataclass\r\nclass CostSummary:\r\n    \"\"\"Summary of cost estimate.\"\"\"\r\n    total_cost: float\r\n    labor_total: float\r\n    material_total: float\r\n    equipment_total: float\r\n    overhead_total: float\r\n    profit_total: float\r\n\r\n    item_count: int\r\n    currency: str\r\n    calculated_at: datetime\r\n\r\n    breakdown_by_category: Dict[str, float] = field(default_factory=dict)\r\n\r\n\r\nclass CWICRCostCalculator:\r\n    \"\"\"Resource-based cost calculator using CWICR methodology.\"\"\"\r\n\r\n    DEFAULT_OVERHEAD_RATE = 0.15  # 15% overhead\r\n    DEFAULT_PROFIT_RATE = 0.10   # 10% profit\r\n\r\n    def __init__(self, cwicr_data: pd.DataFrame,\r\n                 overhead_rate: float = None,\r\n                 profit_rate: float = None,\r\n                 currency: str = \"USD\"):\r\n        \"\"\"Initialize calculator with CWICR data.\"\"\"\r\n        self.data = cwicr_data\r\n        self.overhead_rate = overhead_rate or self.DEFAULT_OVERHEAD_RATE\r\n        self.profit_rate = profit_rate or self.DEFAULT_PROFIT_RATE\r\n        self.currency = currency\r\n\r\n        # Index data for fast lookup\r\n        self._index_data()\r\n\r\n    def _index_data(self):\r\n        \"\"\"Create index for fast work item lookup.\"\"\"\r\n        if 'work_item_code' in self.data.columns:\r\n            self._code_index = self.data.set_index('work_item_code')\r\n        else:\r\n            self._code_index = None\r\n\r\n    def calculate_item_cost(self, work_item_code: str,\r\n                            quantity: float,\r\n                            price_overrides: Dict[str, float] = None) -> CostBreakdown:\r\n        \"\"\"Calculate cost for single work item.\"\"\"\r\n\r\n        # Find work item in database\r\n        if self._code_index is not None and work_item_code in self._code_index.index:\r\n            item = self._code_index.loc[work_item_code]\r\n        else:\r\n            # Try partial match\r\n            matches = self.data[\r\n                self.data['work_item_code'].str.contains(work_item_code, case=False, na=False)\r\n            ]\r\n            if matches.empty:\r\n                return CostBreakdown(\r\n                    work_item_code=work_item_code,\r\n                    description=\"NOT FOUND\",\r\n                    unit=\"\",\r\n                    quantity=quantity,\r\n                    status=CostStatus.MISSING_DATA\r\n                )\r\n            item = matches.iloc[0]\r\n\r\n        # Get base costs\r\n        labor_unit = float(item.get('labor_cost', 0) or 0)\r\n        material_unit = float(item.get('material_cost', 0) or 0)\r\n        equipment_unit = float(item.get('equipment_cost', 0) or 0)\r\n\r\n        # Apply price overrides if provided\r\n        if price_overrides:\r\n            if 'labor_rate' in price_overrides:\r\n                labor_norm = float(item.get('labor_norm', 0) or 0)\r\n                labor_unit = labor_norm * price_overrides['labor_rate']\r\n            if 'material_factor' in price_overrides:\r\n                material_unit *= price_overrides['material_factor']\r\n            if 'equipment_factor' in price_overrides:\r\n                equipment_unit *= price_overrides['equipment_factor']\r\n\r\n        # Calculate component costs\r\n        labor_cost = labor_unit * quantity\r\n        material_cost = material_unit * quantity\r\n        equipment_cost = equipment_unit * quantity\r\n\r\n        # Direct costs\r\n        direct_cost = labor_cost + material_cost + equipment_cost\r\n\r\n        # Overhead and profit\r\n        overhead_cost = direct_cost * self.overhead_rate\r\n        profit_cost = (direct_cost + overhead_cost) * self.profit_rate\r\n\r\n        # Total\r\n        total_cost = direct_cost + overhead_cost + profit_cost\r\n\r\n        # Unit price\r\n        unit_price = total_cost \u002F quantity if quantity > 0 else 0\r\n\r\n        return CostBreakdown(\r\n            work_item_code=work_item_code,\r\n            description=str(item.get('description', '')),\r\n            unit=str(item.get('unit', '')),\r\n            quantity=quantity,\r\n            labor_cost=labor_cost,\r\n            material_cost=material_cost,\r\n            equipment_cost=equipment_cost,\r\n            overhead_cost=overhead_cost,\r\n            profit_cost=profit_cost,\r\n            unit_price=unit_price,\r\n            total_cost=total_cost,\r\n            labor_hours=float(item.get('labor_norm', 0) or 0) * quantity,\r\n            labor_rate=float(item.get('labor_rate', 0) or 0),\r\n            status=CostStatus.CALCULATED\r\n        )\r\n\r\n    def calculate_estimate(self, items: List[Dict[str, Any]],\r\n                          group_by_category: bool = True) -> CostSummary:\r\n        \"\"\"Calculate cost estimate for multiple items.\"\"\"\r\n\r\n        breakdowns = []\r\n        for item in items:\r\n            code = item.get('work_item_code') or item.get('code')\r\n            qty = item.get('quantity', 0)\r\n            overrides = item.get('price_overrides')\r\n\r\n            breakdown = self.calculate_item_cost(code, qty, overrides)\r\n            breakdowns.append(breakdown)\r\n\r\n        # Aggregate totals\r\n        labor_total = sum(b.labor_cost for b in breakdowns)\r\n        material_total = sum(b.material_cost for b in breakdowns)\r\n        equipment_total = sum(b.equipment_cost for b in breakdowns)\r\n        overhead_total = sum(b.overhead_cost for b in breakdowns)\r\n        profit_total = sum(b.profit_cost for b in breakdowns)\r\n        total_cost = sum(b.total_cost for b in breakdowns)\r\n\r\n        # Group by category if requested\r\n        breakdown_by_category = {}\r\n        if group_by_category:\r\n            for b in breakdowns:\r\n                # Extract category from work item code prefix\r\n                category = b.work_item_code.split('-')[0] if '-' in b.work_item_code else 'Other'\r\n                if category not in breakdown_by_category:\r\n                    breakdown_by_category[category] = 0\r\n                breakdown_by_category[category] += b.total_cost\r\n\r\n        return CostSummary(\r\n            total_cost=total_cost,\r\n            labor_total=labor_total,\r\n            material_total=material_total,\r\n            equipment_total=equipment_total,\r\n            overhead_total=overhead_total,\r\n            profit_total=profit_total,\r\n            item_count=len(breakdowns),\r\n            currency=self.currency,\r\n            calculated_at=datetime.now(),\r\n            breakdown_by_category=breakdown_by_category\r\n        )\r\n\r\n    def calculate_from_qto(self, qto_df: pd.DataFrame,\r\n                          code_column: str = 'work_item_code',\r\n                          quantity_column: str = 'quantity') -> pd.DataFrame:\r\n        \"\"\"Calculate costs from Quantity Takeoff DataFrame.\"\"\"\r\n\r\n        results = []\r\n        for _, row in qto_df.iterrows():\r\n            code = row[code_column]\r\n            qty = row[quantity_column]\r\n\r\n            breakdown = self.calculate_item_cost(code, qty)\r\n            result = breakdown.to_dict()\r\n\r\n            # Add original QTO columns\r\n            for col in qto_df.columns:\r\n                if col not in result:\r\n                    result[f'qto_{col}'] = row[col]\r\n\r\n            results.append(result)\r\n\r\n        return pd.DataFrame(results)\r\n\r\n    def apply_regional_factors(self, base_costs: pd.DataFrame,\r\n                               region_factors: Dict[str, float]) -> pd.DataFrame:\r\n        \"\"\"Apply regional adjustment factors.\"\"\"\r\n        adjusted = base_costs.copy()\r\n\r\n        if 'labor_cost' in adjusted.columns and 'labor' in region_factors:\r\n            adjusted['labor_cost'] *= region_factors['labor']\r\n\r\n        if 'material_cost' in adjusted.columns and 'material' in region_factors:\r\n            adjusted['material_cost'] *= region_factors['material']\r\n\r\n        if 'equipment_cost' in adjusted.columns and 'equipment' in region_factors:\r\n            adjusted['equipment_cost'] *= region_factors['equipment']\r\n\r\n        # Recalculate totals\r\n        adjusted['direct_cost'] = (\r\n            adjusted.get('labor_cost', 0) +\r\n            adjusted.get('material_cost', 0) +\r\n            adjusted.get('equipment_cost', 0)\r\n        )\r\n        adjusted['total_cost'] = adjusted['direct_cost'] * (1 + self.overhead_rate) * (1 + self.profit_rate)\r\n\r\n        return adjusted\r\n\r\n    def compare_estimates(self, estimate1: CostSummary,\r\n                         estimate2: CostSummary) -> Dict[str, Any]:\r\n        \"\"\"Compare two cost estimates.\"\"\"\r\n        return {\r\n            'total_difference': estimate2.total_cost - estimate1.total_cost,\r\n            'total_percent_change': (\r\n                (estimate2.total_cost - estimate1.total_cost) \u002F\r\n                estimate1.total_cost * 100 if estimate1.total_cost > 0 else 0\r\n            ),\r\n            'labor_difference': estimate2.labor_total - estimate1.labor_total,\r\n            'material_difference': estimate2.material_total - estimate1.material_total,\r\n            'equipment_difference': estimate2.equipment_total - estimate1.equipment_total,\r\n            'item_count_difference': estimate2.item_count - estimate1.item_count\r\n        }\r\n\r\n\r\nclass CostReportGenerator:\r\n    \"\"\"Generate cost reports from calculations.\"\"\"\r\n\r\n    def __init__(self, calculator: CWICRCostCalculator):\r\n        self.calculator = calculator\r\n\r\n    def generate_summary_report(self, items: List[Dict[str, Any]]) -> Dict[str, Any]:\r\n        \"\"\"Generate summary cost report.\"\"\"\r\n        summary = self.calculator.calculate_estimate(items)\r\n\r\n        return {\r\n            'report_date': datetime.now().isoformat(),\r\n            'currency': summary.currency,\r\n            'total_cost': round(summary.total_cost, 2),\r\n            'breakdown': {\r\n                'labor': round(summary.labor_total, 2),\r\n                'material': round(summary.material_total, 2),\r\n                'equipment': round(summary.equipment_total, 2),\r\n                'overhead': round(summary.overhead_total, 2),\r\n                'profit': round(summary.profit_total, 2)\r\n            },\r\n            'percentages': {\r\n                'labor': round(summary.labor_total \u002F summary.total_cost * 100, 1) if summary.total_cost > 0 else 0,\r\n                'material': round(summary.material_total \u002F summary.total_cost * 100, 1) if summary.total_cost > 0 else 0,\r\n                'equipment': round(summary.equipment_total \u002F summary.total_cost * 100, 1) if summary.total_cost > 0 else 0,\r\n            },\r\n            'item_count': summary.item_count,\r\n            'by_category': summary.breakdown_by_category\r\n        }\r\n\r\n    def generate_detailed_report(self, items: List[Dict[str, Any]]) -> pd.DataFrame:\r\n        \"\"\"Generate detailed line-item report.\"\"\"\r\n        results = []\r\n\r\n        for item in items:\r\n            code = item.get('work_item_code') or item.get('code')\r\n            qty = item.get('quantity', 0)\r\n\r\n            breakdown = self.calculator.calculate_item_cost(code, qty)\r\n            results.append(breakdown.to_dict())\r\n\r\n        df = pd.DataFrame(results)\r\n\r\n        # Add totals row\r\n        totals = df[['labor_cost', 'material_cost', 'equipment_cost',\r\n                     'overhead_cost', 'profit_cost', 'total_cost']].sum()\r\n        totals['description'] = 'TOTAL'\r\n        totals['work_item_code'] = ''\r\n\r\n        df = pd.concat([df, pd.DataFrame([totals])], ignore_index=True)\r\n\r\n        return df\r\n\r\n\r\n# Convenience functions\r\ndef calculate_cost(cwicr_data: pd.DataFrame,\r\n                   work_item_code: str,\r\n                   quantity: float) -> float:\r\n    \"\"\"Quick cost calculation.\"\"\"\r\n    calc = CWICRCostCalculator(cwicr_data)\r\n    breakdown = calc.calculate_item_cost(work_item_code, quantity)\r\n    return breakdown.total_cost\r\n\r\n\r\ndef estimate_project_cost(cwicr_data: pd.DataFrame,\r\n                         items: List[Dict[str, Any]]) -> Dict[str, Any]:\r\n    \"\"\"Quick project cost estimate.\"\"\"\r\n    calc = CWICRCostCalculator(cwicr_data)\r\n    report = CostReportGenerator(calc)\r\n    return report.generate_summary_report(items)\r\n```\r\n\r\n## Quick Start\r\n\r\n```python\r\nimport pandas as pd\r\nfrom cwicr_data_loader import CWICRDataLoader\r\n\r\n# Load CWICR data\r\nloader = CWICRDataLoader()\r\ncwicr = loader.load(\"ddc_cwicr_en.parquet\")\r\n\r\n# Initialize calculator\r\ncalc = CWICRCostCalculator(cwicr)\r\n\r\n# Calculate single item\r\nbreakdown = calc.calculate_item_cost(\"CONC-001\", quantity=150)\r\nprint(f\"Total: ${breakdown.total_cost:,.2f}\")\r\nprint(f\"  Labor: ${breakdown.labor_cost:,.2f}\")\r\nprint(f\"  Material: ${breakdown.material_cost:,.2f}\")\r\nprint(f\"  Equipment: ${breakdown.equipment_cost:,.2f}\")\r\n```\r\n\r\n## Common Use Cases\r\n\r\n### 1. Project Estimate\r\n```python\r\nitems = [\r\n    {'work_item_code': 'CONC-001', 'quantity': 150},\r\n    {'work_item_code': 'EXCV-002', 'quantity': 200},\r\n    {'work_item_code': 'REBAR-003', 'quantity': 15000}  # kg\r\n]\r\n\r\nsummary = calc.calculate_estimate(items)\r\nprint(f\"Project Total: ${summary.total_cost:,.2f}\")\r\n```\r\n\r\n### 2. QTO Integration\r\n```python\r\n# Load BIM quantities\r\nqto = pd.read_excel(\"quantities.xlsx\")\r\n\r\n# Calculate costs\r\ncosts = calc.calculate_from_qto(qto,\r\n    code_column='work_item',\r\n    quantity_column='quantity'\r\n)\r\nprint(costs[['description', 'quantity', 'total_cost']])\r\n```\r\n\r\n### 3. Regional Adjustment\r\n```python\r\n# Apply Berlin pricing\r\nberlin_factors = {\r\n    'labor': 1.15,      # 15% higher labor\r\n    'material': 0.95,   # 5% lower materials\r\n    'equipment': 1.0\r\n}\r\n\r\nadjusted = calc.apply_regional_factors(costs, berlin_factors)\r\n```\r\n\r\n## Resources\r\n\r\n- **GitHub**: [OpenConstructionEstimate-DDC-CWICR](https:\u002F\u002Fgithub.com\u002Fdatadrivenconstruction\u002FOpenConstructionEstimate-DDC-CWICR)\r\n- **DDC Book**: Chapter 3.1 - Construction Cost Estimation\r\n",{"slug":5,"description":7,"display_name":31},"CWICR Cost Calculator","main","e7e336ac628c3e3bd771aff1aaa469c93778f94a","skills\u002Fdatadrivenconstruction\u002Fcwicr-cost-calculator",0,"https:\u002F\u002Fgithub.com\u002Fkbarbel640-del\u002Fskills","https:\u002F\u002Fgithub.com\u002Fkbarbel640-del","2026-08-23 22:39:37",{"source":8,"skillName":5,"commands":40,"prompt":50,"zipAvailable":51},[41,44,47],{"tool":42,"command":43},"npx","npx skills add kbarbel640-del\u002Fskills --skill cwicr-cost-calculator",{"tool":45,"command":46},"bunx","bunx skills add kbarbel640-del\u002Fskills --skill cwicr-cost-calculator",{"tool":48,"command":49},"pnpm","pnpm dlx skills add kbarbel640-del\u002Fskills --skill cwicr-cost-calculator","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fkbarbel640-del\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fdatadrivenconstruction\u002Fcwicr-cost-calculator\u002FSKILL.md",true,[53],{"path":54,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":57,"sourceHtmlUrl":58},"_meta.json","REFERENCE","参考文档",310,"https:\u002F\u002Fgithub.com\u002Fkbarbel640-del\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fdatadrivenconstruction\u002Fcwicr-cost-calculator\u002F_meta.json",[60,85,109,127,132,152],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":26},"01M6G8J55967D6281ACMKAKTEQ","crowd-prompting","A marketplace where AI agents improve prompts, system instructions, tool descriptions, and other text-based content with domain expertise from real-world operations — and earn tokens for valuable contributions.","https:\u002F\u002Fgithub.com\u002Fkbarbel640-del\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fzzadrian\u002Fcrowd-prompting\u002FSKILL.md",[],[67,68,69,25,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84],"crowd prompting","prompting","api","tokens","domain","world","prompts","operations","instructions","text","tool","system","improve","productivity","marketplace","https","content","ai agents",{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":26},"01M6G8J0PKPAYVET6BWE8W4C26","dilemm-ai","Compete in DilemmAI, the prisoner's dilemma AI arena at dilemm.ai. Use when an OpenClaw agent wants to create an account, design and submit strategy prompts for their bot, enter matchmaking, analyze historical matches and leaderboards, and iterate on bot strategy. Requires headless browser automation (no API available yet).","https:\u002F\u002Fgithub.com\u002Fkbarbel640-del\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fzyori\u002Fdilemm-ai\u002FSKILL.md",[],[92,69,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,73,108],"dilemm ai","arena","analyze","browser","openclaw agent","create","automation","browser automation","bot","openclaw","design","strategy","headless","compete","submit","matchmaking","use",{"skillNo":110,"name":111,"nameZh":6,"description":112,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":113,"categories":114,"keywords":115,"publishedAt":26},"01M6G8HWAF3K9SW7NP3Z83CPJ6","arxiv-paper-reviews","Interact with arXiv Crawler API to fetch papers, read reviews, and submit comments. Use when working with arXiv papers, fetching paper lists by date\u002Fcategory\u002Finterest, viewing paper details with comments, or submitting paper reviews via API at http:\u002F\u002F150.158.152.82:8000.","https:\u002F\u002Fgithub.com\u002Fkbarbel640-del\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fzxrys\u002Fweak-accept\u002FSKILL.md",[],[116,117,118,119,120,121,122,25,123,106,108,124,69,125,126],"arxiv paper reviews","reviews","arxiv","paper","crawler","papers","comments","fetch","read","http","via",{"skillNo":128,"name":111,"nameZh":6,"description":112,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":129,"categories":130,"keywords":131,"publishedAt":26},"01M6G8HQJ7N7WMY6YV7D7SSJ16","https:\u002F\u002Fgithub.com\u002Fkbarbel640-del\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fzxrys\u002Farxiv-paper-reviews\u002FSKILL.md",[],[119,118,117,116,126,121,122,25,120,106,108,123,124,69,125],{"skillNo":133,"name":134,"nameZh":6,"description":135,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":136,"categories":137,"keywords":138,"publishedAt":26},"01M6G8HM95Y64JNVFC2HN4E2BG","git-summary","Get a quick summary of the current Git repository including status, recent commits, branches, and contributors.","https:\u002F\u002Fgithub.com\u002Fkbarbel640-del\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fzweack\u002Fgit-summary\u002FSKILL.md",[],[139,140,141,142,143,144,145,146,147,148,149,150,151],"git","summary","git summary","commits","repository","win32","status","linux","contributors","true","quick","get","branches",{"skillNo":153,"name":154,"nameZh":6,"description":155,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":156,"categories":157,"keywords":158,"publishedAt":26},"01M6G8HGEGF05CNEJCGVYFSC4R","agent-constitution","Interact with AgentConstitution governance contracts on Base Sepolia. Check compliance, read rules, log actions, query governance state.","https:\u002F\u002Fgithub.com\u002Fkbarbel640-del\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fztsalexey\u002Fagent-constitution\u002FSKILL.md",[],[159,160,161,162,25,163,164,32,165,124,166,167,168,169,170,82,171,172,173],"agent constitution","constitution","contracts","tree","query","base","log","check","Rules","projects","compliance","actions","state","governance","github"]