krz/daybyday

iOS learning games for young children: days, months, seasons, numbers, letters, animals and more. education ios kids swift https://krz.sh/apps/daybyday/

Commit b2cde9506e

b2cde9506e5f9e5700e960bd080b415fabad404f

parent: 5007a40ca8

Unsigned

cmc <hello@cleberg.net> · 2026-10-17 02:46 UTC

Part 7: Adaptive review and parent screen (!9)

Closes #7

- `ItemProgress`: per child and topic, each item is new, learning (missed, fewer than 3 counted right answers since) or known (2+ counted right, no open miss). The right answer that retries a missed question within 60 s doesn't count. Only recognition games count (find it, listen, odd one out, comes next, which season, and answers from before part 2).
- `QuestionPicker` and `OddOneOut` pick answers by weight (learning 3, others 1). With no weights the pick is unchanged. `GameDestination` passes the current child's weights to find it, listen and odd one out.
- `ProgressSummary` and `ChildProgressView`: a "Progress" section in the gated parent area. Per topic: "Knows all 7 days.", "Knows 5 of 12 months.", "Still mixing up June, July and August.", "Just started.", "Not played yet." Letters show in capitals; more than 4 missed items end with "and N more".
- No entity changes.

Reviews: code review found nothing blocking. Fixed: other games distorting statuses, a blank row for a topic with one right answer, a weights map that was never empty. The screen review blocked on the "abc" symbol overflowing its circle; fixed.

Not addressed:
- `ChildProgressView` scans the child's answers once per topic (11 times) per render.
- `GameDestination` recomputes weights after each answer, because answers are observed.

203 tests pass.

Layout: unified · split

DayByDay/Parent/ChildProgressView.swift added +44
@@ -0,0 +1,44 @@
1//
2// ChildProgressView.swift
3// DayByDay
4//
5
6import SwiftUI
7
8/// For grown-ups: what one child knows and is still mixing up, per topic.
9struct ChildProgressView: View {
10 let profile: Profile
11
12 @Environment(ProfileSession.self) private var session
13
14 var body: some View {
15 List(DayByDay.Category.gridCases) { category in
16 let summary = ProgressSummary(category: category, progress: session.store.progress(for: profile, category: category))
17 HStack(alignment: .top, spacing: 14) {
18 // A fixed box, so wide symbols such as "abc" stay inside the circle.
19 Image(systemName: category.symbol)
20 .resizable()
21 .scaledToFit()
22 .fontWeight(.semibold)
23 .frame(width: 24, height: 24)
24 .foregroundStyle(.white)
25 .frame(width: 44, height: 44)
26 .background(Circle().fill(category.color))
27 VStack(alignment: .leading, spacing: 4) {
28 Text(category.label)
29 .font(.system(size: 20, weight: .semibold, design: .rounded))
30 if let known = summary.known {
31 Text(known)
32 }
33 if let missing = summary.missing {
34 Text(missing)
35 .fontWeight(.semibold)
36 }
37 }
38 }
39 .padding(.vertical, 4)
40 .accessibilityElement(children: .combine)
41 }
42 .navigationTitle("\(profile.name)'s progress")
43 }
44}
DayByDay/Parent/ParentAreaView.swift +13 −1
@@ -5,7 +5,8 @@
55
66import SwiftUI
77
8/// Grown-up screen for adding, editing, and deleting profiles.
8/// Grown-up screen for adding, editing, and deleting profiles, and for
9/// each child's progress.
910struct ParentAreaView: View {
1011 let onDone: () -> Void
1112
@@ -32,6 +33,17 @@ struct ParentAreaView: View {
3233 Label("Add a child", systemImage: "plus.circle.fill")
3334 }
3435 }
36 if !session.profiles.isEmpty {
37 Section("Progress") {
38 ForEach(session.profiles) { profile in
39 NavigationLink {
40 ChildProgressView(profile: profile)
41 } label: {
42 ProfileRow(profile: profile)
43 }
44 }
45 }
46 }
3547 }
3648 .navigationTitle("Grown-Ups")
3749 .toolbar {
DayByDay/Parent/ProgressSummary.swift added +61
@@ -0,0 +1,61 @@
1//
2// ProgressSummary.swift
3// DayByDay
4//
5
6nonisolated extension Category {
7 /// "Knows 5 of 7 days."
8 var progressNoun: String {
9 switch self {
10 case .today, .days: "days"
11 case .months: "months"
12 case .seasons: "seasons"
13 case .numbers: "numbers"
14 case .colors: "colors"
15 case .shapes: "shapes"
16 case .animals: "animals"
17 case .alphabet: "letters"
18 case .weather: "kinds of weather"
19 case .bodyParts: "body parts"
20 case .food: "foods"
21 }
22 }
23}
24
25/// One child's progress in one topic, in plain words for a parent.
26nonisolated struct ProgressSummary {
27 static let listLimit = 4
28
29 let known: String?
30 let missing: String?
31
32 init(category: Category, progress: ItemProgress) {
33 let items = category.quizItems
34 guard items.contains(where: { progress.statuses[$0.id] != nil }) else {
35 known = "Not played yet."
36 missing = nil
37 return
38 }
39 let knownCount = items.filter { progress.status($0.id) == .known }.count
40 let noun = category.progressNoun
41 let knownLine: String? = switch knownCount {
42 case items.count: "Knows all \(items.count) \(noun)."
43 case 0: nil
44 default: "Knows \(knownCount) of \(items.count) \(noun)."
45 }
46 // Letter items are named lowercase for speech; parents read capitals.
47 let learning = items.filter { progress.status($0.id) == .learning }
48 .map { category == .alphabet ? $0.name.uppercased() : $0.name }
49 missing = learning.isEmpty ? nil : "Still mixing up \(Self.list(learning))."
50 known = knownLine ?? (missing == nil ? "Just started." : nil)
51 }
52
53 /// "A", "A and B", "A, B and C", "A, B, C, D and 2 more".
54 static func list(_ names: [String]) -> String {
55 if names.count > listLimit {
56 return names.prefix(listLimit).joined(separator: ", ") + " and \(names.count - listLimit) more"
57 }
58 guard names.count > 1 else { return names.first ?? "" }
59 return names.dropLast().joined(separator: ", ") + " and " + names.last!
60 }
61}
DayByDay/Profiles/ItemProgress.swift added +64
@@ -0,0 +1,64 @@
1//
2// ItemProgress.swift
3// DayByDay
4//
5
6import Foundation
7
8/// One answer, as `ItemProgress` needs it.
9nonisolated struct AnswerFact: Equatable {
10 /// The question's answer.
11 let itemID: String
12 let isCorrect: Bool
13 let timestamp: Date
14}
15
16nonisolated enum ItemStatus: Equatable {
17 case new, learning, known
18}
19
20/// How one child is doing with each item in a topic. A missed item stays
21/// learning until it is answered right `clearAfter` times; the right answer
22/// that just retries the missed question does not count.
23nonisolated struct ItemProgress {
24 static let retryWindow: TimeInterval = 60
25 static let clearAfter = 3
26 static let knownAfter = 2
27 static let learningWeight = 3.0
28
29 private(set) var statuses: [String: ItemStatus] = [:]
30 private(set) var lastMiss: [String: Date] = [:]
31
32 init(_ facts: [AnswerFact]) {
33 var counted: [String: Int] = [:]
34 var awaitingRetry: Set<String> = []
35 for fact in facts.sorted(by: { $0.timestamp < $1.timestamp }) {
36 let id = fact.itemID
37 if !fact.isCorrect {
38 lastMiss[id] = fact.timestamp
39 counted[id] = 0
40 awaitingRetry.insert(id)
41 } else if awaitingRetry.remove(id) != nil,
42 let miss = lastMiss[id], fact.timestamp.timeIntervalSince(miss) < Self.retryWindow {
43 continue
44 } else {
45 counted[id, default: 0] += 1
46 }
47 }
48 for (id, count) in counted {
49 if lastMiss[id] != nil && count < Self.clearAfter {
50 statuses[id] = .learning
51 } else {
52 statuses[id] = count >= Self.knownAfter ? .known : .new
53 }
54 }
55 }
56
57 func status(_ itemID: String) -> ItemStatus {
58 statuses[itemID] ?? .new
59 }
60
61 func weight(_ itemID: String) -> Double {
62 status(itemID) == .learning ? Self.learningWeight : 1
63 }
64}
DayByDay/Profiles/ProfileStore.swift +21
@@ -77,6 +77,27 @@ final class ProfileStore {
7777 .sorted { $0.timestamp < $1.timestamp }
7878 }
7979
80 /// Games where an answer shows whether the child recognizes the item.
81 /// Tracing, sorting, ordering and comparing are left out. Answers with
82 /// no game were recorded before part 2 and are kept.
83 static let recognitionGames: Set<String> = Set([Game.findIt, .listen, .oddOneOut, .comesNext, .whichSeason].map(\.rawValue))
84
85 func progress(for profile: Profile, category: Category) -> ItemProgress {
86 ItemProgress(answers(for: profile, category: category)
87 .filter { $0.gameRaw.map(Self.recognitionGames.contains) ?? true }
88 .map { AnswerFact(itemID: $0.itemID, isCorrect: $0.isCorrect, timestamp: $0.timestamp) })
89 }
90
91 /// Pick weights for the topic's items the child is missing; the rest
92 /// weigh 1. Empty when nothing is being missed.
93 func reviewWeights(for profile: Profile, category: Category) -> [QuizItem: Double] {
94 let progress = progress(for: profile, category: category)
95 return Dictionary(uniqueKeysWithValues: category.quizItems.compactMap { item in
96 let weight = progress.weight(item.id)
97 return weight > 1 ? (item, weight) : nil
98 })
99 }
100
80101 /// Days per month in a leap year, so February 29 birthdays are allowed.
81102 static let daysInMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
82103
DayByDay/Quiz/Game.swift +18 −4
@@ -104,11 +104,13 @@ nonisolated extension Category {
104104 return games
105105 }
106106
107 func questionSource(for game: Game) -> any QuestionSource {
107 /// `weights` favor answers the child has been missing; only the pick-one
108 /// games use them.
109 func questionSource(for game: Game, weights: [QuizItem: Double] = [:]) -> any QuestionSource {
108110 switch game {
109 case .findIt: findIt
110 case .oddOneOut: oddOneOut
111 case .listen: listen
111 case .findIt: with(findIt, weights)
112 case .oddOneOut: with(oddOneOut, weights)
113 case .listen: with(listen, weights)
112114 case .comesNext: ComesNext(items: quizItems, noun: self == .days ? "day" : "month")
113115 case .whichSeason: WhichSeason()
114116 case .most: Most()
@@ -172,6 +174,18 @@ nonisolated extension Category {
172174 }
173175 }
174176
177 private func with(_ picker: QuestionPicker, _ weights: [QuizItem: Double]) -> QuestionPicker {
178 var picker = picker
179 picker.weights = weights
180 return picker
181 }
182
183 private func with(_ source: OddOneOut, _ weights: [QuizItem: Double]) -> OddOneOut {
184 var source = source
185 source.weights = weights
186 return source
187 }
188
175189 private func items<T: CaseIterable>(_ values: [T]) -> [QuizItem] {
176190 values.map { item($0) }
177191 }
DayByDay/Quiz/GameDestination.swift +12 −3
@@ -10,19 +10,28 @@ struct GameDestination: View {
1010 let category: Category
1111 let game: Game
1212
13 @Environment(ProfileSession.self) private var session
14
1315 var body: some View {
1416 content.navigationTitle(game.title)
1517 }
1618
19 /// Weights as of this render: the open round keeps its first question,
20 /// and the next round uses the latest answers.
21 private var source: any QuestionSource {
22 let weights = session.current.map { session.store.reviewWeights(for: $0, category: category) } ?? [:]
23 return category.questionSource(for: game, weights: weights)
24 }
25
1726 @ViewBuilder
1827 private var content: some View {
1928 switch game {
2029 case .most:
21 RoundView(source: category.questionSource(for: game), game: game) { PileTile(item: $0) }
30 RoundView(source: source, game: game) { PileTile(item: $0) }
2231 case .dressUp:
23 RoundView(source: category.questionSource(for: game), game: game) { ClothingTile(item: $0) }
32 RoundView(source: source, game: game) { ClothingTile(item: $0) }
2433 case .findIt, .oddOneOut, .listen, .comesNext, .whichSeason, .mixColors:
25 RoundView(source: category.questionSource(for: game), game: game) { ChoiceTile(item: $0) }
34 RoundView(source: source, game: game) { ChoiceTile(item: $0) }
2635 case .weekTrain:
2736 SequencePuzzleView(game: game) {
2837 var rng = SystemRandomNumberGenerator()
DayByDay/Quiz/Question.swift +20 −2
@@ -31,6 +31,8 @@ nonisolated struct QuestionPicker: QuestionSource {
3131 let distractors: [QuizItem]
3232 let prompt: (QuizItem) -> String
3333 let sound: (QuizItem) -> SoundEffect?
34 /// Answer pick weights; unlisted items weigh 1. Empty picks evenly.
35 var weights: [QuizItem: Double] = [:]
3436
3537 init(answers: [QuizItem], distractors: [QuizItem]? = nil,
3638 prompt: @escaping (QuizItem) -> String,
@@ -46,7 +48,7 @@ nonisolated struct QuestionPicker: QuestionSource {
4648 /// distinct distractors, shuffled.
4749 func next(correctCount: Int, excluding previous: QuizItem?, using rng: inout some RandomNumberGenerator) -> Question {
4850 let candidates = answers.count > 1 ? answers.filter { $0 != previous } : answers
49 let answer = candidates.randomElement(using: &rng)!
51 let answer = weights.isEmpty ? candidates.randomElement(using: &rng)! : candidates.weightedRandom(weights, using: &rng)
5052 let others = distractors.filter { $0 != answer }.shuffled(using: &rng)
5153 let count = min(Round.choiceCount(correctCount: correctCount), others.count + 1)
5254 let choices = ([answer] + others.prefix(count - 1)).shuffled(using: &rng)
@@ -65,6 +67,8 @@ nonisolated struct OddOneOut: QuestionSource {
6567 }
6668
6769 let groups: (Group, Group)
70 /// Answer pick weights; unlisted items weigh 1. Empty picks evenly.
71 var weights: [QuizItem: Double] = [:]
6872
6973 init(_ a: Group, _ b: Group) {
7074 groups = (a, b)
@@ -80,7 +84,7 @@ nonisolated struct OddOneOut: QuestionSource {
8084 }
8185 let (majority, odd) = fitting.randomElement(using: &rng)!
8286 let candidates = odd.members.count > 1 ? odd.members.filter { $0 != previous } : odd.members
83 let answer = candidates.randomElement(using: &rng)!
87 let answer = weights.isEmpty ? candidates.randomElement(using: &rng)! : candidates.weightedRandom(weights, using: &rng)
8488 let others = Array(majority.members.shuffled(using: &rng).prefix(count - 1))
8589 var facts = [answer: odd.fact(answer)]
8690 for item in others { facts[item] = majority.fact(item) }
@@ -89,3 +93,17 @@ nonisolated struct OddOneOut: QuestionSource {
8993 answer: answer, facts: facts)
9094 }
9195}
96
97nonisolated extension Array where Element == QuizItem {
98 /// A non-empty array's element, chosen in proportion to its weight
99 /// (1 when unlisted).
100 func weightedRandom(_ weights: [QuizItem: Double], using rng: inout some RandomNumberGenerator) -> QuizItem {
101 let total = reduce(0) { $0 + weights[$1, default: 1] }
102 var target = Double.random(in: 0..<total, using: &rng)
103 for item in self {
104 target -= weights[item, default: 1]
105 if target < 0 { return item }
106 }
107 return last!
108 }
109}
DayByDayTests/ItemProgressTests.swift added +64
@@ -0,0 +1,64 @@
1import Foundation
2import Testing
3@testable import DayByDay
4
5struct ItemProgressTests {
6 let start = Date(timeIntervalSince1970: 1_800_000_000)
7
8 /// `(id, correct, seconds after start)`.
9 func progress(_ answers: [(String, Bool, TimeInterval)]) -> ItemProgress {
10 ItemProgress(answers.map { AnswerFact(itemID: $0.0, isCorrect: $0.1, timestamp: start + $0.2) })
11 }
12
13 @Test func untouchedIsNew() {
14 #expect(progress([]).status("monday") == .new)
15 }
16
17 @Test func oneRightIsNew() {
18 #expect(progress([("monday", true, 0)]).status("monday") == .new)
19 }
20
21 @Test func twoRightIsKnown() {
22 #expect(progress([("monday", true, 0), ("monday", true, 300)]).status("monday") == .known)
23 }
24
25 @Test func missIsLearning() {
26 #expect(progress([("june", false, 0)]).status("june") == .learning)
27 }
28
29 @Test func threeRightClearsMiss() {
30 let p = progress([("june", false, 0), ("june", true, 300), ("june", true, 600), ("june", true, 900)])
31 #expect(p.status("june") == .known)
32 let two = progress([("june", false, 0), ("june", true, 300), ("june", true, 600)])
33 #expect(two.status("june") == .learning)
34 }
35
36 @Test func retryDoesNotCount() {
37 var answers: [(String, Bool, TimeInterval)] = [("june", false, 0), ("june", true, 5), ("june", true, 300), ("june", true, 600)]
38 #expect(progress(answers).status("june") == .learning)
39 answers.append(("june", true, 900))
40 #expect(progress(answers).status("june") == .known)
41 }
42
43 @Test func newMissReopens() {
44 let answers = (0..<5).map { ("july", true, TimeInterval($0) * 300) } + [("july", false, 2000)]
45 #expect(progress(answers).status("july") == .learning)
46 }
47
48 @Test func weights() {
49 let p = progress([("june", false, 0), ("july", true, 0), ("july", true, 300)])
50 #expect(p.weight("june") == 3)
51 #expect(p.weight("july") == 1)
52 #expect(p.weight("august") == 1)
53 }
54
55 @Test func lastMissIsMostRecent() {
56 let p = progress([("june", false, 0), ("june", true, 300), ("june", false, 600)])
57 #expect(p.lastMiss["june"] == start + 600)
58 }
59
60 @Test func unorderedInput() {
61 let p = progress([("june", true, 900), ("june", true, 300), ("june", false, 0), ("june", true, 600)])
62 #expect(p.status("june") == .known)
63 }
64}
DayByDayTests/ProfileStoreTests.swift +28
@@ -81,4 +81,32 @@ struct ProfileStoreTests {
8181 #expect(records.map(\.chosenID) == ["days.monday", nil])
8282 #expect(records.map(\.gameRaw) == ["findIt", nil])
8383 }
84
85 @Test func storeReviewWeights() throws {
86 let s = store
87 let a = try s.create(name: "A", avatar: .cat, color: .red, birthday: nil)
88 let b = try s.create(name: "B", avatar: .dog, color: .blue, birthday: nil)
89 let monday = Category.days.item(DayOfWeek.monday)
90 s.record(monday, correct: false, for: a)
91 #expect(s.reviewWeights(for: a, category: .days) == [monday: 3])
92 #expect(s.reviewWeights(for: b, category: .days).isEmpty)
93 #expect(s.progress(for: a, category: .days).status(monday.id) == .learning)
94 }
95
96 @Test func progressCountsOnlyRecognitionGames() throws {
97 let s = store
98 let a = try s.create(name: "A", avatar: .cat, color: .red, birthday: nil)
99 let b = Category.alphabet.item(LearnLetter.b)
100 s.record(b, game: .trace, correct: false, for: a)
101 let monday = Category.days.item(DayOfWeek.monday)
102 s.record(monday, game: .weekTrain, correct: true, for: a)
103 s.record(monday, game: .weekTrain, correct: true, for: a)
104 #expect(s.progress(for: a, category: .alphabet).status(b.id) == .new)
105 #expect(s.progress(for: a, category: .days).status(monday.id) == .new)
106 s.record(b, game: .findIt, correct: false, for: a)
107 #expect(s.progress(for: a, category: .alphabet).status(b.id) == .learning)
108 let june = Category.months.item(MonthOfYear.june)
109 s.record(june, correct: false, for: a)
110 #expect(s.progress(for: a, category: .months).status(june.id) == .learning)
111 }
84112}
DayByDayTests/ProgressSummaryTests.swift added +68
@@ -0,0 +1,68 @@
1import Foundation
2import Testing
3@testable import DayByDay
4
5struct ProgressSummaryTests {
6 let start = Date(timeIntervalSince1970: 1_800_000_000)
7
8 /// Each known item gets two right answers; each missed item one miss.
9 func summary(_ category: DayByDay.Category, known: [Int] = [], missed: [Int] = [], extra: [AnswerFact] = []) -> ProgressSummary {
10 let items = category.quizItems
11 var facts = extra
12 for i in known {
13 facts += [AnswerFact(itemID: items[i].id, isCorrect: true, timestamp: start),
14 AnswerFact(itemID: items[i].id, isCorrect: true, timestamp: start + 300)]
15 }
16 for i in missed {
17 facts.append(AnswerFact(itemID: items[i].id, isCorrect: false, timestamp: start + Double(i)))
18 }
19 return ProgressSummary(category: category, progress: ItemProgress(facts))
20 }
21
22 @Test func notPlayed() {
23 let s = summary(.food)
24 #expect(s.known == "Not played yet.")
25 #expect(s.missing == nil)
26 }
27
28 @Test func knowsAll() {
29 let s = summary(.seasons, known: [0, 1, 2, 3])
30 #expect(s.known == "Knows all 4 seasons.")
31 #expect(s.missing == nil)
32 }
33
34 @Test func knowsSome() {
35 #expect(summary(.days, known: [0, 1, 2, 3, 4]).known == "Knows 5 of 7 days.")
36 #expect(summary(.weather, known: [0]).known?.hasSuffix("kinds of weather.") == true)
37 }
38
39 @Test func mixingUpList() {
40 let s = summary(.months, known: [0], missed: [7, 5, 6])
41 #expect(s.known == "Knows 1 of 12 months.")
42 #expect(s.missing == "Still mixing up June, July and August.")
43 #expect(summary(.months, missed: [5]).known == nil)
44 }
45
46 @Test func twoItemsUseAnd() {
47 #expect(summary(.days, missed: [3, 4]).missing == "Still mixing up Wednesday and Thursday.")
48 #expect(summary(.days, missed: [4]).missing == "Still mixing up Thursday.")
49 }
50
51 @Test func longListTruncates() {
52 let s = summary(.alphabet, missed: [1, 3, 15, 16, 20, 21])
53 #expect(s.missing == "Still mixing up B, D, P, Q and 2 more.")
54 }
55
56 @Test func unknownIDsIgnored() {
57 let old = [AnswerFact(itemID: "lizard", isCorrect: false, timestamp: start)]
58 #expect(summary(.animals, extra: old).known == "Not played yet.")
59 #expect(summary(.animals, known: [0], extra: old).missing == nil)
60 }
61
62 @Test func justStarted() {
63 let once = [AnswerFact(itemID: DayByDay.Category.days.quizItems[1].id, isCorrect: true, timestamp: start)]
64 let s = summary(.days, extra: once)
65 #expect(s.known == "Just started.")
66 #expect(s.missing == nil)
67 }
68}
DayByDayTests/ReviewExport.swift +13
@@ -88,6 +88,18 @@ struct ReviewExport {
8888 for (d, w) in [(1, LearnWeather.sunny), (2, .cloudy), (5, .rainy), (9, .windy), (12, .snowy), (15, .sunny)] {
8989 session.store.addSticker(for: maya, on: DateComponents(year: 2026, month: 10, day: d), weather: w)
9090 }
91 let days = DayByDay.Category.days.quizItems, months = DayByDay.Category.months.quizItems
92 let t = Date(timeIntervalSince1970: 1_800_000_000)
93 for (i, day) in days.enumerated() {
94 session.store.record(day, correct: true, for: maya, at: t + Double(i) * 300)
95 session.store.record(day, correct: true, for: maya, at: t + 5000 + Double(i) * 300)
96 }
97 for (i, month) in months.enumerated() where i < 5 {
98 session.store.record(month, correct: true, for: maya, at: t + Double(i) * 300)
99 session.store.record(month, correct: true, for: maya, at: t + 5000 + Double(i) * 300)
100 }
101 for month in months[5...7] { session.store.record(month, correct: false, for: maya, at: t + 9000) }
102 session.store.record(DayByDay.Category.alphabet.quizItems[1], correct: false, for: maya, at: t)
91103 session.profilesChanged()
92104 }
93105 var rng = SeededGenerator(seed: 1)
@@ -113,6 +125,7 @@ struct ReviewExport {
113125 ("calendar", AnyView(StickerCalendarView(profile: session.current, now: DateComponents(calendar: .current, year: 2026, month: 10, day: 16).date!))),
114126 ("banner", AnyView(TodayBanner().padding())),
115127 ("picker", AnyView(ProfilePickerView())),
128 ("parent-progress", AnyView(NavigationStack { ChildProgressView(profile: session.profiles[0]) })),
116129 ("welcome", AnyView(ProfileSetupView())),
117130 ("finished", AnyView(FinishedView {})),
118131 ("find-days", AnyView(RoundView(source: DayByDay.Category.days.questionSource(for: .findIt), game: .findIt) { ChoiceTile(item: $0) })),
DayByDayTests/RoundTests.swift +49
@@ -187,4 +187,53 @@ struct RoundTests {
187187 #expect(round.current.answer != days[3])
188188 }
189189 }
190
191 @Test func weightedPickFavorsLearning() {
192 var weighted = picker
193 weighted.weights = [days[3]: 3]
194 var rng = SeededGenerator(seed: 70)
195 let hits = (0..<2000).filter { _ in weighted.next(correctCount: 0, excluding: nil, using: &rng).answer == days[3] }.count
196 // 3 of 9 shares, against 1 of 7 unweighted.
197 #expect((500...900).contains(hits))
198 }
199
200 @Test func allLearningStillVaries() {
201 var weighted = picker
202 weighted.weights = Dictionary(uniqueKeysWithValues: days.map { ($0, 3.0) })
203 var rng = SeededGenerator(seed: 71)
204 let answers = Set((0..<200).map { _ in weighted.next(correctCount: 0, excluding: nil, using: &rng).answer })
205 #expect(answers.count == days.count)
206 }
207
208 @Test func weightsKeepPreviousRule() {
209 var weighted = picker
210 weighted.weights = [days[0]: 3]
211 var rng = SeededGenerator(seed: 72)
212 for _ in 0..<200 {
213 #expect(weighted.next(correctCount: 0, excluding: days[0], using: &rng).answer != days[0])
214 }
215 var single = QuestionPicker(answers: [days[0]], distractors: days) { $0.name }
216 single.weights = [days[0]: 3]
217 #expect(single.next(correctCount: 0, excluding: days[0], using: &rng).answer == days[0])
218 }
219
220 @Test func emptyWeightsMatchOldPicks() {
221 var a = SeededGenerator(seed: 73), b = SeededGenerator(seed: 73)
222 var unweighted = picker
223 unweighted.weights = [:]
224 for _ in 0..<50 {
225 #expect(picker.next(correctCount: 2, excluding: nil, using: &a) == unweighted.next(correctCount: 2, excluding: nil, using: &b))
226 }
227 }
228
229 @Test func oddOneOutUsesWeights() {
230 guard var source = Category.animals.questionSource(for: .oddOneOut) as? OddOneOut else {
231 Issue.record("not odd one out"); return
232 }
233 let bird = Category.animals.item(LearnAnimal.bird)
234 source.weights = [bird: 50]
235 var rng = SeededGenerator(seed: 74)
236 let hits = (0..<400).filter { _ in source.next(correctCount: 0, excluding: nil, using: &rng).answer == bird }.count
237 #expect(hits > 120)
238 }
190239}
docs/superpowers/plans/2026-10-16-part7-adaptive-review.md added +91
@@ -0,0 +1,91 @@
1# Part 7: Adaptive Review and Parent Screen Implementation Plan
2
3> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
5**Goal:** Missed items come up more often in "pick one" games until the child gets them right a few times, and a gated parent screen says per child and per topic what is known and what is still being missed, in plain words.
6
7**Architecture:** A pure `ItemProgress` reads one child's answers in one topic and gives each item a status (new, learning, known) plus a pick weight. `QuestionPicker` and `OddOneOut` take optional weights and pick answers with them. `GameDestination` reads the current child's weights from the store and passes them in. A pure `ProgressSummary` turns statuses into sentences; `ChildProgressView` lists them per topic inside the existing parent area.
8
9**Tech Stack:** SwiftUI, SwiftData, Swift Testing, Xcode 27.
10
11**Spec:** `docs/superpowers/specs/2026-10-16-learning-games-design.md` (part 7). Builds on the part 1–6 plans in this folder.
12
13## Global Constraints
14
15- iOS 17.5 target; `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor`; pure logic `nonisolated`.
16- No entity changes: everything is read from `AnswerRecord` (`itemID` is the question's answer, `isCorrect`, `timestamp`). No `VersionedSchema` needed in this part.
17- An item's misses count against the question's answer. A correct answer within 60 s after a miss of the same item is the retry of that question and does not count toward getting it right.
18- Learning: the item has a miss and fewer than 3 counted correct answers since its last miss. Known: no open miss and at least 2 counted correct answers. New: anything else.
19- Pick weight: learning 3, otherwise 1. With no weights, `QuestionPicker` and `OddOneOut` pick exactly as before (same RNG use), so existing seeded tests are unchanged.
20- "Never the previous answer when there is an alternative" still holds with weights.
21- Parent copy is plain and neutral, never scolding: "Knows all 7 days.", "Knows 5 of 7 days.", "Still mixing up June, July and August.", "Not played yet."
22- The parent screen is reached only from the gated parent area.
23- Branch `feat/adaptive-review`. Every commit `Ref #N` (last `Closes #N`). No AI attribution.
24- Test command: `xcodebuild test -project DayByDay.xcodeproj -scheme DayByDay -destination 'platform=iOS Simulator,name=iPhone 18 Pro'` (full suite ~10 min; run in background).
25
26## Review Focus
27
281. The retry after a wrong tap (same question, seconds later) must not count as a correct answer toward clearing the miss. Test `retryDoesNotCount` in Task 1.
292. A miss after earlier corrects reopens the item; corrects before the last miss do not count. Test `newMissReopens` in Task 1.
303. Every item in learning (weights all 3) and a one-item pool still pick, and never return the previous answer when another exists. Tests `allLearningStillVaries`, `weightsKeepPreviousRule` in Task 2.
314. Answers from items no longer in the topic (removed in an earlier part) are ignored, not listed by ID. Test `unknownIDsIgnored` in Task 3.
325. Long missed lists stay readable: more than 4 items list the first 4 in topic order and "and N more". Test `longListTruncates` in Task 3.
33
34---
35
36### Task 0: Branch and issue
37
38- [ ] `git checkout -b feat/adaptive-review main`; `gitbay issue create --title "Part 7: Adaptive review and parent screen" --json --file -` (#7); commit this plan with `Ref #N`.
39
40### Task 1: Item progress
41
42**Files:** Create `DayByDay/Profiles/ItemProgress.swift`. Test `DayByDayTests/ItemProgressTests.swift`.
43
44**Interfaces:**
45- `nonisolated struct AnswerFact: Equatable { let itemID: String; let isCorrect: Bool; let timestamp: Date }`.
46- `nonisolated enum ItemStatus: Equatable { case new, learning, known }`.
47- `nonisolated struct ItemProgress { static let retryWindow: TimeInterval = 60; static let clearAfter = 3; static let knownAfter = 2; static let learningWeight = 3.0; private(set) var statuses: [String: ItemStatus]; private(set) var lastMiss: [String: Date]; init(_ facts: [AnswerFact]); func status(_ itemID: String) -> ItemStatus; func weight(_ itemID: String) -> Double }`. Facts may arrive in any order; sort by timestamp.
48
49- [ ] Tests: `untouchedIsNew`, `twoRightIsKnown`, `oneRightIsNew`, `missIsLearning`, `threeRightClearsMiss` (miss, then 3 counted corrects → known), `retryDoesNotCount` (miss, correct 5 s later, 2 more corrects minutes apart → still learning; a third → known), `newMissReopens` (5 corrects, miss → learning), `weights` (learning 3, others 1), `unorderedInput`. RED, implement, GREEN, commit `feat: item progress from answers`.
50
51### Task 2: Weighted picks
52
53**Files:** Modify `DayByDay/Quiz/Question.swift`, `DayByDay/Quiz/Game.swift`, `DayByDay/Quiz/GameDestination.swift`, `DayByDay/Profiles/ProfileStore.swift`. Test `DayByDayTests/RoundTests.swift`, `DayByDayTests/ProfileStoreTests.swift`.
54
55**Interfaces:**
56- `QuestionPicker` and `OddOneOut` gain `var weights: [QuizItem: Double] = [:]`. When non-empty, the answer is drawn from the same candidates by weight (default 1 for unlisted items); when empty, the existing `randomElement` call is kept.
57- `nonisolated extension Array where Element == QuizItem { func weightedRandom(_ weights: [QuizItem: Double], using: inout some RandomNumberGenerator) -> QuizItem }` in `Question.swift`.
58- `Category.questionSource(for: Game, weights: [QuizItem: Double] = [:]) -> any QuestionSource`: findIt, oddOneOut and listen get the weights; the other sources ignore them.
59- `ProfileStore.progress(for: Profile, category: Category) -> ItemProgress` and `reviewWeights(for: Profile, category: Category) -> [QuizItem: Double]` (only items in `category.quizItems`).
60- `GameDestination` reads `ProfileSession` and passes `reviewWeights` for the current child.
61
62- [ ] Tests: `weightedPickFavorsLearning` (one of 7 days weighted 3: picked between 25% and 45% of 2000 seeded draws, against ~14% unweighted), `allLearningStillVaries`, `weightsKeepPreviousRule`, `emptyWeightsMatchOldPicks` (same seed, same answers with and without an empty map), `storeReviewWeights` (record a miss of Monday for one child → weight 3 for that child, 1 for a sibling). RED, implement, GREEN, commit `feat: missed items come up more often`.
63
64### Task 3: Progress summary
65
66**Files:** Create `DayByDay/Parent/ProgressSummary.swift`. Test `DayByDayTests/ProgressSummaryTests.swift`.
67
68**Interfaces:**
69- `nonisolated extension Category { var progressNoun: String }`: days, months, seasons, numbers, colors, shapes, animals, letters, kinds of weather, body parts, foods.
70- `nonisolated struct ProgressSummary { init(category: Category, progress: ItemProgress); let known: String?; let missing: String? }`; played means any of the topic's items has a status. Sentences:
71 - not played → `known = "Not played yet."`, `missing = nil`;
72 - all known → `"Knows all \(count) \(noun)."` (seasons: "Knows all 4 seasons.");
73 - some known → `"Knows \(k) of \(count) \(noun)."`; none known → nil;
74 - learning items in topic order → `"Still mixing up A, B and C."`; more than 4 → first 4 then `"and \(n) more."` ("Still mixing up A, B, C, D and 2 more.").
75- Item names come from `category.quizItems`; unknown IDs are ignored.
76
77- [ ] Tests: `notPlayed`, `knowsAll`, `knowsSome`, `mixingUpList` (June, July, August), `twoItemsUseAnd`, `longListTruncates`, `unknownIDsIgnored`. RED, implement, GREEN, commit `feat: progress summary`.
78
79### Task 4: Parent progress screen
80
81**Files:** Create `DayByDay/Parent/ChildProgressView.swift`. Modify `DayByDay/Parent/ParentAreaView.swift`.
82
83**Interfaces:**
84- `ParentAreaView`: a "Progress" section with one `NavigationLink` per child (`ProfileRow`) to `ChildProgressView(profile:)`.
85- `ChildProgressView(profile:)`: `List` of `Category.gridCases`, each row the topic symbol in a circle of its color (white symbol), the topic label, and the summary's lines (missing line in `.secondary` weight semibold). Title "\(name)'s progress".
86
87- [ ] Add `parent-progress` to `ReviewExport` with a seeded child who has known days, missed months and no food answers. Build, render light and dark, commit `feat: parent progress screen`.
88
89### Task 5: Reviews, MR, merge
90
91- [ ] Fresh whole-branch code reviewer with this Review Focus. Fresh reviewer for the parent screen render and copy (plain, neutral, readable in both modes). One fix pass, RED→GREEN. Full suite green. Push, MR `Closes #N`, squash-merge, delete the branch locally and on the remote.