Гант: красная черта крайнего срока (не позже, до); веха с крайним сроком стоит на прогнозе по предшественникам
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -355,6 +355,10 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt
|
||||
idText(hasBar ? x(t.end) : x(t.end) + 6, hasBar ? "end" : "start");
|
||||
}
|
||||
}
|
||||
if (t.deadline !== null) {
|
||||
const rx = x(t.deadline);
|
||||
out.push(`<line x1="${rx}" y1="${cy - 12}" x2="${rx}" y2="${cy + 12}" stroke="#d32f2f" stroke-width="3"><title>${esc(`Крайний срок: день ${t.deadline}`)}</title></line>`);
|
||||
}
|
||||
out.push("</g>");
|
||||
}
|
||||
}
|
||||
@@ -410,7 +414,8 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt
|
||||
`<rect x="342" y="${ly - 1}" width="22" height="10" rx="3" fill="#cfe8ff" stroke="#3b7dc4" stroke-dasharray="4 2"/><text x="370" y="${ly + 7}">срок «не позже / около»</text>` +
|
||||
`<rect x="530" y="${ly - 1}" width="22" height="10" rx="3" fill="#777" fill-opacity="0.35" stroke="#777"/><text x="558" y="${ly + 7}">повторяется</text>` +
|
||||
`<rect x="645" y="${ly - 1}" width="22" height="10" rx="3" fill="#fff" stroke="#d32f2f" stroke-width="1.6"/><text x="673" y="${ly + 7}">противоречие в сроках</text>` +
|
||||
`<circle cx="820" cy="${ly + 4}" r="4" fill="#e6a100"/><text x="830" y="${ly + 7}">есть открытый вопрос (наведите курсор)</text></g>`,
|
||||
`<circle cx="820" cy="${ly + 4}" r="4" fill="#e6a100"/><text x="830" y="${ly + 7}">есть открытый вопрос (наведите курсор)</text>` +
|
||||
`<line x1="1085" y1="${ly - 3}" x2="1085" y2="${ly + 11}" stroke="#d32f2f" stroke-width="3"/><text x="1094" y="${ly + 7}">крайний срок</text></g>`,
|
||||
);
|
||||
|
||||
const defs = `<marker id="arr" viewBox="0 0 6 6" refX="5" refY="3" markerWidth="6" markerHeight="6" orient="auto"><path d="M0 0 L6 3 L0 6 z" fill="#444"/></marker>`;
|
||||
|
||||
@@ -5,6 +5,8 @@ export interface ParsedConstraint {
|
||||
end: number | null;
|
||||
/** «день N» без «не позже / около / до»: точная дата, а не предел */
|
||||
exact: boolean;
|
||||
/** «не позже» / «до»: крайний срок (на Ганте - красная черта); «около» крайним сроком не считается */
|
||||
deadline: boolean;
|
||||
recurring: "weekly" | "daily" | null;
|
||||
}
|
||||
|
||||
@@ -16,7 +18,7 @@ const numbers = (s: string): number[] => [...s.matchAll(/(?<!\d)-\d+|\d+/g)].map
|
||||
* «день 7», «не позже дня 7», «около дня 45», «день 45–47», «день 80 → день 90», «день 120 …; день 135 …», «еженедельно …».
|
||||
*/
|
||||
export function parseConstraint(text: string | null): ParsedConstraint {
|
||||
const none: ParsedConstraint = { start: null, end: null, exact: false, recurring: null };
|
||||
const none: ParsedConstraint = { start: null, end: null, exact: false, deadline: false, recurring: null };
|
||||
if (!text) return none;
|
||||
const t = text.toLowerCase();
|
||||
if (/еженедельно/.test(t)) return { ...none, recurring: "weekly" };
|
||||
@@ -27,7 +29,8 @@ export function parseConstraint(text: string | null): ParsedConstraint {
|
||||
}
|
||||
const n = numbers(t);
|
||||
if (n.length === 0) return none;
|
||||
if (n.length === 1) return { ...none, end: n[0] ?? null, exact: /^\s*день\s+\d+\s*$/.test(t) };
|
||||
const deadline = /не\s+позже|(^|\s)до\s/.test(t);
|
||||
if (n.length === 1) return { ...none, end: n[0] ?? null, exact: /^\s*день\s+\d+\s*$/.test(t), deadline };
|
||||
return { ...none, start: n[0] ?? null, end: n.at(-1) ?? null };
|
||||
}
|
||||
|
||||
@@ -84,6 +87,8 @@ export interface Timing {
|
||||
fromConstraint: boolean;
|
||||
/** «около», «до», «не позже»: срок не точный */
|
||||
approx: boolean;
|
||||
/** крайний срок («не позже», «до»): день, где рисуется красная черта; null - крайнего срока нет */
|
||||
deadline: number | null;
|
||||
recurring: "weekly" | "daily" | null;
|
||||
}
|
||||
export interface ScheduleWarning { id: string; message: string }
|
||||
@@ -132,7 +137,11 @@ export function computeSchedule(rows: ProcessRow[]): Schedule {
|
||||
end = c.end;
|
||||
} else if (c.end !== null) {
|
||||
end = c.end;
|
||||
if (c.exact || isCheckpoint(id)) start = d !== null && !c.exact ? Math.max(0, end - d) : end;
|
||||
if (isCheckpoint(id) && c.deadline && !c.exact && row.dependsOn.length > 0) {
|
||||
// веха с крайним сроком стоит на прогнозе (по предшественникам), а сам срок рисуется красной чертой (Timing.deadline)
|
||||
start = depEnd;
|
||||
end = depEnd;
|
||||
} else if (c.exact || isCheckpoint(id)) start = d !== null && !c.exact ? Math.max(0, end - d) : end;
|
||||
else start = d !== null ? Math.max(0, end - d) : Math.min(depEnd, end);
|
||||
} else {
|
||||
start = depEnd;
|
||||
@@ -146,11 +155,13 @@ export function computeSchedule(rows: ProcessRow[]): Schedule {
|
||||
kind: c.recurring ? "recurring" : start === end ? "milestone" : "task",
|
||||
fromConstraint: c.start !== null || c.end !== null,
|
||||
approx: c.end !== null && c.start === null && !c.exact,
|
||||
deadline: c.deadline && c.end !== null && c.start === null ? c.end : null,
|
||||
recurring: c.recurring,
|
||||
};
|
||||
timings.set(id, t);
|
||||
|
||||
if (!c.recurring && t.fromConstraint && row.dependsOn.length > 0 && end < depEnd) warnings.push({ id, message: `срок (день ${end}) раньше окончания предшественников (день ${depEnd})` });
|
||||
if (t.deadline !== null && isCheckpoint(id) && row.dependsOn.length > 0 && depEnd > t.deadline) warnings.push({ id, message: `прогноз (день ${depEnd}) позже крайнего срока (день ${t.deadline})` });
|
||||
if (c.start !== null && c.end !== null && d !== null && Math.abs(end - start - d) > 7) warnings.push({ id, message: `срок ${start}→${end} (${end - start} дн.) не сходится с длительностью ${d} дн.` });
|
||||
return t;
|
||||
};
|
||||
|
||||
@@ -175,9 +175,25 @@ describe("computeSchedule", () => {
|
||||
const { timings, warnings, maxDay } = computeSchedule(rows);
|
||||
expect(timings.get("S-1")).toMatchObject({ start: 0, end: 10, kind: "task", fromConstraint: false });
|
||||
expect(timings.get("S-2")).toMatchObject({ start: 10, end: 10, kind: "milestone" });
|
||||
expect(timings.get("CP-1")).toMatchObject({ start: 7, end: 7, approx: true });
|
||||
expect(timings.get("CP-1")).toMatchObject({ start: 10, end: 10, approx: true, deadline: 7 }); // веха на прогнозе, крайний срок отдельно
|
||||
expect(maxDay).toBe(10);
|
||||
expect(warnings).toEqual([{ id: "CP-1", message: expect.stringContaining("раньше окончания предшественников") }]);
|
||||
expect(warnings).toEqual([{ id: "CP-1", message: expect.stringContaining("позже крайнего срока") }]);
|
||||
});
|
||||
|
||||
it("веха с крайним сроком стоит на прогнозе по предшественникам, а крайний срок рисуется красной чертой", () => {
|
||||
const rows = [
|
||||
row({ id: "CP-0", stage: "S", date_constraint: "день 0" }),
|
||||
row({ id: "S-1", stage: "S", depends_on: "CP-0", duration: "5d" }),
|
||||
row({ id: "CP-5", stage: "S", depends_on: "S-1", date_constraint: "не позже дня 75" }),
|
||||
row({ id: "CP-3", stage: "S", depends_on: "CP-0", date_constraint: "около дня 45" }),
|
||||
];
|
||||
const sc = computeSchedule(rows);
|
||||
expect(sc.timings.get("CP-5")).toMatchObject({ start: 5, end: 5, deadline: 75 });
|
||||
expect(sc.timings.get("CP-3")).toMatchObject({ end: 45, deadline: null }); // «около» крайним сроком не считается
|
||||
expect(sc.warnings).toEqual([]);
|
||||
const svg = renderGantt({ ...model, rows }, sc, {});
|
||||
expect(svg.split('stroke="#d32f2f" stroke-width="3"').length - 1).toBe(2); // черта у CP-5 и один знак в легенде
|
||||
expect(svg).toContain("Крайний срок: день 75");
|
||||
});
|
||||
|
||||
it("повторяющиеся шаги тянутся до конца проекта и не считаются предшественниками", () => {
|
||||
|
||||
Reference in New Issue
Block a user