Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Format: [Keep a Changelog](https://keepachangelog.com/); versioning: [SemVer](ht
## [Unreleased]

### Added
- Weak spots on Saved: wrong quiz answers become a personal revision reel of the explanations you missed (Phase 22)
- Study notes `/notes/[id]` and `GET /api/lectures/[id]/notes`: a timestamp-linked study sheet per session, as Markdown or PDF (Phase 22)
- Data saver: a header switch (automatic on Save-Data and 2G/3G) that serves lighter Cloudinary renditions and the `sd` streaming ladder; 33–76% fewer bytes measured (Phase 21)
- Concept Map `/concepts` and Compare view `/concepts/[key]`: the same concept from every teacher as one Compare Reel (Phase 19)
- Cloudinary asset index: tags and contextual metadata on each session's asset, synced from the Studio and read back with the Search API (Phase 19)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Colleges, clubs and coaching institutes record hundreds of hours of lectures and
| **Concept Map** | `/concepts` lines up every concept your lectures teach and how many different teachers explain it. Open one and hear the same idea from each lecturer, back to back, as one Cloudinary-spliced video, until one explanation clicks. |
| **Learning Paths** | `/learn`: type a topic and get a 3–5 step course, ordered basics first, drawn from moments across the library and edited into one video. |
| **Data saver** | One switch (and automatic on Save-Data or 2G/3G) serves smaller, lower-quality Cloudinary renditions: thumbnails 76% lighter, clips and reels 38–41%, and a streaming ladder that tops out at 0.9 Mbps instead of 3.4. Built for India’s mobile data. |
| **Weak spots** | Quiz mistakes are remembered on your device and come back as **one Cloudinary reel of exactly the explanations you missed**, with the answer and the second to jump to. Get a question right and it leaves the list. |
| **Study notes** | Every session has a study sheet at `/notes/[id]`: summary, key concepts, chapters and the quiz with answers, each point linked to its timestamp. Copy it as Markdown, download it, or save it as a PDF. |
| **Study Packs** | Every session gets a summary, key concepts, a quiz whose explanations **play the moment** the teacher explains it, and a "Session in 60 seconds" highlight reel. Pravaha generates them automatically from the transcript. |
| **Moments** | One tap turns any cited clip into a vertical, AI-cropped, subtitled short for WhatsApp or Instagram, with its own share page and preview card. The short is just a Cloudinary URL; nothing is rendered. |
| **Insights** | Organizers see what learners ask, the **knowledge gaps** the library can't answer yet (what to record next), and which Moments get shared. Every report downloads as CSV. Visitors can explore a read-only demo of the Studio. |
Expand Down
8 changes: 8 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,11 @@ Retrieval now rewrites a question into the library's vocabulary when it is in an
### `POST /api/organizer/index` · `GET /api/organizer/index`
- **Auth:** organizer cookie (`401` otherwise) · `maxDuration` 60 s
- `POST` writes tags and contextual metadata onto every session's Cloudinary asset, then returns `{ synced, skipped, assets }` read back with the Search API. `GET` returns just `{ assets: [{ publicId, tags, context }] }`

## Phase 22 additions

### `GET /api/lectures/[id]/notes`
- **Auth:** public (the unguessable session id is the access, like the Watch page)
- **Query:** `format=md` returns Markdown (`text/markdown`); add `download=1` for a `Content-Disposition: attachment` `.md` file. Without `format`, JSON
- **Response (JSON):** `{ title, speaker, durationS, watchUrl, summary[], concepts[{ name, t, label, url }], chapters[{ title, t, label, url }], quiz[{ question, answer, explanation, t, label, url }] }`; every `url` opens the session at that second
- **Errors:** `404` the session isn't ready, doesn't exist, or has no summary, chapters or quiz yet
2 changes: 2 additions & 0 deletions docs/DEMO.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Never show setup, code, dashboards or waiting. Every shot is the problem, the pr
| 2:24–2:35 | **Cloudinary under the hood** panel on the answer: each URL step explained | "Every clip, reel and short is a Cloudinary transformation, and Pravaha shows exactly which." |
| 2:35–2:45 | Architecture strip: Cloudinary (transcription · chaptering · streaming · g_auto · e_preview · transformations) + Pravaha (retrieval · grounded Ask · Moments · Insights) · team | "Cloudinary turns video into data. Pravaha turns data into answers you can watch. Code Blooded, Track 3." |

**Study shots (if there is time):** answer a quiz question wrong → `/saved` → **Play my weak-spot reel** ("What you get wrong comes back as video.") → a session’s **Study notes** → **Download .md** ("Every point links to the second the teacher said it.")

**Bonus shot (if there is time):** header → **Data saver** on → the same answer reel and thumbnails reload visibly lighter. Voice-over: "Built for India’s mobile data: one switch, and Cloudinary serves everything at a fraction of the bytes."

## Pre-Recording Checklist
Expand Down
1 change: 1 addition & 0 deletions docs/IMPLEMENTATION_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ The core loop (Phases 01–09) is built and verified on real Cloudinary + Neon.
| 18 | Query understanding, Learning Paths, AI reliability | Rewrite questions into the library's words (and translate them), honest near-miss answers, `/learn` micro-courses as one Cloudinary reel, circuit breaker + deep health | ✅ done (Oct 3) |
| 19 | Concept Map & Cloudinary asset index | Same concept, every teacher, as one Compare Reel; tags + contextual metadata on Cloudinary assets, read back with the Search API | ✅ done (Oct 3) |
| 21 | Data saver | Light Cloudinary renditions (35–76% fewer bytes, sd streaming ladder) for slow or metered connections; follows Save-Data and 2G/3G automatically | ✅ done (Oct 3) |
| 22 | Weak spots & study notes | Quiz mistakes become a personal revision reel; every session exports a timestamp-linked study sheet (Markdown / print) | ✅ done (Oct 3) |
19 changes: 19 additions & 0 deletions docs/phases/PHASE-22-weak-spots-study-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Phase 22 — Weak spots and study notes

**Status: DONE (Oct 3)** · branch `feature/weak-spots-study-notes`

## Why
Study Packs already quiz a learner, but the result vanished when the tab closed, and a good session left nothing to take away. These two features close the loop: **what you got wrong comes back as video**, and **every session leaves a study sheet you can keep**.

## What shipped
1. **Weak spots** (`src/lib/weak-spots.ts`, `src/components/WeakSpots.tsx`, Saved page): every quiz answer is recorded on this device (`saved.ts`). A wrong answer adds the question (newest first, no duplicates, 50 max); a right answer clears it. The Saved page lists each one with the correct answer, the teacher's explanation and a link to the second it is explained, plus **one Cloudinary reel** (`fl_splice`) of exactly those explanations across sessions, each clip labelled with its question. "I've got this" dismisses one. Nothing leaves the device.
2. **Study notes** (`/notes/[id]`, `GET /api/lectures/[id]/notes`, `src/lib/notes.ts`): a sheet per session built from the Study Pack and the AI chapters: summary, key concepts, chapters, and the quiz with answers. **Every point is linked to its timestamp.** Copy it as Markdown (Notion, Obsidian, a study group chat), download the `.md`, or print / save as PDF (the site header and footer are hidden when printing). The Markdown carries absolute links, so they work wherever it is pasted. It has its own share card. No AI call: it is instant and cannot contradict the session. The Watch page links to it.

## Decisions
- Weak spots live in `localStorage`, like Saved moments: no account, no tracking, works offline from the Saved page. The cost is that they don't follow a learner to another device. Accounts would fix that, but they aren't worth the privacy cost here.
- Notes are built, not generated: a sheet that only reorganises verified Study Pack content can't hallucinate. A session with chapters but no Study Pack still gets a useful sheet; one with neither returns 404.
- The weak-spot reel reuses `reelUrl()`, so it inherits the 5-clip / 90-second cap and data saver.

## Verification
- 13 new unit tests (`weak-spots`, `notes`).
- In a real browser against the real library: a wrong answer on a session's quiz appears under Weak spots on `/saved` with a reel; "I've got this" clears it. `/notes/[id]` renders 9 timestamp links; the Markdown export returns `text/markdown` with a `.md` attachment name; a bad id returns 404.
12 changes: 12 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,15 @@ paths:
responses:
'200': { description: Assets with tags and contextual metadata, content: { application/json: { schema: { type: object } } } }
'401': { description: Not an organizer }
/lectures/{id}/notes:
get:
summary: A session's study notes, every point linked to its timestamp
operationId: getStudyNotes
security: [{}]
parameters:
- { name: id, in: path, required: true, schema: { type: string, format: uuid } }
- { name: format, in: query, required: false, schema: { type: string, enum: [md] }, description: 'md returns Markdown instead of JSON' }
- { name: download, in: query, required: false, schema: { type: string }, description: 'With format=md, send as an attachment' }
responses:
'200': { description: Notes as JSON, or Markdown with format=md, content: { application/json: { schema: { type: object } }, text/markdown: { schema: { type: string } } } }
'404': { description: No notes for this session, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
19 changes: 19 additions & 0 deletions src/app/api/lectures/[id]/notes/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NextResponse } from "next/server";

import { apiError } from "@/lib/http";
import { notesFilename, notesToMarkdown } from "@/lib/notes";
import { loadNotes } from "@/lib/notes-data";

export const dynamic = "force-dynamic";

// A session's study notes: JSON by default, or `?format=md` for Markdown (`&download=1` as a file).
export async function GET(request: Request, { params }: { params: Promise<{ id: string }> }) {
const loaded = await loadNotes((await params).id);
if (!loaded) return apiError(404, "not_found", "No study notes for this session.");
const { searchParams } = new URL(request.url);
if (searchParams.get("format") !== "md") return NextResponse.json(loaded.notes);

const headers: Record<string, string> = { "Content-Type": "text/markdown; charset=utf-8" };
if (searchParams.get("download")) headers["Content-Disposition"] = `attachment; filename="${notesFilename(loaded.notes.title)}"`;
return new NextResponse(notesToMarkdown(loaded.notes), { headers });
}
4 changes: 2 additions & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
Skip to content
</a>
<SiteChrome>
<header className="sticky top-0 z-30 border-b border-transparent bg-bg/80 backdrop-blur supports-[backdrop-filter]:bg-bg/70">
<header className="sticky top-0 z-30 print:hidden border-b border-transparent bg-bg/80 backdrop-blur supports-[backdrop-filter]:bg-bg/70">
<nav aria-label="Main" className="mx-auto flex max-w-280 items-center justify-between px-4 py-3">
<Link href="/" className="flex items-center gap-2 text-lg font-semibold tracking-tight">
<LogoMark />
Expand Down Expand Up @@ -84,7 +84,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
{children}
</main>
<SiteChrome>
<footer className="border-t border-border">
<footer className="border-t border-border print:hidden">
<div className="mx-auto flex max-w-280 flex-col gap-2 px-4 py-6 text-sm text-muted sm:flex-row sm:items-center sm:justify-between">
<p className="flex items-center gap-2">
<LogoMark className="size-5" />
Expand Down
137 changes: 137 additions & 0 deletions src/app/notes/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import type { Metadata } from "next";
import Link from "next/link";
import { notFound } from "next/navigation";

import { NotesActions } from "@/components/NotesActions";
import { formatTime } from "@/lib/format";
import { posterTime, SHARE_CARD, shareCardUrl } from "@/lib/media";
import { notesToMarkdown } from "@/lib/notes";
import { loadNotes } from "@/lib/notes-data";

export const dynamic = "force-dynamic";

type Props = { params: Promise<{ id: string }> };

export async function generateMetadata({ params }: Props): Promise<Metadata> {
const loaded = await loadNotes((await params).id);
if (!loaded) return { title: "Notes not found — Pravaha" };
const { lecture, notes } = loaded;
const image = shareCardUrl(lecture.publicId, posterTime(lecture.durationS), { title: notes.title, subtitle: "Study notes with timestamps" });
const description = `Study notes for “${notes.title}”: summary, key concepts, chapters and a quiz, every point linked to its second.`;
return {
title: `Study notes: ${notes.title} — Pravaha`,
description,
robots: { index: false, follow: true },
openGraph: {
type: "article",
siteName: "Pravaha",
title: `Study notes: ${notes.title}`,
description,
url: `/notes/${lecture.id}`,
images: [{ url: image, ...SHARE_CARD, alt: notes.title }],
},
twitter: { card: "summary_large_image", title: `Study notes: ${notes.title}`, images: [image] },
};
}

// Relative links on the page; the Markdown export carries absolute ones.
const rel = (url: string) => url.replace(/^https?:\/\/[^/]+/, "");

export default async function NotesPage({ params }: Props) {
const { id } = await params;
const loaded = await loadNotes(id);
if (!loaded) notFound();
const { lecture, notes } = loaded;
const stamp = (label: string, url: string) => (
<Link
href={rel(url)}
className="tabular rounded bg-accent/10 px-1.5 py-0.5 text-xs font-semibold text-accent hover:bg-accent/20 print:bg-transparent print:px-0"
>
{label}
</Link>
);
const h2 = "mt-8 text-sm font-semibold tracking-wide text-muted uppercase";
const meta = [notes.speaker, notes.durationS ? formatTime(notes.durationS) : null].filter(Boolean).join(" · ");

return (
<article className="mx-auto mt-6 max-w-3xl">
<p className="text-sm font-semibold tracking-wide text-accent uppercase print:hidden">Study notes</p>
<h1 className="mt-1 text-3xl font-semibold tracking-tight text-balance">{notes.title}</h1>
<p className="mt-1 text-muted">
{meta}
{meta ? " · " : ""}
<Link href={`/watch/${lecture.id}`} className="font-medium text-accent hover:underline">
Watch the session
</Link>
</p>
<NotesActions markdown={notesToMarkdown(notes)} downloadHref={`/api/lectures/${lecture.id}/notes?format=md&download=1`} />

{notes.summary.length > 0 && (
<section>
<h2 className={h2}>In short</h2>
<ul className="mt-2 space-y-1.5">
{notes.summary.map((s) => (
<li key={s} className="flex gap-2">
<span aria-hidden className="text-accent">
•
</span>
{s}
</li>
))}
</ul>
</section>
)}

{notes.concepts.length > 0 && (
<section>
<h2 className={h2}>Key concepts</h2>
<ul className="mt-2 space-y-1.5">
{notes.concepts.map((c) => (
<li key={`${c.name}-${c.t}`} className="flex items-center gap-2">
<span className="font-medium">{c.name}</span>
{stamp(c.label, c.url)}
</li>
))}
</ul>
</section>
)}

{notes.chapters.length > 0 && (
<section>
<h2 className={h2}>Chapters</h2>
<ol className="mt-2 space-y-1.5">
{notes.chapters.map((c) => (
<li key={`${c.title}-${c.t}`} className="flex items-baseline gap-2">
{stamp(c.label, c.url)}
<span>{c.title}</span>
</li>
))}
</ol>
</section>
)}

{notes.quiz.length > 0 && (
<section>
<h2 className={h2}>Check yourself</h2>
<ol className="mt-2 space-y-4">
{notes.quiz.map((q, i) => (
<li key={q.question} className="break-inside-avoid">
<p className="font-medium">
{i + 1}. {q.question}
</p>
<p className="mt-1 text-sm">
<span className="font-semibold">Answer:</span> {q.answer}
</p>
<p className="mt-0.5 flex flex-wrap items-center gap-2 text-sm text-muted">
{q.explanation} {stamp(q.label, q.url)}
</p>
</li>
))}
</ol>
</section>
)}

<p className="mt-10 text-xs text-muted">Made with Pravaha: ask your recordings, watch the answer.</p>
</article>
);
}
8 changes: 8 additions & 0 deletions src/app/watch/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ export default async function WatchPage({ params, searchParams }: Props) {
<p className="mt-1 text-muted">
{lecture.speaker ?? "Unknown speaker"}
{lecture.durationS ? <span className="tabular"> · {formatTime(lecture.durationS)}</span> : null}
{ready && segments.length > 0 && (
<>
{" · "}
<Link href={`/notes/${lecture.id}`} className="font-medium text-accent hover:underline">
Study notes
</Link>
</>
)}
</p>
</header>
{trialHoursLeft !== null && (
Expand Down
33 changes: 33 additions & 0 deletions src/components/NotesActions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use client";

import { useState } from "react";

// Copy as Markdown, download the .md file, or print / save as PDF. Hidden when printing.
export function NotesActions({ markdown, downloadHref }: { markdown: string; downloadHref: string }) {
const [copied, setCopied] = useState(false);

async function copy() {
try {
await navigator.clipboard.writeText(markdown);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch {
// Clipboard blocked: the download button still works.
}
}

const btn = "rounded-lg border border-border px-3 py-1.5 text-sm font-medium hover:border-accent";
return (
<div className="mt-4 flex flex-wrap gap-2 print:hidden">
<button type="button" onClick={copy} className={btn} aria-live="polite">
{copied ? "Copied" : "Copy as Markdown"}
</button>
<a href={downloadHref} download className={btn}>
Download .md
</a>
<button type="button" onClick={() => window.print()} className={btn}>
Print / Save as PDF
</button>
</div>
);
}
8 changes: 7 additions & 1 deletion src/components/SavedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
import Image from "next/image";
import Link from "next/link";

import { WeakSpots } from "@/components/WeakSpots";
import { useLiteUrl } from "@/lib/data-saver";
import { formatTime } from "@/lib/format";
import { thumbUrl } from "@/lib/media";
import { clearSaved, toggleSavedMoment, useRecentQuestions, useSavedMoments, useWatchProgress } from "@/lib/saved";
import { clearSaved, toggleSavedMoment, useRecentQuestions, useSavedMoments, useWatchProgress, useWeakSpots } from "@/lib/saved";

// The learner's Saved page: everything here lives on this device (src/lib/saved.ts).
export function SavedView() {
const lt = useLiteUrl();
const moments = useSavedMoments();
const questions = useRecentQuestions();
const progress = useWatchProgress();
const weak = useWeakSpots();

return (
<div className="space-y-10">
Expand All @@ -25,6 +27,10 @@ export function SavedView() {
)}
</Section>

<Section title="Weak spots" count={weak.length} onClear={() => clearSaved("weak")}>
<WeakSpots />
</Section>

<Section title="Saved moments" count={moments.length} onClear={() => clearSaved("moments")}>
{moments.length === 0 ? (
<Empty>Tap Save on any answer clip or search result to keep the moment here.</Empty>
Expand Down
Loading
Loading