Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0b7cce5
refactor: one shared ProjectLens engine for both pages
MatthewPaver Oct 29, 2026
e9ed93b
feat(engine): read stability claims and dates from the narrative
MatthewPaver Oct 29, 2026
54ea1a0
feat: compare renamed or re-numbered schedules after confirmation
MatthewPaver Oct 29, 2026
8e26ea5
fix: handle real P6 exports (encodings, multi-project files, complete…
MatthewPaver Oct 29, 2026
aa9fcae
feat: read P6 XML, MS Project XML and Word narratives
MatthewPaver Oct 29, 2026
28f0122
feat(cli): compare and monthly batch commands
MatthewPaver Oct 29, 2026
86aa0e7
feat(gmpp): flag commentary that says unchanged when the date moved; …
MatthewPaver Oct 29, 2026
8ff837a
test: public real-case regression suite
MatthewPaver Oct 29, 2026
e80e2e6
feat(engine): more unchanged wording and text normalisation
MatthewPaver Oct 29, 2026
37d73d7
feat(engine): tell reporting periods from finish dates, read quarter …
MatthewPaver Oct 29, 2026
ffa8046
fix(engine): a stated move only explains the published date it lands on
MatthewPaver Oct 29, 2026
63c4835
feat(engine): classify narrative dates by what they describe
MatthewPaver Oct 29, 2026
bd57090
fix(engine): only end-date moves and claims count
MatthewPaver Oct 29, 2026
7bf08c8
feat: separate 'check the published date' from contradictions
MatthewPaver Oct 29, 2026
5a1b555
test: real-case accuracy benchmark with score floors
MatthewPaver Oct 30, 2026
767c6bd
test: let Node expand the test glob so npm test runs every test in an…
MatthewPaver Oct 30, 2026
9cf9c30
feat(engine): programme-level claims, published-date checks and share…
MatthewPaver Oct 30, 2026
dcfc192
fix(gmpp): load the shared engine on the GMPP page for the finding se…
MatthewPaver Oct 30, 2026
c09ac39
refactor: one narrative engine for the site and the GMPP pipeline; sc…
MatthewPaver Oct 30, 2026
83a76d7
feat: catch more 'on track but it moved' cases and show why (round 5)
MatthewPaver Oct 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
cache-dependency-path: |
requirements.txt
requirements-rag.txt
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
node-version: "22"
- name: Install test and RAG dependencies
run: make install-rag
- name: Run deterministic and RAG tests
Expand Down
62 changes: 62 additions & 0 deletions Processing/gmpp_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import json
import math
import re
import subprocess
from collections import Counter, defaultdict
from dataclasses import dataclass
from datetime import datetime
Expand Down Expand Up @@ -344,6 +345,57 @@ def day_delta(current: str | None, previous: str | None) -> int | None:
return (datetime.fromisoformat(current) - datetime.fromisoformat(previous)).days


def _detect_claims_batch(inputs: list[dict[str, Any]]) -> list[dict[str, Any]]:
"""Use the browser/CLI engine, with one Node process for the whole dataset."""
script = """
const fs = require("node:fs");
const engine = require(process.argv[1]);
const inputs = JSON.parse(fs.readFileSync(0, "utf8"));
process.stdout.write(JSON.stringify(inputs.map(({ text, ...options }) =>
engine.detectScheduleClaims(text, options))));
"""
result = subprocess.run(
["node", "-e", script, str(ROOT / "docs/engine/projectlens-engine.js")],
input=json.dumps(inputs), capture_output=True, text=True, check=True, timeout=60,
)
return json.loads(result.stdout)


def detect_schedule_claims(
text: str,
current_finish: str | None,
previous_finish: str | None,
) -> dict[str, Any]:
"""Evaluate a single narrative through the shared schedule engine."""
return _detect_claims_batch([{
"text": text, "currentFinish": current_finish, "previousFinish": previous_finish,
}])[0]


def annotate_history_claims(histories: list[list[dict[str, Any]]]) -> None:
records = []
inputs = []
for history in histories:
for index, record in enumerate(history):
previous = history[index - 1] if index else None
records.append(record)
inputs.append({
"text": record.get("scheduleNarrative") or "",
"currentFinish": record.get("endDate"),
"previousFinish": previous.get("endDate") if previous else None,
})
if not inputs:
return
for record, claims in zip(records, _detect_claims_batch(inputs), strict=True):
record["narrativeSaysUnchangedButMoved"] = claims["contradiction"] is not None
record["narrativeExcerpt"] = record.get("scheduleNarrative") or ""
record["narrativeClaimKind"] = (
claims["contradiction"]["kind"] if claims["contradiction"] else None
)
# Quieter "check the published date" note when the finish did not move.
record["publishedDateCheck"] = claims.get("publishedDateCheck")


def rating_delta(current: str | None, previous: str | None) -> int | None:
current_key = current.upper() if current else None
previous_key = previous.upper() if previous else None
Expand Down Expand Up @@ -398,6 +450,7 @@ def build_payload(records: list[dict[str, Any]]) -> dict[str, Any]:
by_id[record["id"]].append(record)
for history in by_id.values():
history.sort(key=lambda item: item["year"])
annotate_history_claims(list(by_id.values()))

projects = []
transitions = Counter()
Expand All @@ -415,6 +468,12 @@ def build_payload(records: list[dict[str, Any]]) -> dict[str, Any]:
transitions[status] += 1
theme_counts.update(current["themes"])
score, reasons = attention_score(current, previous)
if current.get("narrativeSaysUnchangedButMoved"):
reasons = [
"Published commentary says the end date is unchanged while the published date moved",
*reasons,
][:4]
score = min(100, score + 12)
projects.append(
{
**current,
Expand All @@ -427,6 +486,9 @@ def build_payload(records: list[dict[str, Any]]) -> dict[str, Any]:
),
"attentionScore": score,
"attentionReasons": reasons,
"narrativeSaysUnchangedButMoved": bool(current.get("narrativeSaysUnchangedButMoved")),
"narrativeExcerpt": current.get("narrativeExcerpt") or current.get("scheduleNarrative") or "",
"publishedDateCheck": current.get("publishedDateCheck"),
}
)

Expand Down
131 changes: 131 additions & 0 deletions Processing/tests/test_claim_flag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
"""GMPP narrative claim flag: unchanged wording while the published end date moved."""

from pathlib import Path

from Processing.gmpp_pipeline import SOURCES, build_payload, detect_schedule_claims, load_year


ROOT = Path(__file__).resolve().parents[2]
RAW = ROOT / "Data" / "public" / "raw"


def test_capability_targets_do_not_claim_programme_closure_is_unchanged():
for capability in [
"initial operating capability", "initial operational capability",
"full operating capability", "full operational capability",
]:
result = detect_schedule_claims(
f"The programme remains on track to deliver its {capability} in October 2028.",
"2030-04-30", "2032-04-30",
)
assert result["stable"] == []
assert result["contradiction"] is None
assert result["publishedDateCheck"] is None


def public_payload():
records = []
for year, source in SOURCES.items():
records.extend(load_year(year, RAW / source["file"]))
return build_payload(records)


def test_wedgetail_and_istar_2025_26_are_flagged_but_2021_22_is_not():
payload = public_payload()
by_id = {project["id"]: project for project in payload["projects"]}

wedgetail = next(p for p in payload["projects"] if "WEDGETAIL" in p["name"].upper())
istar = next(p for p in payload["projects"] if "ISTAR" in p["name"].upper())
assert wedgetail["narrativeSaysUnchangedButMoved"] is True
assert istar["narrativeSaysUnchangedButMoved"] is True
assert wedgetail["narrativeExcerpt"]
assert istar["narrativeExcerpt"]

# 2021→2022 Wedgetail stated the move ("increased from… Correction of published position").
history = wedgetail["history"]
pair_2022 = next(item for item in history if item["year"] == 2022)
assert pair_2022["narrativeSaysUnchangedButMoved"] is False


def test_detect_schedule_claims_matches_tuning_cases():
istar = detect_schedule_claims(
"Compared to financial year 24/25-Q4, the programme's end-date at 25/26-Q4 remained the same at 31/12/2027.",
"2033-05-02",
"2027-12-31",
)
assert istar["contradiction"] is not None

correction = detect_schedule_claims(
"Compared to 2021-Q4, the project end-date increased from 30 June 26 to 1 June 27 This is primarily due to the following factors: Correction of published position in March 21.",
"2027-06-01",
"2026-06-30",
)
assert correction["contradiction"] is None


def test_stated_move_must_land_on_published_finish():
# Round 2 N3: same answers as the JS engine for a mistargeted move and a direction-only one.
sentence = "the end date changed from 01/04/2027 to 30/09/2027 due to supplier delays"
miss = detect_schedule_claims(sentence, "2028-03-31", "2027-04-01")
assert miss["contradiction"] is not None
assert miss["contradiction"]["kind"] == "date-mismatch"

near = detect_schedule_claims(sentence, "2027-10-05", "2027-04-01")
assert near["contradiction"] is None

extended = "the end date was extended following re-planning"
later = detect_schedule_claims(extended, "2028-01-01", "2027-10-03")
assert later["contradiction"] is None

earlier = detect_schedule_claims(extended, "2027-07-05", "2027-10-03")
assert earlier["contradiction"] is not None
assert earlier["contradiction"]["kind"] == "date-mismatch"


def test_end_date_scope_for_moves_and_stability():
# Round 3 D2: contract-start moves and "unaffected" end-date claims mirror the JS engine.
narrative = (
"The contract start date has moved back by four weeks. "
"The overall programme end date is unaffected."
)
stable = detect_schedule_claims(narrative, "2028-06-30", "2028-06-30")
assert stable["contradiction"] is None

moved = detect_schedule_claims(narrative, "2028-10-28", "2028-06-30")
assert moved["contradiction"] is not None
assert moved["contradiction"]["kind"] == "says-unchanged"

lengthened = detect_schedule_claims(
"The end date has lengthened by 200 days.",
"2027-07-19",
"2026-12-31",
)
assert lengthened["contradiction"] is None


def test_round4_programme_stability():
for sentence in [
"The programme remains on track.", "Compared to last year, the programme remains on track.",
"The project delivery remains on schedule.", "Delivery is on schedule.",
"The project is progressing to plan.", "The programme remains on course.",
"The project is on target to complete.",
]:
result = detect_schedule_claims(sentence, "2026-12-27", "2026-06-30")
assert result["contradiction"]["kind"] == "says-unchanged"
for sentence in [
"Phase 2 remains on track; the programme end date has moved to 31/03/2027.",
"The programme is not on track.", "The procurement is on schedule.",
"The programme's Phase 2 remains on track.",
"Milestones remain on track: Phase 1 March 2027, Phase 2 June 2027.",
]:
assert detect_schedule_claims(sentence, "2027-03-31", "2026-06-30")["contradiction"] is None
assert detect_schedule_claims("Delivery is on schedule.", "2026-06-30", "2026-06-30")["contradiction"] is None


def test_stability_keeps_the_nearest_subject():
for sentence in [
"Phase 2 completion remains on track.",
"The programme's procurement completion is on schedule.",
"The contract end date is unchanged.",
]:
assert detect_schedule_claims(sentence, "2027-03-31", "2026-06-30")["contradiction"] is None
Loading
Loading