📄 sugarmemolearn2.c
字号:
}
}
MemPtrUnlock(app);
MemHandleUnlock(recordH);
FrmSetControlGroupSelection(FrmGetActiveForm(), DynamicPushButtonGroup, DynamicPushButtonStart + DefaultField);
}
void ClearLowerPaneTab(){
FormType* frmP;
FormType** formPP;
UInt16 index;
WordFields i;
SugarAppInfoType* app;
WordRecordType record;
MemHandle recordH;
app = GetAppInfoPtr(CurrentDB);
GetWordRecord(CurrentDB, CurrentRecord, &record, &recordH);
for (i = WordFieldQuestion; i < WordFieldsCount; i++){
if (i == DefaultField || (GetBitMacro(app -> answerPageFields.allBits, i) != 0)
&& (record.field[i] != NULL)){
frmP = FrmGetActiveForm();
index = FrmGetObjectIndex(frmP, DynamicPushButtonStart + i);
if (index == frmInvalidObjectId) continue;
HideObject(DynamicPushButtonStart + i);
formPP = &frmP;
FrmRemoveObject(formPP, index);
}
}
MemPtrUnlock(app);
MemHandleUnlock(recordH);
}
void ErasePane(UInt16 ObjectID){
RectangleType bounds;
GetObjectBounds(ObjectID, &bounds);
WinEraseRectangle(&bounds, 0);
}
void Learn2FormDoButtonNext(){
Boolean right = false;
// clear up
ClearLowerPaneTab();
ErasePane(Learn2UpperPaneGadget);
ErasePane(Learn2LowerPaneGadget);
HideObject(Learn2NextButton);
ShowNext = false;
if (HeaderRecordIndex == LearningRecordIndex){
if (CurrentLearningStatus == FirstLook) right = true;
Learn2ProcessLearningRating(right);
}
if (HeaderRecordIndex == TestingRecordIndex){
Learn2ProcessReviewRating(FailRating);
}
}
void Learn2FormDoButtonShow(){
WordFieldFlags flag;
HideObject(Learn2ShowButton);
ShowShow = false;
if (HeaderRecordIndex == LearningRecordIndex){
switch(CurrentLearningStatus){
case TranslationRecollection:
DefaultField = WordFieldAnswer;
break;
case WordRecollection:
DefaultField = WordFieldQuestion;
break;
}
ShowObject(Learn2RightPushButton);
ShowObject(Learn2WrongPushButton);
FrmSetControlGroupSelection(FrmGetActiveForm(), RightWrongGroup, Learn2RightPushButton);
ShowRightWrong = true;
}
if (HeaderRecordIndex == TestingRecordIndex){
switch(CurrentLearningStatus){
case TranslationRecollection:
DefaultField = WordFieldAnswer;
break;
case WordRecollection:
DefaultField = WordFieldQuestion;
break;
}
ShowObject(Learn2BingoPushButton);
ShowObject(Learn2PassPushButton);
ShowObject(Learn2FailPushButton);
FrmSetControlGroupSelection(FrmGetActiveForm(), BingoPassFailGroup, Learn2BingoPushButton);
ShowBingoPassFail = true;
}
ResetLowerPane();
LoadLowerPaneTab();
flag.allBits = 0;
SetBitMacro(flag.allBits, DefaultField);
DrawLowerPane(flag);
}
void Learn2FormDoButtonPush(UInt16 objectID){
Boolean right;
Rating rating;
ErasePane(Learn2UpperPaneGadget);
ErasePane(Learn2LowerPaneGadget);
ClearLowerPaneTab();
ResetAllPush();
if (HeaderRecordIndex == LearningRecordIndex){
if (objectID == Learn2RightPushButton) right = true;
else right = false;
Learn2ProcessLearningRating(right);
}
if (HeaderRecordIndex == TestingRecordIndex){
switch(objectID){
case Learn2BingoPushButton:
rating = BingoRating;
break;
case Learn2PassPushButton:
rating = PassRating;
break;
case Learn2FailPushButton:
rating = FailRating;
break;
}
Learn2ProcessReviewRating(rating);
}
}
void Learn2DoDynamicPushButton(WordFields field){
WordFieldFlags flag;
ErasePane(Learn2LowerPaneGadget);
ResetLowerPane();
flag.allBits = BitAtPosition(field);
DrawLowerPane(flag);
}
void ResetAllPush(){
ControlType* control;
if (HeaderRecordIndex == LearningRecordIndex){
control = GetObjectPtr(Learn2RightPushButton);
CtlSetValue(control, 0);
control = GetObjectPtr(Learn2WrongPushButton);
CtlSetValue(control, 0);
HideObject(Learn2RightPushButton);
HideObject(Learn2WrongPushButton);
ShowRightWrong = false;
}
if (HeaderRecordIndex == TestingRecordIndex){
control = GetObjectPtr(Learn2BingoPushButton);
CtlSetValue(control, 0);
control = GetObjectPtr(Learn2PassPushButton);
CtlSetValue(control, 0);
control = GetObjectPtr(Learn2FailPushButton);
CtlSetValue(control, 0);
HideObject(Learn2BingoPushButton);
HideObject(Learn2PassPushButton);
HideObject(Learn2FailPushButton);
ShowBingoPassFail = false;
}
}
void Learn2FormTableSelection(Int16 row){
TableType* table = GetObjectPtr(Learn2ChoiceTable);
Rating rating = NoRating;
MemorizingStatus ms = GetMemorizingStatus(CurrentDB, CurrentRecord);
TblUnhighlightSelection(table);
ErasePane(Learn2UpperPaneGadget);
ClearChoiceTable();
if (HeaderRecordIndex == LearningRecordIndex){
if (TblGetRowID(table, row) == CurrentRecord) {
Learn2ProcessLearningRating(true);
return;
}
if (CurrentLearningStatus == TranslationTest) DrawTranslationLook();
if (CurrentLearningStatus == WordTest) DrawWordLook();
return;
}
if (HeaderRecordIndex == TestingRecordIndex){
if (TblGetRowID(table, row) == CurrentRecord){
if (TimGetTicks() - StartingTicks < 6 * SysTicksPerSecond()) rating = BingoRating;
else rating = PassRating;
Learn2ProcessReviewRating(rating);
return;
}
if (CurrentLearningStatus == TranslationTest) DrawTranslationLook();
if (CurrentLearningStatus == WordTest) DrawWordLook();
return;
}
}
void ClearChoiceTable(){
TableType* table = GetObjectPtr(Learn2ChoiceTable);
RectangleType bounds;
RectangleType compactBounds = {{0, 48}, {160, 97}};
Int16 row;
for (row = 0; row < RowsInChoiceTable; row ++){
TblSetRowUsable(table, row, false);
}
GetObjectBounds(Learn2ChoiceTable, &bounds);
WinEraseRectangle(&bounds, 0);
SetObjectBounds(Learn2ChoiceTable, &compactBounds);
ShowChoices = false;
}
void Learn2FormQuit(){
if (CurrentDB != NULL && CurrentDB != 0)
DmCloseDatabase(CurrentDB);
HeaderRecordIndex = HeaderIndexCounts;
FrmGotoForm(MainForm);
}
LearningStatus TossNextReviewMode(){
SugarAppInfoType* app;
ReviewMode reviewMode;
TestingStatus ts = GetTestingStatus(CurrentDB, CurrentRecord);
UInt16 i = 0, j = 0, r = 0, r0 = 0;
app = GetAppInfoPtr(CurrentDB);
reviewMode = app -> reviewMode;
MemPtrUnlock(app);
r = (UInt32)SysRandom(0) * 12 /sysRandomMax;
r0 = r;
i = TranslationRecollection;
while (true) {
if (GetBitMacro((UInt16)(reviewMode.allBits), i)!= 0 && GetBitMacro((UInt16)(ts.reviewMode.allBits), i) == 0 ){
if (r == 0) return i;
else r--;
}
if (i == 4 && r == r0) return 0; // finished
if (i == 4) i = 1;
else i ++;
}
return 0;
}
void Learn2FinishReview(){
Char rate, strErrTxt[100];
Rating r1, r2;
// Rating maxRating;
TestingStatus ts = GetTestingStatus(CurrentDB, CurrentRecord);
MemorizingStatus ms = GetMemorizingStatus(CurrentDB, CurrentRecord);
UInt16 interval, tFail;
DateType today;
r1 = ts.firstRating;
r2 = ts.secondRating;
tFail = ts.totalFail;
DateSecondsToDate(TimGetSeconds(), &today);
/* if (r1 < r2) {
maxRating = r1;
// Added by hytown
if (maxRating == NoRating) maxRating = r2;
}
else {
maxRating = r2;
// Added by hytown
if (maxRating == NoRating) maxRating = r1;
}*/
// double ace
if ((r1 == BingoRating && r2 == BingoRating) || (r1 == BingoRating && r2 == NoRating)) rate = 'A';
// first ace, second none, or pass
// else if (r1 == BingoRating && r2 <= PassRating) rate = 'B';
// Changed by hytown
// else if (maxRating == BingoRating) rate = 'B';
else if ((r1 == BingoRating && r2 == PassRating) \
|| (r1 == PassRating && r2 == BingoRating) \
|| (r1 == FailRating && r2 == BingoRating && tFail == 1) \
|| (r1 == PassRating && r2 == NoRating)) rate = 'B';
// first pass, second bingo or pass
// else if (maxRating == PassRating) rate = 'C';
// Changed by hytown
else if ((r1 == FailRating && r2 == PassRating && tFail == 1) \
|| (r1 == FailRating && r2 == BingoRating && tFail == 2) \
|| (r1 == PassRating && r2 == PassRating)) rate = 'C';
// at least one fail, only fail once
// else if (maxRating == FailRating && ts.totalFail == 1) rate = 'D';
// Changed by hytown
else if ((r1 == FailRating && r2 == PassRating && tFail == 2) \
|| (r1 == FailRating && r2 == BingoRating && tFail > 2 && tFail < maxFail)) rate = 'D';
// fail many times
// else if (maxRating == FailRating && ts.totalFail < maxFail) rate = 'E';
// Changed by hytown
else if (r1 == FailRating && r2 == PassRating && tFail > 2 && tFail < maxFail) rate = 'E';
// fail too many times
else if (tFail >= maxFail) rate = 'F';
// Added by hytown
// Some situation not expected
else {
rate = 'F';
StrPrintF(strErrTxt, "%s%i%s%i%s%i%s", "The situation is unexpected. firstRating = ", r1, \
"; secondRating = ", r2, "; totalFail = ", tFail, ". Please report this error message on hi-pda.com, thanks.");
DoCustomDialog("Error", strErrTxt, false, NULL, NULL, true);
}
/*
float eFactor; //E-Factor
UInt8 difficulty; //
UInt8 totalLapse;
UInt8 totalRecall;
UInt8 step; //step in current round
DateType lastTest;
DateType currentTest; //when the current test begins, only meaningful for drilling words
DateType nextTest;
DateType firstLearn;
DateType create;
*/
switch (rate){
case 'A':
if (ms.step == 1) {
ms.totalRecall++;
ms.step++;
if (DateToDays(ms.nextTest) - DateToDays(ms.lastTest) > 2)
interval = (Int32)((ms.eFactor - 1.3) * 8 / 1.2) + 13;
else if (DateToDays(ms.nextTest) - DateToDays(ms.lastTest) == 2)
interval = 7;
else
interval = 6;
ms.lastTest = today;
ms.nextTest = today;
DateAdjust(&ms.nextTest, interval);
}
else {
ms.eFactor += 0.1;
ms.difficulty = Difficulty(ms.eFactor);
ms.totalRecall++;
ms.step++;
interval = DateToDays(ms.nextTest) - DateToDays(ms.lastTest);
ms.lastTest = today;
ms.nextTest = today;
DateAdjust(&ms.nextTest, (UInt16)(interval * ms.eFactor));
}
break;
case 'B':
if (ms.step == 1) {
ms.totalRecall++;
ms.step++;
if (DateToDays(ms.nextTest) - DateToDays(ms.lastTest) > 2)
interval = (Int32)((ms.eFactor - 1.3) * 8 / 1.2) + 13;
else if (DateToDays(ms.nextTest) - DateToDays(ms.lastTest) == 2)
interval = 6;
else
interval = 5;
ms.lastTest = today;
ms.nextTest = today;
DateAdjust(&ms.nextTest, interval);
}
else {
ms.difficulty = Difficulty(ms.eFactor);
ms.totalRecall++;
ms.step++;
interval = DateToDays(ms.nextTest) - DateToDays(ms.lastTest);
ms.lastTest = today;
ms.nextTest = today;
DateAdjust(&ms.nextTest, (UInt16)(interval * ms.eFactor));
}
break;
case 'C':
if (ms.step == 1) {
ms.totalRecall++;
ms.step++;
if (DateToDays(ms.nextTest) - DateToDays(ms.lastTest) > 2)
interval = (Int32)((ms.eFactor - 1.3) * 8 / 1.2) + 13;
else if (DateToDays(ms.nextTest) - DateToDays(ms.lastTest) == 2)
interval = 5;
else
interval = 4;
ms.lastTest = today;
ms.nextTest = today;
DateAdjust(&ms.nextTest, interval);
}
else {
ms.eFactor -= 0.14;
if (ms.eFactor < 1.3) ms.eFactor = 1.3;
ms.difficulty = Difficulty(ms.eFactor);
ms.totalRecall++;
ms.step++;
interval = DateToDays(ms.nextTest) - DateToDays(ms.lastTest);
ms.lastTest = today;
ms.nextTest = today;
DateAdjust(&ms.nextTest, (UInt16)(interval * ms.eFactor));
}
break;
case 'D':
ms.eFactor -= 0.32;
if (ms.eFactor < 1.3) ms.eFactor = 1.3;
ms.difficulty = Difficulty(ms.eFactor);
ms.totalLapse++;
ms.step = 1;
interval = 8 - (Int32)((ms.eFactor - 1.3) * 3 / 1.2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -