Feat/evaluation #1
@@ -1,4 +1,5 @@
|
|||||||
import ical, { VEvent } from 'node-ical';
|
import ical, { VEvent } from 'node-ical';
|
||||||
|
|
||||||
interface PageProps {
|
interface PageProps {
|
||||||
params: Promise<{
|
params: Promise<{
|
||||||
'days': string;
|
'days': string;
|
||||||
@@ -19,7 +20,19 @@ function getIcalDate(dateValue: any): Date {
|
|||||||
return new Date(dateValue);
|
return new Date(dateValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCategories(categoriesField: any): string[] {
|
||||||
|
if (!categoriesField) return [];
|
||||||
|
if (Array.isArray(categoriesField)) {
|
||||||
|
return categoriesField.map((cat) => getIcalText(cat));
|
||||||
|
}
|
||||||
|
return [getIcalText(categoriesField)];
|
||||||
|
}
|
||||||
|
|
||||||
|
type TimeMap = Record<string, number>
|
||||||
|
|
||||||
export default async function EvaluationPage({ params }: PageProps) {
|
export default async function EvaluationPage({ params }: PageProps) {
|
||||||
|
let times: TimeMap = {};
|
||||||
|
|
||||||
// get all params
|
// get all params
|
||||||
const resolvedParams = await params;
|
const resolvedParams = await params;
|
||||||
|
|
||||||
@@ -54,10 +67,38 @@ export default async function EvaluationPage({ params }: PageProps) {
|
|||||||
return startDate >= cutoffDate && startDate <= now;
|
return startDate >= cutoffDate && startDate <= now;
|
||||||
})
|
})
|
||||||
.sort((a, b) => getIcalDate(b.start).getTime() - getIcalDate(a.start).getTime()); // newest first
|
.sort((a, b) => getIcalDate(b.start).getTime() - getIcalDate(a.start).getTime()); // newest first
|
||||||
|
|
||||||
|
// read time per categorie
|
||||||
|
events.map((event, index) => {
|
||||||
|
const startDate = getIcalDate(event.start);
|
||||||
|
const endDate = getIcalDate(event.end);
|
||||||
|
const durationInMs = endDate.getTime() - startDate.getTime();
|
||||||
|
const durationInMinutes = durationInMs / (1000 * 60);
|
||||||
|
const categories = getCategories(event.categories);
|
||||||
|
|
||||||
|
categories.forEach((cat) => {
|
||||||
|
times[cat] = (times[cat] || 0) + durationInMinutes
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main style={{ padding: '2rem', fontFamily: 'sans-serif' }}>
|
<main>
|
||||||
<h1>Meine Kalender-Events</h1>
|
<h1>Meine Kalender-Events</h1>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<h2>Gesamtdauer pro Kategorie</h2>
|
||||||
|
{Object.keys(times).length === 0 ? (
|
||||||
|
<p>Keine Zeiten erfasst.</p>
|
||||||
|
) : (
|
||||||
|
<ul>
|
||||||
|
{Object.entries(times).map(([category, minutes]) => (
|
||||||
|
<li key={category}>
|
||||||
|
<strong>{category}:</strong> {Math.floor(minutes / 60)} Std. {minutes % 60} Min. ({minutes} Min. gesamt)
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
|
||||||
{events.length === 0 ? (
|
{events.length === 0 ? (
|
||||||
<p>Keine Termine gefunden.</p>
|
<p>Keine Termine gefunden.</p>
|
||||||
|
|||||||
Reference in new issue
Block a user