dashboard version 1

This commit is contained in:
X4Lo committed 2024-05-10 09:45:54 +01:00
1 parent 1361fc7b18
commit a05fdd44ec
7 files changed
+731 -98

No files matched your search

@@ -1,10 +1,251 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import ApexCharts from 'apexcharts';
import { EntrySeenService } from '../../core/services/entry-seen.service';
import { LibraryService } from '../../core/services/library.service';
import { EpisodeSeenService } from '../../core/services/episode-seen.service';
import { Observable, forkJoin } from 'rxjs';
@Component({
selector: 'app-home-page',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
styleUrls: ['./home.component.css'],
})
export class HomeComponent {
export class HomeComponent implements OnInit {
counts: {
movies: number;
series: number;
favorit: number;
watchlist: number;
} = {
movies: 0,
series: 0,
favorit: 0,
watchlist: 0,
};
yearlyChart: any;
watchCount: {
movies: number[];
series: number[];
moviesTotal: number;
seriesTotal: number;
year: number;
} = {
movies: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
series: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
moviesTotal: 0,
seriesTotal: 0,
year: 0,
};
constructor(
private entrySeenService: EntrySeenService,
private episodeSeenService: EpisodeSeenService,
private libraryService: LibraryService
) {
console.log('hey im home');
}
async ngOnInit() {
// ? get counts (movies, series, favorit, watchlist)
this.getCounts();
// ? get yearly watch stats
let year: number = new Date().getFullYear();
this.watchCount.year = year;
this.getYearlyWatchHistoryStats();
}
changeYear(year: number) {
// TODO implement this in the view
this.watchCount.year = year;
console.log(`Year set to: `, this.watchCount.year);
this.getYearlyWatchHistoryStats();
}
async getYearlyWatchHistoryStats() {
let moviesObs = this.entrySeenService.getYearlyStats(this.watchCount.year);
let seriesObs = this.episodeSeenService.getYearlyStats(
this.watchCount.year
);
const forkObs = forkJoin([moviesObs, seriesObs]).subscribe({
next: ([movies, series]) => {
console.log(`results: `, movies, series);
this.watchCount.moviesTotal = 0;
this.watchCount.seriesTotal = 0;
this.watchCount.movies = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
this.watchCount.series = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for (let i = 0; i < movies.length; i++) {
this.watchCount.movies[movies[i].month - 1] = movies[i].count;
this.watchCount.moviesTotal += movies[i].count;
}
for (let i = 0; i < series.length; i++) {
this.watchCount.series[series[i].month - 1] = series[i].count;
this.watchCount.seriesTotal += series[i].count;
}
console.log(
`Watch stats for the year ${this.watchCount.year} fetched successfully.`
);
this.showYearlyStats();
},
error: (error) => {
console.log(error);
},
complete: () => {
forkObs.unsubscribe();
},
});
// this.entrySeenService.getYearlyStats(year).subscribe({
// next: (stats) => {
// // looping through stats
// for (let i = 0; i < stats.length; i++) {
// this.watchCount.movies[stats[i].month - 1] = stats[i].count;
// }
// console.log(`Movies Stats for the year ${year}`, stats);
// },
// error: (error) => {
// console.log(`Error getting stats for the year ${year}`, error);
// },
// });
// this.episodeSeenService.getYearlyStats(year).subscribe({
// next: (stats) => {
// // looping through stats
// for (let i = 0; i < stats.length; i++) {
// this.watchCount.series[stats[i].month - 1] = stats[i].count;
// }
// this.showYearlyStats();
// console.log(`Series Stats for the year ${year}`, stats);
// },
// error: (error) => {
// console.log(`Error getting series stats for the year ${year}`, error);
// },
// });
}
getCounts() {
// TODO performance: change this to get stats from backend directly
this.libraryService.getAllEntries(true).subscribe((entries) => {
this.counts.favorit = entries.filter((e) => e.favorit).length;
this.counts.watchlist = entries.filter((e) => e.watchlist).length;
this.counts.movies = entries.filter(
(e) => !e.is_tvseries && !e.watchlist
).length;
this.counts.series = entries.filter(
(e) => e.is_tvseries && !e.watchlist
).length;
});
}
showYearlyStats() {
var yearlyChartOptions = {
series: [
{
name: 'Movies',
data: this.watchCount.movies,
},
{
name: 'Tv-Series Episodes',
data: this.watchCount.series,
// data: [17, 10, 45, 15, 25, 15, 40, 10, 24, 5, 6, 3],
},
],
chart: {
//width:150,
foreColor: '#9ba7b2',
height: 235,
type: 'bar',
toolbar: {
show: !1,
},
sparkline: {
enabled: !1,
},
zoom: {
enabled: false,
},
},
dataLabels: {
enabled: false,
},
stroke: {
width: 4,
curve: 'smooth',
colors: ['transparent'],
},
fill: {
type: 'gradient',
gradient: {
shade: 'dark',
gradientToColors: ['#0d6efd', '#6f42c1'],
shadeIntensity: 1,
type: 'vertical',
// opacityFrom: 0.8,
// opacityTo: 0.1,
stops: [0, 100, 100, 100],
},
},
colors: ['#0d6efd', '#6f42c1'],
plotOptions: {
bar: {
horizontal: false,
borderRadius: 0,
borderRadiusApplication: 'around',
borderRadiusWhenStacked: 'last',
columnWidth: '55%',
},
},
grid: {
show: false,
borderColor: 'rgba(0, 0, 0, 0.15)',
strokeDashArray: 4,
},
tooltip: {
theme: 'dark',
fixed: {
enabled: !0,
},
x: {
show: !0,
},
y: {
title: 'dd',
},
marker: {
show: !1,
},
},
xaxis: {
categories: [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
],
},
};
if (this.yearlyChart) {
this.yearlyChart.destroy(); // Destroy the existing chart instance if it exists
}
this.yearlyChart = new ApexCharts(
document.querySelector('#yearlyChart'),
yearlyChartOptions
);
this.yearlyChart.render();
}
}