@shaxpir/duiduidui-models 1.7.0 → 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;
@@ -6,7 +6,6 @@ import { Content, ContentBody, ContentId, ContentMeta, ContentRef } from "./Cont
6
6
  import { Review } from './Review';
7
7
  import { UncertainValue } from './Progress';
8
8
  export interface SessionConfig {
9
- version: number;
10
9
  constraints?: {
11
10
  card_limit?: number | null;
12
11
  time_limit?: number;
@@ -16,7 +15,6 @@ export interface SessionConfig {
16
15
  filters?: ConditionFilters;
17
16
  strategy?: {
18
17
  name: string;
19
- version?: string;
20
18
  constants?: Record<string, any>;
21
19
  };
22
20
  };
@@ -25,7 +23,7 @@ export interface SessionConfig {
25
23
  auto_play_speech?: boolean;
26
24
  };
27
25
  }
28
- export interface SessionMetrics {
26
+ export interface SessionStats {
29
27
  skill_level: UncertainValue;
30
28
  cognitive_load: number;
31
29
  theta_distribution: {
@@ -57,12 +55,13 @@ export interface SessionPayload {
57
55
  duration_minutes: number;
58
56
  reviews: Review[];
59
57
  review_count: number;
58
+ is_complete: boolean;
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
- is_complete?: boolean;
66
65
  }
67
66
  export interface SessionBody extends ContentBody {
68
67
  meta: ContentMeta;
@@ -73,7 +72,7 @@ export declare class Session extends Content {
73
72
  constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
74
73
  static makeSessionId(userId: ContentId): ContentId;
75
74
  static makeSessionRef(userId: ContentId, at: MultiTime): ContentRef;
76
- static create(userId: ContentId, deviceId: ContentId): Session;
75
+ static create(userId: ContentId, deviceId: ContentId, appVersion: string): Session;
77
76
  get payload(): SessionPayload;
78
77
  touch(): void;
79
78
  get start(): MultiTime;
@@ -88,10 +87,12 @@ export declare class Session extends Content {
88
87
  setConfig(config: SessionConfig): void;
89
88
  get isComplete(): boolean;
90
89
  markComplete(): void;
91
- get metricsBefore(): SessionMetrics | undefined;
92
- setMetricsBefore(metrics: SessionMetrics): void;
93
- get metricsAfter(): SessionMetrics | undefined;
94
- setMetricsAfter(metrics: SessionMetrics): void;
90
+ get statsBefore(): SessionStats | undefined;
91
+ setStatsBefore(stats: SessionStats): void;
92
+ get statsAfter(): SessionStats | undefined;
93
+ setStatsAfter(stats: SessionStats): void;
95
94
  isActive(): boolean;
95
+ get appVersion(): string | undefined;
96
+ setAppVersion(version: string): void;
96
97
  modelUpdated(): Promise<void>;
97
98
  }
@@ -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) {
@@ -21,7 +22,7 @@ class Session extends Content_1.Content {
21
22
  let sessionId = Session.makeSessionId(userId);
22
23
  return `${sessionId}_${at.utc_time}`;
23
24
  }
24
- static create(userId, deviceId) {
25
+ static create(userId, deviceId, appVersion) {
25
26
  let now = shaxpir_common_1.ClockService.getClock().now();
26
27
  let sessionId = Session.makeSessionId(userId);
27
28
  let sessionRef = Session.makeSessionRef(userId, now);
@@ -37,11 +38,13 @@ class Session extends Content_1.Content {
37
38
  payload: {
38
39
  start: now,
39
40
  end: now,
41
+ is_complete: false,
40
42
  tz_offset: (new Date()).getTimezoneOffset(),
41
43
  duration_minutes: 0,
42
44
  device_id: deviceId,
43
45
  reviews: [],
44
- review_count: 0
46
+ review_count: 0,
47
+ app_version: appVersion
45
48
  }
46
49
  });
47
50
  }
@@ -126,30 +129,30 @@ class Session extends Content_1.Content {
126
129
  batch.setPathValue(['payload', 'is_complete'], true);
127
130
  batch.commit();
128
131
  }
129
- get metricsBefore() {
130
- this.checkDisposed("Session.metricsBefore");
131
- return this.payload.metrics?.before;
132
+ get statsBefore() {
133
+ this.checkDisposed("Session.statsBefore");
134
+ return this.payload.stats?.before;
132
135
  }
133
- setMetricsBefore(metrics) {
134
- this.checkDisposed("Session.setMetricsBefore");
136
+ setStatsBefore(stats) {
137
+ this.checkDisposed("Session.setStatsBefore");
135
138
  const batch = new Operation_1.BatchOperation(this);
136
- if (!this.payload.metrics) {
137
- batch.setPathValue(['payload', 'metrics'], {});
139
+ if (!this.payload.stats) {
140
+ batch.setPathValue(['payload', 'stats'], {});
138
141
  }
139
- batch.setPathValue(['payload', 'metrics', 'before'], metrics);
142
+ batch.setPathValue(['payload', 'stats', 'before'], stats);
140
143
  batch.commit();
141
144
  }
142
- get metricsAfter() {
143
- this.checkDisposed("Session.metricsAfter");
144
- return this.payload.metrics?.after;
145
+ get statsAfter() {
146
+ this.checkDisposed("Session.statsAfter");
147
+ return this.payload.stats?.after;
145
148
  }
146
- setMetricsAfter(metrics) {
147
- this.checkDisposed("Session.setMetricsAfter");
149
+ setStatsAfter(stats) {
150
+ this.checkDisposed("Session.setStatsAfter");
148
151
  const batch = new Operation_1.BatchOperation(this);
149
- if (!this.payload.metrics) {
150
- batch.setPathValue(['payload', 'metrics'], {});
152
+ if (!this.payload.stats) {
153
+ batch.setPathValue(['payload', 'stats'], {});
151
154
  }
152
- batch.setPathValue(['payload', 'metrics', 'after'], metrics);
155
+ batch.setPathValue(['payload', 'stats', 'after'], stats);
153
156
  batch.commit();
154
157
  }
155
158
  isActive() {
@@ -162,6 +165,16 @@ class Session extends Content_1.Content {
162
165
  const fifteenMinutesAgo = shaxpir_common_1.Time.plus(now.utc_time, -15, 'minutes');
163
166
  return shaxpir_common_1.Time.isDateTimeAfter(this.updatedAt.utc_time, fifteenMinutesAgo);
164
167
  }
168
+ get appVersion() {
169
+ this.checkDisposed("Session.appVersion");
170
+ return this.payload.app_version;
171
+ }
172
+ setAppVersion(version) {
173
+ this.checkDisposed("Session.setAppVersion");
174
+ const batch = new Operation_1.BatchOperation(this);
175
+ batch.setPathValue(['payload', 'app_version'], version);
176
+ batch.commit();
177
+ }
165
178
  async modelUpdated() {
166
179
  this.checkDisposed("Session.modelUpdated");
167
180
  await super.modelUpdated();
@@ -189,7 +202,14 @@ class Session extends Content_1.Content {
189
202
  const reviewCountMetricId = Metric_1.Metric.makeMetricId(userId, Metric_1.MetricName.REVIEW_COUNT);
190
203
  const reviewCountMetric = await shareSync.acquire(ContentKind_1.ContentKind.METRIC, reviewCountMetricId);
191
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);
192
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();
193
213
  }
194
214
  }
195
215
  exports.Session = Session;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.7.0",
3
+ "version": "1.7.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"