[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6FJR34XQ76Z1AMBKVP1RBKR":3,"skill-same:01M6FJR34XQ76Z1AMBKVP1RBKR":62},{"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":29,"linkOnly":30,"markdownContent":31,"markdownBody":32,"frontMatter":33,"refName":35,"commitSha":36,"skillDirectory":37,"forksCount":38,"repositoryHtmlUrl":39,"repositoryHomepageUrl":6,"ownerHtmlUrl":40,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":41,"install":42,"resources":55},"01M6FJR34XQ76Z1AMBKVP1RBKR","cwicr-resource-analyzer",null,"Analyze construction resources (labor, materials, equipment) from DDC CWICR database. Calculate resource requirements, productivity metrics, and optimization recommendations.","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-resource-analyzer\u002FSKILL.md",[],[18,19,20,21,22,23,24,25,26,27,28],"cwicr resource analyzer","optimization recommendations","database","metrics","productivity","Optimization","analyze","calculate","requirements","recommendations","resources","2026-11-10 10:12:30",false,"---\r\nslug: \"cwicr-resource-analyzer\"\r\ndisplay_name: \"CWICR Resource Analyzer\"\r\ndescription: \"Analyze construction resources (labor, materials, equipment) from DDC CWICR database. Calculate resource requirements, productivity metrics, and optimization recommendations.\"\r\n---\r\n\r\n# CWICR Resource Analyzer\r\n\r\n## Business Case\r\n\r\n### Problem Statement\r\nConstruction projects require precise resource planning:\r\n- How many labor hours are needed?\r\n- What materials need to be procured?\r\n- What equipment is required and for how long?\r\n\r\nTraditional methods rely on experience-based estimates, leading to over\u002Funder allocation.\r\n\r\n### Solution\r\nData-driven resource analysis using CWICR's 27,672 resources with detailed breakdowns of labor norms, material requirements, and equipment usage.\r\n\r\n### Business Value\r\n- **Accurate planning** - Based on validated resource norms\r\n- **Cost optimization** - Identify resource inefficiencies\r\n- **Procurement support** - Generate material lists\r\n- **Labor planning** - Calculate crew requirements\r\n\r\n## Technical Implementation\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 collections import defaultdict\r\n\r\n\r\nclass ResourceType(Enum):\r\n    \"\"\"Types of construction resources.\"\"\"\r\n    LABOR = \"labor\"\r\n    MATERIAL = \"material\"\r\n    EQUIPMENT = \"equipment\"\r\n    SUBCONTRACT = \"subcontract\"\r\n\r\n\r\nclass LaborCategory(Enum):\r\n    \"\"\"Labor skill categories.\"\"\"\r\n    UNSKILLED = \"unskilled\"\r\n    SEMI_SKILLED = \"semi_skilled\"\r\n    SKILLED = \"skilled\"\r\n    FOREMAN = \"foreman\"\r\n    SUPERVISOR = \"supervisor\"\r\n    SPECIALIST = \"specialist\"\r\n\r\n\r\nclass EquipmentCategory(Enum):\r\n    \"\"\"Equipment categories.\"\"\"\r\n    EARTHMOVING = \"earthmoving\"\r\n    LIFTING = \"lifting\"\r\n    CONCRETE = \"concrete\"\r\n    TRANSPORT = \"transport\"\r\n    COMPACTION = \"compaction\"\r\n    PUMPING = \"pumping\"\r\n    POWER_TOOLS = \"power_tools\"\r\n    SCAFFOLDING = \"scaffolding\"\r\n\r\n\r\n@dataclass\r\nclass LaborResource:\r\n    \"\"\"Represents a labor resource.\"\"\"\r\n    resource_code: str\r\n    description: str\r\n    category: LaborCategory\r\n    hourly_rate: float\r\n    skill_level: int\r\n    productivity_factor: float = 1.0\r\n\r\n\r\n@dataclass\r\nclass MaterialResource:\r\n    \"\"\"Represents a material resource.\"\"\"\r\n    resource_code: str\r\n    description: str\r\n    unit: str\r\n    unit_price: float\r\n    category: str\r\n    waste_factor: float = 0.05  # 5% default waste\r\n\r\n\r\n@dataclass\r\nclass EquipmentResource:\r\n    \"\"\"Represents an equipment resource.\"\"\"\r\n    resource_code: str\r\n    description: str\r\n    category: EquipmentCategory\r\n    hourly_rate: float\r\n    daily_rate: float\r\n    monthly_rate: float\r\n    fuel_consumption: float = 0.0  # liters per hour\r\n    operator_required: bool = True\r\n\r\n\r\n@dataclass\r\nclass ResourceRequirement:\r\n    \"\"\"Calculated resource requirement.\"\"\"\r\n    resource_code: str\r\n    description: str\r\n    resource_type: ResourceType\r\n    quantity: float\r\n    unit: str\r\n    unit_cost: float\r\n    total_cost: float\r\n    duration_hours: float = 0.0\r\n\r\n\r\n@dataclass\r\nclass ResourceSummary:\r\n    \"\"\"Summary of all resource requirements.\"\"\"\r\n    labor_hours: float\r\n    labor_cost: float\r\n    material_cost: float\r\n    equipment_cost: float\r\n    total_cost: float\r\n\r\n    labor_by_category: Dict[str, float] = field(default_factory=dict)\r\n    materials_list: List[Dict[str, Any]] = field(default_factory=list)\r\n    equipment_list: List[Dict[str, Any]] = field(default_factory=list)\r\n\r\n\r\nclass CWICRResourceAnalyzer:\r\n    \"\"\"Analyze resources from CWICR database.\"\"\"\r\n\r\n    def __init__(self, cwicr_data: pd.DataFrame,\r\n                 resources_data: Optional[pd.DataFrame] = None):\r\n        self.work_items = cwicr_data\r\n        self.resources = resources_data\r\n\r\n        # Create indexes\r\n        self._index_work_items()\r\n        if resources_data is not None:\r\n            self._index_resources()\r\n\r\n    def _index_work_items(self):\r\n        \"\"\"Index work items for fast lookup.\"\"\"\r\n        if 'work_item_code' in self.work_items.columns:\r\n            self._work_index = self.work_items.set_index('work_item_code')\r\n        else:\r\n            self._work_index = None\r\n\r\n    def _index_resources(self):\r\n        \"\"\"Index resources for fast lookup.\"\"\"\r\n        if self.resources is not None and 'resource_code' in self.resources.columns:\r\n            self._resource_index = self.resources.set_index('resource_code')\r\n        else:\r\n            self._resource_index = None\r\n\r\n    def analyze_labor_requirements(self, items: List[Dict[str, Any]]) -> Dict[str, Any]:\r\n        \"\"\"Analyze labor requirements for work items.\"\"\"\r\n\r\n        total_hours = 0.0\r\n        labor_by_category = defaultdict(float)\r\n        labor_by_skill = defaultdict(float)\r\n        labor_details = []\r\n\r\n        for item in items:\r\n            code = item.get('work_item_code', item.get('code'))\r\n            qty = item.get('quantity', 0)\r\n\r\n            if self._work_index is not None and code in self._work_index.index:\r\n                work_item = self._work_index.loc[code]\r\n                labor_norm = float(work_item.get('labor_norm', 0) or 0)\r\n                hours = labor_norm * qty\r\n\r\n                total_hours += hours\r\n\r\n                # Get category if available\r\n                category = str(work_item.get('category', 'General'))\r\n                labor_by_category[category] += hours\r\n\r\n                labor_details.append({\r\n                    'work_item_code': code,\r\n                    'description': work_item.get('description', ''),\r\n                    'quantity': qty,\r\n                    'labor_norm': labor_norm,\r\n                    'total_hours': hours\r\n                })\r\n\r\n        return {\r\n            'total_labor_hours': round(total_hours, 2),\r\n            'labor_by_category': dict(labor_by_category),\r\n            'crew_days_8hr': round(total_hours \u002F 8, 1),\r\n            'crew_weeks_40hr': round(total_hours \u002F 40, 1),\r\n            'details': labor_details\r\n        }\r\n\r\n    def analyze_material_requirements(self, items: List[Dict[str, Any]],\r\n                                       include_waste: bool = True) -> Dict[str, Any]:\r\n        \"\"\"Analyze material requirements.\"\"\"\r\n\r\n        materials = defaultdict(lambda: {'quantity': 0, 'unit': '', 'cost': 0})\r\n        total_cost = 0.0\r\n\r\n        for item in items:\r\n            code = item.get('work_item_code', item.get('code'))\r\n            qty = item.get('quantity', 0)\r\n\r\n            if self._work_index is not None and code in self._work_index.index:\r\n                work_item = self._work_index.loc[code]\r\n                material_cost = float(work_item.get('material_cost', 0) or 0) * qty\r\n\r\n                if include_waste:\r\n                    material_cost *= 1.05  # 5% waste factor\r\n\r\n                total_cost += material_cost\r\n\r\n                # Aggregate by category\r\n                category = str(work_item.get('category', 'General'))\r\n                materials[category]['cost'] += material_cost\r\n\r\n        return {\r\n            'total_material_cost': round(total_cost, 2),\r\n            'by_category': dict(materials),\r\n            'waste_included': include_waste,\r\n            'waste_factor': 0.05 if include_waste else 0\r\n        }\r\n\r\n    def analyze_equipment_requirements(self, items: List[Dict[str, Any]]) -> Dict[str, Any]:\r\n        \"\"\"Analyze equipment requirements.\"\"\"\r\n\r\n        equipment_hours = defaultdict(float)\r\n        total_cost = 0.0\r\n\r\n        for item in items:\r\n            code = item.get('work_item_code', item.get('code'))\r\n            qty = item.get('quantity', 0)\r\n\r\n            if self._work_index is not None and code in self._work_index.index:\r\n                work_item = self._work_index.loc[code]\r\n                equipment_cost = float(work_item.get('equipment_cost', 0) or 0) * qty\r\n                equipment_norm = float(work_item.get('equipment_norm', 0) or 0) * qty\r\n\r\n                total_cost += equipment_cost\r\n\r\n                category = str(work_item.get('category', 'General'))\r\n                equipment_hours[category] += equipment_norm\r\n\r\n        return {\r\n            'total_equipment_cost': round(total_cost, 2),\r\n            'equipment_hours_by_category': dict(equipment_hours),\r\n            'total_equipment_hours': sum(equipment_hours.values())\r\n        }\r\n\r\n    def generate_resource_summary(self, items: List[Dict[str, Any]]) -> ResourceSummary:\r\n        \"\"\"Generate complete resource summary.\"\"\"\r\n\r\n        labor = self.analyze_labor_requirements(items)\r\n        materials = self.analyze_material_requirements(items)\r\n        equipment = self.analyze_equipment_requirements(items)\r\n\r\n        # Calculate labor cost\r\n        avg_labor_rate = 35.0  # Default hourly rate\r\n        labor_cost = labor['total_labor_hours'] * avg_labor_rate\r\n\r\n        return ResourceSummary(\r\n            labor_hours=labor['total_labor_hours'],\r\n            labor_cost=labor_cost,\r\n            material_cost=materials['total_material_cost'],\r\n            equipment_cost=equipment['total_equipment_cost'],\r\n            total_cost=labor_cost + materials['total_material_cost'] + equipment['total_equipment_cost'],\r\n            labor_by_category=labor['labor_by_category']\r\n        )\r\n\r\n    def calculate_crew_requirements(self, labor_hours: float,\r\n                                     project_duration_days: int,\r\n                                     hours_per_day: int = 8) -> Dict[str, Any]:\r\n        \"\"\"Calculate crew size requirements.\"\"\"\r\n\r\n        available_hours = project_duration_days * hours_per_day\r\n        min_crew_size = labor_hours \u002F available_hours if available_hours > 0 else 0\r\n\r\n        return {\r\n            'total_labor_hours': labor_hours,\r\n            'project_duration_days': project_duration_days,\r\n            'hours_per_day': hours_per_day,\r\n            'minimum_crew_size': round(min_crew_size, 1),\r\n            'recommended_crew_size': int(np.ceil(min_crew_size * 1.15)),  # 15% buffer\r\n            'utilization_at_recommended': round(min_crew_size \u002F np.ceil(min_crew_size * 1.15) * 100, 1)\r\n        }\r\n\r\n    def identify_critical_resources(self, items: List[Dict[str, Any]],\r\n                                     top_n: int = 10) -> Dict[str, List[Dict]]:\r\n        \"\"\"Identify critical resources by cost impact.\"\"\"\r\n\r\n        breakdowns = []\r\n        for item in items:\r\n            code = item.get('work_item_code', item.get('code'))\r\n            qty = item.get('quantity', 0)\r\n\r\n            if self._work_index is not None and code in self._work_index.index:\r\n                work_item = self._work_index.loc[code]\r\n\r\n                breakdowns.append({\r\n                    'work_item_code': code,\r\n                    'description': work_item.get('description', ''),\r\n                    'quantity': qty,\r\n                    'labor_cost': float(work_item.get('labor_cost', 0) or 0) * qty,\r\n                    'material_cost': float(work_item.get('material_cost', 0) or 0) * qty,\r\n                    'equipment_cost': float(work_item.get('equipment_cost', 0) or 0) * qty,\r\n                    'total_cost': (\r\n                        float(work_item.get('labor_cost', 0) or 0) +\r\n                        float(work_item.get('material_cost', 0) or 0) +\r\n                        float(work_item.get('equipment_cost', 0) or 0)\r\n                    ) * qty\r\n                })\r\n\r\n        df = pd.DataFrame(breakdowns)\r\n        if df.empty:\r\n            return {'labor': [], 'material': [], 'equipment': [], 'total': []}\r\n\r\n        return {\r\n            'labor': df.nlargest(top_n, 'labor_cost')[['work_item_code', 'description', 'labor_cost']].to_dict('records'),\r\n            'material': df.nlargest(top_n, 'material_cost')[['work_item_code', 'description', 'material_cost']].to_dict('records'),\r\n            'equipment': df.nlargest(top_n, 'equipment_cost')[['work_item_code', 'description', 'equipment_cost']].to_dict('records'),\r\n            'total': df.nlargest(top_n, 'total_cost')[['work_item_code', 'description', 'total_cost']].to_dict('records')\r\n        }\r\n\r\n    def analyze_productivity(self, items: List[Dict[str, Any]],\r\n                             actual_hours: Optional[Dict[str, float]] = None) -> Dict[str, Any]:\r\n        \"\"\"Analyze productivity vs planned norms.\"\"\"\r\n\r\n        if actual_hours is None:\r\n            return {'error': 'Actual hours required for productivity analysis'}\r\n\r\n        analysis = []\r\n        for item in items:\r\n            code = item.get('work_item_code', item.get('code'))\r\n            qty = item.get('quantity', 0)\r\n\r\n            if code in actual_hours and self._work_index is not None:\r\n                if code in self._work_index.index:\r\n                    work_item = self._work_index.loc[code]\r\n                    planned_hours = float(work_item.get('labor_norm', 0) or 0) * qty\r\n                    actual = actual_hours[code]\r\n\r\n                    productivity = planned_hours \u002F actual * 100 if actual > 0 else 0\r\n\r\n                    analysis.append({\r\n                        'work_item_code': code,\r\n                        'planned_hours': planned_hours,\r\n                        'actual_hours': actual,\r\n                        'productivity_percent': round(productivity, 1),\r\n                        'variance_hours': planned_hours - actual\r\n                    })\r\n\r\n        df = pd.DataFrame(analysis)\r\n        if df.empty:\r\n            return {'items': [], 'average_productivity': 0}\r\n\r\n        return {\r\n            'items': analysis,\r\n            'average_productivity': round(df['productivity_percent'].mean(), 1),\r\n            'total_variance': round(df['variance_hours'].sum(), 1),\r\n            'underperforming_items': len(df[df['productivity_percent'] \u003C 90])\r\n        }\r\n\r\n\r\nclass ResourceOptimizer:\r\n    \"\"\"Optimize resource allocation.\"\"\"\r\n\r\n    def __init__(self, analyzer: CWICRResourceAnalyzer):\r\n        self.analyzer = analyzer\r\n\r\n    def suggest_material_substitutions(self, items: List[Dict[str, Any]],\r\n                                        cost_threshold: float = 0.9) -> List[Dict]:\r\n        \"\"\"Suggest cheaper material substitutions.\"\"\"\r\n        # Placeholder for substitution logic\r\n        return []\r\n\r\n    def optimize_crew_allocation(self, labor_by_category: Dict[str, float],\r\n                                  available_crew: Dict[str, int]) -> Dict[str, Any]:\r\n        \"\"\"Optimize crew allocation across categories.\"\"\"\r\n\r\n        allocation = {}\r\n        unmet_demand = {}\r\n\r\n        for category, hours_needed in labor_by_category.items():\r\n            available = available_crew.get(category, 0)\r\n            days_needed = hours_needed \u002F 8\r\n\r\n            if available > 0:\r\n                days_available = available * 1  # 1 day per person\r\n                if days_available >= days_needed:\r\n                    allocation[category] = {\r\n                        'assigned': int(np.ceil(days_needed)),\r\n                        'remaining': available - int(np.ceil(days_needed))\r\n                    }\r\n                else:\r\n                    allocation[category] = {'assigned': available, 'remaining': 0}\r\n                    unmet_demand[category] = days_needed - days_available\r\n            else:\r\n                unmet_demand[category] = days_needed\r\n\r\n        return {\r\n            'allocation': allocation,\r\n            'unmet_demand': unmet_demand,\r\n            'fully_staffed': len(unmet_demand) == 0\r\n        }\r\n```\r\n\r\n## Quick Start\r\n\r\n```python\r\nfrom cwicr_data_loader import CWICRDataLoader\r\n\r\n# Load data\r\nloader = CWICRDataLoader()\r\ncwicr = loader.load(\"ddc_cwicr_en.parquet\")\r\n\r\n# Initialize analyzer\r\nanalyzer = CWICRResourceAnalyzer(cwicr)\r\n\r\n# Define project items\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}\r\n]\r\n\r\n# Analyze labor\r\nlabor = analyzer.analyze_labor_requirements(items)\r\nprint(f\"Total Labor Hours: {labor['total_labor_hours']}\")\r\nprint(f\"Crew Days (8hr): {labor['crew_days_8hr']}\")\r\n```\r\n\r\n## Common Use Cases\r\n\r\n### 1. Crew Planning\r\n```python\r\n# Calculate required crew size\r\nlabor = analyzer.analyze_labor_requirements(items)\r\ncrew = analyzer.calculate_crew_requirements(\r\n    labor_hours=labor['total_labor_hours'],\r\n    project_duration_days=30\r\n)\r\nprint(f\"Minimum Crew: {crew['minimum_crew_size']}\")\r\nprint(f\"Recommended Crew: {crew['recommended_crew_size']}\")\r\n```\r\n\r\n### 2. Material Procurement\r\n```python\r\nmaterials = analyzer.analyze_material_requirements(items, include_waste=True)\r\nprint(f\"Total Material Cost: ${materials['total_material_cost']:,.2f}\")\r\n```\r\n\r\n### 3. Productivity Tracking\r\n```python\r\nactual_hours = {\r\n    'CONC-001': 280,\r\n    'EXCV-002': 85,\r\n    'REBAR-003': 450\r\n}\r\nproductivity = analyzer.analyze_productivity(items, actual_hours)\r\nprint(f\"Average Productivity: {productivity['average_productivity']}%\")\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 - Resource-Based Cost Estimation\r\n","# CWICR Resource Analyzer\r\n\r\n## Business Case\r\n\r\n### Problem Statement\r\nConstruction projects require precise resource planning:\r\n- How many labor hours are needed?\r\n- What materials need to be procured?\r\n- What equipment is required and for how long?\r\n\r\nTraditional methods rely on experience-based estimates, leading to over\u002Funder allocation.\r\n\r\n### Solution\r\nData-driven resource analysis using CWICR's 27,672 resources with detailed breakdowns of labor norms, material requirements, and equipment usage.\r\n\r\n### Business Value\r\n- **Accurate planning** - Based on validated resource norms\r\n- **Cost optimization** - Identify resource inefficiencies\r\n- **Procurement support** - Generate material lists\r\n- **Labor planning** - Calculate crew requirements\r\n\r\n## Technical Implementation\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 collections import defaultdict\r\n\r\n\r\nclass ResourceType(Enum):\r\n    \"\"\"Types of construction resources.\"\"\"\r\n    LABOR = \"labor\"\r\n    MATERIAL = \"material\"\r\n    EQUIPMENT = \"equipment\"\r\n    SUBCONTRACT = \"subcontract\"\r\n\r\n\r\nclass LaborCategory(Enum):\r\n    \"\"\"Labor skill categories.\"\"\"\r\n    UNSKILLED = \"unskilled\"\r\n    SEMI_SKILLED = \"semi_skilled\"\r\n    SKILLED = \"skilled\"\r\n    FOREMAN = \"foreman\"\r\n    SUPERVISOR = \"supervisor\"\r\n    SPECIALIST = \"specialist\"\r\n\r\n\r\nclass EquipmentCategory(Enum):\r\n    \"\"\"Equipment categories.\"\"\"\r\n    EARTHMOVING = \"earthmoving\"\r\n    LIFTING = \"lifting\"\r\n    CONCRETE = \"concrete\"\r\n    TRANSPORT = \"transport\"\r\n    COMPACTION = \"compaction\"\r\n    PUMPING = \"pumping\"\r\n    POWER_TOOLS = \"power_tools\"\r\n    SCAFFOLDING = \"scaffolding\"\r\n\r\n\r\n@dataclass\r\nclass LaborResource:\r\n    \"\"\"Represents a labor resource.\"\"\"\r\n    resource_code: str\r\n    description: str\r\n    category: LaborCategory\r\n    hourly_rate: float\r\n    skill_level: int\r\n    productivity_factor: float = 1.0\r\n\r\n\r\n@dataclass\r\nclass MaterialResource:\r\n    \"\"\"Represents a material resource.\"\"\"\r\n    resource_code: str\r\n    description: str\r\n    unit: str\r\n    unit_price: float\r\n    category: str\r\n    waste_factor: float = 0.05  # 5% default waste\r\n\r\n\r\n@dataclass\r\nclass EquipmentResource:\r\n    \"\"\"Represents an equipment resource.\"\"\"\r\n    resource_code: str\r\n    description: str\r\n    category: EquipmentCategory\r\n    hourly_rate: float\r\n    daily_rate: float\r\n    monthly_rate: float\r\n    fuel_consumption: float = 0.0  # liters per hour\r\n    operator_required: bool = True\r\n\r\n\r\n@dataclass\r\nclass ResourceRequirement:\r\n    \"\"\"Calculated resource requirement.\"\"\"\r\n    resource_code: str\r\n    description: str\r\n    resource_type: ResourceType\r\n    quantity: float\r\n    unit: str\r\n    unit_cost: float\r\n    total_cost: float\r\n    duration_hours: float = 0.0\r\n\r\n\r\n@dataclass\r\nclass ResourceSummary:\r\n    \"\"\"Summary of all resource requirements.\"\"\"\r\n    labor_hours: float\r\n    labor_cost: float\r\n    material_cost: float\r\n    equipment_cost: float\r\n    total_cost: float\r\n\r\n    labor_by_category: Dict[str, float] = field(default_factory=dict)\r\n    materials_list: List[Dict[str, Any]] = field(default_factory=list)\r\n    equipment_list: List[Dict[str, Any]] = field(default_factory=list)\r\n\r\n\r\nclass CWICRResourceAnalyzer:\r\n    \"\"\"Analyze resources from CWICR database.\"\"\"\r\n\r\n    def __init__(self, cwicr_data: pd.DataFrame,\r\n                 resources_data: Optional[pd.DataFrame] = None):\r\n        self.work_items = cwicr_data\r\n        self.resources = resources_data\r\n\r\n        # Create indexes\r\n        self._index_work_items()\r\n        if resources_data is not None:\r\n            self._index_resources()\r\n\r\n    def _index_work_items(self):\r\n        \"\"\"Index work items for fast lookup.\"\"\"\r\n        if 'work_item_code' in self.work_items.columns:\r\n            self._work_index = self.work_items.set_index('work_item_code')\r\n        else:\r\n            self._work_index = None\r\n\r\n    def _index_resources(self):\r\n        \"\"\"Index resources for fast lookup.\"\"\"\r\n        if self.resources is not None and 'resource_code' in self.resources.columns:\r\n            self._resource_index = self.resources.set_index('resource_code')\r\n        else:\r\n            self._resource_index = None\r\n\r\n    def analyze_labor_requirements(self, items: List[Dict[str, Any]]) -> Dict[str, Any]:\r\n        \"\"\"Analyze labor requirements for work items.\"\"\"\r\n\r\n        total_hours = 0.0\r\n        labor_by_category = defaultdict(float)\r\n        labor_by_skill = defaultdict(float)\r\n        labor_details = []\r\n\r\n        for item in items:\r\n            code = item.get('work_item_code', item.get('code'))\r\n            qty = item.get('quantity', 0)\r\n\r\n            if self._work_index is not None and code in self._work_index.index:\r\n                work_item = self._work_index.loc[code]\r\n                labor_norm = float(work_item.get('labor_norm', 0) or 0)\r\n                hours = labor_norm * qty\r\n\r\n                total_hours += hours\r\n\r\n                # Get category if available\r\n                category = str(work_item.get('category', 'General'))\r\n                labor_by_category[category] += hours\r\n\r\n                labor_details.append({\r\n                    'work_item_code': code,\r\n                    'description': work_item.get('description', ''),\r\n                    'quantity': qty,\r\n                    'labor_norm': labor_norm,\r\n                    'total_hours': hours\r\n                })\r\n\r\n        return {\r\n            'total_labor_hours': round(total_hours, 2),\r\n            'labor_by_category': dict(labor_by_category),\r\n            'crew_days_8hr': round(total_hours \u002F 8, 1),\r\n            'crew_weeks_40hr': round(total_hours \u002F 40, 1),\r\n            'details': labor_details\r\n        }\r\n\r\n    def analyze_material_requirements(self, items: List[Dict[str, Any]],\r\n                                       include_waste: bool = True) -> Dict[str, Any]:\r\n        \"\"\"Analyze material requirements.\"\"\"\r\n\r\n        materials = defaultdict(lambda: {'quantity': 0, 'unit': '', 'cost': 0})\r\n        total_cost = 0.0\r\n\r\n        for item in items:\r\n            code = item.get('work_item_code', item.get('code'))\r\n            qty = item.get('quantity', 0)\r\n\r\n            if self._work_index is not None and code in self._work_index.index:\r\n                work_item = self._work_index.loc[code]\r\n                material_cost = float(work_item.get('material_cost', 0) or 0) * qty\r\n\r\n                if include_waste:\r\n                    material_cost *= 1.05  # 5% waste factor\r\n\r\n                total_cost += material_cost\r\n\r\n                # Aggregate by category\r\n                category = str(work_item.get('category', 'General'))\r\n                materials[category]['cost'] += material_cost\r\n\r\n        return {\r\n            'total_material_cost': round(total_cost, 2),\r\n            'by_category': dict(materials),\r\n            'waste_included': include_waste,\r\n            'waste_factor': 0.05 if include_waste else 0\r\n        }\r\n\r\n    def analyze_equipment_requirements(self, items: List[Dict[str, Any]]) -> Dict[str, Any]:\r\n        \"\"\"Analyze equipment requirements.\"\"\"\r\n\r\n        equipment_hours = defaultdict(float)\r\n        total_cost = 0.0\r\n\r\n        for item in items:\r\n            code = item.get('work_item_code', item.get('code'))\r\n            qty = item.get('quantity', 0)\r\n\r\n            if self._work_index is not None and code in self._work_index.index:\r\n                work_item = self._work_index.loc[code]\r\n                equipment_cost = float(work_item.get('equipment_cost', 0) or 0) * qty\r\n                equipment_norm = float(work_item.get('equipment_norm', 0) or 0) * qty\r\n\r\n                total_cost += equipment_cost\r\n\r\n                category = str(work_item.get('category', 'General'))\r\n                equipment_hours[category] += equipment_norm\r\n\r\n        return {\r\n            'total_equipment_cost': round(total_cost, 2),\r\n            'equipment_hours_by_category': dict(equipment_hours),\r\n            'total_equipment_hours': sum(equipment_hours.values())\r\n        }\r\n\r\n    def generate_resource_summary(self, items: List[Dict[str, Any]]) -> ResourceSummary:\r\n        \"\"\"Generate complete resource summary.\"\"\"\r\n\r\n        labor = self.analyze_labor_requirements(items)\r\n        materials = self.analyze_material_requirements(items)\r\n        equipment = self.analyze_equipment_requirements(items)\r\n\r\n        # Calculate labor cost\r\n        avg_labor_rate = 35.0  # Default hourly rate\r\n        labor_cost = labor['total_labor_hours'] * avg_labor_rate\r\n\r\n        return ResourceSummary(\r\n            labor_hours=labor['total_labor_hours'],\r\n            labor_cost=labor_cost,\r\n            material_cost=materials['total_material_cost'],\r\n            equipment_cost=equipment['total_equipment_cost'],\r\n            total_cost=labor_cost + materials['total_material_cost'] + equipment['total_equipment_cost'],\r\n            labor_by_category=labor['labor_by_category']\r\n        )\r\n\r\n    def calculate_crew_requirements(self, labor_hours: float,\r\n                                     project_duration_days: int,\r\n                                     hours_per_day: int = 8) -> Dict[str, Any]:\r\n        \"\"\"Calculate crew size requirements.\"\"\"\r\n\r\n        available_hours = project_duration_days * hours_per_day\r\n        min_crew_size = labor_hours \u002F available_hours if available_hours > 0 else 0\r\n\r\n        return {\r\n            'total_labor_hours': labor_hours,\r\n            'project_duration_days': project_duration_days,\r\n            'hours_per_day': hours_per_day,\r\n            'minimum_crew_size': round(min_crew_size, 1),\r\n            'recommended_crew_size': int(np.ceil(min_crew_size * 1.15)),  # 15% buffer\r\n            'utilization_at_recommended': round(min_crew_size \u002F np.ceil(min_crew_size * 1.15) * 100, 1)\r\n        }\r\n\r\n    def identify_critical_resources(self, items: List[Dict[str, Any]],\r\n                                     top_n: int = 10) -> Dict[str, List[Dict]]:\r\n        \"\"\"Identify critical resources by cost impact.\"\"\"\r\n\r\n        breakdowns = []\r\n        for item in items:\r\n            code = item.get('work_item_code', item.get('code'))\r\n            qty = item.get('quantity', 0)\r\n\r\n            if self._work_index is not None and code in self._work_index.index:\r\n                work_item = self._work_index.loc[code]\r\n\r\n                breakdowns.append({\r\n                    'work_item_code': code,\r\n                    'description': work_item.get('description', ''),\r\n                    'quantity': qty,\r\n                    'labor_cost': float(work_item.get('labor_cost', 0) or 0) * qty,\r\n                    'material_cost': float(work_item.get('material_cost', 0) or 0) * qty,\r\n                    'equipment_cost': float(work_item.get('equipment_cost', 0) or 0) * qty,\r\n                    'total_cost': (\r\n                        float(work_item.get('labor_cost', 0) or 0) +\r\n                        float(work_item.get('material_cost', 0) or 0) +\r\n                        float(work_item.get('equipment_cost', 0) or 0)\r\n                    ) * qty\r\n                })\r\n\r\n        df = pd.DataFrame(breakdowns)\r\n        if df.empty:\r\n            return {'labor': [], 'material': [], 'equipment': [], 'total': []}\r\n\r\n        return {\r\n            'labor': df.nlargest(top_n, 'labor_cost')[['work_item_code', 'description', 'labor_cost']].to_dict('records'),\r\n            'material': df.nlargest(top_n, 'material_cost')[['work_item_code', 'description', 'material_cost']].to_dict('records'),\r\n            'equipment': df.nlargest(top_n, 'equipment_cost')[['work_item_code', 'description', 'equipment_cost']].to_dict('records'),\r\n            'total': df.nlargest(top_n, 'total_cost')[['work_item_code', 'description', 'total_cost']].to_dict('records')\r\n        }\r\n\r\n    def analyze_productivity(self, items: List[Dict[str, Any]],\r\n                             actual_hours: Optional[Dict[str, float]] = None) -> Dict[str, Any]:\r\n        \"\"\"Analyze productivity vs planned norms.\"\"\"\r\n\r\n        if actual_hours is None:\r\n            return {'error': 'Actual hours required for productivity analysis'}\r\n\r\n        analysis = []\r\n        for item in items:\r\n            code = item.get('work_item_code', item.get('code'))\r\n            qty = item.get('quantity', 0)\r\n\r\n            if code in actual_hours and self._work_index is not None:\r\n                if code in self._work_index.index:\r\n                    work_item = self._work_index.loc[code]\r\n                    planned_hours = float(work_item.get('labor_norm', 0) or 0) * qty\r\n                    actual = actual_hours[code]\r\n\r\n                    productivity = planned_hours \u002F actual * 100 if actual > 0 else 0\r\n\r\n                    analysis.append({\r\n                        'work_item_code': code,\r\n                        'planned_hours': planned_hours,\r\n                        'actual_hours': actual,\r\n                        'productivity_percent': round(productivity, 1),\r\n                        'variance_hours': planned_hours - actual\r\n                    })\r\n\r\n        df = pd.DataFrame(analysis)\r\n        if df.empty:\r\n            return {'items': [], 'average_productivity': 0}\r\n\r\n        return {\r\n            'items': analysis,\r\n            'average_productivity': round(df['productivity_percent'].mean(), 1),\r\n            'total_variance': round(df['variance_hours'].sum(), 1),\r\n            'underperforming_items': len(df[df['productivity_percent'] \u003C 90])\r\n        }\r\n\r\n\r\nclass ResourceOptimizer:\r\n    \"\"\"Optimize resource allocation.\"\"\"\r\n\r\n    def __init__(self, analyzer: CWICRResourceAnalyzer):\r\n        self.analyzer = analyzer\r\n\r\n    def suggest_material_substitutions(self, items: List[Dict[str, Any]],\r\n                                        cost_threshold: float = 0.9) -> List[Dict]:\r\n        \"\"\"Suggest cheaper material substitutions.\"\"\"\r\n        # Placeholder for substitution logic\r\n        return []\r\n\r\n    def optimize_crew_allocation(self, labor_by_category: Dict[str, float],\r\n                                  available_crew: Dict[str, int]) -> Dict[str, Any]:\r\n        \"\"\"Optimize crew allocation across categories.\"\"\"\r\n\r\n        allocation = {}\r\n        unmet_demand = {}\r\n\r\n        for category, hours_needed in labor_by_category.items():\r\n            available = available_crew.get(category, 0)\r\n            days_needed = hours_needed \u002F 8\r\n\r\n            if available > 0:\r\n                days_available = available * 1  # 1 day per person\r\n                if days_available >= days_needed:\r\n                    allocation[category] = {\r\n                        'assigned': int(np.ceil(days_needed)),\r\n                        'remaining': available - int(np.ceil(days_needed))\r\n                    }\r\n                else:\r\n                    allocation[category] = {'assigned': available, 'remaining': 0}\r\n                    unmet_demand[category] = days_needed - days_available\r\n            else:\r\n                unmet_demand[category] = days_needed\r\n\r\n        return {\r\n            'allocation': allocation,\r\n            'unmet_demand': unmet_demand,\r\n            'fully_staffed': len(unmet_demand) == 0\r\n        }\r\n```\r\n\r\n## Quick Start\r\n\r\n```python\r\nfrom cwicr_data_loader import CWICRDataLoader\r\n\r\n# Load data\r\nloader = CWICRDataLoader()\r\ncwicr = loader.load(\"ddc_cwicr_en.parquet\")\r\n\r\n# Initialize analyzer\r\nanalyzer = CWICRResourceAnalyzer(cwicr)\r\n\r\n# Define project items\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}\r\n]\r\n\r\n# Analyze labor\r\nlabor = analyzer.analyze_labor_requirements(items)\r\nprint(f\"Total Labor Hours: {labor['total_labor_hours']}\")\r\nprint(f\"Crew Days (8hr): {labor['crew_days_8hr']}\")\r\n```\r\n\r\n## Common Use Cases\r\n\r\n### 1. Crew Planning\r\n```python\r\n# Calculate required crew size\r\nlabor = analyzer.analyze_labor_requirements(items)\r\ncrew = analyzer.calculate_crew_requirements(\r\n    labor_hours=labor['total_labor_hours'],\r\n    project_duration_days=30\r\n)\r\nprint(f\"Minimum Crew: {crew['minimum_crew_size']}\")\r\nprint(f\"Recommended Crew: {crew['recommended_crew_size']}\")\r\n```\r\n\r\n### 2. Material Procurement\r\n```python\r\nmaterials = analyzer.analyze_material_requirements(items, include_waste=True)\r\nprint(f\"Total Material Cost: ${materials['total_material_cost']:,.2f}\")\r\n```\r\n\r\n### 3. Productivity Tracking\r\n```python\r\nactual_hours = {\r\n    'CONC-001': 280,\r\n    'EXCV-002': 85,\r\n    'REBAR-003': 450\r\n}\r\nproductivity = analyzer.analyze_productivity(items, actual_hours)\r\nprint(f\"Average Productivity: {productivity['average_productivity']}%\")\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 - Resource-Based Cost Estimation\r\n",{"slug":5,"description":7,"display_name":34},"CWICR Resource Analyzer","main","e7e336ac628c3e3bd771aff1aaa469c93778f94a","skills\u002Fdatadrivenconstruction\u002Fcwicr-resource-analyzer",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":43,"prompt":53,"zipAvailable":54},[44,47,50],{"tool":45,"command":46},"npx","npx skills add kbarbel640-del\u002Fskills --skill cwicr-resource-analyzer",{"tool":48,"command":49},"bunx","bunx skills add kbarbel640-del\u002Fskills --skill cwicr-resource-analyzer",{"tool":51,"command":52},"pnpm","pnpm dlx skills add kbarbel640-del\u002Fskills --skill cwicr-resource-analyzer","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fkbarbel640-del\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fdatadrivenconstruction\u002Fcwicr-resource-analyzer\u002FSKILL.md",true,[56],{"path":57,"resourceType":58,"resourceTypeDesc":59,"sizeBytes":60,"sourceHtmlUrl":61},"_meta.json","REFERENCE","参考文档",314,"https:\u002F\u002Fgithub.com\u002Fkbarbel640-del\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fdatadrivenconstruction\u002Fcwicr-resource-analyzer\u002F_meta.json",[63,88,111,129,134,154],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":29},"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",[],[70,71,72,73,74,75,76,77,78,79,80,81,82,83,22,84,85,86,87],"crowd prompting","prompting","api","with","tokens","domain","world","prompts","operations","instructions","text","tool","system","improve","marketplace","https","content","ai agents",{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":29},"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",[],[95,72,96,24,97,98,99,100,101,102,103,104,105,106,107,108,109,77,110],"dilemm ai","arena","browser","openclaw agent","create","automation","browser automation","bot","openclaw","design","strategy","headless","compete","submit","matchmaking","use",{"skillNo":112,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":29},"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",[],[118,119,120,121,122,123,124,73,125,108,110,126,72,127,128],"arxiv paper reviews","reviews","arxiv","paper","crawler","papers","comments","fetch","read","http","via",{"skillNo":130,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":131,"categories":132,"keywords":133,"publishedAt":29},"01M6G8HQJ7N7WMY6YV7D7SSJ16","https:\u002F\u002Fgithub.com\u002Fkbarbel640-del\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fzxrys\u002Farxiv-paper-reviews\u002FSKILL.md",[],[121,120,119,118,128,123,124,73,122,108,110,125,126,72,127],{"skillNo":135,"name":136,"nameZh":6,"description":137,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":138,"categories":139,"keywords":140,"publishedAt":29},"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",[],[141,142,143,144,145,146,147,148,149,150,151,152,153],"git","summary","git summary","commits","repository","win32","status","linux","contributors","true","quick","get","branches",{"skillNo":155,"name":156,"nameZh":6,"description":157,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":158,"categories":159,"keywords":160,"publishedAt":29},"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",[],[161,162,163,164,73,165,166,35,167,126,168,169,170,171,172,85,173,174,175],"agent constitution","constitution","contracts","tree","query","base","log","check","Rules","projects","compliance","actions","state","governance","github"]