From 47b393e134a26e746156c8a719da1c977b3e13fc Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 27 Jan 2025 20:17:45 +0100 Subject: [PATCH] Korrektur UserLogo, #12 Easy interal must be greater than good interval --- .gitignore | 4 +- src/app/app.component.ts | 19 +++++-- src/app/training/training.component.ts | 75 ++++++++++++++++---------- 3 files changed, 63 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index f7175a6..e4572a7 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,6 @@ Thumbs.db *.db .nx/cache -.nx/workspace-data \ No newline at end of file +.nx/workspace-data +.aider* +.env diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 5c17f7f..e428bf9 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -30,10 +30,16 @@ import { ClickOutsideDirective } from './service/click-outside.directive';

Vocabulary Training

- User Photo -
+ @if(photoURL){ + User Photo + } @else { +
Image
+ } + @if(showDropdown){ +
+ }
@@ -72,6 +78,7 @@ img:hover { .dropdown button:hover { background-color: #f7fafc; } + `, imports: [CommonModule, DeckListComponent, ClickOutsideDirective], }) @@ -79,7 +86,7 @@ export class AppComponent { isLoggedIn = false; private auth: Auth = inject(Auth); showDropdown = false; - photoURL: string = 'https://via.placeholder.com/40'; + photoURL: string = 'https://placehold.co/40'; // user: User | null = null; ngOnInit() { @@ -88,7 +95,7 @@ export class AppComponent { const accessToken = localStorage.getItem('accessToken'); const refreshToken = localStorage.getItem('refreshToken'); this.photoURL = localStorage.getItem('photoURL'); - this.showDropdown = false; + if (isLoggedIn && accessToken && refreshToken) { this.isLoggedIn = true; } @@ -106,7 +113,9 @@ export class AppComponent { localStorage.setItem('accessToken', await result.user.getIdToken()); localStorage.setItem('refreshToken', result.user.refreshToken); localStorage.setItem('photoURL', result.user.photoURL); - + + this.showDropdown = false; + console.log('Logged in with Google', result.user); } catch (error) { console.error('Google Login failed', error); diff --git a/src/app/training/training.component.ts b/src/app/training/training.component.ts index 781c149..0888223 100644 --- a/src/app/training/training.component.ts +++ b/src/app/training/training.component.ts @@ -1,7 +1,7 @@ -import { Component, Input, Output, EventEmitter, OnInit, ViewChild, ElementRef } from '@angular/core'; -import { Deck, DeckImage, DeckService, Box } from '../deck.service'; import { CommonModule } from '@angular/common'; +import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'; import { lastValueFrom } from 'rxjs'; +import { Box, Deck, DeckImage, DeckService } from '../deck.service'; const LEARNING_STEPS = { AGAIN: 1, // 1 minute @@ -267,59 +267,76 @@ export class TrainingComponent implements OnInit { * @param action The action ('again', 'good', 'easy') * @returns An object with the new values for ivl, factor, reps, and lapses */ - calculateNewInterval(box: Box, action: 'again' | 'good' | 'easy'): { newIvl: number, newFactor: number, newReps: number, newLapses: number, newIsGraduated: boolean } { + calculateNewInterval(box: Box, action: 'again' | 'good' | 'easy'): { + newIvl: number, + newFactor: number, + newReps: number, + newLapses: number, + newIsGraduated: boolean + } { + const LEARNING_STEPS = { + AGAIN: 1, // 1 minute + GOOD: 10, // 10 minutes + GRADUATION: 1440 // 1 day (1440 minutes) + }; + + const EASY_BONUS = 1.3; // Zusätzlicher Easy-Multiplikator +/* const FACTOR_CHANGES = { + MIN: 1.3, + MAX: 2.5, + AGAIN: 0.85, + EASY: 1.15 + }; */ + let newIvl = box.ivl || 0; let newFactor = box.factor || 2.5; let newReps = box.reps || 0; let newLapses = box.lapses || 0; let newIsGraduated = box.isGraduated || false; - + if (action === 'again') { newLapses++; newReps = 0; newIvl = LEARNING_STEPS.AGAIN; newIsGraduated = false; - - // Reduce factor but not below minimum - newFactor = Math.max( - FACTOR_CHANGES.MIN, - newFactor * FACTOR_CHANGES.AGAIN - ); - + newFactor = Math.max(FACTOR_CHANGES.MIN, newFactor * FACTOR_CHANGES.AGAIN); return { newIvl, newFactor, newReps, newLapses, newIsGraduated }; } - + if (action === 'easy') { newReps++; - newIsGraduated = true; - newIvl = EASY_INTERVAL; - - // Increase factor but not above maximum - newFactor = Math.min( - FACTOR_CHANGES.MAX, - newFactor * FACTOR_CHANGES.EASY - ); - + + // Faktor zuerst aktualisieren + const updatedFactor = Math.min(FACTOR_CHANGES.MAX, newFactor * FACTOR_CHANGES.EASY); + + if (!newIsGraduated) { + // Direkte Graduierung mit Easy + newIsGraduated = true; + newIvl = LEARNING_STEPS.GRADUATION; // 1 Tag (1440 Minuten) + } else { + // Anki-Formel für Easy in der Review-Phase + newIvl = Math.round((newIvl + LEARNING_STEPS.GRADUATION / 2) * updatedFactor * EASY_BONUS); + } + + newFactor = updatedFactor; return { newIvl, newFactor, newReps, newLapses, newIsGraduated }; } - + // Handle 'good' action newReps++; - + if (!newIsGraduated) { - // Card is in learning phase if (newReps === 1) { - newIvl = LEARNING_STEPS.GOOD; + newIvl = LEARNING_STEPS.GOOD; // 10 Minuten } else { - // Graduate the card newIsGraduated = true; - newIvl = LEARNING_STEPS.GRADUATION; + newIvl = LEARNING_STEPS.GRADUATION; // 1 Tag nach zweiter Good-Antwort } } else { - // Card is in review phase, apply space repetition + // Standard-SR-Formel newIvl = Math.round(newIvl * newFactor); } - + return { newIvl, newFactor, newReps, newLapses, newIsGraduated }; }