Skip to content

Commit

Permalink
fix: use past 365 days instead of astronomical year (#55)
Browse files Browse the repository at this point in the history
re #55
  • Loading branch information
RaunoT committed Jan 8, 2024
1 parent 5a1233e commit 4d5017f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/app/dashboard/_components/PeriodSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export default function PeriodSelect() {
</li>
<li>
<Link
href={`${pathname}?period=thisYear`}
href={`${pathname}?period=pastYear`}
className='nav-link'
aria-selected={period === 'thisYear'}
aria-selected={period === 'pastYear'}
>
This year
Past year
</Link>
</li>
<li>
Expand Down
8 changes: 4 additions & 4 deletions src/app/rewind/_components/Stories/Audio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function StoryAudio({
<>
<RewindStat isPaused={isPaused} scaleDelay={3}>
<p>
To top it all off, you listened to&nbsp;
To top it all off, you&apos;ve listened to&nbsp;
<span className='rewind-stat'>
{userRewind.audio.duration}
</span>{' '}
Expand All @@ -31,7 +31,7 @@ export default function StoryAudio({

<RewindStat isPaused={isPaused} renderDelay={3} scaleDelay={3}>
<p>
You listened to{' '}
You&apos;ve listened to{' '}
<span className='rewind-stat'>{userRewind.audio.count}</span>{' '}
<span className='rewind-cat'>tracks</span> in total!
</p>
Expand All @@ -44,7 +44,7 @@ export default function StoryAudio({
noScale
>
<p className='mb-2'>
Your favorite was{' '}
Your favorite has been{' '}
<span className='rewind-cat'>
{userRewind.audio.top[0].title}
</span>
Expand All @@ -69,7 +69,7 @@ export default function StoryAudio({
Audio
<MusicalNoteIcon />
</span>{' '}
on <span className='text-yellow-500'>Plex</span> this year{' '}
on <span className='text-yellow-500'>Plex</span> in the past year{' '}
<span className='not-italic'>🥴</span>
</p>
</RewindStat>
Expand Down
8 changes: 4 additions & 4 deletions src/app/rewind/_components/Stories/Movies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function StoryMovies({
<RewindStat isPaused={isPaused} scaleDelay={3}>
<p>
<span className='rewind-stat'>{userRewind.movies.duration}</span>{' '}
of your time was spent watching{' '}
of your time has been spent watching{' '}
<span className='rewind-cat'>
Movies
<FilmIcon />
Expand All @@ -28,7 +28,7 @@ export default function StoryMovies({

<RewindStat isPaused={isPaused} renderDelay={3} scaleDelay={3}>
<p>
You watched{' '}
You&apos;ve watched{' '}
<span className='rewind-stat'>{userRewind.movies.count}</span>{' '}
<span className='rewind-cat'>movies</span> in total!
</p>
Expand All @@ -41,7 +41,7 @@ export default function StoryMovies({
noScale
>
<p className='mb-2'>
Your favorite was{' '}
Your favorite has been{' '}
<span className='rewind-cat'>
{userRewind.movies.top[0].title}
</span>
Expand All @@ -66,7 +66,7 @@ export default function StoryMovies({
Movies
<FilmIcon />
</span>{' '}
on <span className='text-yellow-500'>Plex</span> this year{' '}
on <span className='text-yellow-500'>Plex</span> in the past year{' '}
<span className='not-italic'>😵‍💫</span>
</p>
</RewindStat>
Expand Down
8 changes: 4 additions & 4 deletions src/app/rewind/_components/Stories/Requests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function StoryRequests({
Requests
<QuestionMarkCircleIcon />
</span>{' '}
this year <span className='not-italic'>😲</span>
in the past year <span className='not-italic'>😲</span>
</p>
</RewindStat>
) : (
Expand All @@ -38,7 +38,7 @@ export default function StoryRequests({
Requests
<QuestionMarkCircleIcon />
</span>{' '}
this year! You can make them via{' '}
in the past year! You can make them via{' '}
<a
className='link link--dark relative z-10'
href={process.env.NEXT_PUBLIC_OVERSEERR_URL}
Expand All @@ -61,7 +61,7 @@ export default function StoryRequests({
Requests
<QuestionMarkCircleIcon />
</span>{' '}
this year.
in the past year.
</p>
</RewindStat>
)}
Expand All @@ -74,7 +74,7 @@ export default function StoryRequests({
Requests
<QuestionMarkCircleIcon />
</span>{' '}
this year.
during the same period.
</p>
</RewindStat>

Expand Down
10 changes: 5 additions & 5 deletions src/app/rewind/_components/Stories/Shows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ export default function StoryShows({
TV Shows
<PlayCircleIcon />
</span>{' '}
took up{' '}
have taken up{' '}
<span className='rewind-stat'>
{userRewind.shows.duration}
</span>{' '}
of your year on <span className='text-yellow-500'>Plex</span>.
of your time on <span className='text-yellow-500'>Plex</span>.
</p>
</RewindStat>

<RewindStat isPaused={isPaused} renderDelay={3} scaleDelay={3}>
<p>
You watched{' '}
You&apos;ve watched{' '}
<span className='rewind-stat'>{userRewind.shows.count}</span>{' '}
<span className='rewind-cat'>episodes</span> in total!
</p>
Expand All @@ -43,7 +43,7 @@ export default function StoryShows({
noScale
>
<p className='mb-2'>
Your favorite was{' '}
Your favorite has been{' '}
<span className='rewind-cat'>
{userRewind.shows.top[0].title}
</span>
Expand All @@ -68,7 +68,7 @@ export default function StoryShows({
TV Shows
<PlayCircleIcon />
</span>{' '}
on <span className='text-yellow-500'>Plex</span> this year{' '}
on <span className='text-yellow-500'>Plex</span> in the past year{' '}
<span className='not-italic'>😥</span>
</p>
</RewindStat>
Expand Down
6 changes: 3 additions & 3 deletions src/app/rewind/_components/Stories/Total.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function StoryTotal({
of <span className='rewind-stat'>
{userRewind.duration.user}
</span>{' '}
on <span className='text-yellow-500'>Plex</span> this year!
on <span className='text-yellow-500'>Plex</span> in the past year!
</p>
</RewindStat>

Expand All @@ -34,7 +34,7 @@ export default function StoryTotal({
{userRewind.duration.user_percentage}
<ChartPieIcon />
</span>{' '}
of all plays, which totalled{' '}
of all plays, which total{' '}
<span className='rewind-stat'>{userRewind.duration.total}</span>{' '}
over all users.
</p>
Expand All @@ -44,7 +44,7 @@ export default function StoryTotal({
<RewindStat noScale>
<p>
You haven&apos;t played anything on{' '}
<span className='text-yellow-500'>Plex</span> this year{' '}
<span className='text-yellow-500'>Plex</span> in the past year{' '}
<span className='not-italic'>😫</span>
</p>
</RewindStat>
Expand Down
10 changes: 10 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const DAYS_AGO_30: Date = new Date(
new Date().setDate(new Date().getDate() - 30),
)
const CURRENT_YEAR: Date = new Date(new Date().getFullYear(), 0, 1)
const PAST_YEAR: Date = new Date(
new Date().setFullYear(new Date().getFullYear() - 1),
)
const ALL_TIME: Date = new Date(statisticsStartDate)

type Period = {
Expand All @@ -31,6 +34,13 @@ export const PERIODS: { [key: string]: Period } = {
(new Date().getTime() - CURRENT_YEAR.getTime()) / (1000 * 3600 * 24),
),
},
pastYear: {
date: PAST_YEAR.toISOString(),
string: PAST_YEAR.toISOString().split('T')[0],
daysAgo: Math.ceil(
(new Date().getTime() - PAST_YEAR.getTime()) / (1000 * 3600 * 24),
),
},
allTime: {
date: ALL_TIME.toISOString(),
string: ALL_TIME.toISOString().split('T')[0],
Expand Down
10 changes: 5 additions & 5 deletions src/utils/getRewind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function getTopMediaStats(userId: string, libraries: Library[]) {
total_duration: string
}>('get_history', {
user_id: userId,
after: PERIODS.thisYear.string,
after: PERIODS.pastYear.string,
length: 0,
media_type: mediaTypeMap[library.section_type],
section_id: library.section_id,
Expand Down Expand Up @@ -97,7 +97,7 @@ export async function getLibrariesTotalDuration(libraries: Library[]) {
libraries.map((library) => {
return fetchTautulli<{ total_duration: string }>('get_history', {
section_id: library.section_id,
after: PERIODS.thisYear.string,
after: PERIODS.pastYear.string,
length: 0,
})
}),
Expand All @@ -120,7 +120,7 @@ export async function getUserTotalDuration(
return fetchTautulli<{ total_duration: string }>('get_history', {
user_id: userId,
section_id: library.section_id,
after: PERIODS.thisYear.string,
after: PERIODS.pastYear.string,
length: 0,
})
}),
Expand All @@ -139,7 +139,7 @@ export async function getTopMediaItems(userId: string, libraries: Library[]) {
return fetchTautulli<TautulliItem[]>('get_home_stats', {
user_id: userId,
section_id: library.section_id,
time_range: PERIODS.thisYear.daysAgo,
time_range: PERIODS.pastYear.daysAgo,
stats_count: 5,
stats_type: 'duration',
})
Expand Down Expand Up @@ -181,7 +181,7 @@ export async function getTopMediaItems(userId: string, libraries: Library[]) {
export async function getRequestsTotals(userId: string) {
const requests = await fetchPaginatedOverseerrStats(
'request',
PERIODS.thisYear.date,
PERIODS.pastYear.date,
)

return {
Expand Down

0 comments on commit 4d5017f

Please sign in to comment.