// "Занятия в Полоцке": Word marks the days a group spends in another town over the day's first // row; the parser keeps them as notes of the day (server/places.js). The notes of a day for one // group, shared by the server's timetable and the browser. /** * The notes on a weekday (or a date) of the group: `{place, text, subgroup}`, the subgroup null * for the whole group. The same note in every subgroup (`labels`) is the whole group's. */ export function placesOn(places, group, labels, day, date = null) { const on = (places || []) .filter((p) => p.groups.includes(group) && p.day === day && (!p.date || p.date === date)) .map((p) => ({ place: p.place, text: p.text, subgroup: p.subgroups.find((s) => s.group === group)?.label || null })); const whole = on.filter((p) => !p.subgroup); for (const p of on) if ( p.subgroup && !whole.some((w) => w.text === p.text) && labels.length && labels.every((label) => on.some((o) => o.subgroup === label && o.text === p.text)) ) whole.push({ ...p, subgroup: null }); const parts = on.filter((p) => p.subgroup && !whole.some((w) => w.text === p.text)); return [...whole, ...parts].filter( (p, i, all) => all.findIndex((o) => o.text === p.text && o.subgroup === p.subgroup) === i, ); } /** The notes for the student's subgroup; a note for their own subgroup reads as the whole day's. */ export function placesFor(list, subgroup) { return list .filter((p) => !subgroup || !p.subgroup || p.subgroup === subgroup) .map((p) => (subgroup ? { ...p, subgroup: null } : p)) .filter((p, i, all) => all.findIndex((o) => o.text === p.text && o.subgroup === p.subgroup) === i); }