-
Notifications
You must be signed in to change notification settings - Fork 1
/
page.tsx
184 lines (166 loc) · 4.85 KB
/
page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import {
Breadcrumbs,
CardContent,
Container,
Stack,
Link,
Typography,
Grid,
Card,
Sheet,
Table,
Chip,
Alert,
} from '@mui/joy';
import { sql } from '@vercel/postgres';
interface TotalListening {
total_milliseconds: string;
start_date: string;
end_date: string;
}
interface PodcastTotal {
is_podcast: boolean;
hours: string;
}
interface TopTrack {
artist: string;
trackname: string;
minutes: string;
}
export interface Podcast {
name: string;
publisher: string;
url: string;
}
export default async function SpotifyPage() {
const { rows: rowsa }: { rows: TotalListening[] } =
await sql`select sum(msplayed) total_milliseconds, min(endtime) start_date,max(endtime) end_date from spotify_streaming_history`;
const { rows }: { rows: PodcastTotal[] } =
await sql`select is_podcast, sum(msplayed) / 3600000 as hours from vw_spotify_history_v2 group by is_podcast`;
const { rows: rows3 }: { rows: TopTrack[] } =
await sql`select max(artistname) as artist, trackname,sum(msplayed) / 60000 as minutes from vw_spotify_history_v2 where is_podcast = false group by trackname order by sum(msplayed) desc limit 5`;
const { rows: podcasts }: { rows: Podcast[] } =
await sql`select name,publisher,replace(uri,'spotify:show:', 'https://open.spotify.com/show/') as url from spotify_podcasts order by name`;
const total = rowsa[0];
const podcastTotal = rows.find((x) => x.is_podcast);
const nonPodcastTotal = rows.find((x) => !x.is_podcast);
return (
<Container maxWidth="sm">
<Breadcrumbs>
<Link color="neutral" href="/">
Home
</Link>
<Typography>Spotify Data</Typography>
</Breadcrumbs>
<Typography level={'h2'} gutterBottom>
Spotify Data
</Typography>
<Link
target="_blank"
href="https://www.lanekatris.com/Consuming-Spotify-Data"
>
How this page was made
</Link>
<br />
<Link
target="_blank"
href="https://github.com/lanekatris/monorepo/blob/main/software/js/packages/web/app/spotify/page.tsx"
>
Source Code and SQL Queries
</Link>
<br />
<br />
<Typography level={'h4'}>Stats</Typography>
<Grid container spacing={2}>
<Grid xs={12} md={6}>
<Sheet>
<Card>
<CardContent>
<Typography level={'body-md'}>Total Listen Time</Typography>
<Typography level="h2">
{Math.round(parseInt(total.total_milliseconds) / 3600000)}{' '}
Hours
</Typography>
<Typography level={'body-xs'}>
{total.start_date.split(' ')[0]} -{' '}
{total.end_date.split(' ')[0]}
</Typography>
</CardContent>
</Card>
</Sheet>
</Grid>
<Grid xs={12} md={6}>
<Card>
<CardContent>
<Typography level={'body-md'}>Total Podcast Time</Typography>
<Typography level="h2">{podcastTotal?.hours} Hours</Typography>
</CardContent>
</Card>
</Grid>
<Grid xs={12} md={6}>
<Card>
<CardContent>
<Typography level={'body-md'}>Total Music Time</Typography>
<Typography level="h2">{nonPodcastTotal?.hours} Hours</Typography>
</CardContent>
</Card>
</Grid>
</Grid>
<br />
<br />
<Typography level={'h4'}>Top 5 Listened to Songs</Typography>
<Alert color={'warning'} size={'sm'}>
No link to the song is given in the export
</Alert>
<Table stripe={'odd'}>
<thead>
<tr>
<th>Artist</th>
<th>Track</th>
<th>Minutes</th>
</tr>
</thead>
<tbody>
{rows3.map(({ artist, trackname, minutes }) => (
<tr key={`${artist}-${trackname}`}>
<td>{artist}</td>
<td>{trackname}</td>
<td>{minutes}</td>
</tr>
))}
</tbody>
</Table>
<br />
<br />
<Typography level={'h4'}>
My Podcasts{' '}
<Chip color={'primary'} size={'sm'}>
{podcasts.length}
</Chip>
</Typography>
<Typography level={'body-sm'}>Ordered by podcast name</Typography>
<Table stripe={'odd'}>
<thead>
<tr>
<th>Name</th>
<th>Publisher</th>
</tr>
</thead>
<tbody>
{podcasts.map(({ name, publisher, url }) => (
<tr key={url}>
<td>
<Link target={'_blank'} href={url}>
{name}
</Link>
</td>
<td>{publisher}</td>
</tr>
))}
</tbody>
</Table>
<br />
<br />
</Container>
);
}