good time

This commit is contained in:
Tykayn 2024-01-20 23:53:42 +01:00 committed by tykayn
parent e76ef0b241
commit 95be931ec8
2 changed files with 76 additions and 35 deletions

View File

@ -101,7 +101,7 @@
{{ subjects[currentSubjectId].title }}
</h1>
<p>{{ subjects[currentSubjectId].duration }} min, par {{ subjects[currentSubjectId].author }}</p>
<p>Reste: {{ countRemainingMinutes(subjects[currentSubjectId]) }} min</p>
<!-- <p>Reste: {{ countRemainingMinutes(subjects[currentSubjectId]) }} min</p>-->
<div class="actions">
@ -120,9 +120,35 @@
<button class="btn btn-primary" (click)="updateProgressEveryPeriod()">
up temps
</button>
<br>
<br>
<br>
<div class="timeseries">
topic duration:<br> {{subjects[currentSubjectId].duration}} min
topic start:<br>
{{subjects[currentSubjectId].startDate| date: 'HH:mm'}}
<br>
topic end:<br>
{{subjects[currentSubjectId].endDate| date: 'HH:mm'}}
<br>
temps passé:
{{round(subjects[currentSubjectId].spentSeconds)}}
<br>
secondes max:
{{
Math.floor(
getSecondsBetweenTwoDates(
null,
subjects[currentSubjectId].endDate
)
- subjects[currentSubjectId].spentSeconds
)
}}
</div>
</div>
<p>avancement: {{ getPercentProgressTimeForTopic(subjects[currentSubjectId]) }} %</p>
<!-- <p>avancement: {{ getPercentProgressTimeForTopic(subjects[currentSubjectId]) }} %</p>-->
</div>
<div class="stats">
<h2>

View File

@ -45,6 +45,7 @@ export class AppComponent implements OnInit, OnDestroy {
statsExplication: string = ''
hints: string = "";
Math:Math = Math
showDebug: boolean = true;
startDate: Date = new Date();
@ -52,7 +53,6 @@ export class AppComponent implements OnInit, OnDestroy {
private topicChangeDate: Date = new Date();
updateTopicChangeDate(): void {
const currentTime = new Date();
const timeDifferenceInMilliseconds = this.topicChangeDate.getTime() - currentTime.getTime();
@ -81,19 +81,20 @@ export class AppComponent implements OnInit, OnDestroy {
topics.forEach((topic: string) => {
let boom = topic.split('-')
if (boom[0]) {
accumulatedDuration += this.findMinutesDurationInDescription(topic) | 0
let duration = this.findMinutesDurationInDescription(topic) | 0
accumulatedDuration += duration
newTopics.push({
id: ii,
title: boom[0],
duration: 15,
duration: duration,
spentSeconds: 0,
author: this.findAuthorInDescription(topic),
notes: '',
finished: false,
startDate: this.getStartDateAfterDuration(accumulatedDuration + ''),
endDate: this.getEndDateAfterDuration(accumulatedDuration + ''),
startDate: this.getEndDateAfterDuration(accumulatedDuration, this.startDate),
endDate: this.getEndDateAfterDuration(duration + accumulatedDuration, this.startDate),
})
}
ii += 1;
@ -110,11 +111,15 @@ export class AppComponent implements OnInit, OnDestroy {
* @param {string} [minute='00'] - A string representation of the minute (00-59).
* @returns {Date} A new Date object set to the specified time.
*/
makeDateFromHourToday(hourInput: string, minuteInput: string = '00') {
makeDateFromHourToday(hourInput: string){
let [hour, minute] = hourInput.split(":");
let date = new Date();
if (!minute) {
return date;
}
date.setHours(parseInt(hour));
date.setMinutes(minuteInput ? parseInt(minuteInput) : parseInt(minute));
date.setMinutes(parseInt(minute));
console.log('hourInput', hourInput, date)
return date;
}
@ -137,8 +142,8 @@ export class AppComponent implements OnInit, OnDestroy {
ngOnInit() {
this.parseTheListOfTopicsInPasteLand()
this.startDate = this.makeDateFromHourToday(this.startTime + '');
this.endDate = this.makeDateFromHourToday(this.endTime + '');
this.startDate = this.makeDateFromHourToday(this.startTime);
this.endDate = this.makeDateFromHourToday(this.endTime);
}
@ -149,8 +154,8 @@ export class AppComponent implements OnInit, OnDestroy {
nextSubject() {
this.updateTopicChangeDate()
if(this.currentSubjectId < this.subjects.length-1) {
this.currentSubjectId++
if (this.currentSubjectId < this.subjects.length - 1) {
this.currentSubjectId++
}
}
@ -163,11 +168,12 @@ export class AppComponent implements OnInit, OnDestroy {
return 0;
}
private getEndDateAfterDuration(accumulatedDuration: string) {
return this.makeDateFromHourToday(accumulatedDuration)
private getEndDateAfterDuration(minutes: number, startDate: Date) {
return new Date(startDate.getTime() + minutes * 60000);
}
private getStartDateAfterDuration(accumulatedDuration: string) {
getStartDateAfterDuration(accumulatedDuration: string) {
return this.makeDateFromHourToday(accumulatedDuration)
}
@ -183,6 +189,8 @@ export class AppComponent implements OnInit, OnDestroy {
getPercentProgressTimeForTopic(topic: Topic) {
let now = new Date();
console.log('topic démarré', topic.startDate.getTime())
console.log('topic va se finir', topic.endDate.getTime(), topic.endDate.getTime() - topic.startDate.getTime())
return Math.floor((now.getTime() - topic.startDate.getTime()) / (topic.endDate.getTime() - topic.startDate.getTime()) * 100);
}
@ -252,8 +260,8 @@ export class AppComponent implements OnInit, OnDestroy {
this.statsExplication = `Temps passé: ${this.round(totalSeconds)}
Moyenne par sujet: ${this.round(averageSeconds)}
Sujet le plus long: ${longestTopic.title.replace('*','')} (${this.round(longestSeconds)} )
Sujet le plus court : ${shortestTopic.title.replace('*','')} (${this.round(shortestSeconds)})`;
Sujet le plus long: ${longestTopic.title.replace('*', '')} (${this.round(longestSeconds)} )
Sujet le plus court : ${shortestTopic.title.replace('*', '')} (${this.round(shortestSeconds)})`;
}
@ -286,38 +294,38 @@ export class AppComponent implements OnInit, OnDestroy {
if (this.animator) {
compteRendu += `Animation: ${this.animator}.\n`;
}
compteRendu += `Statistiques:\n
compteRendu += `Statistiques:\n
${this.statsExplication}.`;
for (const topic of this.subjects) {
compteRendu += `* ${topic.title}-`;
compteRendu += ` ${topic.duration} min`;
compteRendu += ` (${topic.author})\n`;
compteRendu += ` ${topic.notes}\n`;
if(topic.spentSeconds){
if (topic.spentSeconds) {
compteRendu += `Temps écoulé : ${this.round(topic.spentSeconds)}\n\n`;
compteRendu += `Temps écoulé : ${this.round(topic.spentSeconds)}\n\n`;
}
}
this.compteRendu = compteRendu
return compteRendu
}
/**
/**
* returns each present person for each line with a dash at the beggining if missing
*/
formatPresentLines(){
formatPresentLines() {
let lines = ''
if (this.presents) {
lines += this.presents.split('\n').map(line => {
if(!line.length){
return '';
}
if (!line.startsWith('- ')) {
return `- ${line}`;
}
return line;
}).join('\n') + '\n'
}
if (this.presents) {
lines += this.presents.split('\n').map(line => {
if (!line.length) {
return '';
}
if (!line.startsWith('- ')) {
return `- ${line}`;
}
return line;
}).join('\n') + '\n'
}
return lines.trim();
}
@ -347,7 +355,14 @@ export class AppComponent implements OnInit, OnDestroy {
lien.click();
}
getMinutesBetweenTwoDates(date1: Date, date2: Date) {
getMinutesBetweenTwoDates(date1: Date = new Date(), date2: Date) {
return Math.floor((date2.getTime() - date1.getTime()) / 60000);
}
getSecondsBetweenTwoDates(date1: Date | null, date2: Date) {
if (!date1) {
date1 = new Date()
}
return Math.floor((date2.getTime() - date1.getTime()) / 1000);
}
}