Update app.py
Browse files
app.py
CHANGED
|
@@ -477,192 +477,7 @@ def compute_gsd_metrics(diams: List[float], passing: List[float]) -> Dict[str, f
|
|
| 477 |
Cc = (D30 ** 2) / (D10 * D60) if (D10 > 0 and D60 > 0) else 0.0
|
| 478 |
return {"D10":D10, "D30":D30, "D60":D60, "Cu":Cu, "Cc":Cc}
|
| 479 |
|
| 480 |
-
# PDF builder (reportlab) — create professional document similar to uploaded sample
|
| 481 |
-
def build_full_geotech_pdf(site: Dict[str, Any], filename: str, include_map_image: Optional[bytes]=None, ext_refs: Optional[List[str]]=None):
|
| 482 |
-
"""
|
| 483 |
-
site: dictionary of site data
|
| 484 |
-
filename: output file path
|
| 485 |
-
include_map_image: bytes of image to embed (optional)
|
| 486 |
-
ext_refs: list of external refs (strings)
|
| 487 |
-
"""
|
| 488 |
-
styles = getSampleStyleSheet()
|
| 489 |
-
title_style = ParagraphStyle("title", parent=styles["Title"], fontSize=20, alignment=1, textColor=colors.HexColor("#FF7A00"))
|
| 490 |
-
h1 = ParagraphStyle("h1", parent=styles["Heading1"], fontSize=14, textColor=colors.HexColor("#1F4E79"), spaceAfter=6)
|
| 491 |
-
body = ParagraphStyle("body", parent=styles["BodyText"], fontSize=10.5, leading=13)
|
| 492 |
-
bullet = ParagraphStyle("bullet", parent=body, leftIndent=12, bulletIndent=6)
|
| 493 |
-
doc = SimpleDocTemplate(filename, pagesize=A4, leftMargin=18*mm, rightMargin=18*mm, topMargin=18*mm, bottomMargin=18*mm)
|
| 494 |
-
elems = []
|
| 495 |
-
# --- Title page (collect company/user info from site if present) ---
|
| 496 |
-
elems.append(Paragraph("GEOTECHNICAL INVESTIGATION REPORT", title_style))
|
| 497 |
-
elems.append(Spacer(1,12))
|
| 498 |
-
# Company / client block (if present)
|
| 499 |
-
company = site.get("Company Name", "Client / Company: Not provided")
|
| 500 |
-
contact = site.get("Company Contact", "")
|
| 501 |
-
elems.append(Paragraph(f"<b>{company}</b>", body))
|
| 502 |
-
if contact:
|
| 503 |
-
elems.append(Paragraph(contact, body))
|
| 504 |
-
elems.append(Spacer(1,12))
|
| 505 |
-
elems.append(Paragraph(f"<b>Project:</b> {site.get('Project Name','-')}", body))
|
| 506 |
-
elems.append(Paragraph(f"<b>Site:</b> {site.get('Site Name','-')}", body))
|
| 507 |
-
elems.append(Paragraph(f"<b>Date:</b> {datetime.today().strftime('%Y-%m-%d')}", body))
|
| 508 |
-
elems.append(PageBreak())
|
| 509 |
-
|
| 510 |
-
# --- Table of contents (simple listing with section titles) ---
|
| 511 |
-
elems.append(Paragraph("TABLE OF CONTENTS", h1))
|
| 512 |
-
toc_items = [
|
| 513 |
-
"1.0 Introduction",
|
| 514 |
-
"2.0 Site description and geology",
|
| 515 |
-
"3.0 Field investigation & laboratory testing",
|
| 516 |
-
"4.0 Evaluation of geotechnical properties",
|
| 517 |
-
"5.0 Provisional site classification",
|
| 518 |
-
"6.0 Recommendations",
|
| 519 |
-
"7.0 Figures & Tables",
|
| 520 |
-
"8.0 Appendices & References"
|
| 521 |
-
]
|
| 522 |
-
for i, t in enumerate(toc_items, start=1):
|
| 523 |
-
elems.append(Paragraph(f"{i}. {t}", body))
|
| 524 |
-
elems.append(PageBreak())
|
| 525 |
-
|
| 526 |
-
# --- (existing summary and subsequent sections as before) ---
|
| 527 |
-
elems.append(Paragraph("SUMMARY", h1))
|
| 528 |
-
...
|
| 529 |
-
# after '6.0 RECOMMENDATIONS' insertion, include LLM analysis if present
|
| 530 |
-
elems.append(Paragraph("7.0 LLM Analysis (GeoMate)", h1))
|
| 531 |
-
llm_text = site.get("LLM_Report_Text", None)
|
| 532 |
-
if llm_text:
|
| 533 |
-
elems.append(Paragraph(llm_text.replace("\n","\n\n"), body))
|
| 534 |
-
else:
|
| 535 |
-
elems.append(Paragraph("No LLM analysis saved for this site.", body))
|
| 536 |
-
|
| 537 |
-
# --- Figures/Tables index (simple lists from site data, if present) ---
|
| 538 |
-
elems.append(PageBreak())
|
| 539 |
-
elems.append(Paragraph("List of Tables & Figures", h1))
|
| 540 |
-
# Example: list lab samples and any GSD figure
|
| 541 |
-
if site.get("Laboratory Results"):
|
| 542 |
-
elems.append(Paragraph("Tables:", body))
|
| 543 |
-
for r in site.get("Laboratory Results", []):
|
| 544 |
-
elems.append(Paragraph(f"- Laboratory sample: {r.get('sampleId','-')}", body))
|
| 545 |
-
if site.get("GSD"):
|
| 546 |
-
elems.append(Paragraph("- GSD Curve (see section 3)", body))
|
| 547 |
-
|
| 548 |
-
# --- Appendices & References ---
|
| 549 |
-
elems.append(PageBreak())
|
| 550 |
-
elems.append(Paragraph("Appendices", h1))
|
| 551 |
-
elems.append(Paragraph("A. Test certificates and raw data (provided as CSV or appendices).", body))
|
| 552 |
-
elems.append(PageBreak())
|
| 553 |
-
elems.append(Paragraph("References", h1))
|
| 554 |
-
if ext_refs:
|
| 555 |
-
for r in ext_refs:
|
| 556 |
-
elems.append(Paragraph(f"- {r}", body))
|
| 557 |
-
else:
|
| 558 |
-
elems.append(Paragraph("- No external references provided.", body))
|
| 559 |
-
|
| 560 |
-
# Cover
|
| 561 |
-
elems.append(Paragraph("GEOTECHNICAL INVESTIGATION REPORT", title_style))
|
| 562 |
-
elems.append(Spacer(1,6))
|
| 563 |
-
elems.append(Paragraph(f"<b>Project:</b> {site.get('Project Name','-')}", body))
|
| 564 |
-
elems.append(Paragraph(f"<b>Site:</b> {site.get('Site Name','-')}", body))
|
| 565 |
-
elems.append(Paragraph(f"<b>Date:</b> {datetime.today().strftime('%Y-%m-%d')}", body))
|
| 566 |
-
elems.append(Spacer(1,8))
|
| 567 |
-
elems.append(Paragraph("<b>Prepared by:</b> GeoMate AI", body))
|
| 568 |
-
elems.append(PageBreak())
|
| 569 |
-
|
| 570 |
-
# Summary
|
| 571 |
-
elems.append(Paragraph("SUMMARY", h1))
|
| 572 |
-
summary_bullets = [
|
| 573 |
-
f"Site: {site.get('Site Name','-')}.",
|
| 574 |
-
f"General geology: {site.get('Soil Profile','Not provided')}.",
|
| 575 |
-
f"Key lab tests: {', '.join([r.get('sampleId','') for r in site.get('Laboratory Results',[])]) if site.get('Laboratory Results') else 'No lab results provided.'}",
|
| 576 |
-
f"Classification: USCS = {site.get('USCS','Not provided')}; AASHTO = {site.get('AASHTO','Not provided')}.",
|
| 577 |
-
"Primary recommendation: See Recommendations section."
|
| 578 |
-
]
|
| 579 |
-
for s in summary_bullets:
|
| 580 |
-
elems.append(Paragraph(f"• {s}", bullet))
|
| 581 |
-
elems.append(PageBreak())
|
| 582 |
-
|
| 583 |
-
# 1.0 Introduction
|
| 584 |
-
elems.append(Paragraph("1.0 INTRODUCTION", h1))
|
| 585 |
-
intro_text = site.get("Project Description", "Project description not provided.")
|
| 586 |
-
elems.append(Paragraph(intro_text, body))
|
| 587 |
-
|
| 588 |
-
# 2.0 Site description and geology
|
| 589 |
-
elems.append(Paragraph("2.0 SITE DESCRIPTION AND GEOLOGY", h1))
|
| 590 |
-
site_geo = []
|
| 591 |
-
site_geo.append(f"Topography: {site.get('Topography','Not provided')}")
|
| 592 |
-
site_geo.append(f"Drainage: {site.get('Drainage','Not provided')}")
|
| 593 |
-
site_geo.append(f"Current land use: {site.get('Current Land Use','Not provided')}")
|
| 594 |
-
site_geo.append(f"Regional geology: {site.get('Regional Geology','Not provided')}")
|
| 595 |
-
for t in site_geo:
|
| 596 |
-
elems.append(Paragraph(t, body))
|
| 597 |
-
elems.append(PageBreak())
|
| 598 |
-
|
| 599 |
-
# 3.0 Field investigation and laboratory testing
|
| 600 |
-
elems.append(Paragraph("3.0 FIELD INVESTIGATION & LABORATORY TESTING", h1))
|
| 601 |
-
if site.get("Field Investigation"):
|
| 602 |
-
for item in site["Field Investigation"]:
|
| 603 |
-
elems.append(Paragraph(f"<b>{item.get('id','Test')}</b> — depth {item.get('depth','-')}", body))
|
| 604 |
-
for layer in item.get("layers",[]):
|
| 605 |
-
elems.append(Paragraph(f"- {layer.get('depth','')} : {layer.get('description','')}", body))
|
| 606 |
-
else:
|
| 607 |
-
elems.append(Paragraph("No field investigation data supplied.", body))
|
| 608 |
-
# Lab table
|
| 609 |
-
lab_rows = site.get("Laboratory Results", [])
|
| 610 |
-
if lab_rows:
|
| 611 |
-
elems.append(Spacer(1,6))
|
| 612 |
-
elems.append(Paragraph("Laboratory Results", h1))
|
| 613 |
-
data = [["Sample ID","Material","LL","PI","Linear Shrinkage","%Clay","%Silt","%Sand","%Gravel","Expansiveness"]]
|
| 614 |
-
for r in lab_rows:
|
| 615 |
-
data.append([
|
| 616 |
-
r.get("sampleId","-"),
|
| 617 |
-
r.get("material","-"),
|
| 618 |
-
str(r.get("liquidLimit","-")),
|
| 619 |
-
str(r.get("plasticityIndex","-")),
|
| 620 |
-
str(r.get("linearShrinkage","-")),
|
| 621 |
-
str(r.get("percentClay","-")),
|
| 622 |
-
str(r.get("percentSilt","-")),
|
| 623 |
-
str(r.get("percentSand","-")),
|
| 624 |
-
str(r.get("percentGravel","-")),
|
| 625 |
-
r.get("potentialExpansiveness","-")
|
| 626 |
-
])
|
| 627 |
-
t = Table(data, repeatRows=1, colWidths=[40*mm,40*mm,18*mm,18*mm,22*mm,20*mm,20*mm,20*mm,20*mm,30*mm])
|
| 628 |
-
t.setStyle(TableStyle([
|
| 629 |
-
('BACKGROUND',(0,0),(-1,0),colors.HexColor("#1F4E79")),
|
| 630 |
-
('TEXTCOLOR',(0,0),(-1,0),colors.white),
|
| 631 |
-
('GRID',(0,0),(-1,-1),0.4,colors.grey),
|
| 632 |
-
('BOX',(0,0),(-1,-1),1,colors.HexColor("#FF7A00"))
|
| 633 |
-
]))
|
| 634 |
-
elems.append(t)
|
| 635 |
-
elems.append(PageBreak())
|
| 636 |
-
|
| 637 |
-
# 4.0 Evaluation & 5.0 Classification & 6.0 Recommendations
|
| 638 |
-
elems.append(Paragraph("4.0 EVALUATION OF GEOTECHNICAL PROPERTIES", h1))
|
| 639 |
-
elems.append(Paragraph(site.get("Evaluation","Evaluation not provided."), body))
|
| 640 |
-
elems.append(Paragraph("5.0 PROVISIONAL SITE CLASSIFICATION", h1))
|
| 641 |
-
elems.append(Paragraph(site.get("Provisional Classification","Not provided."), body))
|
| 642 |
-
elems.append(Paragraph("6.0 RECOMMENDATIONS", h1))
|
| 643 |
-
elems.append(Paragraph(site.get("Recommendations","Not provided."), body))
|
| 644 |
-
|
| 645 |
-
# Map
|
| 646 |
-
if include_map_image:
|
| 647 |
-
try:
|
| 648 |
-
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
|
| 649 |
-
tmp.write(include_map_image)
|
| 650 |
-
tmp.flush()
|
| 651 |
-
elems.append(PageBreak())
|
| 652 |
-
elems.append(Paragraph("Map Snapshot", h1))
|
| 653 |
-
elems.append(RLImage(tmp.name, width=160*mm, height=90*mm))
|
| 654 |
-
except Exception:
|
| 655 |
-
pass
|
| 656 |
|
| 657 |
-
# External refs
|
| 658 |
-
if ext_refs:
|
| 659 |
-
elems.append(PageBreak())
|
| 660 |
-
elems.append(Paragraph("References", h1))
|
| 661 |
-
for r in ext_refs:
|
| 662 |
-
elems.append(Paragraph(f"- {r}", body))
|
| 663 |
-
|
| 664 |
-
doc.build(elems)
|
| 665 |
-
return filename
|
| 666 |
|
| 667 |
# 4) Session state initialization
|
| 668 |
if "sites" not in st.session_state:
|
|
|
|
| 477 |
Cc = (D30 ** 2) / (D10 * D60) if (D10 > 0 and D60 > 0) else 0.0
|
| 478 |
return {"D10":D10, "D30":D30, "D60":D60, "Cu":Cu, "Cc":Cc}
|
| 479 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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