#!/usr/bin/env python3
"""
Wednesday Generator for Math Curriculum
"""
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
from math_helpers import CSS, page_multi, sec, b, bw, bl, BLUE, GREEN
from weasyprint import HTML
def generate_wednesday(week_dir: str, week_num: int, day_data: dict):
topic = day_data.get("topic", "Wednesday Practice")
activities = day_data.get("activities", [])
sections = []
for i, activity in enumerate(activities, 1):
activity_type = activity.get("type", "generic")
activity_data = activity.get("data", {})
title = activity_data.get("title", f"Activity {i}")
section_html = build_activity_section(activity_type, activity_data)
sections.append((i, title, section_html))
mid = (len(sections) + 1) // 2
page1 = ""
for i, title, html in sections[:mid]:
page1 += sec(i, title, html)
page2 = ""
for i, title, html in sections[mid:]:
page2 += sec(i, title, html, pb=True)
html_content = page_multi(week_num, "Wednesday", topic, page1, page2)
pdf_path = os.path.join(week_dir, f"Week_{week_num}_Wednesday.pdf")
HTML(string=html_content).write_pdf(pdf_path)
print(f"[ok] Week {week_num} Wednesday generated: {pdf_path}")
return day_data.get("answers", [])
def build_activity_section(activity_type: str, data: dict) -> str:
builders = {
"digit_place": build_digit_place,
"tens_ones_chart": build_tens_ones_chart,
"expanded_form": build_expanded_form,
"build_from_expanded": build_build_from_expanded,
"draw_base10": build_draw_base10,
"compare": build_compare,
"generic": build_generic,
}
builder = builders.get(activity_type, build_generic)
return builder(data)
def build_digit_place(data: dict) -> str:
"""Activity to identify if digit is in tens or ones place."""
html = '<p class="note">' + data.get("note", "Circle whether the digit is in the tens or ones place.") + '</p>'
html += '<div class="mgrid c2">'
for num, digit in data.get("items", []):
html += f'<div class="abox"><p>{num} → <span style="text-decoration:underline;">{digit}</span> is <b>tens</b> / <b>ones</b></p></div>'
html += '</div>'
return html
def build_tens_ones_chart(data: dict) -> str:
html = '<table class="tbl"><tr><th>Number</th><th>Tens</th><th>Ones</th></tr>'
for num in data.get("numbers", []):
html += f'<tr><td>{num}</td><td>{b("4em")}</td><td>{b("4em")}</td></tr>'
html += '</table>'
return html
def build_expanded_form(data: dict) -> str:
html = '<p class="note">' + data.get("note", "Write each number as tens + ones.") + '</p>'
html += '<div class="mgrid c2">'
for num in data.get("numbers", []):
html += f'<div class="abox"><p>{num} = {b("4em")} + {b("4em")}</p></div>'
html += '</div>'
return html
def build_build_from_expanded(data: dict) -> str:
html = '<p class="note">' + data.get("note", "What number does the expanded form make?") + '</p>'
html += '<div class="mgrid c3">'
for tens, ones in data.get("pairs", []):
html += f'<div class="abox" style="text-align:center"><p>{tens} + {ones} = {b("4em")}</p></div>'
html += '</div>'
return html
def build_draw_base10(data: dict) -> str:
html = '<p class="note">' + data.get("note", "Draw rods (tens) and cubes (ones).") + '</p>'
html += '<div class="mgrid c2">'
for num in data.get("numbers", []):
html += f'<div class="abox"><p style="font-size:16px; font-weight:700;">{num}</p>'
html += '<div class="draw-box" style="min-height:50px;"></div></div>'
html += '</div>'
return html
def build_compare(data: dict) -> str:
html = '<p class="note">' + data.get("note", "Write >, <, or =.") + '</p>'
html += '<div class="mgrid c2">'
for left, right in data.get("pairs", []):
html += f'<div class="abox"><p>{left} {b("4em")} {right}</p></div>'
html += '</div>'
return html
def build_generic(data: dict) -> str:
return data.get("html", "")