forked from bkinnightskytw/report_skill_expm
140 lines
4.0 KiB
Python
140 lines
4.0 KiB
Python
"""
|
|
Example: Generate Weekly Report
|
|
|
|
This script demonstrates how to use the week_report_gen skill
|
|
to generate a weekly report from a cost report Excel file.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
# Add the skill directory to the path
|
|
skill_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'skills', 'week_report_gen')
|
|
sys.path.insert(0, skill_path)
|
|
|
|
from generate_report import generate_weekly_report
|
|
|
|
|
|
def main():
|
|
"""
|
|
Example: Generate a weekly report from the sample cost report.
|
|
"""
|
|
print("=" * 70)
|
|
print("Weekly Report Generator - Example")
|
|
print("=" * 70)
|
|
print()
|
|
|
|
# Define paths
|
|
base_dir = os.path.dirname(os.path.abspath(__file__))
|
|
skill_dir = os.path.join(base_dir, 'skills', 'week_report_gen')
|
|
|
|
input_file = os.path.join(
|
|
skill_dir,
|
|
'references',
|
|
'cost-report-2026-01-16-T-16-22-3620260116-7-1r1n4h.xls'
|
|
)
|
|
|
|
output_file = os.path.join(
|
|
skill_dir,
|
|
'references',
|
|
'項目週報-示例輸出-20260116.xlsx'
|
|
)
|
|
|
|
template_file = os.path.join(
|
|
skill_dir,
|
|
'references',
|
|
'項目週報-模板.xlsx'
|
|
)
|
|
|
|
# Verify input file exists
|
|
if not os.path.exists(input_file):
|
|
print(f"❌ Error: Input file not found: {input_file}")
|
|
return 1
|
|
|
|
print(f"📁 Input: {os.path.basename(input_file)}")
|
|
print(f"📁 Output: {os.path.basename(output_file)}")
|
|
print(f"📋 Template: {os.path.basename(template_file)}")
|
|
print()
|
|
print("-" * 70)
|
|
print()
|
|
|
|
try:
|
|
# Generate the report
|
|
output_path, summary_data = generate_weekly_report(
|
|
input_file=input_file,
|
|
output_file=output_file,
|
|
template_file=template_file if os.path.exists(template_file) else None,
|
|
team_name="智能控制組"
|
|
)
|
|
|
|
# Display results
|
|
print()
|
|
print("=" * 70)
|
|
print("📊 REPORT SUMMARY")
|
|
print("=" * 70)
|
|
print()
|
|
|
|
total_hours = summary_data['工時'].sum()
|
|
total_projects = len(summary_data)
|
|
|
|
print(f"Total Projects: {total_projects}")
|
|
print(f"Total Work Hours: {total_hours}")
|
|
print()
|
|
print("-" * 70)
|
|
print()
|
|
|
|
# Display each project
|
|
for idx, row in summary_data.iterrows():
|
|
print(f"🔹 {row['專案名稱']}")
|
|
print(f" Team: {row['參與人員']}")
|
|
print(f" Hours: {row['工時']}")
|
|
|
|
if row['本周主要進展'] and str(row['本周主要進展']) != 'nan':
|
|
progress_lines = str(row['本周主要進展']).split('\n')
|
|
print(f" Progress:")
|
|
for line in progress_lines:
|
|
if line.strip():
|
|
print(f" • {line.strip()}")
|
|
print()
|
|
|
|
print("=" * 70)
|
|
print("✅ SUCCESS!")
|
|
print("=" * 70)
|
|
print()
|
|
print(f"Report saved to:")
|
|
print(f" {output_path}")
|
|
print()
|
|
print("📝 Next steps:")
|
|
print(" 1. Open the generated Excel file")
|
|
print(" 2. Review and edit the '本周主要進展' (progress) entries")
|
|
print(" 3. Fill in the '進度' (progress percentage) for each project")
|
|
print(" 4. Add '交付物' (deliverables) if any")
|
|
print(" 5. Indicate '代碼上傳' (code upload) status (Y/N)")
|
|
print(" 6. Fill in '下周計畫' (next week's plan)")
|
|
print()
|
|
|
|
return 0
|
|
|
|
except Exception as e:
|
|
print()
|
|
print("=" * 70)
|
|
print("❌ ERROR")
|
|
print("=" * 70)
|
|
print()
|
|
print(f"An error occurred while generating the report:")
|
|
print(f" {str(e)}")
|
|
print()
|
|
|
|
import traceback
|
|
print("Detailed error information:")
|
|
print("-" * 70)
|
|
traceback.print_exc()
|
|
print("-" * 70)
|
|
print()
|
|
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|