czapp-shared 1.0.28 → 1.0.29
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.
- package/dist/index.d.mts +16 -5
- package/dist/index.d.ts +16 -5
- package/dist/index.js +38 -0
- package/dist/index.mjs +37 -0
- package/package.json +1 -1
- package/src/concrete/date.ts +2 -2
- package/src/concrete/vocabCheck.ts +52 -0
- package/src/design/api.ts +5 -0
- package/src/design/types.ts +2 -2
- package/src/index.ts +1 -0
- package/test/vocabCheck.test.ts +49 -0
package/dist/index.d.mts
CHANGED
|
@@ -48,7 +48,7 @@ declare const isClientDateTooFarFromServerDate: (clientDateMySQLFormat: MySQLDat
|
|
|
48
48
|
declare const dateDifferenceInDays: (date1: MySQLDate, date2: MySQLDate) => number;
|
|
49
49
|
declare const isThePreviousDay: (date: MySQLDate, referenceDate: MySQLDate) => boolean;
|
|
50
50
|
declare const isTheSameDay: (date1: MySQLDate, date2: MySQLDate) => boolean;
|
|
51
|
-
declare const getFormattedDate: (date: Date) =>
|
|
51
|
+
declare const getFormattedDate: (date: Date) => DateString;
|
|
52
52
|
declare const isExpired: (date: MySQLDate) => boolean;
|
|
53
53
|
|
|
54
54
|
interface ISession {
|
|
@@ -90,12 +90,12 @@ interface ITestResult {
|
|
|
90
90
|
thinkingTimeSecs: number;
|
|
91
91
|
}
|
|
92
92
|
interface IVocabCheckActivity {
|
|
93
|
-
testDate:
|
|
93
|
+
testDate: DateString;
|
|
94
94
|
flashcardCount: number;
|
|
95
95
|
testQuestionCount: number;
|
|
96
96
|
}
|
|
97
97
|
type MySQLDate = `${number}-${number}-${number} ${number}:${number}:${number}`;
|
|
98
|
-
type DateString = `${number}-${
|
|
98
|
+
type DateString = `${number}-${string}-${string}`;
|
|
99
99
|
declare enum ReminderFrequency {
|
|
100
100
|
ALWAYS = "ALWAYS",
|
|
101
101
|
DAILY = "DAILY",
|
|
@@ -206,6 +206,12 @@ declare class LexemePair implements ILexemePair {
|
|
|
206
206
|
declare const isStringContainingInteger: (str: any) => boolean;
|
|
207
207
|
declare const parameterReplace: (path: string, params?: string[]) => string;
|
|
208
208
|
|
|
209
|
+
type Streaks = {
|
|
210
|
+
flashcardStreak: number;
|
|
211
|
+
testStreak: number;
|
|
212
|
+
};
|
|
213
|
+
declare const deriveStreakFromVocabCheckActivity: (activity: IVocabCheckActivity[], today: DateString) => Streaks;
|
|
214
|
+
|
|
209
215
|
interface IActivityCount {
|
|
210
216
|
date: DateString;
|
|
211
217
|
count: number;
|
|
@@ -269,7 +275,8 @@ declare enum ApiPath {
|
|
|
269
275
|
TRANSLATIONS_ALL = "/lexemes/allTranslations/:sourceText/:sourceLang",
|
|
270
276
|
USER = "/user",
|
|
271
277
|
USER_ONBOARDING = "/user/onboarding",
|
|
272
|
-
USER_RESET_TEST = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd"
|
|
278
|
+
USER_RESET_TEST = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd",
|
|
279
|
+
VOCAB_CHECK_ACTIVITY = "/vocabCheckActivity/:endDate/:noOfDays"
|
|
273
280
|
}
|
|
274
281
|
declare enum ClientPlatform {
|
|
275
282
|
IOS = "ios",
|
|
@@ -363,6 +370,10 @@ interface HeatMapParams {
|
|
|
363
370
|
weekCount: number;
|
|
364
371
|
endDate: DateString;
|
|
365
372
|
}
|
|
373
|
+
interface SelectVocabCheckActivityParams {
|
|
374
|
+
endDate: DateString;
|
|
375
|
+
noOfDays: number;
|
|
376
|
+
}
|
|
366
377
|
/**
|
|
367
378
|
* Response payloads
|
|
368
379
|
*/
|
|
@@ -412,4 +423,4 @@ type DeeplTranslation = {
|
|
|
412
423
|
}>;
|
|
413
424
|
};
|
|
414
425
|
|
|
415
|
-
export { ApiMethod, ApiPath, AppError, type AutologinRequestBody, ClientPlatform, type ControllerResponse, type DateString, type DeeplTranslation, type DeleteLexemePairRequestParams, Familiarity, type HeatMapParams, type HeatMapResponseData, HttpStatusCode, type IActivityCount, type ICount, type ILexeme, type ILexemeIdPair, type ILexemeLearningInfo, type ILexemePair, type ILexemePairTexts, type ISession, type ITestResult, type IUserData, type IVocabCheckActivity, type InsertOrUpdateRequestBody, type InsertOrUpdateResponseData, Language, LearningStage, Lexeme, LexemePair, type LexemePairRequestBody, type LexemePairWithLang, type MySQLDate, Progress, type RecycleLexemePairParams, ReminderFrequency, type ResetTestUserParams, type Result, Scenario, type SelectAllTranslationsParams, type SelectLexemeCountParams, type SelectLexemePairParams, type SelectLexemePairsByTextParams, type SelectLexemesParams, type SelectTestLexemesParams, type SignInRequestBody, type SignInResponseData, type TestCompleteRequestBody, type TestCompleteResponseData, type TestInitRequestBody, type TestInitResponseData, type TranslationRequestBody, type TranslationResponseData, type UpdateLexemePairFamiliarityParams, type UpdateOnboardingStatusRequestBody, type UpdateUserRequestBody, VocabCheckType, convertJSDateStringToMySQLDate, dateDifferenceInDays, getFormattedDate, getMysqlDateIgnoreTZ, isClientDateTooFarFromServerDate, isExpired, isStringContainingInteger, isThePreviousDay, isTheSameDay, isValidJsDateString, isValidMysqlDateString, parameterReplace };
|
|
426
|
+
export { ApiMethod, ApiPath, AppError, type AutologinRequestBody, ClientPlatform, type ControllerResponse, type DateString, type DeeplTranslation, type DeleteLexemePairRequestParams, Familiarity, type HeatMapParams, type HeatMapResponseData, HttpStatusCode, type IActivityCount, type ICount, type ILexeme, type ILexemeIdPair, type ILexemeLearningInfo, type ILexemePair, type ILexemePairTexts, type ISession, type ITestResult, type IUserData, type IVocabCheckActivity, type InsertOrUpdateRequestBody, type InsertOrUpdateResponseData, Language, LearningStage, Lexeme, LexemePair, type LexemePairRequestBody, type LexemePairWithLang, type MySQLDate, Progress, type RecycleLexemePairParams, ReminderFrequency, type ResetTestUserParams, type Result, Scenario, type SelectAllTranslationsParams, type SelectLexemeCountParams, type SelectLexemePairParams, type SelectLexemePairsByTextParams, type SelectLexemesParams, type SelectTestLexemesParams, type SelectVocabCheckActivityParams, type SignInRequestBody, type SignInResponseData, type Streaks, type TestCompleteRequestBody, type TestCompleteResponseData, type TestInitRequestBody, type TestInitResponseData, type TranslationRequestBody, type TranslationResponseData, type UpdateLexemePairFamiliarityParams, type UpdateOnboardingStatusRequestBody, type UpdateUserRequestBody, VocabCheckType, convertJSDateStringToMySQLDate, dateDifferenceInDays, deriveStreakFromVocabCheckActivity, getFormattedDate, getMysqlDateIgnoreTZ, isClientDateTooFarFromServerDate, isExpired, isStringContainingInteger, isThePreviousDay, isTheSameDay, isValidJsDateString, isValidMysqlDateString, parameterReplace };
|
package/dist/index.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ declare const isClientDateTooFarFromServerDate: (clientDateMySQLFormat: MySQLDat
|
|
|
48
48
|
declare const dateDifferenceInDays: (date1: MySQLDate, date2: MySQLDate) => number;
|
|
49
49
|
declare const isThePreviousDay: (date: MySQLDate, referenceDate: MySQLDate) => boolean;
|
|
50
50
|
declare const isTheSameDay: (date1: MySQLDate, date2: MySQLDate) => boolean;
|
|
51
|
-
declare const getFormattedDate: (date: Date) =>
|
|
51
|
+
declare const getFormattedDate: (date: Date) => DateString;
|
|
52
52
|
declare const isExpired: (date: MySQLDate) => boolean;
|
|
53
53
|
|
|
54
54
|
interface ISession {
|
|
@@ -90,12 +90,12 @@ interface ITestResult {
|
|
|
90
90
|
thinkingTimeSecs: number;
|
|
91
91
|
}
|
|
92
92
|
interface IVocabCheckActivity {
|
|
93
|
-
testDate:
|
|
93
|
+
testDate: DateString;
|
|
94
94
|
flashcardCount: number;
|
|
95
95
|
testQuestionCount: number;
|
|
96
96
|
}
|
|
97
97
|
type MySQLDate = `${number}-${number}-${number} ${number}:${number}:${number}`;
|
|
98
|
-
type DateString = `${number}-${
|
|
98
|
+
type DateString = `${number}-${string}-${string}`;
|
|
99
99
|
declare enum ReminderFrequency {
|
|
100
100
|
ALWAYS = "ALWAYS",
|
|
101
101
|
DAILY = "DAILY",
|
|
@@ -206,6 +206,12 @@ declare class LexemePair implements ILexemePair {
|
|
|
206
206
|
declare const isStringContainingInteger: (str: any) => boolean;
|
|
207
207
|
declare const parameterReplace: (path: string, params?: string[]) => string;
|
|
208
208
|
|
|
209
|
+
type Streaks = {
|
|
210
|
+
flashcardStreak: number;
|
|
211
|
+
testStreak: number;
|
|
212
|
+
};
|
|
213
|
+
declare const deriveStreakFromVocabCheckActivity: (activity: IVocabCheckActivity[], today: DateString) => Streaks;
|
|
214
|
+
|
|
209
215
|
interface IActivityCount {
|
|
210
216
|
date: DateString;
|
|
211
217
|
count: number;
|
|
@@ -269,7 +275,8 @@ declare enum ApiPath {
|
|
|
269
275
|
TRANSLATIONS_ALL = "/lexemes/allTranslations/:sourceText/:sourceLang",
|
|
270
276
|
USER = "/user",
|
|
271
277
|
USER_ONBOARDING = "/user/onboarding",
|
|
272
|
-
USER_RESET_TEST = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd"
|
|
278
|
+
USER_RESET_TEST = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd",
|
|
279
|
+
VOCAB_CHECK_ACTIVITY = "/vocabCheckActivity/:endDate/:noOfDays"
|
|
273
280
|
}
|
|
274
281
|
declare enum ClientPlatform {
|
|
275
282
|
IOS = "ios",
|
|
@@ -363,6 +370,10 @@ interface HeatMapParams {
|
|
|
363
370
|
weekCount: number;
|
|
364
371
|
endDate: DateString;
|
|
365
372
|
}
|
|
373
|
+
interface SelectVocabCheckActivityParams {
|
|
374
|
+
endDate: DateString;
|
|
375
|
+
noOfDays: number;
|
|
376
|
+
}
|
|
366
377
|
/**
|
|
367
378
|
* Response payloads
|
|
368
379
|
*/
|
|
@@ -412,4 +423,4 @@ type DeeplTranslation = {
|
|
|
412
423
|
}>;
|
|
413
424
|
};
|
|
414
425
|
|
|
415
|
-
export { ApiMethod, ApiPath, AppError, type AutologinRequestBody, ClientPlatform, type ControllerResponse, type DateString, type DeeplTranslation, type DeleteLexemePairRequestParams, Familiarity, type HeatMapParams, type HeatMapResponseData, HttpStatusCode, type IActivityCount, type ICount, type ILexeme, type ILexemeIdPair, type ILexemeLearningInfo, type ILexemePair, type ILexemePairTexts, type ISession, type ITestResult, type IUserData, type IVocabCheckActivity, type InsertOrUpdateRequestBody, type InsertOrUpdateResponseData, Language, LearningStage, Lexeme, LexemePair, type LexemePairRequestBody, type LexemePairWithLang, type MySQLDate, Progress, type RecycleLexemePairParams, ReminderFrequency, type ResetTestUserParams, type Result, Scenario, type SelectAllTranslationsParams, type SelectLexemeCountParams, type SelectLexemePairParams, type SelectLexemePairsByTextParams, type SelectLexemesParams, type SelectTestLexemesParams, type SignInRequestBody, type SignInResponseData, type TestCompleteRequestBody, type TestCompleteResponseData, type TestInitRequestBody, type TestInitResponseData, type TranslationRequestBody, type TranslationResponseData, type UpdateLexemePairFamiliarityParams, type UpdateOnboardingStatusRequestBody, type UpdateUserRequestBody, VocabCheckType, convertJSDateStringToMySQLDate, dateDifferenceInDays, getFormattedDate, getMysqlDateIgnoreTZ, isClientDateTooFarFromServerDate, isExpired, isStringContainingInteger, isThePreviousDay, isTheSameDay, isValidJsDateString, isValidMysqlDateString, parameterReplace };
|
|
426
|
+
export { ApiMethod, ApiPath, AppError, type AutologinRequestBody, ClientPlatform, type ControllerResponse, type DateString, type DeeplTranslation, type DeleteLexemePairRequestParams, Familiarity, type HeatMapParams, type HeatMapResponseData, HttpStatusCode, type IActivityCount, type ICount, type ILexeme, type ILexemeIdPair, type ILexemeLearningInfo, type ILexemePair, type ILexemePairTexts, type ISession, type ITestResult, type IUserData, type IVocabCheckActivity, type InsertOrUpdateRequestBody, type InsertOrUpdateResponseData, Language, LearningStage, Lexeme, LexemePair, type LexemePairRequestBody, type LexemePairWithLang, type MySQLDate, Progress, type RecycleLexemePairParams, ReminderFrequency, type ResetTestUserParams, type Result, Scenario, type SelectAllTranslationsParams, type SelectLexemeCountParams, type SelectLexemePairParams, type SelectLexemePairsByTextParams, type SelectLexemesParams, type SelectTestLexemesParams, type SelectVocabCheckActivityParams, type SignInRequestBody, type SignInResponseData, type Streaks, type TestCompleteRequestBody, type TestCompleteResponseData, type TestInitRequestBody, type TestInitResponseData, type TranslationRequestBody, type TranslationResponseData, type UpdateLexemePairFamiliarityParams, type UpdateOnboardingStatusRequestBody, type UpdateUserRequestBody, VocabCheckType, convertJSDateStringToMySQLDate, dateDifferenceInDays, deriveStreakFromVocabCheckActivity, getFormattedDate, getMysqlDateIgnoreTZ, isClientDateTooFarFromServerDate, isExpired, isStringContainingInteger, isThePreviousDay, isTheSameDay, isValidJsDateString, isValidMysqlDateString, parameterReplace };
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
VocabCheckType: () => VocabCheckType,
|
|
36
36
|
convertJSDateStringToMySQLDate: () => convertJSDateStringToMySQLDate,
|
|
37
37
|
dateDifferenceInDays: () => dateDifferenceInDays,
|
|
38
|
+
deriveStreakFromVocabCheckActivity: () => deriveStreakFromVocabCheckActivity,
|
|
38
39
|
getFormattedDate: () => getFormattedDate,
|
|
39
40
|
getMysqlDateIgnoreTZ: () => getMysqlDateIgnoreTZ,
|
|
40
41
|
isClientDateTooFarFromServerDate: () => isClientDateTooFarFromServerDate,
|
|
@@ -220,6 +221,41 @@ var parameterReplace = (path, params = []) => {
|
|
|
220
221
|
return path.replace(/\:([a-zA-Z0-9]+)/g, (match, p1) => params.shift() || "");
|
|
221
222
|
};
|
|
222
223
|
|
|
224
|
+
// src/concrete/vocabCheck.ts
|
|
225
|
+
var deriveStreakFromVocabCheckActivity = (activity, today) => {
|
|
226
|
+
if (activity.length === 0) return { flashcardStreak: 0, testStreak: 0 };
|
|
227
|
+
let flashcardStreak = 0;
|
|
228
|
+
let testStreak = 0;
|
|
229
|
+
const sortedActivity = activity.sort((a, b) => a.testDate < b.testDate ? 1 : -1);
|
|
230
|
+
let currentDate = today;
|
|
231
|
+
for (const record of sortedActivity) {
|
|
232
|
+
if (record.flashcardCount > 0) {
|
|
233
|
+
if (record.testDate === currentDate) {
|
|
234
|
+
flashcardStreak++;
|
|
235
|
+
const dateObj = new Date(currentDate);
|
|
236
|
+
dateObj.setDate(dateObj.getDate() - 1);
|
|
237
|
+
currentDate = dateObj.toISOString().split("T")[0];
|
|
238
|
+
} else if (record.testDate < currentDate) {
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
currentDate = today;
|
|
244
|
+
for (const record of sortedActivity) {
|
|
245
|
+
if (record.testQuestionCount > 0) {
|
|
246
|
+
if (record.testDate === currentDate) {
|
|
247
|
+
testStreak++;
|
|
248
|
+
const dateObj = new Date(currentDate);
|
|
249
|
+
dateObj.setDate(dateObj.getDate() - 1);
|
|
250
|
+
currentDate = dateObj.toISOString().split("T")[0];
|
|
251
|
+
} else if (record.testDate < currentDate) {
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return { flashcardStreak, testStreak };
|
|
257
|
+
};
|
|
258
|
+
|
|
223
259
|
// src/design/api.ts
|
|
224
260
|
var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
|
|
225
261
|
HttpStatusCode2[HttpStatusCode2["OK"] = 200] = "OK";
|
|
@@ -263,6 +299,7 @@ var ApiPath = /* @__PURE__ */ ((ApiPath2) => {
|
|
|
263
299
|
ApiPath2["USER"] = "/user";
|
|
264
300
|
ApiPath2["USER_ONBOARDING"] = "/user/onboarding";
|
|
265
301
|
ApiPath2["USER_RESET_TEST"] = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd";
|
|
302
|
+
ApiPath2["VOCAB_CHECK_ACTIVITY"] = "/vocabCheckActivity/:endDate/:noOfDays";
|
|
266
303
|
return ApiPath2;
|
|
267
304
|
})(ApiPath || {});
|
|
268
305
|
var ClientPlatform = /* @__PURE__ */ ((ClientPlatform2) => {
|
|
@@ -289,6 +326,7 @@ var ClientPlatform = /* @__PURE__ */ ((ClientPlatform2) => {
|
|
|
289
326
|
VocabCheckType,
|
|
290
327
|
convertJSDateStringToMySQLDate,
|
|
291
328
|
dateDifferenceInDays,
|
|
329
|
+
deriveStreakFromVocabCheckActivity,
|
|
292
330
|
getFormattedDate,
|
|
293
331
|
getMysqlDateIgnoreTZ,
|
|
294
332
|
isClientDateTooFarFromServerDate,
|
package/dist/index.mjs
CHANGED
|
@@ -170,6 +170,41 @@ var parameterReplace = (path, params = []) => {
|
|
|
170
170
|
return path.replace(/\:([a-zA-Z0-9]+)/g, (match, p1) => params.shift() || "");
|
|
171
171
|
};
|
|
172
172
|
|
|
173
|
+
// src/concrete/vocabCheck.ts
|
|
174
|
+
var deriveStreakFromVocabCheckActivity = (activity, today) => {
|
|
175
|
+
if (activity.length === 0) return { flashcardStreak: 0, testStreak: 0 };
|
|
176
|
+
let flashcardStreak = 0;
|
|
177
|
+
let testStreak = 0;
|
|
178
|
+
const sortedActivity = activity.sort((a, b) => a.testDate < b.testDate ? 1 : -1);
|
|
179
|
+
let currentDate = today;
|
|
180
|
+
for (const record of sortedActivity) {
|
|
181
|
+
if (record.flashcardCount > 0) {
|
|
182
|
+
if (record.testDate === currentDate) {
|
|
183
|
+
flashcardStreak++;
|
|
184
|
+
const dateObj = new Date(currentDate);
|
|
185
|
+
dateObj.setDate(dateObj.getDate() - 1);
|
|
186
|
+
currentDate = dateObj.toISOString().split("T")[0];
|
|
187
|
+
} else if (record.testDate < currentDate) {
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
currentDate = today;
|
|
193
|
+
for (const record of sortedActivity) {
|
|
194
|
+
if (record.testQuestionCount > 0) {
|
|
195
|
+
if (record.testDate === currentDate) {
|
|
196
|
+
testStreak++;
|
|
197
|
+
const dateObj = new Date(currentDate);
|
|
198
|
+
dateObj.setDate(dateObj.getDate() - 1);
|
|
199
|
+
currentDate = dateObj.toISOString().split("T")[0];
|
|
200
|
+
} else if (record.testDate < currentDate) {
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return { flashcardStreak, testStreak };
|
|
206
|
+
};
|
|
207
|
+
|
|
173
208
|
// src/design/api.ts
|
|
174
209
|
var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
|
|
175
210
|
HttpStatusCode2[HttpStatusCode2["OK"] = 200] = "OK";
|
|
@@ -213,6 +248,7 @@ var ApiPath = /* @__PURE__ */ ((ApiPath2) => {
|
|
|
213
248
|
ApiPath2["USER"] = "/user";
|
|
214
249
|
ApiPath2["USER_ONBOARDING"] = "/user/onboarding";
|
|
215
250
|
ApiPath2["USER_RESET_TEST"] = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd";
|
|
251
|
+
ApiPath2["VOCAB_CHECK_ACTIVITY"] = "/vocabCheckActivity/:endDate/:noOfDays";
|
|
216
252
|
return ApiPath2;
|
|
217
253
|
})(ApiPath || {});
|
|
218
254
|
var ClientPlatform = /* @__PURE__ */ ((ClientPlatform2) => {
|
|
@@ -238,6 +274,7 @@ export {
|
|
|
238
274
|
VocabCheckType,
|
|
239
275
|
convertJSDateStringToMySQLDate,
|
|
240
276
|
dateDifferenceInDays,
|
|
277
|
+
deriveStreakFromVocabCheckActivity,
|
|
241
278
|
getFormattedDate,
|
|
242
279
|
getMysqlDateIgnoreTZ,
|
|
243
280
|
isClientDateTooFarFromServerDate,
|
package/package.json
CHANGED
package/src/concrete/date.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MySQLDate } from '../index';
|
|
1
|
+
import { DateString, MySQLDate } from '../index';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @name getMysqlDateIgnoreTZ
|
|
@@ -100,7 +100,7 @@ export const isTheSameDay = (date1: MySQLDate, date2: MySQLDate): boolean => {
|
|
|
100
100
|
return new Date(date1).toDateString() === new Date(date2).toDateString();
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
export const getFormattedDate = (date: Date) => {
|
|
103
|
+
export const getFormattedDate = (date: Date): DateString => {
|
|
104
104
|
const year = date.getFullYear();
|
|
105
105
|
const month = (1 + date.getMonth()).toString().padStart(2, '0');
|
|
106
106
|
const day = date.getDate().toString().padStart(2, '0');
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { DateString, IVocabCheckActivity } from '../design/types';
|
|
2
|
+
|
|
3
|
+
export type Streaks = {
|
|
4
|
+
flashcardStreak: number;
|
|
5
|
+
testStreak: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const deriveStreakFromVocabCheckActivity = (activity: IVocabCheckActivity[], today: DateString): Streaks => {
|
|
9
|
+
if (activity.length === 0) return { flashcardStreak: 0, testStreak: 0 };
|
|
10
|
+
let flashcardStreak = 0;
|
|
11
|
+
let testStreak = 0;
|
|
12
|
+
|
|
13
|
+
// Sort activity by date descending
|
|
14
|
+
const sortedActivity = activity.sort((a, b) => (a.testDate < b.testDate ? 1 : -1));
|
|
15
|
+
|
|
16
|
+
// Derive flashcard streak
|
|
17
|
+
let currentDate = today;
|
|
18
|
+
for (const record of sortedActivity) {
|
|
19
|
+
if (record.flashcardCount > 0) {
|
|
20
|
+
if (record.testDate === currentDate) {
|
|
21
|
+
flashcardStreak++;
|
|
22
|
+
// Move to previous day
|
|
23
|
+
const dateObj = new Date(currentDate);
|
|
24
|
+
dateObj.setDate(dateObj.getDate() - 1);
|
|
25
|
+
currentDate = dateObj.toISOString().split('T')[0] as DateString;
|
|
26
|
+
} else if (record.testDate < currentDate) {
|
|
27
|
+
// Break the streak if there's a gap
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Reset currentDate for test streak calculation
|
|
34
|
+
currentDate = today;
|
|
35
|
+
for (const record of sortedActivity) {
|
|
36
|
+
if (record.testQuestionCount > 0) {
|
|
37
|
+
if (record.testDate === currentDate) {
|
|
38
|
+
testStreak++;
|
|
39
|
+
// Move to previous day
|
|
40
|
+
const dateObj = new Date(currentDate);
|
|
41
|
+
dateObj.setDate(dateObj.getDate() - 1);
|
|
42
|
+
currentDate = dateObj.toISOString().split('T')[0] as DateString;
|
|
43
|
+
} else if (record.testDate < currentDate) {
|
|
44
|
+
// Break the streak if there's a gap
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { flashcardStreak, testStreak };
|
|
51
|
+
|
|
52
|
+
}
|
package/src/design/api.ts
CHANGED
|
@@ -54,6 +54,7 @@ export enum ApiPath {
|
|
|
54
54
|
USER = '/user',
|
|
55
55
|
USER_ONBOARDING = '/user/onboarding',
|
|
56
56
|
USER_RESET_TEST = '/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd',
|
|
57
|
+
VOCAB_CHECK_ACTIVITY = '/vocabCheckActivity/:endDate/:noOfDays',
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
export enum ClientPlatform {
|
|
@@ -151,6 +152,10 @@ export interface HeatMapParams {
|
|
|
151
152
|
weekCount: number;
|
|
152
153
|
endDate: DateString;
|
|
153
154
|
}
|
|
155
|
+
export interface SelectVocabCheckActivityParams {
|
|
156
|
+
endDate: DateString;
|
|
157
|
+
noOfDays: number;
|
|
158
|
+
}
|
|
154
159
|
|
|
155
160
|
|
|
156
161
|
/**
|
package/src/design/types.ts
CHANGED
|
@@ -45,14 +45,14 @@ export interface ITestResult {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export interface IVocabCheckActivity {
|
|
48
|
-
testDate:
|
|
48
|
+
testDate: DateString;
|
|
49
49
|
flashcardCount: number;
|
|
50
50
|
testQuestionCount: number
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export type MySQLDate = `${number}-${number}-${number} ${number}:${number}:${number}`;
|
|
54
54
|
|
|
55
|
-
export type DateString = `${number}-${
|
|
55
|
+
export type DateString = `${number}-${string}-${string}`;
|
|
56
56
|
|
|
57
57
|
export enum ReminderFrequency {
|
|
58
58
|
ALWAYS = "ALWAYS",
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { IVocabCheckActivity } from '../src';
|
|
3
|
+
import { deriveStreakFromVocabCheckActivity } from '../src/concrete/vocabCheck';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
describe('deriveStreakFromVocabCheckActivity', () => {
|
|
8
|
+
it('should return 0 for empty activity', () => {
|
|
9
|
+
const mockToday = '2025-09-03';
|
|
10
|
+
expect(deriveStreakFromVocabCheckActivity([], mockToday)).to.deep.equal({flashcardStreak: 0, testStreak: 0});
|
|
11
|
+
});
|
|
12
|
+
it('should return correct streak for consecutive days', () => {
|
|
13
|
+
const mockToday = '2025-09-03';
|
|
14
|
+
const activity = [
|
|
15
|
+
{ testDate: '2025-09-01', flashcardCount: 10, testQuestionCount: 0 },
|
|
16
|
+
{ testDate: '2025-09-02', flashcardCount: 1, testQuestionCount: 0 },
|
|
17
|
+
{ testDate: '2025-09-03', flashcardCount: 20, testQuestionCount: 1 }
|
|
18
|
+
] as IVocabCheckActivity[];
|
|
19
|
+
expect(deriveStreakFromVocabCheckActivity(activity, mockToday)).to.deep.equal({flashcardStreak: 3, testStreak: 1});
|
|
20
|
+
});
|
|
21
|
+
it('should return correct streak with gaps in activity', () => {
|
|
22
|
+
const mockToday = '2025-09-04';
|
|
23
|
+
const activity = [
|
|
24
|
+
{ testDate: '2025-09-01', flashcardCount: 10, testQuestionCount: 10 },
|
|
25
|
+
{ testDate: '2025-09-03', flashcardCount: 15, testQuestionCount: 10 },
|
|
26
|
+
{ testDate: '2025-09-04', flashcardCount: 20, testQuestionCount: 10 },
|
|
27
|
+
] as IVocabCheckActivity[];
|
|
28
|
+
expect(deriveStreakFromVocabCheckActivity(activity, mockToday)).to.deep.equal({flashcardStreak: 2, testStreak: 2});
|
|
29
|
+
});
|
|
30
|
+
it('should return 0 if no activity today', () => {
|
|
31
|
+
const mockToday = '2025-09-04';
|
|
32
|
+
const activity = [
|
|
33
|
+
{ testDate: '2025-08-30', flashcardCount: 10, testQuestionCount: 10 },
|
|
34
|
+
{ testDate: '2025-08-31', flashcardCount: 15, testQuestionCount: 10 },
|
|
35
|
+
] as IVocabCheckActivity[];
|
|
36
|
+
expect(deriveStreakFromVocabCheckActivity(activity, mockToday)).to.deep.equal({flashcardStreak: 0, testStreak: 0});
|
|
37
|
+
});
|
|
38
|
+
it('should handle non-consecutive activity correctly', () => {
|
|
39
|
+
const mockToday = '2025-09-05';
|
|
40
|
+
const activity = [
|
|
41
|
+
{ testDate: '2025-09-01', flashcardCount: 10, testQuestionCount: 10 },
|
|
42
|
+
{ testDate: '2025-09-02', flashcardCount: 15, testQuestionCount: 10 },
|
|
43
|
+
{ testDate: '2025-09-04', flashcardCount: 20, testQuestionCount: 10 },
|
|
44
|
+
{ testDate: '2025-09-05', flashcardCount: 25, testQuestionCount: 10 },
|
|
45
|
+
] as IVocabCheckActivity[];
|
|
46
|
+
expect(deriveStreakFromVocabCheckActivity(activity, mockToday)).to.deep.equal({flashcardStreak: 2, testStreak: 2});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
});
|