add statistic service & add new stats to home page
This commit is contained in:
1 parent
90e3f936fc
commit
1b36bc66fe
7 files changed
+213
-210
No files matched your search
@@ -0,0 +1,3 @@
|
||||
.time-color {
|
||||
color: var(--shz-blue-default);
|
||||
}
|
||||
@@ -83,184 +83,106 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 col-xl-5 col-xxl-4 d-flex">
|
||||
<div class="card rounded-4 w-100 shadow-none bg-transparent border-0">
|
||||
<div class="card-body p-0">
|
||||
<div class="row g-4">
|
||||
<div class="col-12 col-xl-6 d-flex">
|
||||
<div class="card mb-0 rounded-4 w-100">
|
||||
<div class="card-body">
|
||||
<div class="d-flex align-items-start justify-content-between mb-3">
|
||||
<div class="">
|
||||
<h4 class="mb-0">97.4K</h4>
|
||||
<p class="mb-0">Total Users</p>
|
||||
</div>
|
||||
<div class="dropdown">
|
||||
<a href="javascript:;" class="dropdown-toggle-nocaret options dropdown-toggle"
|
||||
data-bs-toggle="dropdown">
|
||||
<span class="material-icons-outlined fs-5">more_vert</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item" href="javascript:;">Action</a></li>
|
||||
<li><a class="dropdown-item" href="javascript:;">Another action</a></li>
|
||||
<li><a class="dropdown-item" href="javascript:;">Something else here</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-container2">
|
||||
<div id="chart3"></div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<p class="mb-0"><span class="text-success me-1">12.5%</span> from last month</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-xl-6 d-flex">
|
||||
<div class="card mb-0 rounded-4 w-100">
|
||||
<div class="card-body">
|
||||
<div class="d-flex align-items-start justify-content-between mb-1">
|
||||
<div class="">
|
||||
<h4 class="mb-0">42.5K</h4>
|
||||
<p class="mb-0">Active Users</p>
|
||||
</div>
|
||||
<div class="dropdown">
|
||||
<a href="javascript:;" class="dropdown-toggle-nocaret options dropdown-toggle"
|
||||
data-bs-toggle="dropdown">
|
||||
<span class="material-icons-outlined fs-5">more_vert</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item" href="javascript:;">Action</a></li>
|
||||
<li><a class="dropdown-item" href="javascript:;">Another action</a></li>
|
||||
<li><a class="dropdown-item" href="javascript:;">Something else here</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-container2">
|
||||
<div id="chart2" style="min-height: 131.818px;">
|
||||
<div id="apexcharts3qnjc9lg" class="apexcharts-canvas apexcharts3qnjc9lg apexcharts-theme-light"
|
||||
style="width: 131px; height: 131.818px;"><svg id="SvgjsSvg1785" width="131"
|
||||
height="131.81753540039062" xmlns="http://www.w3.org/2000/svg" version="1.1"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.dev" class="apexcharts-svg"
|
||||
xmlns:data="ApexChartsNS" transform="translate(0, 0)" style="background: transparent;">
|
||||
<foreignObject x="0" y="0" width="131" height="131.81753540039062">
|
||||
<div class="apexcharts-legend" xmlns="http://www.w3.org/1999/xhtml"></div>
|
||||
</foreignObject>
|
||||
<g id="SvgjsG1787" class="apexcharts-inner apexcharts-graphical"
|
||||
transform="translate(-11.5, 0)">
|
||||
<defs id="SvgjsDefs1786">
|
||||
<clipPath id="gridRectMask3qnjc9lg">
|
||||
<rect id="SvgjsRect1788" width="162" height="180" x="-3" y="-1" rx="0" ry="0" opacity="1"
|
||||
stroke-width="0" stroke="none" stroke-dasharray="0" fill="#fff"></rect>
|
||||
</clipPath>
|
||||
<clipPath id="forecastMask3qnjc9lg"></clipPath>
|
||||
<clipPath id="nonForecastMask3qnjc9lg"></clipPath>
|
||||
<clipPath id="gridRectMarkerMask3qnjc9lg">
|
||||
<rect id="SvgjsRect1789" width="160" height="182" x="-2" y="-2" rx="0" ry="0" opacity="1"
|
||||
stroke-width="0" stroke="none" stroke-dasharray="0" fill="#fff"></rect>
|
||||
</clipPath>
|
||||
<linearGradient id="SvgjsLinearGradient1794" x1="0" y1="1" x2="1" y2="1">
|
||||
<stop id="SvgjsStop1795" stop-opacity="0.1" stop-color="rgba(8,102,255,0.1)" offset="0">
|
||||
</stop>
|
||||
<stop id="SvgjsStop1796" stop-opacity="1" stop-color="rgba(0,0,0,1)" offset="1"></stop>
|
||||
<stop id="SvgjsStop1797" stop-opacity="1" stop-color="rgba(0,0,0,1)" offset="1"></stop>
|
||||
</linearGradient>
|
||||
<linearGradient id="SvgjsLinearGradient1804" x1="0" y1="1" x2="1" y2="1">
|
||||
<stop id="SvgjsStop1805" stop-opacity="1" stop-color="rgba(8,102,255,1)" offset="0">
|
||||
</stop>
|
||||
<stop id="SvgjsStop1806" stop-opacity="1" stop-color="rgba(252,24,90,1)" offset="1">
|
||||
</stop>
|
||||
<stop id="SvgjsStop1807" stop-opacity="1" stop-color="rgba(252,24,90,1)" offset="1">
|
||||
</stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g id="SvgjsG1790" class="apexcharts-radialbar">
|
||||
<g id="SvgjsG1791">
|
||||
<g id="SvgjsG1792" class="apexcharts-tracks">
|
||||
<g id="SvgjsG1793" class="apexcharts-radialbar-track apexcharts-track" rel="1">
|
||||
<path id="apexcharts-radialbarTrack-0"
|
||||
d="M 23.999529440199204 103.18083296600864 A 59.5829268292683 59.5829268292683 0 1 1 132.0004705598008 103.18083296600865"
|
||||
fill="none" fill-opacity="1" stroke="rgba(0, 0, 0, 0.1)" stroke-opacity="1"
|
||||
stroke-linecap="round" stroke-width="4.696536585365855" stroke-dasharray="0"
|
||||
class="apexcharts-radialbar-area"
|
||||
data:pathOrig="M 23.999529440199204 103.18083296600864 A 59.5829268292683 59.5829268292683 0 1 1 132.0004705598008 103.18083296600865">
|
||||
</path>
|
||||
</g>
|
||||
</g>
|
||||
<g id="SvgjsG1799">
|
||||
<g id="SvgjsG1803" class="apexcharts-series apexcharts-radial-series"
|
||||
seriesName="TotalxOrders" rel="1" data:realIndex="0">
|
||||
<path id="SvgjsPath1808"
|
||||
d="M 23.999529440199204 103.18083296600864 A 59.5829268292683 59.5829268292683 0 0 1 131.55277989522526 51.88056403680397"
|
||||
fill="none" fill-opacity="0.85" stroke="url(#SvgjsLinearGradient1804)"
|
||||
stroke-opacity="1" stroke-linecap="round" stroke-width="7.009756097560977"
|
||||
stroke-dasharray="0" class="apexcharts-radialbar-area apexcharts-radialbar-slice-0"
|
||||
data:angle="179" data:value="78" index="0" j="0"
|
||||
data:pathOrig="M 23.999529440199204 103.18083296600864 A 59.5829268292683 59.5829268292683 0 0 1 131.55277989522526 51.88056403680397">
|
||||
</path>
|
||||
</g>
|
||||
<circle id="SvgjsCircle1800" r="57.23465853658537" cx="78" cy="78"
|
||||
class="apexcharts-radialbar-hollow" fill="transparent"></circle>
|
||||
<g id="SvgjsG1801" class="apexcharts-datalabels-group"
|
||||
transform="translate(0, 0) scale(1)" style="opacity: 1;"><text id="SvgjsText1802"
|
||||
font-family="Helvetica, Arial, sans-serif" x="78" y="88" text-anchor="middle"
|
||||
dominant-baseline="auto" font-size="24px" font-weight="400" fill="#111111"
|
||||
class="apexcharts-text apexcharts-datalabel-value"
|
||||
style="font-family: Helvetica, Arial, sans-serif;">78%</text></g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<line id="SvgjsLine1809" x1="0" y1="0" x2="156" y2="0" stroke="#b6b6b6" stroke-dasharray="0"
|
||||
stroke-width="1" stroke-linecap="butt" class="apexcharts-ycrosshairs"></line>
|
||||
<line id="SvgjsLine1810" x1="0" y1="0" x2="156" y2="0" stroke-dasharray="0" stroke-width="0"
|
||||
stroke-linecap="butt" class="apexcharts-ycrosshairs-hidden"></line>
|
||||
</g>
|
||||
</svg></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<p class="mb-0">24K users increased from last month</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-xl-12">
|
||||
<div class="card rounded-4 mb-0">
|
||||
<div class="card-body">
|
||||
<div class="d-flex align-items-center gap-3 mb-2">
|
||||
<div class="">
|
||||
<h2 class="mb-0">$65,129</h2>
|
||||
</div>
|
||||
<div class="">
|
||||
<p
|
||||
class="dash-lable d-flex align-items-center gap-1 rounded mb-0 bg-success text-success bg-opacity-10">
|
||||
<span class="material-icons-outlined fs-6">arrow_upward</span>8.6%
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<p class="mb-0">Sales This Year</p>
|
||||
<div class="mt-4">
|
||||
<p class="mb-2 d-flex align-items-center justify-content-between">285 left to Goal<span
|
||||
class="">78%</span></p>
|
||||
<div class="progress w-100" style="height: 7px;">
|
||||
<div class="progress-bar bg-primary" style="width: 65%"></div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- watchtime -->
|
||||
<div class="col-12 col-xl-4 d-flex flex-column justify-content-between">
|
||||
<!-- movies watchtime -->
|
||||
<div class="card rounded-4">
|
||||
<div class="card-body">
|
||||
<div class="d-flex gap-2 mb-4">
|
||||
<h5 class="mb-0 d-flex align-items-center gap-2 fw-bold">
|
||||
Total Time Spent Watching
|
||||
</h5>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between p-3">
|
||||
|
||||
<div id="watchTimeMovies">
|
||||
<div class="d-flex gap-2 mb-4">
|
||||
<div
|
||||
class="wh-48 d-flex bg-success text-success bg-opacity-10 align-items-center justify-content-center rounded-circle"
|
||||
style="min-width: 48px;">
|
||||
<span class="material-icons-outlined">movie</span>
|
||||
</div>
|
||||
<h5 class="mb-0 d-flex align-items-center gap-2">
|
||||
Movies
|
||||
</h5>
|
||||
</div>
|
||||
<div class="d-flex align-items-start justify-content">
|
||||
<div class="d-flex flex-column align-items-start gap-1">
|
||||
<h5 class="mb-0 time-color">{{ watchTime.allTime.movies | number }} minutes</h5>
|
||||
<p class="mb-0">and it is</p>
|
||||
<h5 class="mb-0 time-color">{{ watchTime.allTime.movies | minutesFormat:'hours' | number }} hours</h5>
|
||||
<p class="mb-0">which is about {{watchTime.allTime.movies | minutesFormat:'days'}} days.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div><!--end row-->
|
||||
<div id="watchTimeSeries">
|
||||
<div class="d-flex gap-2 mb-4">
|
||||
<div
|
||||
class="wh-48 d-flex bg-danger text-danger bg-opacity-10 align-items-center justify-content-center rounded-circle"
|
||||
style="min-width: 48px;">
|
||||
<span class="material-icons-outlined">tv</span>
|
||||
</div>
|
||||
<h5 class="mb-0 d-flex align-items-center gap-2">
|
||||
Tv-Series
|
||||
</h5>
|
||||
</div>
|
||||
<div class="d-flex align-items-start justify-content">
|
||||
<div class="d-flex flex-column align-items-start gap-1">
|
||||
<h5 class="mb-0 time-color">{{ watchTime.allTime.series | number }} minutes</h5>
|
||||
<p class="mb-0">and it is</p>
|
||||
<h5 class="mb-0 time-color">{{ watchTime.allTime.series | minutesFormat:'hours' | number }} hours</h5>
|
||||
<p class="mb-0">which is about {{watchTime.allTime.series | minutesFormat:'days'}} days.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-body align-content-center">
|
||||
|
||||
<p class="mb-0">You've spent {{ watchTime.allTime.total | minutesFormat:'days' | number }} days of your life
|
||||
watching this crap.
|
||||
<br>
|
||||
<span>{{ (watchTime.allTime.total * 100) / minutesAge | floatFormat:2 }}% of your life.</span>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- series watchtime -->
|
||||
<!-- <div class="card rounded-4">
|
||||
<div class="card-body">
|
||||
<div class="d-flex gap-2 mb-4">
|
||||
<div
|
||||
class="wh-48 d-flex bg-danger text-danger bg-opacity-10 align-items-center justify-content-center rounded-circle"
|
||||
style="min-width: 48px;">
|
||||
<span class="material-icons-outlined">tv</span>
|
||||
</div>
|
||||
<h5 class="mb-0 d-flex align-items-center gap-2">
|
||||
Total Time Spent Watching Tv-Series
|
||||
</h5>
|
||||
</div>
|
||||
<div class="d-flex align-items-start justify-content">
|
||||
<div class="d-flex flex-column align-items-start gap-1">
|
||||
<h5 class="mb-0 time-color">{{ watchTime.allTime.series | number }} minutes</h5>
|
||||
<p class="mb-0">and it is</p>
|
||||
<h5 class="mb-0 time-color">{{ watchTime.allTime.series | minutesFormat:'hours' | number }} hours</h5>
|
||||
<p class="mb-0">which is about {{watchTime.allTime.series | minutesFormat:'days'}} days.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- watch history graph -->
|
||||
<div class="col-12 col-xl-7 col-xxl-8 d-flex">
|
||||
<div class="card w-100 rounded-4">
|
||||
<div class="card-body">
|
||||
<div class="d-flex align-items-start justify-content-between mb-3">
|
||||
<div class="">
|
||||
<h5 class="mb-0 fw-bold">{{watchCount.year}} Watch Stats</h5>
|
||||
<h5 class="mb-0 fw-bold">{{watchCount.year}} Watch History</h5>
|
||||
</div>
|
||||
<div class="dropdown">
|
||||
<a href="javascript:;" class="dropdown-toggle-nocaret options dropdown-toggle" data-bs-toggle="dropdown">
|
||||
@@ -328,5 +250,9 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
|
||||
@@ -4,6 +4,9 @@ import { EntrySeenService } from '../../core/services/entry-seen.service';
|
||||
import { LibraryService } from '../../core/services/library.service';
|
||||
import { EpisodeSeenService } from '../../core/services/episode-seen.service';
|
||||
import { forkJoin } from 'rxjs';
|
||||
import { StatisticsService } from '../../core/services/statistics.service';
|
||||
import { WatchTime } from '../../shared/models/statistics/watchTime.model';
|
||||
import { WatchCount } from '../../shared/models/statistics/watchCount.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-home-page',
|
||||
@@ -24,23 +27,32 @@ export class HomeComponent implements OnInit {
|
||||
};
|
||||
|
||||
yearlyChart: any;
|
||||
watchCount: {
|
||||
movies: number[];
|
||||
series: number[];
|
||||
moviesTotal: number;
|
||||
seriesTotal: number;
|
||||
year: number;
|
||||
} = {
|
||||
watchCount: WatchCount = {
|
||||
year: 0,
|
||||
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,
|
||||
};
|
||||
|
||||
watchTime: WatchTime = {
|
||||
allTime: {
|
||||
series: 0,
|
||||
movies: 0,
|
||||
},
|
||||
yearly: {
|
||||
year: 0,
|
||||
series: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
movies: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
moviesTotal: 0,
|
||||
seriesTotal: 0,
|
||||
},
|
||||
} as WatchTime;
|
||||
|
||||
minutesAge = 0;
|
||||
|
||||
constructor(
|
||||
private entrySeenService: EntrySeenService,
|
||||
private episodeSeenService: EpisodeSeenService,
|
||||
private statisticsService: StatisticsService,
|
||||
private libraryService: LibraryService
|
||||
) {
|
||||
console.log('hey im home');
|
||||
@@ -53,44 +65,83 @@ export class HomeComponent implements OnInit {
|
||||
// ? get yearly watch stats
|
||||
let year: number = new Date().getFullYear();
|
||||
this.watchCount.year = year;
|
||||
this.getYearlyWatchHistoryStats();
|
||||
this.getYearlyWatchCount();
|
||||
this.getWatchTime();
|
||||
|
||||
this.minutesAge =
|
||||
(new Date().getTime() - new Date('2000-08-07').getTime()) / 1000 / 60;
|
||||
}
|
||||
|
||||
changeYear(year: number) {
|
||||
// TODO implement this in the view
|
||||
this.watchCount.year = year;
|
||||
console.log(`Year set to: `, this.watchCount.year);
|
||||
this.getYearlyWatchHistoryStats();
|
||||
this.getYearlyWatchCount();
|
||||
}
|
||||
|
||||
async getYearlyWatchHistoryStats() {
|
||||
let moviesObs = this.entrySeenService.getYearlyStats(this.watchCount.year);
|
||||
let seriesObs = this.episodeSeenService.getYearlyStats(
|
||||
this.watchCount.year
|
||||
);
|
||||
async getYearlyWatchCount() {
|
||||
let watchCountObs = this.statisticsService
|
||||
.fetchYearlyWatchCount(this.watchCount.year)
|
||||
.subscribe({
|
||||
next: (wc) => {
|
||||
// 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];
|
||||
|
||||
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 < wc.movies.length; i++) {
|
||||
this.watchCount.movies[wc.movies[i].month - 1] = wc.movies[i].count;
|
||||
this.watchCount.moviesTotal += wc.movies[i].count;
|
||||
}
|
||||
|
||||
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 < wc.series.length; i++) {
|
||||
this.watchCount.series[wc.series[i].month - 1] = wc.series[i].count;
|
||||
this.watchCount.seriesTotal += wc.series[i].count;
|
||||
}
|
||||
|
||||
console.log(
|
||||
`Watch stats for the year ${this.watchCount.year} fetched successfully.`
|
||||
);
|
||||
this.showYearlyStats();
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(error);
|
||||
},
|
||||
complete: () => {
|
||||
watchCountObs.unsubscribe();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getWatchTime() {
|
||||
const thisYear = new Date().getFullYear();
|
||||
let allTimeObs = this.statisticsService.fetchAllTimeTotalWatchTime();
|
||||
let yearlyObs = this.statisticsService.fetchYearlyTotalWatchTime(thisYear);
|
||||
|
||||
const forkObs = forkJoin([allTimeObs, yearlyObs]).subscribe({
|
||||
next: ([allTime, yearly]) => {
|
||||
// console.log(`results: `, allTime, yearly);
|
||||
this.watchTime.allTime.series = allTime.series;
|
||||
this.watchTime.allTime.movies = allTime.movies;
|
||||
this.watchTime.allTime.total =
|
||||
Number.parseInt(allTime.series) + Number.parseInt(allTime.movies);
|
||||
|
||||
this.watchTime.yearly.year = thisYear;
|
||||
|
||||
for (let i = 0; i < yearly.series.length; i++) {
|
||||
this.watchTime.yearly.series[yearly.series[i].month - 1] =
|
||||
yearly.series[i].watchTime;
|
||||
this.watchTime.yearly.seriesTotal += yearly.series[i].watchTime;
|
||||
}
|
||||
|
||||
for (let i = 0; i < series.length; i++) {
|
||||
this.watchCount.series[series[i].month - 1] = series[i].count;
|
||||
this.watchCount.seriesTotal += series[i].count;
|
||||
for (let i = 0; i < yearly.movies.length; i++) {
|
||||
this.watchTime.yearly.movies[yearly.movies[i].month - 1] =
|
||||
yearly.movies[i].watchTime;
|
||||
this.watchTime.yearly.moviesTotal += yearly.movies[i].watchTime;
|
||||
}
|
||||
|
||||
console.log(
|
||||
`Watch stats for the year ${this.watchCount.year} fetched successfully.`
|
||||
);
|
||||
this.showYearlyStats();
|
||||
console.log(this.watchTime);
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(error);
|
||||
|
||||
Reference in new issue
Block a user