-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checkpoint: Fetch/Parse/Convert Roam/sr practice Data
- Loading branch information
1 parent
81afa8f
commit 43872cc
Showing
9 changed files
with
217 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
[*] | ||
max_line_length = 100 | ||
insert_final_newline = true | ||
indent_size = 2 | ||
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import practice from '~/practice'; | ||
import * as queries from '~/queries'; | ||
|
||
export const importRoamSrOldData = async ({ pluginPageTitle }) => { | ||
const oldReviewData = await queries.getOldRoamSrPracticeData(); | ||
const newReviewData = await convertRoamSrPracticeData(oldReviewData, pluginPageTitle); | ||
console.log('DEBUG:: ~ file: migration.ts ~ line 8 ~ newReviewData', newReviewData); | ||
|
||
// Used to Filter blocks that already exist | ||
const pluginPageData = await queries.getPluginPageData({ pluginPageTitle }); | ||
// Ignore old data if already started practicing | ||
// if (typeof pluginPageData[refUid] !== 'undefined') continue; | ||
}; | ||
|
||
const convertRoamSrPracticeData = async (oldReviewRecords, pluginPageTitle) => { | ||
const results = {}; | ||
for (const [_, resultsArr] of Object.entries(oldReviewRecords)) { | ||
//@ts-ignore | ||
for (const result of resultsArr) { | ||
const { refUid, dateCreated, grade } = result; | ||
|
||
let practiceInputData = { | ||
refUid, | ||
grade, | ||
pluginPageTitle, | ||
dateCreated, | ||
eFactor: undefined, | ||
repetitions: undefined, | ||
interval: undefined, | ||
}; | ||
|
||
if (results[refUid]) { | ||
const lastPracticeResult = results[refUid][results[refUid].length - 1]; | ||
const { eFactor, repetitions, interval } = lastPracticeResult; | ||
practiceInputData = { ...practiceInputData, eFactor, repetitions, interval }; | ||
} else { | ||
const newCardData = queries.generateNewCardProps({ dateCreated }); | ||
practiceInputData = { ...practiceInputData, ...newCardData }; | ||
} | ||
|
||
const practiceResult = { | ||
...(await practice(practiceInputData, true)), | ||
grade, | ||
dateCreated, | ||
}; | ||
if (results[refUid]) { | ||
results[refUid].push(practiceResult); | ||
} else { | ||
results[refUid] = [practiceResult]; | ||
} | ||
} | ||
} | ||
|
||
return results; | ||
}; |