2024-01-20 17:53:21 +01:00
|
|
|
import {Component, OnDestroy, OnInit} from '@angular/core';
|
2023-12-04 11:22:35 +01:00
|
|
|
import {CommonModule} from '@angular/common';
|
|
|
|
import {RouterOutlet} from '@angular/router';
|
2023-12-04 11:01:56 +01:00
|
|
|
import {FormsModule} from "@angular/forms";
|
|
|
|
|
2023-12-04 11:22:35 +01:00
|
|
|
|
2024-01-20 17:53:21 +01:00
|
|
|
interface Topic {
|
|
|
|
id: number, // numéro du sujet
|
2023-12-04 11:01:56 +01:00
|
|
|
title: string, // titre du sujet à aborder
|
2024-01-20 18:44:40 +01:00
|
|
|
notes: string, // titre du sujet à aborder
|
2023-12-04 11:01:56 +01:00
|
|
|
duration: number, // nombre de minutes du sujet
|
2024-01-20 17:53:21 +01:00
|
|
|
author: string,// auteur du sujet qui anime la discussion
|
|
|
|
startDate: Date, // date de début du sujet
|
|
|
|
endDate: Date,// date de fin du sujet
|
|
|
|
finished: boolean,// si le sujet est terminé
|
|
|
|
spentSeconds: number, // nombre de secondes passées au sujet
|
2023-12-04 11:01:56 +01:00
|
|
|
}
|
2023-12-04 11:22:35 +01:00
|
|
|
|
2023-12-04 11:01:56 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'app-root',
|
|
|
|
standalone: true,
|
|
|
|
imports: [CommonModule, RouterOutlet, FormsModule],
|
|
|
|
templateUrl: './app.component.html',
|
2023-12-04 11:22:35 +01:00
|
|
|
styleUrl: './app.component.scss',
|
2023-12-04 11:01:56 +01:00
|
|
|
})
|
2024-01-20 17:53:21 +01:00
|
|
|
export class AppComponent implements OnInit, OnDestroy {
|
2023-12-04 11:01:56 +01:00
|
|
|
title = 'odj';
|
2024-01-20 17:53:21 +01:00
|
|
|
subjects: Array<Topic> = [];
|
|
|
|
currentSubjectId = 0;
|
2024-01-20 18:44:40 +01:00
|
|
|
startTime: string = "20:30";
|
|
|
|
// startTime: string = "17:00";
|
2023-12-04 11:01:56 +01:00
|
|
|
endTime: string = "22:00";
|
|
|
|
pasteLand: string = "* Présentation du suivi sur Nextcloud - 5min (tykayn)\n" +
|
|
|
|
"* Réduction de bus factor - 5min (tykayn)\n" +
|
|
|
|
"* Réunion avec Wikimedia France - 5min (tykayn)\n" +
|
2024-01-20 17:53:21 +01:00
|
|
|
"";
|
2023-12-04 11:01:56 +01:00
|
|
|
|
2024-01-20 18:44:40 +01:00
|
|
|
statsExplication: string = ''
|
|
|
|
|
|
|
|
hints: string = "";
|
|
|
|
|
|
|
|
showDebug: boolean = true;
|
2024-01-20 17:53:21 +01:00
|
|
|
private startDate: Date = new Date();
|
|
|
|
private endDate: Date = new Date();
|
|
|
|
private topicChangeDate: Date = new Date();
|
|
|
|
|
|
|
|
|
|
|
|
updateTopicChangeDate(): void {
|
|
|
|
const currentTime = new Date();
|
|
|
|
const timeDifferenceInMilliseconds = this.topicChangeDate.getTime() - currentTime.getTime();
|
|
|
|
const timeDifferenceInSeconds = Math.abs(timeDifferenceInMilliseconds / 1000);
|
|
|
|
|
|
|
|
console.log(`Spent ${timeDifferenceInSeconds} seconds`);
|
|
|
|
this.subjects[this.currentSubjectId].spentSeconds += timeDifferenceInSeconds;
|
|
|
|
this.topicChangeDate = currentTime;
|
|
|
|
}
|
2024-01-20 18:44:40 +01:00
|
|
|
round(val:number){
|
|
|
|
if (val < 60) {
|
|
|
|
return Math.round(val) +' s'
|
|
|
|
}
|
|
|
|
return (Math.round(val / 60) * 60) + ' min'
|
|
|
|
}
|
2023-12-04 11:01:56 +01:00
|
|
|
|
2023-12-04 11:22:35 +01:00
|
|
|
parseTheListOfTopicsInPasteLand() {
|
2023-12-04 11:01:56 +01:00
|
|
|
|
2023-12-04 11:22:35 +01:00
|
|
|
let newTopics: any = []
|
2023-12-04 11:01:56 +01:00
|
|
|
let topics: any = this.pasteLand.split('*')
|
2024-01-20 17:53:21 +01:00
|
|
|
let accumulatedDuration: number = 0;
|
|
|
|
let ii = 0;
|
2023-12-04 11:22:35 +01:00
|
|
|
|
2024-01-20 17:53:21 +01:00
|
|
|
topics.forEach((topic: string) => {
|
|
|
|
let boom = topic.split('-')
|
2023-12-04 11:22:35 +01:00
|
|
|
if (boom[0]) {
|
2024-01-20 17:53:21 +01:00
|
|
|
accumulatedDuration += this.findMinutesDurationInDescription(topic) | 0
|
|
|
|
|
2023-12-04 11:22:35 +01:00
|
|
|
newTopics.push({
|
2024-01-20 17:53:21 +01:00
|
|
|
id: ii,
|
2023-12-04 11:22:35 +01:00
|
|
|
title: boom[0],
|
|
|
|
duration: 15,
|
2024-01-20 18:44:40 +01:00
|
|
|
spentSeconds: 0,
|
2024-01-20 17:53:21 +01:00
|
|
|
author: '',
|
2024-01-20 18:44:40 +01:00
|
|
|
notes: '',
|
|
|
|
finished: false,
|
2024-01-20 17:53:21 +01:00
|
|
|
startDate: this.getStartDateAfterDuration(accumulatedDuration + ''),
|
|
|
|
endDate: this.getEndDateAfterDuration(accumulatedDuration + ''),
|
2023-12-04 11:22:35 +01:00
|
|
|
})
|
|
|
|
}
|
2024-01-20 17:53:21 +01:00
|
|
|
ii += 1;
|
2023-12-04 11:01:56 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
this.subjects = newTopics
|
|
|
|
}
|
2023-12-04 11:22:35 +01:00
|
|
|
|
2024-01-20 17:53:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new Date object set to the specified time in the current time zone.
|
|
|
|
*
|
|
|
|
* @param {string} hour - A string representation of the hour, in 24-hour format.
|
|
|
|
* @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') {
|
|
|
|
let [hour, minute] = hourInput.split(":");
|
|
|
|
let date = new Date();
|
|
|
|
date.setHours(parseInt(hour));
|
|
|
|
date.setMinutes(minuteInput ? parseInt(minuteInput) : parseInt(minute));
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes the remaining time for a given topic, based on the current time and the start and end times of the topic.
|
|
|
|
*
|
|
|
|
* @param {Topic} topic - The topic for which to compute the remaining time.
|
|
|
|
*/
|
2024-01-20 18:44:40 +01:00
|
|
|
computeResteTopicMinutes(topic: Topic): number {
|
2024-01-20 17:53:21 +01:00
|
|
|
let currentSubjectDuration = topic.duration; // The duration of the current subject, in minutes
|
|
|
|
let currentSubjectStartTime = new Date(this.startTime); // The start time of the current subject
|
|
|
|
let currentSubjectEndTime = new Date(currentSubjectStartTime.getTime() + currentSubjectDuration * 60000); // The end time of the current subject
|
|
|
|
|
2024-01-20 18:44:40 +01:00
|
|
|
return currentSubjectEndTime.getTime() - new Date().getTime(); // The remaining time, in milliseconds
|
|
|
|
|
2024-01-20 17:53:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
interval: any;
|
|
|
|
|
2023-12-04 11:22:35 +01:00
|
|
|
ngOnInit() {
|
2023-12-04 11:01:56 +01:00
|
|
|
this.parseTheListOfTopicsInPasteLand()
|
2024-01-20 17:53:21 +01:00
|
|
|
|
|
|
|
this.startDate = this.makeDateFromHourToday(this.startTime + '');
|
|
|
|
this.endDate = this.makeDateFromHourToday(this.endTime + '');
|
|
|
|
|
|
|
|
// this.interval = setInterval(() => {
|
|
|
|
this.updateProgressEveryPeriod();
|
|
|
|
// }, 1 * 1000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
clearInterval(this.interval);
|
2023-12-04 11:01:56 +01:00
|
|
|
}
|
2023-12-04 11:22:35 +01:00
|
|
|
|
|
|
|
nextSubject() {
|
2024-01-20 17:53:21 +01:00
|
|
|
this.updateTopicChangeDate()
|
2023-12-04 11:22:35 +01:00
|
|
|
this.currentSubjectId++
|
|
|
|
}
|
2024-01-20 17:53:21 +01:00
|
|
|
|
|
|
|
findMinutesDurationInDescription(topic: string): number {
|
|
|
|
let durationRegex = /-\s(\d+)min/g;
|
|
|
|
let matches = durationRegex.exec(topic);
|
|
|
|
if (matches) {
|
|
|
|
return parseInt(matches[1]);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private getEndDateAfterDuration(accumulatedDuration: string) {
|
|
|
|
return this.makeDateFromHourToday(accumulatedDuration)
|
|
|
|
}
|
|
|
|
|
|
|
|
private getStartDateAfterDuration(accumulatedDuration: string) {
|
|
|
|
return this.makeDateFromHourToday(accumulatedDuration)
|
|
|
|
}
|
|
|
|
|
|
|
|
isTopicRunning(topic: Topic) {
|
|
|
|
let now = new Date();
|
|
|
|
return now >= topic.startDate && now <= topic.endDate && !topic.finished;
|
|
|
|
}
|
|
|
|
|
|
|
|
countRemainingMinutes(topic: Topic) {
|
|
|
|
let now = new Date();
|
|
|
|
return Math.floor((topic.endDate.getTime() - now.getTime()) / 60000);
|
|
|
|
}
|
|
|
|
|
|
|
|
getPercentProgressTimeForTopic(topic: Topic) {
|
|
|
|
let now = new Date();
|
|
|
|
return Math.floor((now.getTime() - topic.startDate.getTime()) / (topic.endDate.getTime() - topic.startDate.getTime()) * 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
finishTopic(currentSubjectId: number) {
|
|
|
|
this.subjects[currentSubjectId].finished = true
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* only had one second to the current topic
|
|
|
|
*/
|
|
|
|
updateProgressEveryPeriod() {
|
|
|
|
this.subjects[this.currentSubjectId].spentSeconds += 1;
|
|
|
|
console.log('ajout au topic', this.currentSubjectId)
|
|
|
|
}
|
|
|
|
|
2024-01-20 18:44:40 +01:00
|
|
|
resteTopicMinutes(topic: Topic) {
|
|
|
|
return this.round(topic.spentSeconds / topic.duration * 60) + ' min'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-20 17:53:21 +01:00
|
|
|
convertTextToHTMLLinks(text: string): string {
|
|
|
|
let urlRegex = /(https?:\/\/[^\s<]+[^<.,:;\"\'\]\s])(?!["\])\s])/g;
|
|
|
|
let matches = urlRegex.exec(text);
|
|
|
|
while (matches) {
|
|
|
|
let url = matches[1];
|
|
|
|
let linkText = url;
|
|
|
|
if (url.length > 30) {
|
|
|
|
linkText = url.substring(0, 30) + "...";
|
|
|
|
}
|
|
|
|
text = text.replace(url, `<a href="${url}">${linkText}</a>`);
|
|
|
|
matches = urlRegex.exec(text);
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
previousSubject() {
|
|
|
|
this.updateTopicChangeDate()
|
|
|
|
this.currentSubjectId < 1 ? this.currentSubjectId = 0 : this.currentSubjectId -= 1;
|
|
|
|
}
|
2024-01-20 18:44:40 +01:00
|
|
|
|
|
|
|
makeStatisticsOnTopicsSpentSeconds() {
|
|
|
|
let totalSeconds = 0;
|
|
|
|
for (const topic of this.subjects) {
|
|
|
|
totalSeconds += topic.spentSeconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
let averageSeconds = totalSeconds / this.subjects.length;
|
|
|
|
|
|
|
|
let longestTopic = this.subjects[0];
|
|
|
|
let longestSeconds = longestTopic.spentSeconds;
|
|
|
|
for (const topic of this.subjects) {
|
|
|
|
if (topic.spentSeconds > longestSeconds) {
|
|
|
|
longestSeconds = topic.spentSeconds;
|
|
|
|
longestTopic = topic;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let shortestTopic = this.subjects[0];
|
|
|
|
let shortestSeconds = shortestTopic.spentSeconds;
|
|
|
|
for (const topic of this.subjects) {
|
|
|
|
if (topic.spentSeconds < shortestSeconds) {
|
|
|
|
shortestSeconds = topic.spentSeconds;
|
|
|
|
shortestTopic = topic;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.statsExplication = `Total spent seconds: ${totalSeconds}\nAverage spent seconds: ${averageSeconds}\nLongest topic: ${longestTopic.title} (${longestSeconds} seconds)\nShortest topic: ${shortestTopic.title} (${shortestSeconds} seconds)`;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setSubject(i: number) {
|
|
|
|
this.currentSubjectId = i;
|
|
|
|
this.updateTopicChangeDate()
|
|
|
|
}
|
|
|
|
|
|
|
|
compteRendu:string = ''
|
|
|
|
|
|
|
|
|
|
|
|
buildCompteRendu(){
|
|
|
|
let compteRendu = 'Compte rendu :\n\n';
|
|
|
|
for (const topic of this.subjects) {
|
|
|
|
compteRendu += `Sujet ${topic.id + 1} : ${topic.title}\n`;
|
|
|
|
compteRendu += `Durée : ${topic.duration} minutes\n`;
|
|
|
|
compteRendu += `Temps écoulé : ${this.resteTopicMinutes(topic)}\n\n`;
|
|
|
|
}
|
|
|
|
this.compteRendu = compteRendu
|
|
|
|
return compteRendu
|
|
|
|
}
|
|
|
|
copyCompteRenduToClipboard() {
|
|
|
|
|
|
|
|
navigator.clipboard.writeText(this.compteRendu);
|
|
|
|
}
|
2023-12-04 11:01:56 +01:00
|
|
|
}
|