Template
up
This commit is contained in:
1 parent
5788c92c6f
commit
866bed2fae
4 files changed
+31
-11
No files matched your search
@@ -20,7 +20,7 @@ rem Keep uv's cache within the authorized report-workflow folder.
|
||||
set "UV_CACHE_DIR=%CD%\Report\python_script\uv-cache"
|
||||
|
||||
echo Building the Characterization working draft with uv...
|
||||
uv run --script "Report\python_script\build_characterization_report.py" --workbook "FAT_Checklist.xlsx" --agent-data "Report\Agent_Report_Data.json" --manifest "Report\Report_Input_Manifest.json" --output "Report\Linear_Stage_Characterization_Working_Draft.pdf"
|
||||
uv run --script "Report\python_script\build_characterization_report.py" --workbook "FAT_Checklist.xlsx" --agent-data "Report\python_script\Agent_Report_Data.json" --manifest "Report\python_script\Report_Input_Manifest.json" --output "Report\Linear_Stage_Characterization_Working_Draft.pdf"
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
echo ERROR: Report build failed. Read the message above; do not use a partial PDF.
|
||||
|
||||
File renamed without changes.
File renamed without changes.
@@ -345,6 +345,26 @@ def value(name: str) -> str:
|
||||
return str(REPORT_DATA[name]) if REPORT_DATA[name] else ""
|
||||
|
||||
|
||||
def measurement_records(pdfs: list[Path]) -> list[dict[str, str]]:
|
||||
"""Extract one evidence-labelled result record per delivered analysis PDF."""
|
||||
def find(text: str, expression: str) -> str:
|
||||
match = re.search(expression, text, re.IGNORECASE)
|
||||
return match.group(1).strip() if match else ""
|
||||
def environment(text: str, code: str, unit: str) -> str:
|
||||
match = re.search(rf"{code}\s*\([^)]*\)\s*(-?[\d.]+)\s+(-?[\d.]+)\s+(-?[\d.]+)", text, re.IGNORECASE)
|
||||
return f"{match.group(2)} / {match.group(3)} / {match.group(1)} {unit} (min / mean / max)" if match else ""
|
||||
records: list[dict[str, str]] = []
|
||||
for path in pdfs:
|
||||
text = "\n".join(page.extract_text() or "" for page in PdfReader(str(path)).pages)
|
||||
test_type = "straightness" if "Straightness" in path.name else "positioning"
|
||||
records.append({"title": path.stem.replace("_", " "), "test_type": test_type, "source": path.name,
|
||||
"accuracy": find(text, r"Accuracy:\s*(A\s*=\s*[^\n]+)"),
|
||||
"repeatability": find(text, r"Repeatability:\s*(R\s*=\s*[^\n]+)"),
|
||||
"reversal": find(text, r"Max Reversal Error:\s*(B\s*=\s*[^\n]+)"),
|
||||
"temperature": environment(text, "AT", "°C"), "pressure": environment(text, "AP", "mmHg"), "humidity": environment(text, "RH", "%RH")})
|
||||
return records
|
||||
|
||||
|
||||
def p(text: str, style: ParagraphStyle) -> Paragraph:
|
||||
return Paragraph(html.escape(text).replace("\n", "<br/>"), style)
|
||||
|
||||
@@ -413,6 +433,7 @@ def build_story(report_dir: Path, workbook_inputs: WorkbookInputs) -> tuple[list
|
||||
small = ParagraphStyle("ReportSmall", parent=body, fontSize=8, leading=10)
|
||||
media_dir, measurements_dir = report_dir.parent / "Media", report_dir.parent / "Measurements"
|
||||
pdfs = sorted(path for path in measurements_dir.glob("*.pdf") if path.is_file())
|
||||
tests = measurement_records(pdfs)
|
||||
story: list[object] = []
|
||||
|
||||
story += [Spacer(1, 43 * mm), Paragraph("Overall stage image", subheading), EvidenceImage(media_dir, "I1", 130 * mm, 75 * mm), Spacer(1, 5 * mm)]
|
||||
@@ -428,22 +449,21 @@ def build_story(report_dir: Path, workbook_inputs: WorkbookInputs) -> tuple[list
|
||||
story += [grid(coordinates, [45 * mm, 115 * mm]), Spacer(1, 6 * mm)]
|
||||
hardware = [["Component", "Verified specification"], ["Stage", value("stage_model")], ["Stage identifier", value("stage_identifier")], ["Travel", value("travel_range")], ["Encoder", "; ".join(part for part in (value("encoder_manufacturer"), value("encoder_model")) if part)], ["Encoder protocol", value("encoder_interface")], ["Encoder resolution", "; ".join(part for part in (value("encoder_resolution"), value("encoder_bits")) if part)], ["Motor or actuator", "; ".join(part for part in (value("motor_manufacturer"), value("motor_model")) if part)], ["Motor type and steps", "; ".join(part for part in (value("motor_type"), value("motor_step_count")) if part)], ["Motor resistance", value("motor_resistance")], ["Drive", value("drive_model")], ["Controller and control mode", value("controller")], ["Measurement system", value("measurement_system")]]
|
||||
story += [grid(hardware, [45 * mm, 115 * mm]), Spacer(1, 7 * mm)]
|
||||
evidence = [[EvidenceImage(media_dir, "I2", 48 * mm, 45 * mm), EvidenceImage(media_dir, "I3", 48 * mm, 45 * mm), EvidenceImage(media_dir, "I4", 48 * mm, 45 * mm)], [p("Encoder", small), p("Motor", small), p("Motor coupling", small)], [EvidenceImage(media_dir, "I5", 74 * mm, 60 * mm), "", EvidenceImage(media_dir, "I6", 74 * mm, 60 * mm)], [p("General test setup - view 1", small), "", p("General test setup - view 2", small)]]
|
||||
story += [Table(evidence, colWidths=[53 * mm, 53 * mm, 53 * mm])]
|
||||
story += [PageBreak(), Paragraph("Evidence Images", heading)]
|
||||
story += [Table([[EvidenceImage(media_dir, "I2", 50 * mm, 58 * mm), EvidenceImage(media_dir, "I3", 50 * mm, 58 * mm), EvidenceImage(media_dir, "I4", 50 * mm, 58 * mm)], [p("Encoder", small), p("Motor", small), p("Coupling", small)]], colWidths=[53 * mm, 53 * mm, 53 * mm]), Spacer(1, 5 * mm), Table([[EvidenceImage(media_dir, "I5", 78 * mm, 82 * mm), EvidenceImage(media_dir, "I6", 78 * mm, 82 * mm)], [p("Measurement setup", small), p("Measurement setup 2", small)]], colWidths=[80 * mm, 80 * mm])]
|
||||
|
||||
story += [PageBreak(), Paragraph("Test Description", heading), Paragraph("Applicable Standards and Procedures", subheading)]
|
||||
story += [p(f"Applicable standard(s), edition(s), and clause(s): {value('applicable_standards')}", body), p(f"Internal test procedure and revision: {value('applicable_procedures')}", body), p(f"Measurement-system operating procedure and revision: {value('measurement_procedure')}", body)]
|
||||
for title, entries in (("Positioning Test", (("Measured positions", "positioning_travel_and_targets"), ("Speed", "positioning_speed"), ("Acceleration", "positioning_acceleration"), ("PID settings", "positioning_pid_settings"))), ("Straightness Test", (("Measured positions", "straightness_method"), ("Speed", "straightness_speed"), ("Acceleration", "straightness_acceleration"), ("PID settings", "straightness_pid_settings")))):
|
||||
story += [Paragraph(title, subheading), grid([["Parameter", "Characterization setup"]] + [[label, value(key)] for label, key in entries], [68 * mm, 92 * mm])]
|
||||
story += [Paragraph("Environmental Conditions", heading)]
|
||||
environment = [["Test", "Temperature (°C)", "Pressure", "Humidity (%)"], ["Positioning", value("positioning_temperature"), value("positioning_pressure"), value("positioning_humidity")], ["Straightness", value("straightness_temperature"), value("straightness_pressure"), value("straightness_humidity")], ["Additional test", value("additional_temperature"), value("additional_pressure"), value("additional_humidity")]]
|
||||
story += [grid(environment, [35 * mm, 40 * mm, 40 * mm, 45 * mm])]
|
||||
for test in tests:
|
||||
prefix = "positioning" if test["test_type"] == "positioning" else "straightness"
|
||||
positions = value("positioning_travel_and_targets") if prefix == "positioning" else value("straightness_method")
|
||||
story += [Paragraph(test["title"], subheading), p(f"Evidence file: {test['source']}", small), grid([["Parameter", "Characterization setup"], ["Measured positions", positions], ["Speed", value(f"{prefix}_speed")], ["Acceleration", value(f"{prefix}_acceleration")], ["PID settings", value(f"{prefix}_pid_settings")]], [68 * mm, 92 * mm]), Paragraph("Environmental Conditions (min / mean / max)", small), grid([["Temperature", "Pressure", "Humidity"], [test["temperature"], test["pressure"], test["humidity"]]], [53 * mm, 53 * mm, 54 * mm]), grid([["Accuracy", "Repeatability", "Reversal error"], [test["accuracy"], test["repeatability"], test["reversal"]]], [53 * mm, 53 * mm, 54 * mm]), Spacer(1, 5 * mm)]
|
||||
|
||||
story += [PageBreak(), Paragraph("Test Files and Data", heading), p("The following exact evidence basenames identify the delivered raw and analysis files.", body), Paragraph("Raw Files", subheading)]
|
||||
non_pdf_files = sorted(path.name for path in measurements_dir.iterdir() if path.is_file() and path.suffix.lower() != ".pdf" and path.name.lower() != "readme.md")
|
||||
story += [p("• " + name, body) for name in non_pdf_files] or [p("", body)]
|
||||
story += [Paragraph("Analysis Files", subheading)] + ([p("• " + path.name, body) for path in pdfs] or [p("", body)])
|
||||
story += [Paragraph("Characterization Results", heading), grid([["Test", "Accuracy", "Precision / repeatability", "Reversal error / backlash"], ["Positioning", value("positioning_accuracy"), value("positioning_precision_repeatability"), value("positioning_reversal_error_backlash")], ["Straightness", value("straightness_accuracy"), value("straightness_precision_repeatability"), value("straightness_reversal_error_backlash")]], [27 * mm, 44 * mm, 44 * mm, 45 * mm])]
|
||||
story += [Paragraph("Characterization Results", heading), grid([["Test", "Accuracy", "Repeatability", "Reversal error"]] + [[test["title"], test["accuracy"], test["repeatability"], test["reversal"]] for test in tests], [48 * mm, 37 * mm, 37 * mm, 38 * mm])]
|
||||
procedures = "; ".join(part for part in (value("applicable_standards"), value("applicable_procedures"), value("measurement_procedure")) if part)
|
||||
story += [Paragraph("References", heading), p(f"Stage manufacturer document, number, and revision: {value('stage_reference')}", body), p(f"Encoder, motor, drive, and controller documents and revisions: {value('component_references')}", body), p(f"Standards and procedures: {procedures}", body), p(f"Calibration certificates: {value('calibration_references')}", body)]
|
||||
story += [PageBreak(), Paragraph("Document History", heading), grid([["Date", "Version", "Description"], [value("report_date"), value("report_version"), "Initial project-specific report generated by direct Python build"]], [30 * mm, 25 * mm, 105 * mm])]
|
||||
@@ -467,8 +487,8 @@ def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--output", type=Path, default=Path("Report/Linear_Stage_Characterization_Working_Draft.pdf"))
|
||||
parser.add_argument("--workbook", type=Path, default=Path("FAT_Checklist.xlsx"), help="Authoritative checklist workbook")
|
||||
parser.add_argument("--agent-data", type=Path, default=Path("Report/Agent_Report_Data.json"), help="Source-bound agent report data")
|
||||
parser.add_argument("--manifest", type=Path, default=Path("Report/Report_Input_Manifest.json"), help="Input-source manifest")
|
||||
parser.add_argument("--agent-data", type=Path, default=Path("Report/python_script/Agent_Report_Data.json"), help="Source-bound agent report data")
|
||||
parser.add_argument("--manifest", type=Path, default=Path("Report/python_script/Report_Input_Manifest.json"), help="Input-source manifest")
|
||||
args = parser.parse_args()
|
||||
# The script is stored at Report/python_script; the repository is three
|
||||
# directory levels above it. Keep this relative to the script, not the
|
||||
|
||||
Reference in new issue
Block a user