mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
feat: combining subjects, percentage bands and advanced analytics custoisation
This commit is contained in:
1 parent
6f4728aa18
commit
80287caacb
12 files changed
+959
-414
No files matched your search
@@ -20,10 +20,6 @@
|
|||||||
showNavigation?: boolean;
|
showNavigation?: boolean;
|
||||||
listMode?: ThemeListMode;
|
listMode?: ThemeListMode;
|
||||||
}>();
|
}>();
|
||||||
let isDragging = $state(false);
|
|
||||||
let dragDepth = $state(0);
|
|
||||||
let tempTheme = $state(null);
|
|
||||||
let fileInput = $state<HTMLInputElement | null>(null);
|
|
||||||
let favoriteStatus = $state<Record<string, boolean>>({});
|
let favoriteStatus = $state<Record<string, boolean>>({});
|
||||||
let cloudLoggedIn = $state(cloudAuth.state.isLoggedIn);
|
let cloudLoggedIn = $state(cloudAuth.state.isLoggedIn);
|
||||||
let prevLoggedIn = $state(false);
|
let prevLoggedIn = $state(false);
|
||||||
@@ -78,70 +74,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const allowsFileImport = $derived(listMode === 'custom');
|
|
||||||
|
|
||||||
const handleDragEnter = (e: DragEvent) => {
|
|
||||||
if (!allowsFileImport) return;
|
|
||||||
e.preventDefault();
|
|
||||||
dragDepth += 1;
|
|
||||||
isDragging = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleDragOver = (e: DragEvent) => {
|
|
||||||
if (!allowsFileImport) return;
|
|
||||||
e.preventDefault();
|
|
||||||
if (e.dataTransfer) e.dataTransfer.dropEffect = 'copy';
|
|
||||||
isDragging = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleDragLeave = (e: DragEvent) => {
|
|
||||||
if (!allowsFileImport) return;
|
|
||||||
e.preventDefault();
|
|
||||||
dragDepth -= 1;
|
|
||||||
if (dragDepth <= 0) {
|
|
||||||
dragDepth = 0;
|
|
||||||
isDragging = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function importThemeFromFile(file: File) {
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.onload = async (event: ProgressEvent<FileReader>) => {
|
|
||||||
try {
|
|
||||||
const result = JSON.parse(event.target?.result as string);
|
|
||||||
tempTheme = result;
|
|
||||||
await themeManager.installTheme(result, { fromStore: false });
|
|
||||||
await fetchThemes();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error parsing file:', error);
|
|
||||||
alert('Error parsing file. Please upload a valid JSON theme file.');
|
|
||||||
}
|
|
||||||
tempTheme = null;
|
|
||||||
};
|
|
||||||
reader.readAsText(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleDrop = async (e: DragEvent) => {
|
|
||||||
if (!allowsFileImport) return;
|
|
||||||
e.preventDefault();
|
|
||||||
dragDepth = 0;
|
|
||||||
isDragging = false;
|
|
||||||
const file = e.dataTransfer?.files[0];
|
|
||||||
if (!file) return;
|
|
||||||
await importThemeFromFile(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleFileInputChange = async (e: Event) => {
|
|
||||||
const input = e.currentTarget as HTMLInputElement;
|
|
||||||
const file = input.files?.[0];
|
|
||||||
if (file) await importThemeFromFile(file);
|
|
||||||
input.value = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
const triggerFileUpload = () => {
|
|
||||||
fileInput?.click();
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetchThemes = async () => {
|
const fetchThemes = async () => {
|
||||||
themes = {
|
themes = {
|
||||||
themes: await themeManager.getAvailableThemes(),
|
themes: await themeManager.getAvailableThemes(),
|
||||||
@@ -245,49 +177,8 @@
|
|||||||
class="relative mb-1 w-full {useTwoColumnLayout ? '' : 'max-w-lg mx-auto'}"
|
class="relative mb-1 w-full {useTwoColumnLayout ? '' : 'max-w-lg mx-auto'}"
|
||||||
role="list"
|
role="list"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
ondragenter={handleDragEnter}
|
|
||||||
ondragover={handleDragOver}
|
|
||||||
ondragleave={handleDragLeave}
|
|
||||||
ondrop={handleDrop}
|
|
||||||
>
|
>
|
||||||
{#if allowsFileImport}
|
|
||||||
<input
|
|
||||||
bind:this={fileInput}
|
|
||||||
type="file"
|
|
||||||
accept=".json,application/json"
|
|
||||||
class="hidden"
|
|
||||||
onchange={(e) => void handleFileInputChange(e)}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if allowsFileImport && isDragging}
|
|
||||||
<div class="absolute inset-0 z-50 flex items-center justify-center p-3 pointer-events-none">
|
|
||||||
<div class="flex h-full w-full flex-col items-center justify-center gap-3 rounded-xl border-4 border-dashed border-zinc-300 bg-white/95 px-6 text-center shadow-xl dark:border-zinc-600 dark:bg-zinc-900/95 dark:text-white">
|
|
||||||
<svg height="48" width="48" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
||||||
<g fill="currentColor">
|
|
||||||
<path d="M44,31a1,1,0,0,0-1,1v8a3,3,0,0,1-3,3H8a3,3,0,0,1-3-3V32a1,1,0,0,0-2,0v8a5.006,5.006,0,0,0,5,5H40a5.006,5.006,0,0,0,5-5V32A1,1,0,0,0,44,31Z" fill="currentColor"/>
|
|
||||||
<path d="M23.2,33.6a1,1,0,0,0,1.6,0l9-12A1,1,0,0,0,33,20H26V5a2,2,0,0,0-4,0V20H15a1,1,0,0,0-.8,1.6Z" fill="currentColor"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
<span class="text-lg font-medium">Drop theme file to import</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div class="{useTwoColumnLayout ? 'grid grid-cols-2 gap-3' : 'flex flex-col gap-2 px-2'}">
|
<div class="{useTwoColumnLayout ? 'grid grid-cols-2 gap-3' : 'flex flex-col gap-2 px-2'}">
|
||||||
{#if allowsFileImport}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onclick={triggerFileUpload}
|
|
||||||
class="flex aspect-[10/1] w-full items-center justify-center gap-3 rounded-xl border-2 border-dashed border-zinc-300 bg-zinc-50 px-4 text-center transition hover:border-zinc-400 hover:bg-zinc-100 dark:border-zinc-600 dark:bg-zinc-900/40 dark:hover:border-zinc-500 dark:hover:bg-zinc-900 {useTwoColumnLayout ? 'col-span-2' : ''}"
|
|
||||||
>
|
|
||||||
<span class="text-xl font-IconFamily text-zinc-500 dark:text-zinc-400" aria-hidden="true"></span>
|
|
||||||
<div class="text-left">
|
|
||||||
<span class="block text-sm font-medium text-zinc-700 dark:text-zinc-200">Drag and drop theme files here</span>
|
|
||||||
<span class="block text-xs text-zinc-500 dark:text-zinc-400">or click to upload</span>
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
{#if themes}
|
{#if themes}
|
||||||
{#each visibleThemes as theme (theme.id)}
|
{#each visibleThemes as theme (theme.id)}
|
||||||
<button
|
<button
|
||||||
@@ -382,24 +273,34 @@
|
|||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if tempTheme}
|
{#if themes && visibleThemes.length === 0}
|
||||||
<div class="flex justify-center place-items-center w-full bg-gray-200 rounded-xl animate-pulse dark:bg-zinc-700/50 aspect-theme {useTwoColumnLayout ? 'col-span-2' : ''}">
|
|
||||||
<svg class="w-5 h-5 text-white animate-spin" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
|
||||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
|
||||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if themes && visibleThemes.length === 0 && !tempTheme}
|
|
||||||
<div class="flex min-h-56 flex-col items-center justify-center px-4 py-10 text-center {useTwoColumnLayout ? 'col-span-2' : ''}">
|
<div class="flex min-h-56 flex-col items-center justify-center px-4 py-10 text-center {useTwoColumnLayout ? 'col-span-2' : ''}">
|
||||||
{#if listMode === 'custom'}
|
{#if listMode === 'custom'}
|
||||||
<h3 class="text-xl font-semibold text-zinc-900 dark:text-white" style="text-wrap: balance">
|
<h3 class="text-xl font-semibold text-zinc-900 dark:text-white" style="text-wrap: balance">
|
||||||
No custom themes yet
|
No custom themes yet
|
||||||
</h3>
|
</h3>
|
||||||
<p class="mt-2 max-w-md text-base text-zinc-500 dark:text-zinc-400" style="text-wrap: pretty">
|
<p class="mt-2 max-w-md text-base text-zinc-500 dark:text-zinc-400" style="text-wrap: pretty">
|
||||||
Drag and drop a theme file above, create your own theme, or follow our guide to get started.
|
Create a theme with the builder, or follow our guide to get started.
|
||||||
</p>
|
</p>
|
||||||
|
<div class="mt-6 grid w-full max-w-md grid-cols-1 gap-2 sm:grid-cols-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onclick={() => void openThemeCreator()}
|
||||||
|
class="flex h-11 items-center justify-center gap-2 rounded-lg bg-zinc-200 px-4 font-medium text-zinc-900 transition-[background-color,color,transform] duration-150 hover:bg-zinc-300 active:scale-[0.96] focus:outline-none focus:ring-2 focus:ring-zinc-400 dark:bg-zinc-700 dark:text-white dark:hover:bg-zinc-600"
|
||||||
|
>
|
||||||
|
<span class="font-IconFamily text-lg" aria-hidden="true"></span>
|
||||||
|
Create a theme
|
||||||
|
</button>
|
||||||
|
<a
|
||||||
|
href="https://docs.betterseqta.org/theme-creation/"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
class="flex h-11 items-center justify-center gap-2 rounded-lg bg-zinc-200 px-4 font-medium text-zinc-900 transition-[background-color,color,transform] duration-150 hover:bg-zinc-300 active:scale-[0.96] focus:outline-none focus:ring-2 focus:ring-zinc-400 dark:bg-zinc-700 dark:text-white dark:hover:bg-zinc-600"
|
||||||
|
>
|
||||||
|
<span class="font-IconFamily text-lg" aria-hidden="true">{'\uecb3'}</span>
|
||||||
|
View docs
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
{:else if listMode === 'downloaded'}
|
{:else if listMode === 'downloaded'}
|
||||||
<h3 class="text-xl font-semibold text-zinc-900 dark:text-white" style="text-wrap: balance">
|
<h3 class="text-xl font-semibold text-zinc-900 dark:text-white" style="text-wrap: balance">
|
||||||
No downloaded themes
|
No downloaded themes
|
||||||
|
|||||||
@@ -60,9 +60,13 @@
|
|||||||
|
|
||||||
function gradeDisplay(a: Assessment) {
|
function gradeDisplay(a: Assessment) {
|
||||||
if (a.finalGrade !== undefined) {
|
if (a.finalGrade !== undefined) {
|
||||||
return a.letterGrade
|
const base = a.letterGrade
|
||||||
? `${a.finalGrade}% (${a.letterGrade})`
|
? `${a.finalGrade}% (${a.letterGrade})`
|
||||||
: `${a.finalGrade}%`;
|
: `${a.finalGrade}%`;
|
||||||
|
if (a.gradeSource === "criteriaRollup") return `${base} · est. from parts`;
|
||||||
|
if (a.gradeSource === "customBand") return `${base} · custom band`;
|
||||||
|
if (a.gradeSource === "defaultLetter") return `${base} · approx.`;
|
||||||
|
return base;
|
||||||
}
|
}
|
||||||
return a.letterGrade ?? "—";
|
return a.letterGrade ?? "—";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,253 +1,254 @@
|
|||||||
<script lang="ts">␍
|
<script lang="ts">
|
||||||
import { fade, scale } from "svelte/transition";␍
|
import { fade, scale } from "svelte/transition";
|
||||||
import type { AnalyticsClassGroup, AnalyticsClassOption } from "./types";␍
|
import type { AnalyticsClassGroup, AnalyticsClassOption } from "./types";
|
||||||
import { animationsEnabled } from "@/seqta/utils/performanceMode";␍
|
import { animationsEnabled } from "@/seqta/utils/performanceMode";
|
||||||
␍
|
|
||||||
type Props = {␍
|
type Props = {
|
||||||
classOptions: AnalyticsClassOption[];␍
|
classOptions: AnalyticsClassOption[];
|
||||||
groups: AnalyticsClassGroup[];␍
|
groups: AnalyticsClassGroup[];
|
||||||
activeGroupId: string | null;␍
|
activeGroupId: string | null;
|
||||||
onSelectGroup: (group: AnalyticsClassGroup | null) => void;␍
|
onSelectGroup: (group: AnalyticsClassGroup | null) => void;
|
||||||
onSaveGroups: (groups: AnalyticsClassGroup[]) => void;␍
|
onSaveGroups: (groups: AnalyticsClassGroup[]) => void;
|
||||||
};␍
|
};
|
||||||
␍
|
|
||||||
let { classOptions, groups, activeGroupId, onSelectGroup, onSaveGroups }: Props = $props();␍
|
let { classOptions, groups, activeGroupId, onSelectGroup, onSaveGroups }: Props = $props();
|
||||||
␍
|
|
||||||
let showEditor = $state(false);␍
|
let showEditor = $state(false);
|
||||||
let groupName = $state("");␍
|
let groupName = $state("");
|
||||||
let draftClassKeys = $state<string[]>([]);␍
|
let draftClassKeys = $state<string[]>([]);
|
||||||
let editingId = $state<string | null>(null);␍
|
let editingId = $state<string | null>(null);
|
||||||
␍
|
|
||||||
const fadeDuration = $derived(animationsEnabled() ? 180 : 0);␍
|
const fadeDuration = $derived(animationsEnabled() ? 180 : 0);
|
||||||
const optionByKey = $derived(new Map(classOptions.map((option) => [option.key, option])));␍
|
const optionByKey = $derived(new Map(classOptions.map((option) => [option.key, option])));
|
||||||
␍
|
|
||||||
function classLabel(key: string): string {␍
|
function classLabel(key: string): string {
|
||||||
const option = optionByKey.get(key);␍
|
const option = optionByKey.get(key);
|
||||||
return option ? `${option.title} (${option.yearLabel})` : key;␍
|
return option ? `${option.title} (${option.yearLabel})` : key;
|
||||||
}␍
|
}
|
||||||
␍
|
|
||||||
function defaultGroupName(keys: string[]): string {␍
|
function defaultGroupName(keys: string[]): string {
|
||||||
if (!keys.length) return "";␍
|
if (!keys.length) return "";
|
||||||
const labels = keys.map(classLabel);␍
|
const labels = keys.map(classLabel);
|
||||||
if (labels.length === 1) return labels[0]!;␍
|
if (labels.length === 1) return labels[0]!;
|
||||||
return `${labels[0]} + ${labels.length - 1} more`;␍
|
return `${labels[0]} + ${labels.length - 1} more`;
|
||||||
}␍
|
}
|
||||||
␍
|
|
||||||
function openCreate() {␍
|
function openCreate() {
|
||||||
editingId = null;␍
|
editingId = null;
|
||||||
const active = groups.find((g) => g.id === activeGroupId);␍
|
const active = groups.find((g) => g.id === activeGroupId);
|
||||||
draftClassKeys = active?.classKeys.length␍
|
draftClassKeys = active?.classKeys.length
|
||||||
? [...active.classKeys]␍
|
? [...active.classKeys]
|
||||||
: classOptions.slice(0, Math.min(2, classOptions.length)).map((option) => option.key);␍
|
: classOptions.slice(0, Math.min(2, classOptions.length)).map((option) => option.key);
|
||||||
groupName = defaultGroupName(draftClassKeys);␍
|
groupName = defaultGroupName(draftClassKeys);
|
||||||
showEditor = true;␍
|
showEditor = true;
|
||||||
}␍
|
}
|
||||||
␍
|
|
||||||
function openEdit(group: AnalyticsClassGroup) {␍
|
function openEdit(group: AnalyticsClassGroup) {
|
||||||
editingId = group.id;␍
|
editingId = group.id;
|
||||||
groupName = group.name;␍
|
groupName = group.name;
|
||||||
draftClassKeys = [...group.classKeys];␍
|
draftClassKeys = [...group.classKeys];
|
||||||
showEditor = true;␍
|
showEditor = true;
|
||||||
}␍
|
}
|
||||||
␍
|
|
||||||
function cancelEditor() {␍
|
function cancelEditor() {
|
||||||
showEditor = false;␍
|
showEditor = false;
|
||||||
editingId = null;␍
|
editingId = null;
|
||||||
groupName = "";␍
|
groupName = "";
|
||||||
draftClassKeys = [];␍
|
draftClassKeys = [];
|
||||||
}␍
|
}
|
||||||
␍
|
|
||||||
function toggleDraftClass(key: string) {␍
|
function toggleDraftClass(key: string) {
|
||||||
draftClassKeys = draftClassKeys.includes(key)␍
|
draftClassKeys = draftClassKeys.includes(key)
|
||||||
? draftClassKeys.filter((entry) => entry !== key)␍
|
? draftClassKeys.filter((entry) => entry !== key)
|
||||||
: [...draftClassKeys, key];␍
|
: [...draftClassKeys, key];
|
||||||
}␍
|
}
|
||||||
␍
|
|
||||||
function saveGroup() {␍
|
function saveGroup() {
|
||||||
if (!draftClassKeys.length) return;␍
|
if (!draftClassKeys.length) return;
|
||||||
␍
|
|
||||||
if (editingId) {␍
|
if (editingId) {
|
||||||
onSaveGroups(␍
|
onSaveGroups(
|
||||||
groups.map((g) =>␍
|
groups.map((g) =>
|
||||||
g.id === editingId␍
|
g.id === editingId
|
||||||
? { ...g, name: groupName.trim() || g.name, classKeys: [...draftClassKeys] }␍
|
? { ...g, name: groupName.trim() || g.name, classKeys: [...draftClassKeys] }
|
||||||
: g,␍
|
: g,
|
||||||
),␍
|
),
|
||||||
);␍
|
);
|
||||||
} else {␍
|
} else {
|
||||||
const created: AnalyticsClassGroup = {␍
|
const created: AnalyticsClassGroup = {
|
||||||
id: crypto.randomUUID(),␍
|
id: crypto.randomUUID(),
|
||||||
name: groupName.trim() || defaultGroupName(draftClassKeys),␍
|
name: groupName.trim() || defaultGroupName(draftClassKeys),
|
||||||
classKeys: [...new Set(draftClassKeys)],␍
|
classKeys: [...new Set(draftClassKeys)],
|
||||||
};␍
|
};
|
||||||
onSaveGroups([...groups, created]);␍
|
onSaveGroups([...groups, created]);
|
||||||
onSelectGroup(created);␍
|
onSelectGroup(created);
|
||||||
}␍
|
}
|
||||||
cancelEditor();␍
|
cancelEditor();
|
||||||
}␍
|
}
|
||||||
␍
|
|
||||||
function deleteGroup(id: string) {␍
|
function deleteGroup(id: string) {
|
||||||
onSaveGroups(groups.filter((g) => g.id !== id));␍
|
onSaveGroups(groups.filter((g) => g.id !== id));
|
||||||
if (activeGroupId === id) onSelectGroup(null);␍
|
if (activeGroupId === id) onSelectGroup(null);
|
||||||
}␍
|
}
|
||||||
␍
|
|
||||||
function onModalKeydown(event: KeyboardEvent) {␍
|
function onModalKeydown(event: KeyboardEvent) {
|
||||||
if (event.key === "Escape") {␍
|
if (event.key === "Escape") {
|
||||||
event.preventDefault();␍
|
event.preventDefault();
|
||||||
cancelEditor();␍
|
cancelEditor();
|
||||||
}␍
|
}
|
||||||
}␍
|
}
|
||||||
</script>␍
|
</script>
|
||||||
␍
|
|
||||||
<svelte:window onkeydown={showEditor ? onModalKeydown : undefined} />␍
|
<svelte:window onkeydown={showEditor ? onModalKeydown : undefined} />
|
||||||
␍
|
|
||||||
<div class="bsplus-analytics-filter-group bsplus-analytics-class-groups">␍
|
<div class="bsplus-analytics-filter-group bsplus-analytics-class-groups">
|
||||||
<div class="bsplus-analytics-class-groups-head">␍
|
<div class="bsplus-analytics-class-groups-head">
|
||||||
<span class="bsplus-analytics-field-label">Combined classes</span>␍
|
<span class="bsplus-analytics-field-label">Combined classes</span>
|
||||||
<button␍
|
<button
|
||||||
type="button"␍
|
type="button"
|
||||||
class="bsplus-analytics-class-groups-add"␍
|
class="bsplus-analytics-class-groups-add"
|
||||||
onclick={openCreate}␍
|
onclick={openCreate}
|
||||||
disabled={!classOptions.length}␍
|
disabled={!classOptions.length}
|
||||||
>␍
|
>
|
||||||
Combine␍
|
Combine
|
||||||
</button>␍
|
</button>
|
||||||
</div>␍
|
</div>
|
||||||
␍
|
|
||||||
{#if groups.length}␍
|
{#if groups.length}
|
||||||
<ul class="bsplus-analytics-class-groups-list" role="list">␍
|
<ul class="bsplus-analytics-class-groups-list" role="list">
|
||||||
{#each groups as group (group.id)}␍
|
{#each groups as group (group.id)}
|
||||||
{@const active = activeGroupId === group.id}␍
|
{@const active = activeGroupId === group.id}
|
||||||
<li class="bsplus-analytics-class-group-row">␍
|
<li class="bsplus-analytics-class-group-row">
|
||||||
<button␍
|
<button
|
||||||
type="button"␍
|
type="button"
|
||||||
class="bsplus-analytics-class-group-btn"␍
|
class="bsplus-analytics-class-group-btn"
|
||||||
class:is-active={active}␍
|
class:is-active={active}
|
||||||
onclick={() => onSelectGroup(active ? null : group)}␍
|
onclick={() => onSelectGroup(active ? null : group)}
|
||||||
title={group.classKeys.map(classLabel).join(", ")}␍
|
title={group.classKeys.map(classLabel).join(", ")}
|
||||||
>␍
|
>
|
||||||
<span class="bsplus-analytics-class-group-name">{group.name}</span>␍
|
<span class="bsplus-analytics-class-group-name">{group.name}</span>
|
||||||
<span class="bsplus-analytics-class-group-meta"␍
|
<span class="bsplus-analytics-class-group-meta"
|
||||||
>{group.classKeys.length} class{group.classKeys.length === 1 ? "" : "es"}</span␍
|
>{group.classKeys.length} class{group.classKeys.length === 1 ? "" : "es"}</span
|
||||||
>␍
|
>
|
||||||
</button>␍
|
</button>
|
||||||
<button␍
|
<button
|
||||||
type="button"␍
|
type="button"
|
||||||
class="bsplus-analytics-class-group-icon"␍
|
class="bsplus-analytics-class-group-icon"
|
||||||
aria-label="Edit {group.name}"␍
|
aria-label="Edit {group.name}"
|
||||||
onclick={() => openEdit(group)}␍
|
onclick={() => openEdit(group)}
|
||||||
>␍
|
>
|
||||||
✎␍
|
✎
|
||||||
</button>␍
|
</button>
|
||||||
<button␍
|
<button
|
||||||
type="button"␍
|
type="button"
|
||||||
class="bsplus-analytics-class-group-icon bsplus-analytics-class-group-delete"␍
|
class="bsplus-analytics-class-group-icon bsplus-analytics-class-group-delete"
|
||||||
aria-label="Delete {group.name}"␍
|
aria-label="Delete {group.name}"
|
||||||
onclick={() => deleteGroup(group.id)}␍
|
onclick={() => deleteGroup(group.id)}
|
||||||
>␍
|
>
|
||||||
×␍
|
×
|
||||||
</button>␍
|
</button>
|
||||||
</li>␍
|
</li>
|
||||||
{/each}␍
|
{/each}
|
||||||
</ul>␍
|
</ul>
|
||||||
{:else}␍
|
{:else}
|
||||||
<p class="bsplus-analytics-class-groups-empty">␍
|
<p class="bsplus-analytics-class-groups-empty">
|
||||||
Save classes from any year to view their combined grades in one trend.␍
|
Combine the same subject across years (e.g. English 2024 + English 2025) into one grade trend.
|
||||||
</p>␍
|
</p>
|
||||||
{/if}␍
|
{/if}
|
||||||
</div>␍
|
</div>
|
||||||
␍
|
|
||||||
{#if showEditor}␍
|
{#if showEditor}
|
||||||
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->␍
|
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
||||||
<div␍
|
<div
|
||||||
class="bsplus-analytics-class-groups-modal"␍
|
class="bsplus-analytics-class-groups-modal"
|
||||||
role="presentation"␍
|
role="presentation"
|
||||||
transition:fade={{ duration: fadeDuration }}␍
|
transition:fade={{ duration: fadeDuration }}
|
||||||
onclick={(e) => {␍
|
onclick={(e) => {
|
||||||
if (e.target === e.currentTarget) cancelEditor();␍
|
if (e.target === e.currentTarget) cancelEditor();
|
||||||
}}␍
|
}}
|
||||||
>␍
|
>
|
||||||
<div␍
|
<div
|
||||||
class="bsplus-analytics-class-groups-dialog"␍
|
class="bsplus-analytics-class-groups-dialog"
|
||||||
role="dialog"␍
|
role="dialog"
|
||||||
aria-modal="true"␍
|
aria-modal="true"
|
||||||
aria-labelledby="bsplus-class-group-modal-title"␍
|
aria-labelledby="bsplus-class-group-modal-title"
|
||||||
transition:scale={{ duration: fadeDuration, start: 0.96 }}␍
|
transition:scale={{ duration: fadeDuration, start: 0.96 }}
|
||||||
onclick={(e) => e.stopPropagation()}␍
|
onclick={(e) => e.stopPropagation()}
|
||||||
>␍
|
>
|
||||||
<header class="bsplus-analytics-class-groups-dialog-head">␍
|
<header class="bsplus-analytics-class-groups-dialog-head">
|
||||||
<div>␍
|
<div>
|
||||||
<h2 id="bsplus-class-group-modal-title" class="bsplus-analytics-class-groups-dialog-title">␍
|
<h2 id="bsplus-class-group-modal-title" class="bsplus-analytics-class-groups-dialog-title">
|
||||||
{editingId ? "Edit combined classes" : "Combine classes"}␍
|
{editingId ? "Edit combined classes" : "Combine classes"}
|
||||||
</h2>␍
|
</h2>
|
||||||
<p class="bsplus-analytics-class-groups-dialog-desc">␍
|
<p class="bsplus-analytics-class-groups-dialog-desc">
|
||||||
Every class from every programme year — same folders as Courses.␍
|
Pick two or more classes from any year — useful when your school splits a subject by
|
||||||
</p>␍
|
year. Same class list as Courses.
|
||||||
</div>␍
|
</p>
|
||||||
<button␍
|
</div>
|
||||||
type="button"␍
|
<button
|
||||||
class="bsplus-analytics-class-groups-close"␍
|
type="button"
|
||||||
aria-label="Close"␍
|
class="bsplus-analytics-class-groups-close"
|
||||||
onclick={cancelEditor}␍
|
aria-label="Close"
|
||||||
>␍
|
onclick={cancelEditor}
|
||||||
×␍
|
>
|
||||||
</button>␍
|
×
|
||||||
</header>␍
|
</button>
|
||||||
␍
|
</header>
|
||||||
<div class="bsplus-analytics-class-groups-dialog-body">␍
|
|
||||||
<label class="bsplus-analytics-class-groups-field">␍
|
<div class="bsplus-analytics-class-groups-dialog-body">
|
||||||
<span class="bsplus-analytics-field-label">Group name</span>␍
|
<label class="bsplus-analytics-class-groups-field">
|
||||||
<input␍
|
<span class="bsplus-analytics-field-label">Group name</span>
|
||||||
type="text"␍
|
<input
|
||||||
class="bsplus-analytics-input"␍
|
type="text"
|
||||||
bind:value={groupName}␍
|
class="bsplus-analytics-input"
|
||||||
placeholder="e.g. English block"␍
|
bind:value={groupName}
|
||||||
/>␍
|
placeholder="e.g. English block"
|
||||||
</label>␍
|
/>
|
||||||
␍
|
</label>
|
||||||
<div class="bsplus-analytics-class-groups-field">␍
|
|
||||||
<span class="bsplus-analytics-field-label">␍
|
<div class="bsplus-analytics-class-groups-field">
|
||||||
Classes ({draftClassKeys.length} selected)␍
|
<span class="bsplus-analytics-field-label">
|
||||||
</span>␍
|
Classes ({draftClassKeys.length} selected)
|
||||||
<div␍
|
</span>
|
||||||
class="bsplus-analytics-class-groups-picks"␍
|
<div
|
||||||
role="group"␍
|
class="bsplus-analytics-class-groups-picks"
|
||||||
aria-label="Classes in this group"␍
|
role="group"
|
||||||
>␍
|
aria-label="Classes in this group"
|
||||||
{#each classOptions as option (option.key)}␍
|
>
|
||||||
{@const picked = draftClassKeys.includes(option.key)}␍
|
{#each classOptions as option (option.key)}
|
||||||
<label class="bsplus-analytics-class-groups-pick">␍
|
{@const picked = draftClassKeys.includes(option.key)}
|
||||||
<input␍
|
<label class="bsplus-analytics-class-groups-pick">
|
||||||
type="checkbox"␍
|
<input
|
||||||
checked={picked}␍
|
type="checkbox"
|
||||||
onchange={() => toggleDraftClass(option.key)}␍
|
checked={picked}
|
||||||
/>␍
|
onchange={() => toggleDraftClass(option.key)}
|
||||||
<span class="bsplus-analytics-class-groups-check" aria-hidden="true">␍
|
/>
|
||||||
{#if picked}✓{/if}␍
|
<span class="bsplus-analytics-class-groups-check" aria-hidden="true">
|
||||||
</span>␍
|
{#if picked}✓{/if}
|
||||||
<span class="bsplus-analytics-class-groups-pick-text">␍
|
</span>
|
||||||
<span class="bsplus-analytics-class-groups-pick-label">{option.title}</span>␍
|
<span class="bsplus-analytics-class-groups-pick-text">
|
||||||
<span class="bsplus-analytics-class-groups-year">{option.yearLabel}</span>␍
|
<span class="bsplus-analytics-class-groups-pick-label">{option.title}</span>
|
||||||
</span>␍
|
<span class="bsplus-analytics-class-groups-year">{option.yearLabel}</span>
|
||||||
</label>␍
|
</span>
|
||||||
{/each}␍
|
</label>
|
||||||
</div>␍
|
{/each}
|
||||||
</div>␍
|
</div>
|
||||||
</div>␍
|
</div>
|
||||||
␍
|
</div>
|
||||||
<footer class="bsplus-analytics-class-groups-dialog-actions">␍
|
|
||||||
<button type="button" class="bsplus-analytics-btn" onclick={cancelEditor}>␍
|
<footer class="bsplus-analytics-class-groups-dialog-actions">
|
||||||
Cancel␍
|
<button type="button" class="bsplus-analytics-btn" onclick={cancelEditor}>
|
||||||
</button>␍
|
Cancel
|
||||||
<button␍
|
</button>
|
||||||
type="button"␍
|
<button
|
||||||
class="bsplus-analytics-btn bsplus-analytics-btn-primary"␍
|
type="button"
|
||||||
disabled={!draftClassKeys.length}␍
|
class="bsplus-analytics-btn bsplus-analytics-btn-primary"
|
||||||
onclick={saveGroup}␍
|
disabled={!draftClassKeys.length}
|
||||||
>␍
|
onclick={saveGroup}
|
||||||
{editingId ? "Save changes" : "Create group"}␍
|
>
|
||||||
</button>␍
|
{editingId ? "Save changes" : "Create group"}
|
||||||
</footer>␍
|
</button>
|
||||||
</div>␍
|
</footer>
|
||||||
</div>␍
|
</div>
|
||||||
{/if}␍
|
</div>
|
||||||
|
{/if}
|
||||||
@@ -25,8 +25,16 @@
|
|||||||
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||||
import { animationsEnabled } from "@/seqta/utils/performanceMode";
|
import { animationsEnabled } from "@/seqta/utils/performanceMode";
|
||||||
import ClassGroupsPanel from "./ClassGroupsPanel.svelte";
|
import ClassGroupsPanel from "./ClassGroupsPanel.svelte";
|
||||||
|
import GradeInferencePanel from "./GradeInferencePanel.svelte";
|
||||||
import type { AnalyticsClassGroup, AnalyticsClassOption } from "./types";
|
import type { AnalyticsClassGroup, AnalyticsClassOption } from "./types";
|
||||||
import { loadClassGroups, saveClassGroups } from "./storage";
|
import type { AnalyticsGradeInferenceSettings } from "./gradeInferenceSettings";
|
||||||
|
import { DEFAULT_ANALYTICS_GRADE_INFERENCE } from "./gradeInferenceSettings";
|
||||||
|
import {
|
||||||
|
loadClassGroups,
|
||||||
|
loadGradeInferenceSettings,
|
||||||
|
saveClassGroups,
|
||||||
|
saveGradeInferenceSettings,
|
||||||
|
} from "./storage";
|
||||||
|
|
||||||
let { simpleMode = false } = $props<{ simpleMode?: boolean }>();
|
let { simpleMode = false } = $props<{ simpleMode?: boolean }>();
|
||||||
|
|
||||||
@@ -49,6 +57,9 @@
|
|||||||
let classCatalog: AnalyticsClassOption[] = $state([]);
|
let classCatalog: AnalyticsClassOption[] = $state([]);
|
||||||
let activeClassGroupId: string | null = $state(null);
|
let activeClassGroupId: string | null = $state(null);
|
||||||
let studentId: number | null = $state(null);
|
let studentId: number | null = $state(null);
|
||||||
|
let gradeInference = $state<AnalyticsGradeInferenceSettings>(
|
||||||
|
DEFAULT_ANALYTICS_GRADE_INFERENCE,
|
||||||
|
);
|
||||||
|
|
||||||
let timestampInterval: ReturnType<typeof setInterval> | null = null;
|
let timestampInterval: ReturnType<typeof setInterval> | null = null;
|
||||||
let contentReady = $state(false);
|
let contentReady = $state(false);
|
||||||
@@ -191,6 +202,13 @@
|
|||||||
await saveClassGroups(location.origin, studentId, groups);
|
await saveClassGroups(location.origin, studentId, groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function persistGradeInference(settings: AnalyticsGradeInferenceSettings) {
|
||||||
|
gradeInference = settings;
|
||||||
|
if (studentId == null) return;
|
||||||
|
await saveGradeInferenceSettings(location.origin, studentId, settings);
|
||||||
|
await runSync();
|
||||||
|
}
|
||||||
|
|
||||||
async function loadClassCatalog(assessments: Assessment[]) {
|
async function loadClassCatalog(assessments: Assessment[]) {
|
||||||
classCatalog = await loadAnalyticsClassCatalog(assessments);
|
classCatalog = await loadAnalyticsClassCatalog(assessments);
|
||||||
}
|
}
|
||||||
@@ -230,6 +248,7 @@
|
|||||||
const id = await getStudentId();
|
const id = await getStudentId();
|
||||||
studentId = id;
|
studentId = id;
|
||||||
classGroups = await loadClassGroups(location.origin, id);
|
classGroups = await loadClassGroups(location.origin, id);
|
||||||
|
gradeInference = await loadGradeInferenceSettings(location.origin, id);
|
||||||
await loadClassCatalog(result.assessments);
|
await loadClassCatalog(result.assessments);
|
||||||
} catch {
|
} catch {
|
||||||
classGroups = [];
|
classGroups = [];
|
||||||
@@ -464,6 +483,12 @@
|
|||||||
onSelectGroup={selectClassGroup}
|
onSelectGroup={selectClassGroup}
|
||||||
onSaveGroups={persistClassGroups}
|
onSaveGroups={persistClassGroups}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<GradeInferencePanel
|
||||||
|
settings={gradeInference}
|
||||||
|
onSave={persistGradeInference}
|
||||||
|
disabled={syncing}
|
||||||
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="bsplus-analytics-filter-group">
|
<div class="bsplus-analytics-filter-group">
|
||||||
|
|||||||
@@ -0,0 +1,239 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {
|
||||||
|
createGradeBand,
|
||||||
|
DEFAULT_ANALYTICS_GRADE_INFERENCE,
|
||||||
|
type AnalyticsGradeInferenceSettings,
|
||||||
|
type GradeBandMapping,
|
||||||
|
} from "./gradeInferenceSettings";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
settings: AnalyticsGradeInferenceSettings;
|
||||||
|
onSave: (settings: AnalyticsGradeInferenceSettings) => void | Promise<void>;
|
||||||
|
disabled?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
let { settings, onSave, disabled = false }: Props = $props();
|
||||||
|
|
||||||
|
let expanded = $state(false);
|
||||||
|
let draft = $state<AnalyticsGradeInferenceSettings>(
|
||||||
|
structuredClone(DEFAULT_ANALYTICS_GRADE_INFERENCE),
|
||||||
|
);
|
||||||
|
let saving = $state(false);
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
draft = structuredClone(settings);
|
||||||
|
});
|
||||||
|
|
||||||
|
function updateDraft(patch: Partial<AnalyticsGradeInferenceSettings>) {
|
||||||
|
draft = { ...draft, ...patch };
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateBand(id: string, patch: Partial<GradeBandMapping>) {
|
||||||
|
draft = {
|
||||||
|
...draft,
|
||||||
|
gradeBands: draft.gradeBands.map((band) =>
|
||||||
|
band.id === id ? { ...band, ...patch } : band,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeBand(id: string) {
|
||||||
|
draft = {
|
||||||
|
...draft,
|
||||||
|
gradeBands: draft.gradeBands.filter((band) => band.id !== id),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function addBand() {
|
||||||
|
draft = {
|
||||||
|
...draft,
|
||||||
|
gradeBands: [...draft.gradeBands, createGradeBand("", 75)],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
saving = true;
|
||||||
|
try {
|
||||||
|
const cleaned: AnalyticsGradeInferenceSettings = {
|
||||||
|
useCustomGradeBands: draft.useCustomGradeBands,
|
||||||
|
rollupCriteriaGrades: draft.rollupCriteriaGrades,
|
||||||
|
gradeBands: draft.gradeBands
|
||||||
|
.map((band) => ({
|
||||||
|
...band,
|
||||||
|
label: band.label.trim(),
|
||||||
|
percent: Math.min(100, Math.max(0, Number(band.percent) || 0)),
|
||||||
|
}))
|
||||||
|
.filter((band) => band.label.length > 0),
|
||||||
|
};
|
||||||
|
await onSave(cleaned);
|
||||||
|
} finally {
|
||||||
|
saving = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const dirty = $derived(JSON.stringify(draft) !== JSON.stringify(settings));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="bsplus-analytics-filter-group bsplus-analytics-grade-inference">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="bsplus-analytics-grade-inference-toggle"
|
||||||
|
aria-expanded={expanded}
|
||||||
|
onclick={() => (expanded = !expanded)}
|
||||||
|
>
|
||||||
|
<span class="bsplus-analytics-field-label">Grade inference (optional)</span>
|
||||||
|
<span class="bsplus-analytics-grade-inference-chevron" aria-hidden="true"
|
||||||
|
>{expanded ? "▾" : "▸"}</span
|
||||||
|
>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{#if expanded}
|
||||||
|
<p class="bsplus-analytics-grade-inference-desc">
|
||||||
|
Analytics works without these options. Turn them on if teachers use rubrics without an overall
|
||||||
|
percentage, or if sub-parts of an assessment are marked separately.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<label class="bsplus-analytics-grade-inference-option">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={draft.useCustomGradeBands}
|
||||||
|
disabled={disabled || saving}
|
||||||
|
onchange={(e) =>
|
||||||
|
updateDraft({ useCustomGradeBands: e.currentTarget.checked })}
|
||||||
|
/>
|
||||||
|
<span>Map rubric / letter bands to percentages</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
{#if draft.useCustomGradeBands}
|
||||||
|
<div class="bsplus-analytics-grade-bands">
|
||||||
|
{#each draft.gradeBands as band (band.id)}
|
||||||
|
<div class="bsplus-analytics-grade-band-row">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
class="bsplus-analytics-input"
|
||||||
|
placeholder="Band label (e.g. A, Proficient)"
|
||||||
|
value={band.label}
|
||||||
|
disabled={disabled || saving}
|
||||||
|
oninput={(e) =>
|
||||||
|
updateBand(band.id, { label: e.currentTarget.value })}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
class="bsplus-analytics-input bsplus-analytics-grade-band-percent"
|
||||||
|
min="0"
|
||||||
|
max="100"
|
||||||
|
step="1"
|
||||||
|
value={band.percent}
|
||||||
|
disabled={disabled || saving}
|
||||||
|
oninput={(e) =>
|
||||||
|
updateBand(band.id, { percent: Number(e.currentTarget.value) })}
|
||||||
|
/>
|
||||||
|
<span class="bsplus-analytics-grade-band-suffix">%</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="bsplus-analytics-class-group-icon bsplus-analytics-class-group-delete"
|
||||||
|
aria-label="Remove band"
|
||||||
|
disabled={disabled || saving}
|
||||||
|
onclick={() => removeBand(band.id)}
|
||||||
|
>
|
||||||
|
×
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="bsplus-analytics-btn"
|
||||||
|
disabled={disabled || saving}
|
||||||
|
onclick={addBand}
|
||||||
|
>
|
||||||
|
Add band
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<label class="bsplus-analytics-grade-inference-option">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={draft.rollupCriteriaGrades}
|
||||||
|
disabled={disabled || saving}
|
||||||
|
onchange={(e) =>
|
||||||
|
updateDraft({ rollupCriteriaGrades: e.currentTarget.checked })}
|
||||||
|
/>
|
||||||
|
<span>Estimate overall % from marked criteria (sub-assessments)</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="bsplus-analytics-btn bsplus-analytics-btn-primary bsplus-analytics-grade-inference-save"
|
||||||
|
disabled={disabled || saving || !dirty}
|
||||||
|
onclick={() => void save()}
|
||||||
|
>
|
||||||
|
{saving ? "Saving…" : "Save & refresh grades"}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.bsplus-analytics-grade-inference-toggle {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 0.5rem;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-analytics-grade-inference-chevron {
|
||||||
|
opacity: 0.6;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-analytics-grade-inference-desc {
|
||||||
|
margin: 0.5rem 0 0.75rem;
|
||||||
|
font-size: 0.8125rem;
|
||||||
|
line-height: 1.45;
|
||||||
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-analytics-grade-inference-option {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 0.5rem;
|
||||||
|
margin-bottom: 0.65rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
line-height: 1.35;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-analytics-grade-bands {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
margin: 0 0 0.75rem 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-analytics-grade-band-row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 4.5rem auto auto;
|
||||||
|
gap: 0.35rem;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-analytics-grade-band-percent {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-analytics-grade-band-suffix {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-analytics-grade-inference-save {
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,11 +1,17 @@
|
|||||||
import { getUserInfo } from "@/seqta/ui/AddBetterSEQTAElements";
|
import { getUserInfo } from "@/seqta/ui/AddBetterSEQTAElements";
|
||||||
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||||
import { getMockGradeAnalyticsData } from "@/seqta/ui/dev/hideSensitiveContent";
|
import { getMockGradeAnalyticsData } from "@/seqta/ui/dev/hideSensitiveContent";
|
||||||
|
import { resolveGradeFromAssessmentPayload } from "./gradeResolution";
|
||||||
import {
|
import {
|
||||||
extractLetterGradeStringFromPayload,
|
extractLetterGradeStringFromPayload,
|
||||||
resolveNumericGradeFromAssessmentPayload,
|
resolveNumericGradeFromAssessmentPayload,
|
||||||
} from "./letterGradeScale";
|
} from "./letterGradeScale";
|
||||||
import { loadAnalyticsCache, saveAnalyticsCache } from "./storage";
|
import {
|
||||||
|
loadAnalyticsCache,
|
||||||
|
loadGradeInferenceSettings,
|
||||||
|
saveAnalyticsCache,
|
||||||
|
} from "./storage";
|
||||||
|
import type { AnalyticsGradeInferenceSettings } from "./gradeInferenceSettings";
|
||||||
import type { Assessment, AssessmentStatus, AnalyticsClassOption } from "./types";
|
import type { Assessment, AssessmentStatus, AnalyticsClassOption } from "./types";
|
||||||
|
|
||||||
const PAST_FETCH_CONCURRENCY = 8;
|
const PAST_FETCH_CONCURRENCY = 8;
|
||||||
@@ -72,6 +78,13 @@ export function parseAssessment(data: unknown): Assessment | null {
|
|||||||
availability: String(raw.availability || ""),
|
availability: String(raw.availability || ""),
|
||||||
finalGrade,
|
finalGrade,
|
||||||
letterGrade,
|
letterGrade,
|
||||||
|
gradeSource:
|
||||||
|
raw.gradeSource === "seqta" ||
|
||||||
|
raw.gradeSource === "criteriaRollup" ||
|
||||||
|
raw.gradeSource === "customBand" ||
|
||||||
|
raw.gradeSource === "defaultLetter"
|
||||||
|
? raw.gradeSource
|
||||||
|
: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -95,40 +108,14 @@ function jsonGradeToString(grade: unknown): string | undefined {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractFinalGrade(assessment: Record<string, unknown>): number | undefined {
|
function applyResolvedGrade(
|
||||||
if (assessment.status !== "MARKS_RELEASED") return undefined;
|
raw: Record<string, unknown>,
|
||||||
|
inference: AnalyticsGradeInferenceSettings,
|
||||||
const criteria = assessment.criteria as
|
): void {
|
||||||
| { results?: { percentage?: unknown } }[]
|
const resolved = resolveGradeFromAssessmentPayload(raw, inference);
|
||||||
| undefined;
|
if (resolved.finalGrade !== undefined) raw.finalGrade = resolved.finalGrade;
|
||||||
if (criteria?.[0]?.results?.percentage !== undefined) {
|
if (resolved.letterGrade !== undefined) raw.letterGrade = resolved.letterGrade;
|
||||||
const n = Number(criteria[0].results!.percentage);
|
if (resolved.source) raw.gradeSource = resolved.source;
|
||||||
if (!isNaN(n)) return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
const results = assessment.results as { percentage?: unknown } | undefined;
|
|
||||||
if (results?.percentage !== undefined) {
|
|
||||||
const n = Number(results.percentage);
|
|
||||||
if (!isNaN(n)) return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (assessment.finalGrade !== undefined && assessment.finalGrade !== null) {
|
|
||||||
const n = Number(assessment.finalGrade);
|
|
||||||
if (!isNaN(n)) return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
const letter = extractLetterGradeStringFromPayload(
|
|
||||||
assessment as Parameters<typeof extractLetterGradeStringFromPayload>[0],
|
|
||||||
);
|
|
||||||
if (letter) {
|
|
||||||
const approx = resolveNumericGradeFromAssessmentPayload({
|
|
||||||
status: "MARKS_RELEASED",
|
|
||||||
letterGrade: letter,
|
|
||||||
});
|
|
||||||
if (approx !== undefined) return approx;
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractLetterGrade(
|
function extractLetterGrade(
|
||||||
@@ -331,6 +318,7 @@ async function loadAllPast(
|
|||||||
function mergeRawAssessments(
|
function mergeRawAssessments(
|
||||||
existing: Assessment[],
|
existing: Assessment[],
|
||||||
rawItems: Record<string, unknown>[],
|
rawItems: Record<string, unknown>[],
|
||||||
|
inference: AnalyticsGradeInferenceSettings,
|
||||||
): Assessment[] {
|
): Assessment[] {
|
||||||
const existingMap = new Map<number, Assessment>();
|
const existingMap = new Map<number, Assessment>();
|
||||||
for (const a of existing) {
|
for (const a of existing) {
|
||||||
@@ -341,10 +329,10 @@ function mergeRawAssessments(
|
|||||||
const id = Number(raw.id);
|
const id = Number(raw.id);
|
||||||
if (!id) continue;
|
if (!id) continue;
|
||||||
|
|
||||||
const finalGrade = extractFinalGrade(raw);
|
applyResolvedGrade(raw, inference);
|
||||||
|
const finalGrade =
|
||||||
|
raw.finalGrade !== undefined ? Number(raw.finalGrade) : undefined;
|
||||||
const letterGrade = extractLetterGrade(raw);
|
const letterGrade = extractLetterGrade(raw);
|
||||||
if (finalGrade !== undefined) raw.finalGrade = finalGrade;
|
|
||||||
if (letterGrade !== undefined) raw.letterGrade = letterGrade;
|
|
||||||
|
|
||||||
const existingItem = existingMap.get(id);
|
const existingItem = existingMap.get(id);
|
||||||
if (existingItem?.finalGrade !== undefined && finalGrade === undefined) {
|
if (existingItem?.finalGrade !== undefined && finalGrade === undefined) {
|
||||||
@@ -407,13 +395,14 @@ export async function syncGradeAnalytics(): Promise<{
|
|||||||
const existing = cached?.assessments ?? [];
|
const existing = cached?.assessments ?? [];
|
||||||
|
|
||||||
const subjectList = await loadAllSubjects(existing);
|
const subjectList = await loadAllSubjects(existing);
|
||||||
|
const inference = await loadGradeInferenceSettings(location.origin, studentId);
|
||||||
|
|
||||||
const [upcoming, past] = await Promise.all([
|
const [upcoming, past] = await Promise.all([
|
||||||
loadUpcoming(studentId),
|
loadUpcoming(studentId),
|
||||||
loadAllPast(studentId, subjectList),
|
loadAllPast(studentId, subjectList),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const merged = mergeRawAssessments(existing, [...upcoming, ...past]);
|
const merged = mergeRawAssessments(existing, [...upcoming, ...past], inference);
|
||||||
await saveAnalyticsCache(location.origin, studentId, merged);
|
await saveAnalyticsCache(location.origin, studentId, merged);
|
||||||
|
|
||||||
return { assessments: merged, updatedAt: Date.now() };
|
return { assessments: merged, updatedAt: Date.now() };
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
export interface GradeBandMapping {
|
||||||
|
id: string;
|
||||||
|
/** Rubric or letter label as shown in SEQTA (e.g. A, B+, Highly accomplished). */
|
||||||
|
label: string;
|
||||||
|
/** Approximate percentage (0–100) used in charts when SEQTA has no numeric mark. */
|
||||||
|
percent: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AnalyticsGradeInferenceSettings {
|
||||||
|
/** Map rubric / letter bands to percentages (optional). */
|
||||||
|
useCustomGradeBands: boolean;
|
||||||
|
gradeBands: GradeBandMapping[];
|
||||||
|
/**
|
||||||
|
* When the overall assessment has no percentage, derive one from marked criteria
|
||||||
|
* (e.g. sub-parts of a task). Analytics still works when this is off.
|
||||||
|
*/
|
||||||
|
rollupCriteriaGrades: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DEFAULT_ANALYTICS_GRADE_INFERENCE: AnalyticsGradeInferenceSettings = {
|
||||||
|
useCustomGradeBands: false,
|
||||||
|
gradeBands: [],
|
||||||
|
rollupCriteriaGrades: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export function normalizeGradeBandLabel(raw: string): string {
|
||||||
|
return raw.trim().toLowerCase().replace(/\s+/g, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createGradeBand(label: string, percent: number): GradeBandMapping {
|
||||||
|
return {
|
||||||
|
id: crypto.randomUUID(),
|
||||||
|
label: label.trim(),
|
||||||
|
percent: Math.min(100, Math.max(0, percent)),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { DEFAULT_ANALYTICS_GRADE_INFERENCE } from "./gradeInferenceSettings";
|
||||||
|
import {
|
||||||
|
resolveGradeFromAssessmentPayload,
|
||||||
|
rollupPercentFromCriteria,
|
||||||
|
} from "./gradeResolution";
|
||||||
|
|
||||||
|
describe("rollupPercentFromCriteria", () => {
|
||||||
|
it("returns undefined when no criterion marks exist", () => {
|
||||||
|
expect(rollupPercentFromCriteria([], DEFAULT_ANALYTICS_GRADE_INFERENCE)).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("averages criterion percentages when weights are missing", () => {
|
||||||
|
const result = rollupPercentFromCriteria(
|
||||||
|
[
|
||||||
|
{ results: { percentage: 80 } },
|
||||||
|
{ results: { percentage: 60 } },
|
||||||
|
],
|
||||||
|
DEFAULT_ANALYTICS_GRADE_INFERENCE,
|
||||||
|
);
|
||||||
|
expect(result).toBe(70);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses weighted mean when weights are present on every part", () => {
|
||||||
|
const result = rollupPercentFromCriteria(
|
||||||
|
[
|
||||||
|
{ results: { percentage: 100 }, weight: 2 },
|
||||||
|
{ results: { percentage: 50 }, weight: 1 },
|
||||||
|
],
|
||||||
|
DEFAULT_ANALYTICS_GRADE_INFERENCE,
|
||||||
|
);
|
||||||
|
expect(result).toBe(83.3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("maps rubric labels through custom bands when rollup is enabled", () => {
|
||||||
|
const settings = {
|
||||||
|
...DEFAULT_ANALYTICS_GRADE_INFERENCE,
|
||||||
|
useCustomGradeBands: true,
|
||||||
|
gradeBands: [{ id: "1", label: "Excellent", percent: 95 }],
|
||||||
|
};
|
||||||
|
const result = rollupPercentFromCriteria(
|
||||||
|
[{ results: { grade: "Excellent" } }, { results: { grade: "Excellent" } }],
|
||||||
|
settings,
|
||||||
|
);
|
||||||
|
expect(result).toBe(95);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("resolveGradeFromAssessmentPayload", () => {
|
||||||
|
it("prefers SEQTA overall percentage", () => {
|
||||||
|
const resolved = resolveGradeFromAssessmentPayload(
|
||||||
|
{
|
||||||
|
status: "MARKS_RELEASED",
|
||||||
|
results: { percentage: 88 },
|
||||||
|
},
|
||||||
|
DEFAULT_ANALYTICS_GRADE_INFERENCE,
|
||||||
|
);
|
||||||
|
expect(resolved.finalGrade).toBe(88);
|
||||||
|
expect(resolved.source).toBe("seqta");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not rollup criteria unless the option is enabled", () => {
|
||||||
|
const payload = {
|
||||||
|
status: "MARKS_RELEASED",
|
||||||
|
criteria: [
|
||||||
|
{ results: { percentage: 70 } },
|
||||||
|
{ results: { percentage: 90 } },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
expect(
|
||||||
|
resolveGradeFromAssessmentPayload(payload, DEFAULT_ANALYTICS_GRADE_INFERENCE)
|
||||||
|
.finalGrade,
|
||||||
|
).toBe(70);
|
||||||
|
|
||||||
|
const withRollup = {
|
||||||
|
...DEFAULT_ANALYTICS_GRADE_INFERENCE,
|
||||||
|
rollupCriteriaGrades: true,
|
||||||
|
};
|
||||||
|
expect(
|
||||||
|
resolveGradeFromAssessmentPayload(payload, withRollup).finalGrade,
|
||||||
|
).toBe(80);
|
||||||
|
expect(resolveGradeFromAssessmentPayload(payload, withRollup).source).toBe(
|
||||||
|
"criteriaRollup",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses custom bands for letter-only marks", () => {
|
||||||
|
const settings = {
|
||||||
|
...DEFAULT_ANALYTICS_GRADE_INFERENCE,
|
||||||
|
useCustomGradeBands: true,
|
||||||
|
gradeBands: [{ id: "1", label: "Proficient", percent: 72 }],
|
||||||
|
};
|
||||||
|
const resolved = resolveGradeFromAssessmentPayload(
|
||||||
|
{
|
||||||
|
status: "MARKS_RELEASED",
|
||||||
|
results: { grade: "Proficient" },
|
||||||
|
},
|
||||||
|
settings,
|
||||||
|
);
|
||||||
|
expect(resolved.finalGrade).toBe(72);
|
||||||
|
expect(resolved.source).toBe("customBand");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
import { approximatePercentFromLetterGrade } from "./letterGradeScale";
|
||||||
|
import {
|
||||||
|
normalizeGradeBandLabel,
|
||||||
|
type AnalyticsGradeInferenceSettings,
|
||||||
|
} from "./gradeInferenceSettings";
|
||||||
|
|
||||||
|
export type GradeResolutionSource =
|
||||||
|
| "seqta"
|
||||||
|
| "criteriaRollup"
|
||||||
|
| "customBand"
|
||||||
|
| "defaultLetter";
|
||||||
|
|
||||||
|
export type GradeResolution = {
|
||||||
|
finalGrade?: number;
|
||||||
|
letterGrade?: string;
|
||||||
|
source?: GradeResolutionSource;
|
||||||
|
};
|
||||||
|
|
||||||
|
type CriterionRow = {
|
||||||
|
results?: { percentage?: unknown; grade?: unknown; score?: unknown };
|
||||||
|
weight?: unknown;
|
||||||
|
weighting?: unknown;
|
||||||
|
maxMark?: unknown;
|
||||||
|
max?: unknown;
|
||||||
|
};
|
||||||
|
|
||||||
|
function parsePercent(value: unknown): number | undefined {
|
||||||
|
if (value === null || value === undefined || value === "") return undefined;
|
||||||
|
const n = Number(value);
|
||||||
|
if (Number.isNaN(n)) return undefined;
|
||||||
|
return Math.min(100, Math.max(0, n));
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseGradeString(value: unknown): string | undefined {
|
||||||
|
if (value == null) return undefined;
|
||||||
|
const s = String(value).trim();
|
||||||
|
return s || undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function percentFromGradeLabel(
|
||||||
|
label: string | undefined,
|
||||||
|
settings: AnalyticsGradeInferenceSettings,
|
||||||
|
): number | undefined {
|
||||||
|
if (!label) return undefined;
|
||||||
|
if (settings.useCustomGradeBands && settings.gradeBands.length > 0) {
|
||||||
|
const key = normalizeGradeBandLabel(label);
|
||||||
|
for (const band of settings.gradeBands) {
|
||||||
|
if (normalizeGradeBandLabel(band.label) === key) {
|
||||||
|
return band.percent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const approx = approximatePercentFromLetterGrade(label);
|
||||||
|
if (approx !== undefined) return approx;
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function criterionWeight(row: CriterionRow): number | undefined {
|
||||||
|
const raw = row.weight ?? row.weighting ?? row.maxMark ?? row.max;
|
||||||
|
const n = Number(raw);
|
||||||
|
if (Number.isNaN(n) || n <= 0) return undefined;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Average or weighted mean of criterion percentages / mapped rubric grades. */
|
||||||
|
export function rollupPercentFromCriteria(
|
||||||
|
criteria: CriterionRow[] | undefined,
|
||||||
|
settings: AnalyticsGradeInferenceSettings,
|
||||||
|
): number | undefined {
|
||||||
|
if (!criteria?.length) return undefined;
|
||||||
|
|
||||||
|
const parts: { percent: number; weight?: number }[] = [];
|
||||||
|
|
||||||
|
for (const row of criteria) {
|
||||||
|
const direct = parsePercent(row.results?.percentage ?? row.results?.score);
|
||||||
|
if (direct !== undefined) {
|
||||||
|
parts.push({ percent: direct, weight: criterionWeight(row) });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const letter = parseGradeString(row.results?.grade);
|
||||||
|
const mapped = percentFromGradeLabel(letter, settings);
|
||||||
|
if (mapped !== undefined) {
|
||||||
|
parts.push({ percent: mapped, weight: criterionWeight(row) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parts.length) return undefined;
|
||||||
|
|
||||||
|
const withWeights = parts.filter((p) => p.weight !== undefined);
|
||||||
|
if (withWeights.length === parts.length) {
|
||||||
|
const totalWeight = withWeights.reduce((sum, p) => sum + (p.weight ?? 0), 0);
|
||||||
|
if (totalWeight > 0) {
|
||||||
|
const weighted = withWeights.reduce(
|
||||||
|
(sum, p) => sum + p.percent * (p.weight ?? 0),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
return Math.round((weighted / totalWeight) * 10) / 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const avg = parts.reduce((sum, p) => sum + p.percent, 0) / parts.length;
|
||||||
|
return Math.round(avg * 10) / 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveGradeFromAssessmentPayload(
|
||||||
|
assessment: Record<string, unknown>,
|
||||||
|
settings: AnalyticsGradeInferenceSettings,
|
||||||
|
): GradeResolution {
|
||||||
|
if (assessment.status !== "MARKS_RELEASED") {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const criteria = assessment.criteria as CriterionRow[] | undefined;
|
||||||
|
|
||||||
|
const topPercent = parsePercent(
|
||||||
|
(assessment.results as { percentage?: unknown } | undefined)?.percentage,
|
||||||
|
);
|
||||||
|
if (topPercent !== undefined) {
|
||||||
|
return {
|
||||||
|
finalGrade: topPercent,
|
||||||
|
letterGrade: extractLetterFromPayload(assessment),
|
||||||
|
source: "seqta",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const finalDirect = parsePercent(assessment.finalGrade);
|
||||||
|
if (finalDirect !== undefined) {
|
||||||
|
return {
|
||||||
|
finalGrade: finalDirect,
|
||||||
|
letterGrade: extractLetterFromPayload(assessment),
|
||||||
|
source: "seqta",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.rollupCriteriaGrades) {
|
||||||
|
const rolled = rollupPercentFromCriteria(criteria, settings);
|
||||||
|
if (rolled !== undefined) {
|
||||||
|
return {
|
||||||
|
finalGrade: rolled,
|
||||||
|
letterGrade: extractLetterFromPayload(assessment),
|
||||||
|
source: "criteriaRollup",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const firstCriterionPercent = parsePercent(criteria?.[0]?.results?.percentage);
|
||||||
|
if (firstCriterionPercent !== undefined) {
|
||||||
|
return {
|
||||||
|
finalGrade: firstCriterionPercent,
|
||||||
|
letterGrade: extractLetterFromPayload(assessment),
|
||||||
|
source: "seqta",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const letter = extractLetterFromPayload(assessment);
|
||||||
|
if (letter) {
|
||||||
|
const custom = settings.useCustomGradeBands
|
||||||
|
? percentFromGradeLabel(letter, settings)
|
||||||
|
: undefined;
|
||||||
|
const finalGrade =
|
||||||
|
custom ?? approximatePercentFromLetterGrade(letter);
|
||||||
|
if (finalGrade !== undefined) {
|
||||||
|
return {
|
||||||
|
finalGrade,
|
||||||
|
letterGrade: letter,
|
||||||
|
source: custom !== undefined ? "customBand" : "defaultLetter",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { letterGrade: letter };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractLetterFromPayload(assessment: Record<string, unknown>): string | undefined {
|
||||||
|
const criteria = assessment.criteria as CriterionRow[] | undefined;
|
||||||
|
const fromCriteria = parseGradeString(criteria?.[0]?.results?.grade);
|
||||||
|
if (fromCriteria) return fromCriteria;
|
||||||
|
const fromResults = parseGradeString(
|
||||||
|
(assessment.results as { grade?: unknown } | undefined)?.grade,
|
||||||
|
);
|
||||||
|
if (fromResults) return fromResults;
|
||||||
|
if (assessment.letterGrade != null) {
|
||||||
|
return parseGradeString(assessment.letterGrade);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
@@ -1,10 +1,16 @@
|
|||||||
import browser from "webextension-polyfill";
|
import browser from "webextension-polyfill";
|
||||||
import type { DistributionMode } from "./gradeDistribution";
|
import type { DistributionMode } from "./gradeDistribution";
|
||||||
|
import {
|
||||||
|
DEFAULT_ANALYTICS_GRADE_INFERENCE,
|
||||||
|
type AnalyticsGradeInferenceSettings,
|
||||||
|
type GradeBandMapping,
|
||||||
|
} from "./gradeInferenceSettings";
|
||||||
import type { AnalyticsCache, AnalyticsClassGroup } from "./types";
|
import type { AnalyticsCache, AnalyticsClassGroup } from "./types";
|
||||||
|
|
||||||
const STORAGE_PREFIX = "bsplus.analytics.v2";
|
const STORAGE_PREFIX = "bsplus.analytics.v2";
|
||||||
const DISTRIBUTION_MODE_PREFIX = "bsplus.analytics.distMode.v1";
|
const DISTRIBUTION_MODE_PREFIX = "bsplus.analytics.distMode.v1";
|
||||||
const CLASS_GROUPS_PREFIX = "bsplus.analytics.groups.v1";
|
const CLASS_GROUPS_PREFIX = "bsplus.analytics.groups.v1";
|
||||||
|
const GRADE_INFERENCE_PREFIX = "bsplus.analytics.gradeInference.v1";
|
||||||
|
|
||||||
export function analyticsStorageKey(origin: string, studentId: number): string {
|
export function analyticsStorageKey(origin: string, studentId: number): string {
|
||||||
return `${STORAGE_PREFIX}.${origin}.${studentId}`;
|
return `${STORAGE_PREFIX}.${origin}.${studentId}`;
|
||||||
@@ -102,3 +108,54 @@ export async function saveClassGroups(
|
|||||||
const key = classGroupsStorageKey(origin, studentId);
|
const key = classGroupsStorageKey(origin, studentId);
|
||||||
await browser.storage.local.set({ [key]: groups });
|
await browser.storage.local.set({ [key]: groups });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function gradeInferenceStorageKey(origin: string, studentId: number): string {
|
||||||
|
return `${GRADE_INFERENCE_PREFIX}.${origin}.${studentId}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isGradeBand(value: unknown): value is GradeBandMapping {
|
||||||
|
if (!value || typeof value !== "object") return false;
|
||||||
|
const row = value as GradeBandMapping;
|
||||||
|
return (
|
||||||
|
typeof row.id === "string" &&
|
||||||
|
typeof row.label === "string" &&
|
||||||
|
typeof row.percent === "number" &&
|
||||||
|
!Number.isNaN(row.percent)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sanitizeInferenceSettings(raw: unknown): AnalyticsGradeInferenceSettings {
|
||||||
|
if (!raw || typeof raw !== "object") {
|
||||||
|
return { ...DEFAULT_ANALYTICS_GRADE_INFERENCE, gradeBands: [] };
|
||||||
|
}
|
||||||
|
const row = raw as Partial<AnalyticsGradeInferenceSettings>;
|
||||||
|
const gradeBands = Array.isArray(row.gradeBands)
|
||||||
|
? row.gradeBands.filter(isGradeBand).map((band) => ({
|
||||||
|
...band,
|
||||||
|
percent: Math.min(100, Math.max(0, band.percent)),
|
||||||
|
}))
|
||||||
|
: [];
|
||||||
|
return {
|
||||||
|
useCustomGradeBands: Boolean(row.useCustomGradeBands),
|
||||||
|
rollupCriteriaGrades: Boolean(row.rollupCriteriaGrades),
|
||||||
|
gradeBands,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function loadGradeInferenceSettings(
|
||||||
|
origin: string,
|
||||||
|
studentId: number,
|
||||||
|
): Promise<AnalyticsGradeInferenceSettings> {
|
||||||
|
const key = gradeInferenceStorageKey(origin, studentId);
|
||||||
|
const result = await browser.storage.local.get(key);
|
||||||
|
return sanitizeInferenceSettings(result[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function saveGradeInferenceSettings(
|
||||||
|
origin: string,
|
||||||
|
studentId: number,
|
||||||
|
settings: AnalyticsGradeInferenceSettings,
|
||||||
|
): Promise<void> {
|
||||||
|
const key = gradeInferenceStorageKey(origin, studentId);
|
||||||
|
await browser.storage.local.set({ [key]: sanitizeInferenceSettings(settings) });
|
||||||
|
}
|
||||||
@@ -19,6 +19,8 @@ export interface Assessment {
|
|||||||
availability: string;
|
availability: string;
|
||||||
finalGrade?: number;
|
finalGrade?: number;
|
||||||
letterGrade?: string;
|
letterGrade?: string;
|
||||||
|
/** How finalGrade was derived (for optional inference features). */
|
||||||
|
gradeSource?: "seqta" | "criteriaRollup" | "customBand" | "defaultLetter";
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AnalyticsData = Assessment[];
|
export type AnalyticsData = Assessment[];
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export const WHATS_NEW_CHANGELOG: WhatsNewRelease[] = [
|
|||||||
"Added a new toggleable titlebar founder badge to the topbar for BetterSEQTA Cloud celebrations.",
|
"Added a new toggleable titlebar founder badge to the topbar for BetterSEQTA Cloud celebrations.",
|
||||||
"Addded Editing a teacher's name in the timetable editor now affect Assements.",
|
"Addded Editing a teacher's name in the timetable editor now affect Assements.",
|
||||||
"Added a 'this year' & custom date range option to grade analyitics.",
|
"Added a 'this year' & custom date range option to grade analyitics.",
|
||||||
|
"Added Community Themes for you all to show off your best BetterSEQTA setups!",
|
||||||
"Removed white background around SEQTA Learn mobile App icons in settings.",
|
"Removed white background around SEQTA Learn mobile App icons in settings.",
|
||||||
"Re-added the kitten back to the 404 Error pages.",
|
"Re-added the kitten back to the 404 Error pages.",
|
||||||
"Improved the sidebar to be more stable and performant.",
|
"Improved the sidebar to be more stable and performant.",
|
||||||
|
|||||||
Reference in new issue
Block a user