@shaxpir/duiduidui-models 1.4.28 → 1.5.0

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.
@@ -1,14 +1,7 @@
1
1
  import { Doc } from '@shaxpir/sharedb/lib/client';
2
- import { CompactDateTime } from "@shaxpir/shaxpir-common";
3
2
  import { ShareSync } from '../repo';
4
- import { BayesianScore, Bounds } from './BayesianScore';
3
+ import { Bounds } from './BayesianScore';
5
4
  import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
6
- export interface PhraseProgress extends BayesianScore {
7
- text: string;
8
- sense_rank: number;
9
- difficulty: number;
10
- last_review_utc?: CompactDateTime;
11
- }
12
5
  export interface UncertainValue {
13
6
  value: number;
14
7
  uncertainty: number;
@@ -16,7 +9,6 @@ export interface UncertainValue {
16
9
  }
17
10
  export interface ProgressPayload {
18
11
  skill_level: UncertainValue;
19
- phrases: Record<string, PhraseProgress>;
20
12
  cognitive_load: number;
21
13
  }
22
14
  export interface ProgressBody extends ContentBody {
@@ -28,18 +20,17 @@ export declare class Progress extends Content {
28
20
  static create(userId: ContentId): Progress;
29
21
  constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
30
22
  get payload(): ProgressPayload;
23
+ getSkillLevel(): UncertainValue;
31
24
  getSkillLevelValue(): number;
32
25
  getSkillLevelUncertainty(): number;
33
26
  getSkillLevelLowerBound(): number;
34
27
  getSkillLevelUpperBound(): number;
35
28
  needsCalibration(): boolean;
36
29
  getCognitiveLoad(): number;
37
- getPhrases(): Record<string, PhraseProgress>;
30
+ setSkillLevel(uncertainValue: UncertainValue): void;
38
31
  setSkillLevelValue(value: number): void;
39
32
  setSkillLevelUncertainty(uncertainty: number): void;
40
33
  setSkillLevelLowerBound(lowerBound: number): void;
41
34
  setSkillLevelUpperBound(upperBound: number): void;
42
35
  setCognitiveLoad(value: number): void;
43
- updatePhraseProgress(phraseId: string, progress: PhraseProgress): void;
44
- updateMultiplePhrases(updates: Record<string, PhraseProgress>): void;
45
36
  }
@@ -31,7 +31,6 @@ class Progress extends Content_1.Content {
31
31
  upper: 1000 // Could potentially be advanced
32
32
  }
33
33
  },
34
- phrases: {},
35
34
  cognitive_load: 0
36
35
  }
37
36
  });
@@ -43,6 +42,10 @@ class Progress extends Content_1.Content {
43
42
  this.checkDisposed("Progress.payload");
44
43
  return this.doc.data.payload;
45
44
  }
45
+ getSkillLevel() {
46
+ this.checkDisposed("Progress.getSkillLevel");
47
+ return shaxpir_common_1.Struct.clone(this.payload.skill_level);
48
+ }
46
49
  getSkillLevelValue() {
47
50
  this.checkDisposed("Progress.getSkillLevelValue");
48
51
  return this.payload.skill_level.value;
@@ -68,9 +71,16 @@ class Progress extends Content_1.Content {
68
71
  this.checkDisposed("Progress.getCognitiveLoad");
69
72
  return this.payload.cognitive_load;
70
73
  }
71
- getPhrases() {
72
- this.checkDisposed("Progress.getPhrases");
73
- return this.payload.phrases;
74
+ setSkillLevel(uncertainValue) {
75
+ this.checkDisposed("Progress.setSkillLevel");
76
+ if (!shaxpir_common_1.Struct.equals(this.payload.skill_level, uncertainValue)) {
77
+ const batch = new Operation_1.BatchOperation(this);
78
+ batch.setPathValue(['payload', 'skill_level', 'value'], uncertainValue.value);
79
+ batch.setPathValue(['payload', 'skill_level', 'uncertainty'], uncertainValue.uncertainty);
80
+ batch.setPathValue(['payload', 'skill_level', 'bounds', 'lower'], uncertainValue.bounds.lower);
81
+ batch.setPathValue(['payload', 'skill_level', 'bounds', 'upper'], uncertainValue.bounds.upper);
82
+ batch.commit();
83
+ }
74
84
  }
75
85
  setSkillLevelValue(value) {
76
86
  this.checkDisposed("Progress.setSkillLevelValue");
@@ -112,19 +122,5 @@ class Progress extends Content_1.Content {
112
122
  batch.commit();
113
123
  }
114
124
  }
115
- updatePhraseProgress(phraseId, progress) {
116
- this.checkDisposed("Progress.updatePhraseProgress");
117
- const batch = new Operation_1.BatchOperation(this);
118
- batch.setPathValue(['payload', 'phrases', phraseId], progress);
119
- batch.commit();
120
- }
121
- updateMultiplePhrases(updates) {
122
- this.checkDisposed("Progress.updateMultiplePhrases");
123
- const batch = new Operation_1.BatchOperation(this);
124
- for (const [phraseId, progress] of Object.entries(updates)) {
125
- batch.setPathValue(['payload', 'phrases', phraseId], progress);
126
- }
127
- batch.commit();
128
- }
129
125
  }
130
126
  exports.Progress = Progress;
@@ -22,6 +22,8 @@ export interface TermPayload extends BayesianScore {
22
22
  keywords?: string[];
23
23
  tags: string[];
24
24
  reviews: ReviewLike[];
25
+ review_count: number;
26
+ last_review_utc: CompactDateTime;
25
27
  }
26
28
  export interface TermBody extends ContentBody {
27
29
  meta: ContentMeta;
@@ -47,4 +49,6 @@ export declare class Term extends Content {
47
49
  setStarredAt(value: CompactDateTime | null): void;
48
50
  updateBayesianScore(alpha: number, beta: number, theta: number): void;
49
51
  addReview(review: ReviewLike): void;
52
+ getReviewCount(): number;
53
+ getLastReviewUtc(): CompactDateTime | null;
50
54
  }
@@ -69,7 +69,9 @@ class Term extends Content_1.Content {
69
69
  beta: 0.5,
70
70
  theta: 0.5,
71
71
  uncertainty: BayesianScore_1.BayesianScoreModel.getUncertainty({ alpha: 0.5, beta: 0.5, theta: 0.5, uncertainty: 0 }),
72
- reviews: []
72
+ reviews: [],
73
+ review_count: 0,
74
+ last_review_utc: null
73
75
  }
74
76
  });
75
77
  }
@@ -96,7 +98,9 @@ class Term extends Content_1.Content {
96
98
  beta: 0.5,
97
99
  theta: 0.5,
98
100
  uncertainty: BayesianScore_1.BayesianScoreModel.getUncertainty({ alpha: 0.5, beta: 0.5, theta: 0.5, uncertainty: 0 }),
99
- reviews: []
101
+ reviews: [],
102
+ review_count: 0,
103
+ last_review_utc: null
100
104
  }
101
105
  });
102
106
  }
@@ -160,6 +164,31 @@ class Term extends Content_1.Content {
160
164
  addReview(review) {
161
165
  this.checkDisposed("Term.addReview");
162
166
  this._reviewsView.push(review);
167
+ // Count reviews again.
168
+ let reviewCount = 0;
169
+ let lastReviewUtc = null;
170
+ this._reviewsView.forEach((idx, r) => {
171
+ // We only count *actual* reviews, not implied reviews...
172
+ if (!r.hasOwnProperty('context') && !r.hasOwnProperty('weight')) {
173
+ const reviewUtc = r.at.utc_time;
174
+ if (!lastReviewUtc || shaxpir_common_1.Time.isDateTimeAfter(reviewUtc, lastReviewUtc)) {
175
+ lastReviewUtc = reviewUtc;
176
+ }
177
+ reviewCount++;
178
+ }
179
+ });
180
+ const batch = new Operation_1.BatchOperation(this);
181
+ batch.setPathValue(['payload', 'review_count'], reviewCount);
182
+ batch.setPathValue(['payload', 'last_review_utc'], lastReviewUtc);
183
+ batch.commit();
184
+ }
185
+ getReviewCount() {
186
+ this.checkDisposed("Term.getReviewCount");
187
+ return this.payload.review_count;
188
+ }
189
+ getLastReviewUtc() {
190
+ this.checkDisposed("Term.getLastReviewUtc");
191
+ return this.payload.last_review_utc;
163
192
  }
164
193
  }
165
194
  exports.Term = Term;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.4.28",
3
+ "version": "1.5.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"