@shaxpir/duiduidui-models 1.4.24 → 1.4.25

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.
@@ -3,8 +3,8 @@ import { CompactDate } from "@shaxpir/shaxpir-common";
3
3
  import { ShareSync } from '../repo';
4
4
  import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
5
5
  export declare enum MetricName {
6
- WORD_COUNT = "word_count",
7
- MINUTES_WRITING = "minutes_writing"
6
+ REVIEW_COUNT = "review_count",
7
+ MINUTES_STUDYING = "minutes_studying"
8
8
  }
9
9
  export interface MetricEntry {
10
10
  date: CompactDate;
@@ -14,8 +14,8 @@ const Operation_1 = require("./Operation");
14
14
  dayjs_1.default.extend(utc_1.default);
15
15
  var MetricName;
16
16
  (function (MetricName) {
17
- MetricName["WORD_COUNT"] = "word_count";
18
- MetricName["MINUTES_WRITING"] = "minutes_writing";
17
+ MetricName["REVIEW_COUNT"] = "review_count";
18
+ MetricName["MINUTES_STUDYING"] = "minutes_studying";
19
19
  })(MetricName || (exports.MetricName = MetricName = {}));
20
20
  class Metric extends Content_1.Content {
21
21
  static makeMetricId(userId, metricName) {
@@ -3,6 +3,7 @@ import { MultiTime } from "@shaxpir/shaxpir-common";
3
3
  import { ShareSync } from '../repo';
4
4
  import { Content, ContentBody, ContentId, ContentMeta, ContentRef } from "./Content";
5
5
  import { Review } from './Review';
6
+ import { ArrayView } from './ArrayView';
6
7
  export interface SessionPayload {
7
8
  start: MultiTime;
8
9
  end: MultiTime;
@@ -28,6 +29,7 @@ export declare class Session extends Content {
28
29
  get tzOffset(): number;
29
30
  get durationMinutes(): number;
30
31
  get deviceId(): ContentId;
32
+ get reviews(): ArrayView<Review>;
31
33
  modelUpdated(): Promise<void>;
32
34
  addReview(review: Review): void;
33
35
  }
@@ -79,6 +79,10 @@ class Session extends Content_1.Content {
79
79
  this.checkDisposed("Session.deviceId");
80
80
  return this.payload.device_id;
81
81
  }
82
+ get reviews() {
83
+ this.checkDisposed("Session.reviews");
84
+ return this._reviewsView;
85
+ }
82
86
  async modelUpdated() {
83
87
  this.checkDisposed("Session.modelUpdated");
84
88
  await super.modelUpdated();
@@ -90,16 +94,24 @@ class Session extends Content_1.Content {
90
94
  const workspace = await this.shareSync.acquire(ContentKind_1.ContentKind.WORKSPACE, workspaceId);
91
95
  const sessionsOnDate = await workspace.acquireSessionsFromDate(sessionId, date);
92
96
  workspace.release();
93
- let minutesWritingOnDate = 0;
97
+ let minutesStudyingOnDate = 0;
98
+ let reviewCountOnDate = 0;
94
99
  for (let i = 0, len = sessionsOnDate.length; i < len; i++) {
95
100
  const sessionOnDate = sessionsOnDate[i];
96
- minutesWritingOnDate += sessionOnDate.durationMinutes;
101
+ minutesStudyingOnDate += sessionOnDate.durationMinutes;
102
+ reviewCountOnDate += sessionOnDate.reviews.length;
97
103
  sessionOnDate.release();
98
104
  }
99
- const minutesWritingMetricId = Metric_1.Metric.makeMetricId(userId, Metric_1.MetricName.MINUTES_WRITING);
100
- const minutesWritingMetric = await shareSync.acquire(ContentKind_1.ContentKind.METRIC, minutesWritingMetricId);
101
- minutesWritingMetric.setDateAmount(date, minutesWritingOnDate);
102
- minutesWritingMetric.release();
105
+ // Update minutes studying metric
106
+ const minutesStudyingMetricId = Metric_1.Metric.makeMetricId(userId, Metric_1.MetricName.MINUTES_STUDYING);
107
+ const minutesStudyingMetric = await shareSync.acquire(ContentKind_1.ContentKind.METRIC, minutesStudyingMetricId);
108
+ minutesStudyingMetric.setDateAmount(date, minutesStudyingOnDate);
109
+ minutesStudyingMetric.release();
110
+ // Update review count metric
111
+ const reviewCountMetricId = Metric_1.Metric.makeMetricId(userId, Metric_1.MetricName.REVIEW_COUNT);
112
+ const reviewCountMetric = await shareSync.acquire(ContentKind_1.ContentKind.METRIC, reviewCountMetricId);
113
+ reviewCountMetric.setDateAmount(date, reviewCountOnDate);
114
+ reviewCountMetric.release();
103
115
  }
104
116
  addReview(review) {
105
117
  this.checkDisposed("Session.addReview");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.4.24",
3
+ "version": "1.4.25",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"