cwicr-report-generator
Generate professional cost estimation reports from CWICR calculations. HTML, PDF, Excel outputs with charts and breakdowns.
What this skill does
# CWICR Report Generator
## Overview
Generate professional cost reports from CWICR calculations - executive summaries, detailed breakdowns, charts, and export to multiple formats.
## Python Implementation
```python
import pandas as pd
from typing import Dict, Any, List, Optional
from dataclasses import dataclass, field
from datetime import datetime
from pathlib import Path
import json
@dataclass
class ReportSection:
"""Report section content."""
title: str
content: str
chart_type: Optional[str] = None
chart_data: Optional[Dict] = None
@dataclass
class CostReport:
"""Complete cost report."""
project_name: str
generated_date: datetime
total_cost: float
currency: str
sections: List[ReportSection]
line_items: List[Dict]
summary: Dict[str, Any]
class CWICRReportGenerator:
"""Generate cost estimation reports."""
def __init__(self, project_name: str = "Project",
currency: str = "USD"):
self.project_name = project_name
self.currency = currency
self.sections: List[ReportSection] = []
self.line_items: List[Dict] = []
def add_summary(self, summary_data: Dict[str, float]):
"""Add executive summary section."""
content = f"""
<div class="summary-box">
<h3>Cost Summary</h3>
<table class="summary-table">
<tr><td>Labor</td><td class="amount">${summary_data.get('labor', 0):,.2f}</td></tr>
<tr><td>Materials</td><td class="amount">${summary_data.get('material', 0):,.2f}</td></tr>
<tr><td>Equipment</td><td class="amount">${summary_data.get('equipment', 0):,.2f}</td></tr>
<tr><td>Overhead</td><td class="amount">${summary_data.get('overhead', 0):,.2f}</td></tr>
<tr><td>Profit</td><td class="amount">${summary_data.get('profit', 0):,.2f}</td></tr>
<tr class="total"><td>TOTAL</td><td class="amount">${summary_data.get('total', 0):,.2f}</td></tr>
</table>
</div>
"""
self.sections.append(ReportSection(
title="Executive Summary",
content=content,
chart_type="pie",
chart_data={
'labels': ['Labor', 'Materials', 'Equipment', 'Overhead', 'Profit'],
'values': [
summary_data.get('labor', 0),
summary_data.get('material', 0),
summary_data.get('equipment', 0),
summary_data.get('overhead', 0),
summary_data.get('profit', 0)
]
}
))
def add_breakdown_by_category(self, breakdown: Dict[str, float]):
"""Add breakdown by category section."""
rows = ""
for category, cost in sorted(breakdown.items(), key=lambda x: -x[1]):
rows += f"<tr><td>{category}</td><td class='amount'>${cost:,.2f}</td></tr>"
content = f"""
<table class="detail-table">
<thead><tr><th>Category</th><th>Cost</th></tr></thead>
<tbody>{rows}</tbody>
</table>
"""
self.sections.append(ReportSection(
title="Cost by Category",
content=content,
chart_type="bar",
chart_data={
'labels': list(breakdown.keys()),
'values': list(breakdown.values())
}
))
def add_line_items(self, items: List[Dict]):
"""Add detailed line items."""
self.line_items = items
rows = ""
for item in items[:50]: # Limit for report
rows += f"""
<tr>
<td>{item.get('code', '')}</td>
<td>{item.get('description', '')[:50]}</td>
<td>{item.get('quantity', 0):,.2f}</td>
<td>{item.get('unit', '')}</td>
<td class="amount">${item.get('unit_price', 0):,.2f}</td>
<td class="amount">${item.get('total', 0):,.2f}</td>
</tr>
"""
content = f"""
<table class="line-items">
<thead>
<tr>
<th>Code</th>
<th>Description</th>
<th>Qty</th>
<th>Unit</th>
<th>Unit Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>{rows}</tbody>
</table>
"""
self.sections.append(ReportSection(
title="Line Items",
content=content
))
def generate_html(self) -> str:
"""Generate HTML report."""
sections_html = ""
for section in self.sections:
sections_html += f"""
<section class="report-section">
<h2>{section.title}</h2>
{section.content}
</section>
"""
html = f"""
<!DOCTYPE html>
<html>
<head>
<title>Cost Report - {self.project_name}</title>
<style>
body {{ font-family: 'Segoe UI', Arial, sans-serif; margin: 40px; background: #f5f5f5; }}
.report-container {{ max-width: 1200px; margin: 0 auto; background: white; padding: 40px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }}
h1 {{ color: #2c3e50; border-bottom: 3px solid #3498db; padding-bottom: 10px; }}
h2 {{ color: #34495e; margin-top: 30px; }}
.summary-box {{ background: #ecf0f1; padding: 20px; border-radius: 8px; }}
table {{ width: 100%; border-collapse: collapse; margin: 20px 0; }}
th, td {{ padding: 12px; text-align: left; border-bottom: 1px solid #ddd; }}
th {{ background: #3498db; color: white; }}
.amount {{ text-align: right; font-family: monospace; }}
.total {{ font-weight: bold; background: #f8f9fa; }}
.line-items td {{ font-size: 0.9em; }}
.meta {{ color: #7f8c8d; font-size: 0.9em; margin-bottom: 20px; }}
</style>
</head>
<body>
<div class="report-container">
<h1>Cost Estimation Report</h1>
<div class="meta">
<p>Project: {self.project_name}</p>
<p>Generated: {datetime.now().strftime('%Y-%m-%d %H:%M')}</p>
<p>Currency: {self.currency}</p>
</div>
{sections_html}
<footer style="margin-top: 40px; color: #95a5a6; text-align: center;">
Generated by DDC CWICR | DataDrivenConstruction.io
</footer>
</div>
</body>
</html>
"""
return html
def save_html(self, output_path: str) -> str:
"""Save HTML report to file."""
html = self.generate_html()
with open(output_path, 'w', encoding='utf-8') as f:
f.write(html)
return output_path
def generate_excel(self, output_path: str) -> str:
"""Generate Excel report."""
with pd.ExcelWriter(output_path, engine='openpyxl') as writer:
# Summary sheet
if self.sections:
summary_data = []
for section in self.sections:
if section.chart_data:
for i, label in enumerate(section.chart_data.get('labels', [])):
summary_data.append({
'Category': label,
'Amount': section.chart_data.get('values', [])[i]
})
if summary_data:
pd.DataFrame(summary_data).to_excel(
writer, sheet_name='Summary', index=False)
# Line items sheet
if self.line_items:
pd.DataFrame(self.line_items).to_excel(
writer, sheet_name='Line Items', index=False)
return output_path
def generate_json(self) -> str:
"""Generate JSON report."""
report = {
'project_name': self.project_name,
'generated_date': datetime.now().isoformat(),
'cRelated in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.