@shaxpir/duiduidui-models 1.36.2 → 1.36.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.
|
@@ -37,6 +37,7 @@ export interface CollectionPayload {
|
|
|
37
37
|
term_scores: {
|
|
38
38
|
[termKey: string]: number;
|
|
39
39
|
};
|
|
40
|
+
engagement_score: number;
|
|
40
41
|
total_cards: number;
|
|
41
42
|
last_activity_utc: CompactDateTime | null;
|
|
42
43
|
is_visible: boolean;
|
|
@@ -96,6 +97,12 @@ export declare class Collection extends Content {
|
|
|
96
97
|
get termScores(): {
|
|
97
98
|
[termKey: string]: number;
|
|
98
99
|
};
|
|
100
|
+
/**
|
|
101
|
+
* Cached sum of all term_scores values. Maintained incrementally by
|
|
102
|
+
* setTermScore() and removeTermScore() so that engagement-based sorting
|
|
103
|
+
* doesn't need to iterate the full map.
|
|
104
|
+
*/
|
|
105
|
+
get engagementScore(): number;
|
|
99
106
|
/**
|
|
100
107
|
* Get the number of unique terms the user has reviewed in this collection.
|
|
101
108
|
*/
|
|
@@ -59,6 +59,7 @@ class Collection extends Content_1.Content {
|
|
|
59
59
|
proficiency: SkillLevel_1.SkillLevelModel.createDefault(),
|
|
60
60
|
// Empty term scores map - populated as user reviews cards
|
|
61
61
|
term_scores: {},
|
|
62
|
+
engagement_score: 0,
|
|
62
63
|
// Progress starts at zero
|
|
63
64
|
total_cards: 0,
|
|
64
65
|
last_activity_utc: null,
|
|
@@ -141,6 +142,15 @@ class Collection extends Content_1.Content {
|
|
|
141
142
|
this.checkDisposed("Collection.termScores");
|
|
142
143
|
return this.payload.term_scores;
|
|
143
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Cached sum of all term_scores values. Maintained incrementally by
|
|
147
|
+
* setTermScore() and removeTermScore() so that engagement-based sorting
|
|
148
|
+
* doesn't need to iterate the full map.
|
|
149
|
+
*/
|
|
150
|
+
get engagementScore() {
|
|
151
|
+
this.checkDisposed("Collection.engagementScore");
|
|
152
|
+
return this.payload.engagement_score ?? 0;
|
|
153
|
+
}
|
|
144
154
|
/**
|
|
145
155
|
* Get the number of unique terms the user has reviewed in this collection.
|
|
146
156
|
*/
|
|
@@ -274,8 +284,11 @@ class Collection extends Content_1.Content {
|
|
|
274
284
|
setTermScore(text, senseRank, theta) {
|
|
275
285
|
this.checkDisposed("Collection.setTermScore");
|
|
276
286
|
const termKey = Collection.encodeTermKey(text, senseRank);
|
|
287
|
+
const prevTheta = this.payload.term_scores[termKey] ?? 0;
|
|
288
|
+
const prevEngagement = this.payload.engagement_score ?? 0;
|
|
277
289
|
const batch = new Operation_1.BatchOperation(this);
|
|
278
290
|
batch.setPathValue(['payload', 'term_scores', termKey], theta);
|
|
291
|
+
batch.setPathValue(['payload', 'engagement_score'], prevEngagement - prevTheta + theta);
|
|
279
292
|
batch.commit();
|
|
280
293
|
}
|
|
281
294
|
/**
|
|
@@ -284,9 +297,12 @@ class Collection extends Content_1.Content {
|
|
|
284
297
|
removeTermScore(text, senseRank) {
|
|
285
298
|
this.checkDisposed("Collection.removeTermScore");
|
|
286
299
|
const termKey = Collection.encodeTermKey(text, senseRank);
|
|
287
|
-
|
|
300
|
+
const prevTheta = this.payload.term_scores[termKey];
|
|
301
|
+
if (prevTheta !== undefined) {
|
|
302
|
+
const prevEngagement = this.payload.engagement_score ?? 0;
|
|
288
303
|
const batch = new Operation_1.BatchOperation(this);
|
|
289
304
|
batch.removeValueAtPath(['payload', 'term_scores', termKey]);
|
|
305
|
+
batch.setPathValue(['payload', 'engagement_score'], prevEngagement - prevTheta);
|
|
290
306
|
batch.commit();
|
|
291
307
|
}
|
|
292
308
|
}
|