@shaxpir/duiduidui-models 1.7.2 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,7 +34,7 @@ export declare class Metric extends Content {
34
34
  get maxDate(): CompactDate;
35
35
  get length(): number;
36
36
  get(index: number): MetricEntry;
37
- sumBetween(minDate: CompactDate, maxDate: CompactDate): number;
37
+ sumBetween(minDate?: CompactDate | null, maxDate?: CompactDate | null): number;
38
38
  forDate(date: CompactDate): number;
39
39
  nonZeroDayCount(): number;
40
40
  setDateAmount(date: CompactDate, amount: number): void;
@@ -97,8 +97,16 @@ class Metric extends Content_1.Content {
97
97
  }
98
98
  sumBetween(minDate, maxDate) {
99
99
  this.checkDisposed("Metric.sumBetween");
100
+ // Use payload min/max dates as defaults for null parameters
101
+ const effectiveMinDate = minDate || this.payload.min_date;
102
+ const effectiveMaxDate = maxDate || this.payload.max_date;
103
+ // If we still don't have dates (empty metric), return 0
104
+ if (!effectiveMinDate || !effectiveMaxDate) {
105
+ return 0;
106
+ }
107
+ // Sum between the effective dates
100
108
  let sum = 0;
101
- const dates = shaxpir_common_1.Time.datesBetween(minDate, maxDate);
109
+ const dates = shaxpir_common_1.Time.datesBetween(effectiveMinDate, effectiveMaxDate);
102
110
  for (let i = 0, len = dates.length; i < len; i++) {
103
111
  const date = dates[i];
104
112
  sum += this.forDate(date);
@@ -30,6 +30,7 @@ export interface ProgressPayload {
30
30
  skill_level: UncertainValue;
31
31
  cognitive_load: number;
32
32
  streaks?: StreakData;
33
+ total_review_count: number;
33
34
  }
34
35
  export interface ProgressBody extends ContentBody {
35
36
  meta: ContentMeta;
@@ -55,4 +56,6 @@ export declare class Progress extends Content {
55
56
  setCognitiveLoad(value: number): void;
56
57
  getStreaks(): StreakData | undefined;
57
58
  setStreaks(streaks: StreakData): void;
59
+ getTotalReviewCount(): number;
60
+ setTotalReviewCount(count: number): void;
58
61
  }
@@ -31,7 +31,8 @@ class Progress extends Content_1.Content {
31
31
  upper: 1000 // Could potentially be advanced
32
32
  }
33
33
  },
34
- cognitive_load: 0
34
+ cognitive_load: 0,
35
+ total_review_count: 0 // Start with zero lifetime reviews
35
36
  }
36
37
  });
37
38
  }
@@ -134,5 +135,17 @@ class Progress extends Content_1.Content {
134
135
  batch.commit();
135
136
  }
136
137
  }
138
+ getTotalReviewCount() {
139
+ this.checkDisposed("Progress.getTotalReviewCount");
140
+ return this.payload.total_review_count;
141
+ }
142
+ setTotalReviewCount(count) {
143
+ this.checkDisposed("Progress.setTotalReviewCount");
144
+ if (this.payload.total_review_count !== count) {
145
+ const batch = new Operation_1.BatchOperation(this);
146
+ batch.setPathValue(['payload', 'total_review_count'], count);
147
+ batch.commit();
148
+ }
149
+ }
137
150
  }
138
151
  exports.Progress = Progress;
@@ -23,7 +23,7 @@ export interface SessionConfig {
23
23
  auto_play_speech?: boolean;
24
24
  };
25
25
  }
26
- export interface SessionMetrics {
26
+ export interface SessionStats {
27
27
  skill_level: UncertainValue;
28
28
  cognitive_load: number;
29
29
  theta_distribution: {
@@ -58,9 +58,9 @@ export interface SessionPayload {
58
58
  is_complete: boolean;
59
59
  app_version?: string;
60
60
  config?: SessionConfig;
61
- metrics?: {
62
- before?: SessionMetrics;
63
- after?: SessionMetrics;
61
+ stats?: {
62
+ before?: SessionStats;
63
+ after?: SessionStats;
64
64
  };
65
65
  }
66
66
  export interface SessionBody extends ContentBody {
@@ -87,10 +87,10 @@ export declare class Session extends Content {
87
87
  setConfig(config: SessionConfig): void;
88
88
  get isComplete(): boolean;
89
89
  markComplete(): void;
90
- get metricsBefore(): SessionMetrics | undefined;
91
- setMetricsBefore(metrics: SessionMetrics): void;
92
- get metricsAfter(): SessionMetrics | undefined;
93
- setMetricsAfter(metrics: SessionMetrics): void;
90
+ get statsBefore(): SessionStats | undefined;
91
+ setStatsBefore(stats: SessionStats): void;
92
+ get statsAfter(): SessionStats | undefined;
93
+ setStatsAfter(stats: SessionStats): void;
94
94
  isActive(): boolean;
95
95
  get appVersion(): string | undefined;
96
96
  setAppVersion(version: string): void;
@@ -8,6 +8,7 @@ const Content_1 = require("./Content");
8
8
  const ContentKind_1 = require("./ContentKind");
9
9
  const Metric_1 = require("./Metric");
10
10
  const Operation_1 = require("./Operation");
11
+ const Progress_1 = require("./Progress");
11
12
  const Workspace_1 = require("./Workspace");
12
13
  class Session extends Content_1.Content {
13
14
  constructor(doc, shouldAcquire, shareSync) {
@@ -128,30 +129,30 @@ class Session extends Content_1.Content {
128
129
  batch.setPathValue(['payload', 'is_complete'], true);
129
130
  batch.commit();
130
131
  }
131
- get metricsBefore() {
132
- this.checkDisposed("Session.metricsBefore");
133
- return this.payload.metrics?.before;
132
+ get statsBefore() {
133
+ this.checkDisposed("Session.statsBefore");
134
+ return this.payload.stats?.before;
134
135
  }
135
- setMetricsBefore(metrics) {
136
- this.checkDisposed("Session.setMetricsBefore");
136
+ setStatsBefore(stats) {
137
+ this.checkDisposed("Session.setStatsBefore");
137
138
  const batch = new Operation_1.BatchOperation(this);
138
- if (!this.payload.metrics) {
139
- batch.setPathValue(['payload', 'metrics'], {});
139
+ if (!this.payload.stats) {
140
+ batch.setPathValue(['payload', 'stats'], {});
140
141
  }
141
- batch.setPathValue(['payload', 'metrics', 'before'], metrics);
142
+ batch.setPathValue(['payload', 'stats', 'before'], stats);
142
143
  batch.commit();
143
144
  }
144
- get metricsAfter() {
145
- this.checkDisposed("Session.metricsAfter");
146
- return this.payload.metrics?.after;
145
+ get statsAfter() {
146
+ this.checkDisposed("Session.statsAfter");
147
+ return this.payload.stats?.after;
147
148
  }
148
- setMetricsAfter(metrics) {
149
- this.checkDisposed("Session.setMetricsAfter");
149
+ setStatsAfter(stats) {
150
+ this.checkDisposed("Session.setStatsAfter");
150
151
  const batch = new Operation_1.BatchOperation(this);
151
- if (!this.payload.metrics) {
152
- batch.setPathValue(['payload', 'metrics'], {});
152
+ if (!this.payload.stats) {
153
+ batch.setPathValue(['payload', 'stats'], {});
153
154
  }
154
- batch.setPathValue(['payload', 'metrics', 'after'], metrics);
155
+ batch.setPathValue(['payload', 'stats', 'after'], stats);
155
156
  batch.commit();
156
157
  }
157
158
  isActive() {
@@ -201,7 +202,14 @@ class Session extends Content_1.Content {
201
202
  const reviewCountMetricId = Metric_1.Metric.makeMetricId(userId, Metric_1.MetricName.REVIEW_COUNT);
202
203
  const reviewCountMetric = await shareSync.acquire(ContentKind_1.ContentKind.METRIC, reviewCountMetricId);
203
204
  reviewCountMetric.setDateAmount(date, reviewCountOnDate);
205
+ // Calculate total review count using sumBetween with null arguments (sums all entries)
206
+ const totalReviewCount = reviewCountMetric.sumBetween(null, null);
204
207
  reviewCountMetric.release();
208
+ // Update total review count in Progress
209
+ const progressId = Progress_1.Progress.makeProgressId(userId);
210
+ const progress = await shareSync.acquire(ContentKind_1.ContentKind.PROGRESS, progressId);
211
+ progress.setTotalReviewCount(totalReviewCount);
212
+ progress.release();
205
213
  }
206
214
  }
207
215
  exports.Session = Session;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"