commit 29d004212803942be0a68913dfcba3ec7cc30660
parent 1c46f13c71e2f65ffccd2f53f7122cd61c527de9
Author: Jean Schurger <jean@schurger.org>
Date: Sat, 14 Nov 2026 00:16:12 -0500
Readable statistics: years without gaps, dives per month, labelled depth and duration bars
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K7deYG3yp7VDUZJzSBkvTc
Diffstat:
3 files changed, 110 insertions(+), 23 deletions(-)
diff --git a/App/Model/AppModel.swift b/App/Model/AppModel.swift
@@ -39,6 +39,18 @@ final class AppModel {
await startDemo()
return
}
+ #if DEBUG
+ // Essais dans le simulateur sur un vrai carnet : identifiants passés par l'environnement, jamais en version publiée.
+ let environment = ProcessInfo.processInfo.environment
+ if let devEmail = environment["DEV_CLOUD_EMAIL"], let devPassword = environment["DEV_CLOUD_PASSWORD"] {
+ do {
+ try await signIn(email: devEmail, password: devPassword)
+ } catch {
+ phase = .signedOut
+ }
+ return
+ }
+ #endif
let saved = UserDefaults.standard.string(forKey: "email") ?? ""
guard !saved.isEmpty, let secret = Keychain.password(account: saved) else {
phase = .signedOut
diff --git a/App/Views/StatsView.swift b/App/Views/StatsView.swift
@@ -8,12 +8,61 @@ struct StatsView: View {
private struct Bucket: Identifiable {
let id: String
let count: Int
+ var label: String?
+ var name: String { label ?? id }
+ }
+
+ /// Colonnes : une par catégorie, le nombre écrit au-dessus, sans axe vertical (les nombres suffisent).
+ private func columns(_ buckets: [Bucket], label: String) -> some View {
+ let top = Double(max(buckets.map(\.count).max() ?? 1, 1))
+ return Chart(buckets) { bucket in
+ BarMark(x: .value(label, bucket.id), y: .value("Plongées", bucket.count), width: .ratio(0.72))
+ .foregroundStyle(Color.accentColor.gradient)
+ .cornerRadius(4)
+ .annotation(position: .top, spacing: 3) {
+ if bucket.count > 0 {
+ Text("\(bucket.count)").font(.caption.monospacedDigit().weight(.medium)).foregroundStyle(.secondary)
+ }
+ }
+ }
+ .chartYScale(domain: 0...(top * 1.12))
+ .chartYAxis(.hidden)
+ .chartXAxis {
+ AxisMarks { value in
+ AxisValueLabel {
+ if let id = value.as(String.self) {
+ Text(buckets.first { $0.id == id }?.name ?? id).font(.caption)
+ }
+ }
+ }
+ }
+ }
+
+ /// Barres horizontales : le nom de la tranche à gauche, le nombre au bout de la barre.
+ private func rows(_ buckets: [Bucket], label: String) -> some View {
+ let top = Double(max(buckets.map(\.count).max() ?? 1, 1))
+ return Chart(buckets) { bucket in
+ BarMark(x: .value("Plongées", bucket.count), y: .value(label, bucket.id), height: .fixed(20))
+ .foregroundStyle(Color.accentColor.gradient)
+ .cornerRadius(4)
+ .annotation(position: .trailing, spacing: 5) {
+ Text("\(bucket.count)").font(.caption.monospacedDigit().weight(.medium)).foregroundStyle(.secondary)
+ }
+ }
+ .chartXScale(domain: 0...(top * 1.15))
+ .chartXAxis(.hidden)
+ .chartYAxis {
+ AxisMarks(preset: .extended, position: .leading) { _ in
+ AxisValueLabel().font(.callout).foregroundStyle(Color.primary)
+ }
+ }
}
var body: some View {
NavigationStack {
let dives = model.logbook.dives.filter { !$0.invalid }
let units = model.units
+ ScrollViewReader { proxy in
List {
if dives.isEmpty {
ContentUnavailableView("Pas encore de statistiques", systemImage: "chart.bar",
@@ -41,38 +90,55 @@ struct StatsView: View {
}
Section("Plongées par année") {
- let years = Dictionary(grouping: dives, by: { DiveDate.year($0.when) })
- .map { Bucket(id: String($0.key), count: $0.value.count) }
- .sorted { $0.id < $1.id }
- Chart(years) { bucket in
- BarMark(x: .value("Année", bucket.id), y: .value("Plongées", bucket.count))
- .foregroundStyle(Color.accentColor.gradient)
- .annotation(position: .top) {
- Text("\(bucket.count)").font(.caption2).foregroundStyle(.secondary)
- }
- }
- .frame(height: 170)
- .padding(.vertical, 6)
+ EmptyView().id("years")
+ // Toutes les années de la première à la dernière, y compris celles sans plongée.
+ let counts = Dictionary(grouping: dives, by: { DiveDate.year($0.when) }).mapValues(\.count)
+ let span = (counts.keys.min() ?? 0)...(counts.keys.max() ?? 0)
+ let years = span.map { Bucket(id: span.count > 10 ? "’" + String(format: "%02d", $0 % 100) : String($0), count: counts[$0] ?? 0) }
+ columns(years, label: "Année")
+ .frame(height: 190)
+ .padding(.vertical, 6)
+ .accessibilityLabel("Nombre de plongées par année")
+ }
+
+ Section("Plongées par mois") {
+ EmptyView().id("months")
+ let counts = Dictionary(grouping: dives, by: { NaiveTime.components($0.when).month ?? 0 }).mapValues(\.count)
+ let initials = ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"]
+ // L'identifiant porte le rang du mois : plusieurs mois ont la même initiale.
+ let months = (1...12).map { Bucket(id: "\($0)", count: counts[$0] ?? 0, label: initials[$0 - 1]) }
+ columns(months, label: "Mois")
+ .frame(height: 170)
+ .padding(.vertical, 6)
+ .accessibilityLabel("Nombre de plongées par mois de l'année")
}
Section("Profondeur maximale") {
+ EmptyView().id("depth")
let step = units.imperial ? 30.0 : 10.0
let grouped = Dictionary(grouping: dives, by: { Int(units.depthValue($0.maxDepth) / step) })
let buckets = (0...(grouped.keys.max() ?? 0)).map { index in
- Bucket(id: "\(Int(Double(index) * step))–\(Int(Double(index + 1) * step))", count: grouped[index]?.count ?? 0)
+ Bucket(id: "\(Int(Double(index) * step)) à \(Int(Double(index + 1) * step)) \(units.depthUnit)", count: grouped[index]?.count ?? 0)
}
- Chart(buckets) { bucket in
- BarMark(x: .value("Plongées", bucket.count), y: .value("Profondeur (\(units.depthUnit))", bucket.id))
- .foregroundStyle(Color.accentColor.gradient)
- .annotation(position: .trailing) {
- if bucket.count > 0 { Text("\(bucket.count)").font(.caption2).foregroundStyle(.secondary) }
- }
- }
- .frame(height: CGFloat(max(buckets.count, 2)) * 30)
- .padding(.vertical, 6)
+ rows(buckets, label: "Profondeur")
+ .frame(height: CGFloat(buckets.count) * 36 + 8)
+ .padding(.vertical, 6)
+ .accessibilityLabel("Nombre de plongées par tranche de profondeur")
+ }
+
+ Section("Durée") {
+ EmptyView().id("duration")
+ let grouped = Dictionary(grouping: dives, by: { min($0.durationSeconds / 60 / 15, 5) })
+ let names = ["moins de 15 min", "15 à 30 min", "30 à 45 min", "45 à 60 min", "60 à 75 min", "75 min et plus"]
+ let buckets = (0...(grouped.keys.max() ?? 0)).map { Bucket(id: names[$0], count: grouped[$0]?.count ?? 0) }
+ rows(buckets, label: "Durée")
+ .frame(height: CGFloat(buckets.count) * 36 + 8)
+ .padding(.vertical, 6)
+ .accessibilityLabel("Nombre de plongées par tranche de durée")
}
Section("Gaz") {
+ EmptyView().id("gas")
let gases = Dictionary(grouping: dives.filter { !$0.cylinders.isEmpty }, by: { gasFamily($0) })
ForEach(gases.keys.sorted(), id: \.self) { family in
LabeledContent(family, value: "\(gases[family]?.count ?? 0)")
@@ -101,6 +167,13 @@ struct StatsView: View {
}
}
.listStyle(.insetGrouped)
+ .onAppear {
+ // Option de capture d'écran : montrer une section plus bas.
+ if let target = LaunchOptions.value("-statsScroll") {
+ DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { proxy.scrollTo(target, anchor: .top) }
+ }
+ }
+ }
.navigationTitle("Statistiques")
}
}
diff --git a/Makefile b/Makefile
@@ -26,12 +26,14 @@ test: project
SIM ?= DiveLog test iPhone
ARGS ?=
DEMO ?= -demo
+# Variables d'environnement passées à l'app (SIMCTL_CHILD_NOM=valeur), par exemple pour un vrai carnet.
+SIMENV ?=
SHOT ?= shot
WAIT ?= 4
APP_ID = org.schurger.subrascasse
.PHONY: shot
shot:
- @ssh $(CHUNGA) 'cd $(REMOTE) && xcrun simctl bootstatus "$(SIM)" -b >/dev/null && xcrun simctl install "$(SIM)" build/Build/Products/Debug-iphonesimulator/DiveLog.app && (xcrun simctl terminate "$(SIM)" $(APP_ID) 2>/dev/null; true) && xcrun simctl launch "$(SIM)" $(APP_ID) $(DEMO) -AppleLanguages "(fr)" -AppleLocale fr_CA $(ARGS) >/dev/null && sleep $(WAIT) && mkdir -p build/shots && xcrun simctl io "$(SIM)" screenshot build/shots/$(SHOT).png 2>/dev/null && sips -Z 1100 build/shots/$(SHOT).png --out build/shots/$(SHOT)-small.png >/dev/null'
+ @ssh $(CHUNGA) 'cd $(REMOTE) && xcrun simctl bootstatus "$(SIM)" -b >/dev/null && xcrun simctl install "$(SIM)" build/Build/Products/Debug-iphonesimulator/DiveLog.app && (xcrun simctl terminate "$(SIM)" $(APP_ID) 2>/dev/null; true) && $(SIMENV) xcrun simctl launch "$(SIM)" $(APP_ID) $(DEMO) -AppleLanguages "(fr)" -AppleLocale fr_CA $(ARGS) >/dev/null && sleep $(WAIT) && mkdir -p build/shots && xcrun simctl io "$(SIM)" screenshot build/shots/$(SHOT).png 2>/dev/null && sips -Z 1100 build/shots/$(SHOT).png --out build/shots/$(SHOT)-small.png >/dev/null'
@mkdir -p build/shots && scp -q $(CHUNGA):$(REMOTE)/build/shots/$(SHOT)-small.png build/shots/$(SHOT).png
# Archive signée pour TestFlight (signature automatique, clé API perso de chunga). BUILD=n fixe le numéro ;