Skip to content
Draft
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
33 changes: 0 additions & 33 deletions assets/academic_ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -400,36 +400,3 @@ div.st-key-create_course_button button > div > span { justify-content: flex-star
padding: .75rem 0;
}
}

.flight-waypoints {
display: flex;
position: relative;
justify-content: space-between;
align-items: center;
min-height: 2.35rem;
max-width: 38rem;
isolation: isolate;
}
.flight-waypoints::before {
content: "";
position: absolute;
z-index: -1;
inset: 50% .4rem auto;
border-top: 1px dashed #aaa284;
}
.flight-waypoint {
display: grid;
place-items: center;
width: .56rem;
height: .56rem;
border: 1px solid #a49a7e;
border-radius: 50%;
background: var(--flight-paper);
}
.flight-waypoint.is-current {
width: 2.25rem;
height: 2.25rem;
color: #985831;
border-color: #d7ad8e;
font-size: 1.25rem;
}
16 changes: 15 additions & 1 deletion assets/paper_practice.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,24 @@
min-width: 0;
}
/* Markdown pulls the next block up by 1rem; these hold no paragraph, so keep them centred. */
.st-key-flight_practice_progress [data-testid="stMarkdownContainer"]:has(> :is(.flight-clock, .flight-waypoints)) {
.st-key-flight_practice_progress [data-testid="stMarkdownContainer"]:has(> :is(.flight-clock, .flight-route)) {
margin-bottom: 0;
}

.flight-route {
display: block;
width: min(100%, 38rem);
height: auto;
margin-inline: auto;
}

@media (max-width: 560px) {
.st-key-flight_practice_progress > [data-testid="stLayoutWrapper"]:has(> .st-key-flight_progress_track) {
order: 1;
flex: 1 0 100%;
}
}

/* Session clock: a small paper box. The text is the server value; where the
browser can, CSS counts on from it every second while the clock runs. */
.flight-clock {
Expand Down
115 changes: 48 additions & 67 deletions assets/paper_shell.css
Original file line number Diff line number Diff line change
Expand Up @@ -738,93 +738,74 @@ label[data-baseweb="radio"]:focus-within {
border-color: #D9CFC2 !important;
}

/* ---- Loading: a paper plane instead of a spinner --------------------------- */
/* The brand plane (assets/brand-plane.svg), inlined so the sheet stays one file. */
/* ---- Loading: the paper plane over the center of the page ----------------- */
:root {
/* The brand plane (assets/brand-plane.svg), inlined for the shared loader. */
--paper-plane: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 480 348'%3E%3Cpolygon points='28,158 436,34 140,212' fill='%23F4B45B'/%3E%3Cpolygon points='436,34 238,302 150,224' fill='%235F849F'/%3E%3Cpolygon points='126,230 170,256 130,296' fill='%235F849F'/%3E%3C/svg%3E");
--paper-loading-trail: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='192' height='56' viewBox='0 0 192 56'%3E%3Cpath d='M 8 32 C 34 0 60 6 93 27 S 151 56 184 22' fill='none' stroke='%238F8266' stroke-width='1.4' stroke-linecap='round' stroke-dasharray='2 5'/%3E%3C/svg%3E");
}

/* Out and back along a short track, turning round at each end. */
@keyframes paper-plane-patrol {
0% { transform: translate(0, 0) scaleX(1); }
22% { transform: translate(1.4rem, -.25rem) scaleX(1); }
45% { transform: translate(2.8rem, 0) scaleX(1); }
50% { transform: translate(2.8rem, 0) scaleX(-1); }
72% { transform: translate(1.4rem, -.25rem) scaleX(-1); }
95% { transform: translate(0, 0) scaleX(-1); }
100% { transform: translate(0, 0) scaleX(1); }
}

/* The same trip across the whole window. */
@keyframes paper-plane-crossing {
0% { transform: translate(8vw, 0) scaleX(1); }
24% { transform: translate(46vw, -.25rem) scaleX(1); }
47% { transform: translate(calc(92vw - 1.6rem), 0) scaleX(1); }
50% { transform: translate(calc(92vw - 1.6rem), 0) scaleX(-1); }
74% { transform: translate(46vw, -.25rem) scaleX(-1); }
97% { transform: translate(8vw, 0) scaleX(-1); }
100% { transform: translate(8vw, 0) scaleX(1); }
}

/* st.spinner: the round spinner gives way to the plane on its track. The
icon's holder is widened to the track, so the message starts after it. */
[data-testid="stSpinner"] span:has(> [data-testid="stSpinnerIcon"]) {
flex-shrink: 0;
justify-content: flex-start;
width: 4.9rem;
height: 1.5rem;
[data-testid="stMain"] {
anchor-name: --paper-loading-main;
}

[data-testid="stSpinner"] [data-testid="stSpinnerIcon"] {
position: relative;
flex-shrink: 0;
width: 4.9rem;
height: 1.5rem;
border: 0;
border-radius: 0;
animation: none;
/* Keep the spinner messages and run status available while replacing their icons. */
[data-testid="stSpinnerIcon"],
[data-testid="stStatusWidgetRunningIcon"] {
color: transparent;
opacity: 0;
}

[data-testid="stSpinner"] [data-testid="stSpinnerIcon"]::after {
[data-testid="stApp"]:has(:is([data-testid="stSpinner"], [data-testid="stStatusWidgetRunningIcon"])) [data-testid="stAppViewContainer"]::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 2.1rem;
height: 1.5rem;
position: fixed;
inset: 0;
/* Modern browsers center the effect in the learning area with the sidebar open. */
left: anchor(--paper-loading-main left, 0px);
right: anchor(--paper-loading-main right, 0px);
z-index: 100;
pointer-events: none;
background: rgba(251, 246, 237, .52) var(--paper-loading-trail) center / 192px 56px no-repeat;
backdrop-filter: blur(3px);
animation: paper-loading-veil .18s ease-out .16s both;
}

[data-testid="stApp"]:has(:is([data-testid="stSpinner"], [data-testid="stStatusWidgetRunningIcon"]))::after {
content: "";
position: fixed;
top: calc(50% - 28px);
left: calc(50% - 96px);
left: calc(anchor(--paper-loading-main center, 50%) - 96px);
z-index: 101;
pointer-events: none;
width: 38px;
height: 28px;
background: var(--paper-plane) center / contain no-repeat;
animation: paper-plane-patrol 2s ease-in-out infinite;
/* Same coordinates as the visible dashed trail. */
offset-path: path("M 8 32 C 34 0 60 6 93 27 S 151 56 184 22");
offset-rotate: auto 24deg;
animation: paper-loading-flight 2.7s ease-in-out .16s infinite both;
}

/* While the app is working, the plane crosses the window just under the
header controls, and Streamlit's own running figure (which would sit
behind the avatar) is hidden. Streamlit shows that state only after half
a second, so quick updates do not flash it. A spinner on the page already
has its own plane, so this one stays away then. */
[data-testid="stStatusWidgetRunningIcon"] {
display: none;
@keyframes paper-loading-veil {
from { opacity: 0; }
to { opacity: 1; }
}

[data-testid="stApp"]:has([data-testid="stStatusWidgetRunningIcon"]):not(:has([data-testid="stSpinner"])) [data-testid="stHeader"]::after {
content: "";
position: absolute;
top: 3.2rem;
left: 0;
width: 1.6rem;
height: 1.15rem;
background: var(--paper-plane) center / contain no-repeat;
pointer-events: none;
animation: paper-plane-crossing 3.6s ease-in-out infinite;
@keyframes paper-loading-flight {
0% { offset-distance: 0%; opacity: 0; }
12%, 85% { opacity: 1; }
100% { offset-distance: 100%; opacity: 0; }
}

/* Reduced motion: the plane is shown, parked. */
/* Keep a single, still paper plane on the path with reduced motion enabled. */
@media (prefers-reduced-motion: reduce) {
[data-testid="stSpinner"] [data-testid="stSpinnerIcon"]::after {
[data-testid="stApp"]:has(:is([data-testid="stSpinner"], [data-testid="stStatusWidgetRunningIcon"])) [data-testid="stAppViewContainer"]::after {
animation: none;
}

[data-testid="stApp"]:has([data-testid="stStatusWidgetRunningIcon"]):not(:has([data-testid="stSpinner"])) [data-testid="stHeader"]::after {
left: calc(50vw - .8rem);
[data-testid="stApp"]:has(:is([data-testid="stSpinner"], [data-testid="stStatusWidgetRunningIcon"]))::after {
offset-distance: 50%;
animation: none;
}
}
93 changes: 93 additions & 0 deletions components/flight_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"""Responsive paper-plane route for the practice worksheet."""

from base64 import b64encode
from functools import lru_cache
from math import cos, pi, sin

from services.ui_style import BRAND_PLANE


@lru_cache(maxsize=1)
def _plane() -> str:
return BRAND_PLANE.read_text(encoding="utf-8").replace(
"<svg ", '<svg x="-19" y="-14" width="38" height="28" ', 1
).strip()


def _point(fraction: float) -> tuple[float, float]:
x = 24 + 372 * fraction
y = 29 + 11 * sin(4 * pi * fraction - 0.28) + 3 * sin(2 * pi * fraction)
return x, y


def _slope(fraction: float) -> float:
"""Vertical change per unit of route fraction, for matching curve tangents."""
return 44 * pi * cos(4 * pi * fraction - 0.28) + 6 * pi * cos(2 * pi * fraction)


def _coordinates(point: tuple[float, float]) -> str:
return f"{point[0]:.2f} {point[1]:.2f}"


def _trail(stops: list[float]) -> str:
path = f"M {_coordinates(_point(stops[0]))}"
for start, end in zip(stops, stops[1:]):
x0, y0 = _point(start)
x1, y1 = _point(end)
handle = (end - start) / 3
path += (
f" C {_coordinates((x0 + 372 * handle, y0 + _slope(start) * handle))}"
f" {_coordinates((x1 - 372 * handle, y1 - _slope(end) * handle))}"
f" {_coordinates((x1, y1))}"
)
return path


def practice_route(count: int, index: int, previous: int | None = None) -> str:
"""Produce an SVG image that can animate from either neighboring question."""
stops = [step / (count - 1) for step in range(count)] if count > 1 else [0.5]
# A short exercise still follows the same curves as a long one. Keep each
# question on a spline vertex by including its fraction in the full route.
bends = sorted(set(stops) | {step / 8 for step in range(9)})
completed = [stop for stop in bends if stop <= stops[index]]
x, y = _point(stops[index])
dots = []
for step, fraction in enumerate(stops):
cx, cy = _point(fraction)
radius = 5 if step == index else (2.7 if count <= 16 else 1.45)
fill = "#FAF4EA" if step >= index else "#AD673C"
stroke = "#9B582F" if step == index else "#8F8266"
dots.append(
f'<circle cx="{cx:.2f}" cy="{cy:.2f}" r="{radius}" fill="{fill}" '
f'stroke="{stroke}" stroke-width=".9"/>'
)
paths = ""
if count > 1:
paths = (
f'<path d="{_trail(bends)}" stroke="#A3987A" stroke-width="1.35" stroke-dasharray="3.5 4.7"/>'
f'<path d="{_trail(completed)}" stroke="#AD673C" stroke-width="1.65" stroke-dasharray="3.5 4.7"/>'
)

plane = _plane()
parked = f'<g class="parked" transform="translate({x:.2f} {y:.2f})">{plane}</g>'
motion = ""
if previous is not None and 0 <= previous < count and previous != index:
start, end = stops[previous], stops[index]
lower, upper = sorted((start, end))
trip = [stop for stop in bends if lower <= stop <= upper]
if start > end:
trip.reverse()
motion = (
'<g class="flying">'
f'<animateMotion dur=".66s" fill="freeze" rotate="auto" path="{_trail(trip)}"/>'
f'<g transform="rotate(24)">{plane}</g></g>'
'<style>.parked{display:none}'
'@media (prefers-reduced-motion:reduce){.parked{display:inline}.flying{display:none}}</style>'
)

svg = (
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 420 58">'
f'<g fill="none" stroke-linecap="round">{paths}</g>{"".join(dots)}{parked}{motion}</svg>'
)
source = b64encode(svg.encode("utf-8")).decode("ascii")
return f'<img class="flight-route" alt="" src="data:image/svg+xml;base64,{source}">'
12 changes: 4 additions & 8 deletions pages/2_Practice_Center.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)
from services.auth_session import current_user
from services import learning_radar
from components.flight_path import practice_route
from components.knowledge_graph import load_course_radar, render_topic_radar
from components.page_links import open_page_button
from services.learning_flow import install_practice, remember_widget, hydrate_widgets, open_lab
Expand Down Expand Up @@ -226,6 +227,7 @@ def move_question(practice_key, session_id, step):
target = max(0, min(len(questions) - 1, current + step))
if target == current:
return
active["worksheet_previous_index"] = current
active["worksheet_index"] = target
# Read once by the next render: it names the page-turn (see paper_practice.css).
active["worksheet_move"] = "next" if step > 0 else "prev"
Expand Down Expand Up @@ -448,15 +450,9 @@ def render_question_screen(course, active, topic_names):
with st.container(key="flight_progress_count", width="content"):
st.caption(tr("Question") + f" {index + 1:02} / {len(questions):02}")
with st.container(key="flight_progress_track"):
stops = min(len(questions), 12)
current_stop = index * (stops - 1) // max(1, len(questions) - 1)
markers = "".join(
'<span class="flight-waypoint is-current">✈</span>' if step == current_stop
else '<span class="flight-waypoint"></span>'
for step in range(stops)
)
previous = active.pop("worksheet_previous_index", None)
st.markdown(
f'<div class="flight-waypoints" aria-hidden="true">{markers}</div>',
practice_route(len(questions), index, previous),
unsafe_allow_html=True,
)
with st.container(
Expand Down
44 changes: 44 additions & 0 deletions tests/test_paper_practice.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
"""Paper practice page: question card, one-click choices, Learning Radar and clean wording."""
import ast
from base64 import b64decode
import re
import sys
from pathlib import Path
from types import ModuleType
from xml.etree import ElementTree

import pytest
import streamlit as st
from streamlit.testing.v1 import AppTest

import components
from components.flight_path import practice_route
from components.knowledge_graph import radar_count_text
from models.schemas import ExamSession, Question
from services import practice_insights_ui
Expand Down Expand Up @@ -110,6 +113,47 @@ def test_badge_is_translated_with_the_interface():
assert badges(app) == ["第 1 题"]


def route_svg(markup):
source = re.search(r"data:image/svg\+xml;base64,([A-Za-z0-9+/=]+)", markup)
assert source
return ElementTree.fromstring(b64decode(source.group(1)))


def test_paper_plane_follows_the_same_dotted_route_forward_and_back():
app, _ = start_app()

def current_route():
return route_svg(next(value for value in page_markdown(app) if 'class="flight-route"' in value))

svg = "{http://www.w3.org/2000/svg}"
assert current_route().find(f".//{svg}animateMotion") is None
app.button(key="worksheet_next_s").click().run()
route = current_route()
dots = route.findall(f"{svg}circle")
left = f"{dots[0].get('cx')} {dots[0].get('cy')}"
right = f"{dots[1].get('cx')} {dots[1].get('cy')}"
forward = route.find(f".//{svg}animateMotion").get("path")
assert forward.startswith(f"M {left} C ") and forward.endswith(right)
trail = route.find(f".//{svg}path")
assert trail.get("d").startswith(forward)
assert trail.get("stroke-dasharray")
assert route.find(f".//{svg}polygon").get("fill") == "#F4B45B"

app.button(key="worksheet_previous_s").click().run()
back = current_route().find(f".//{svg}animateMotion").get("path")
assert back.startswith(f"M {right} C ") and back.endswith(left)
app.run()
assert current_route().find(f".//{svg}animateMotion") is None


def test_the_paper_route_has_one_stop_per_question():
svg = "{http://www.w3.org/2000/svg}"
for count in (1, 50):
route = route_svg(practice_route(count, count - 1))
assert len(route.findall(f"{svg}circle")) == count
assert route.find(f".//{svg}animateMotion") is None


# 2 · Confidence in one click ---------------------------------------------

def test_confidence_is_one_click_and_survives_worksheet_paging():
Expand Down
Loading
Loading