mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
Five more of the features other kanban apps call AI, done with plain code (docs/Features/General/Assistants/Assistants.md): - Board menu -> Summary: what each person did in the last day or week - done, moved, added, commented - and what they have overdue, from the activities and History; Copy as text gives Markdown with card links. - Board menu -> Since your last visit (N): what others changed since the visit before this one, by card. The visit is kept in profile.boardVisits, at most 500 boards. - At risk: a weighted score of overdue, due soon with little done, blocked, idle in a middle list and sent back; a triangle on the minicard and the reasons in the opened card. - Suggested members in the Members and Assignees popups, from who handles the same labels, list and swimlane. - Forecast done date: the 50th and 85th percentile of the board's cycle times, counting only the cards that took at least as long as this one has been open. The server sends the times once per board, numbers only. Summary and Since your last visit are features of Admin Panel / Settings / Visibility / Features; At risk, Suggested members and Forecast are rows of Board Settings / Card and of the Admin Panel's Card fields. Every server answer applies the board's read rules and the assigned-only role. Translated in every language. The guards of the earlier helpers are brought up to date as well: the date words of models/lib/titleDueDate.js are a reviewed RegExp site, server/methods/ruleSuggestions.js is a board-admin-only path, the Rules page's list branch carries the suggestions, and Tigre's new strings use its own word for a board. Thanks to xet7 !
71 lines
2.5 KiB
JavaScript
71 lines
2.5 KiB
JavaScript
'use strict';
|
|
|
|
// Forecast done date for one card (docs/Features/Cards/Dates/Forecast.md):
|
|
// when it is likely to be done, from how long the board's finished cards
|
|
// took - ClickUp's and Jira's AI estimate, here two percentiles. The
|
|
// board-wide forecasts are the Monte Carlo view (models/lib/flowAnalytics.js).
|
|
//
|
|
// Pure, no Meteor. Tests: tests/cardForecast.test.cjs.
|
|
|
|
const { quantile } = require('./flowAnalytics');
|
|
|
|
const DAY = 24 * 60 * 60 * 1000;
|
|
const WINDOW_DAYS = 180;
|
|
const MIN_SAMPLES = 5;
|
|
|
|
const time = value => {
|
|
const t = value ? new Date(value).getTime() : NaN;
|
|
return Number.isNaN(t) ? null : t;
|
|
};
|
|
|
|
function startOf(card) {
|
|
return time(card.startAt) || time(card.createdAt);
|
|
}
|
|
|
|
// When a finished card was finished: its end date, when it was archived, or
|
|
// when it was last changed if it was only marked complete.
|
|
function endOf(card) {
|
|
if (time(card.endAt)) return time(card.endAt);
|
|
if (card.archived && time(card.archivedAt)) return time(card.archivedAt);
|
|
if (card.dueComplete === true) return time(card.modifiedAt) || time(card.dateLastActivity);
|
|
return null;
|
|
}
|
|
|
|
function isOpen(card) {
|
|
return !!card && !card.archived && card.dueComplete !== true && !card.endAt;
|
|
}
|
|
|
|
// The cycle times, in milliseconds, of the cards finished in the window.
|
|
function cycleTimes(cards, now = Date.now(), windowDays = WINDOW_DAYS) {
|
|
const since = now - windowDays * DAY;
|
|
const out = [];
|
|
for (const card of cards || []) {
|
|
if (!card || isOpen(card)) continue;
|
|
const start = startOf(card);
|
|
const end = endOf(card);
|
|
if (start === null || end === null || end < since || end < start) continue;
|
|
out.push(end - start);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
// { enough: false, samples } or { enough: true, samples, p50, p85 } as Dates.
|
|
// Only the finished cards that took at least as long as this one has already
|
|
// been open count: a card open ten days cannot be done in three.
|
|
function forecastCard(card, times, now = Date.now()) {
|
|
if (!isOpen(card)) return null;
|
|
const start = startOf(card);
|
|
if (start === null) return null;
|
|
const elapsed = Math.max(0, now - start);
|
|
const usable = (times || []).filter(t => t >= elapsed);
|
|
if (usable.length < MIN_SAMPLES) return { enough: false, samples: usable.length };
|
|
return {
|
|
enough: true,
|
|
samples: usable.length,
|
|
p50: new Date(start + quantile(usable, 0.5)),
|
|
p85: new Date(start + quantile(usable, 0.85)),
|
|
};
|
|
}
|
|
|
|
module.exports = { WINDOW_DAYS, MIN_SAMPLES, startOf, endOf, isOpen, cycleTimes, forecastCard };
|