feat: 🎉 Rating Orama!

This commit is contained in:
2023-04-09 06:45:27 +02:00
commit b2f4b573f3
61 changed files with 8130 additions and 0 deletions
+178
View File
@@ -0,0 +1,178 @@
export function initCharts (tvShowParsed) {
new EpisodeChart(tvShowParsed, 'episodes', 0)
new SeasonsChart(tvShowParsed, 'seasons')
}
export function loadSpecificSeason (tvShowParsed, seasonId) {
new EpisodeChart(tvShowParsed, 'episodes', seasonId - 1)
}
let chartInstance
class SeasonsChart {
constructor (tvShowParsed, canvasId) {
this.tvShowParsed = tvShowParsed
this.canvasId = canvasId
this.createChart()
}
createChart () {
const seasons = this.tvShowParsed.seasons
const labels = seasons.map((season) => `Season ${season.number}`)
const averageRating = seasons.map((season) => season.avg_rating)
const medianRating = seasons.map((season) => season.median_rating)
const votes = seasons.map((season) => season.votes)
const title = 'Seasons'
const ctx = document.getElementById(this.canvasId)
new Chart(ctx, {
type: 'bar',
data: {
labels,
datasets: [
{
label: 'Average rating',
data: averageRating,
backgroundColor: 'rgba(75, 192, 192, 0.5)',
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1,
Range: 10,
yAxisID: 'y-axis-ratings'
},
{
label: 'Median rating',
data: medianRating,
backgroundColor: 'rgba(255, 206, 86, 0.5)',
borderColor: 'rgba(255, 206, 86, 1)',
borderWidth: 1,
Range: 10,
yAxisID: 'y-axis-ratings'
},
{
label: 'Votes',
data: votes,
type: 'line',
tension: 0.4,
fill: false,
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 2,
yAxisID: 'y-axis-votes'
}
]
},
options: {
animation: {
duration: 0
},
y: {
stacked: true
},
scales: {
'y-axis-ratings': {
min: 0,
max: 10,
type: 'linear',
display: true,
position: 'left',
beginAtZero: true
},
'y-axis-votes': {
type: 'linear',
display: true,
position: 'right',
beginAtZero: true
}
}
},
plugins: {
title: {
display: true,
text: title
}
}
})
}
}
class EpisodeChart {
constructor (tvShowParsed, canvasId, seasonId) {
this.tvShowParsed = tvShowParsed
this.canvasId = canvasId
this.seasonId = seasonId
this.createChart()
}
createChart () {
if (chartInstance) {
chartInstance.destroy()
}
const episodes = this.tvShowParsed.seasons[this.seasonId].episodes
const labels = episodes.map((episode) => `Ep. ${episode.number}`)
const ratings = episodes.map((episode) => episode.avg_rating)
const votes = episodes.map((episode) => episode.votes)
const title = `Episodes of season ${this.seasonId + 1}`
const ctx = document.getElementById(this.canvasId)
chartInstance = new Chart(ctx, {
type: 'bar',
data: {
labels,
datasets: [
{
label: 'Average rating',
data: ratings,
backgroundColor: 'rgba(75, 192, 192, 0.5)',
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1,
Range: 10,
yAxisID: 'y-axis-ratings'
},
{
label: 'Votes',
data: votes,
type: 'line',
tension: 0.4,
fill: false,
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 2,
yAxisID: 'y-axis-votes'
}
]
},
options: {
animation: {
duration: 0
},
scales: {
'y-axis-ratings': {
min: 0,
max: 10,
type: 'linear',
display: true,
position: 'left',
beginAtZero: true
},
'y-axis-votes': {
type: 'linear',
display: true,
position: 'right',
beginAtZero: true
}
},
plugins: {
tooltip: {
callbacks: {
title: function (context) {
const index = context[0].dataIndex
const episode = episodes[index]
return `${episode.title} (${episode.aired.split('T')[0]})`
}
}
}
}
}
})
}
}
+12
View File
@@ -0,0 +1,12 @@
export function search() {
return {
url: '/tv-show?id=',
ttID: '',
isLoading: false,
isError: false,
submit() {
this.isLoading = true;
fetch(this.url+this.ttID)
}
}
}
+546
View File
@@ -0,0 +1,546 @@
export const data = {
show_id: '0903747',
title: 'Breaking Bad',
runtime: '49',
votes: 1970456,
avg_rating: 8.957686180794227,
median_rating: 8.851234567891,
seasons: [
{
number: 1,
avg_rating: 8.701234567891,
median_rating: 8.701234567891,
votes: 202551,
episodes: [
{
number: 1,
episode_id: '0959621',
title: 'Pilot',
aired: '2008-01-20T00:00:00Z',
avg_rating: 9.001234567891,
votes: 38574
},
{
number: 2,
episode_id: '1054724',
title: "Cat's in the Bag...",
aired: '2008-01-27T00:00:00Z',
avg_rating: 8.601234567891,
votes: 28116
},
{
number: 3,
episode_id: '1054725',
title: "...And the Bag's in the River",
aired: '2008-02-10T00:00:00Z',
avg_rating: 8.701234567891,
votes: 27227
},
{
number: 4,
episode_id: '1054726',
title: 'Cancer Man',
aired: '2008-02-17T00:00:00Z',
avg_rating: 8.201234567891,
votes: 26251
},
{
number: 5,
episode_id: '1054727',
title: 'Gray Matter',
aired: '2008-02-24T00:00:00Z',
avg_rating: 8.301234567891,
votes: 25788
},
{
number: 6,
episode_id: '1054728',
title: "Crazy Handful of Nothin'",
aired: '2008-03-02T00:00:00Z',
avg_rating: 9.301234567891,
votes: 30318
},
{
number: 7,
episode_id: '1054729',
title: 'A No-Rough-Stuff-Type Deal',
aired: '2008-03-09T00:00:00Z',
avg_rating: 8.801234567891,
votes: 26277
}
]
},
{
number: 2,
avg_rating: 8.793542260198691,
median_rating: 8.801234567891,
votes: 314689,
episodes: [
{
number: 1,
episode_id: '1232244',
title: 'Seven Thirty-Seven',
aired: '2009-03-08T00:00:00Z',
avg_rating: 8.601234567891,
votes: 23829
},
{
number: 2,
episode_id: '1232249',
title: 'Grilled',
aired: '2009-03-15T00:00:00Z',
avg_rating: 9.301234567891,
votes: 27376
},
{
number: 3,
episode_id: '1232250',
title: 'Bit by a Dead Bee',
aired: '2009-03-22T00:00:00Z',
avg_rating: 8.301234567891,
votes: 22927
},
{
number: 4,
episode_id: '1232251',
title: 'Down',
aired: '2009-03-29T00:00:00Z',
avg_rating: 8.201234567891,
votes: 23044
},
{
number: 5,
episode_id: '1232252',
title: 'Breakage',
aired: '2009-04-05T00:00:00Z',
avg_rating: 8.301234567891,
votes: 22405
},
{
number: 6,
episode_id: '1232253',
title: 'Peekaboo',
aired: '2009-04-12T00:00:00Z',
avg_rating: 8.801234567891,
votes: 24596
},
{
number: 7,
episode_id: '1232254',
title: 'Negro y Azul',
aired: '2009-04-19T00:00:00Z',
avg_rating: 8.601234567891,
votes: 22516
},
{
number: 8,
episode_id: '1232255',
title: 'Better Call Saul',
aired: '2009-04-26T00:00:00Z',
avg_rating: 9.201234567891,
votes: 26928
},
{
number: 9,
episode_id: '1232256',
title: '4 Days Out',
aired: '2009-05-03T00:00:00Z',
avg_rating: 9.101234567891,
votes: 25676
},
{
number: 10,
episode_id: '1232245',
title: 'Over',
aired: '2009-05-10T00:00:00Z',
avg_rating: 8.501234567891,
votes: 21990
},
{
number: 11,
episode_id: '1232246',
title: 'Mandala',
aired: '2009-05-17T00:00:00Z',
avg_rating: 8.901234567891,
votes: 22706
},
{
number: 12,
episode_id: '1232247',
title: 'Phoenix',
aired: '2009-05-24T00:00:00Z',
avg_rating: 9.301234567891,
votes: 25512
},
{
number: 13,
episode_id: '1232248',
title: 'ABQ',
aired: '2009-05-31T00:00:00Z',
avg_rating: 9.201234567891,
votes: 25184
}
]
},
{
number: 3,
avg_rating: 8.73200379866023,
median_rating: 8.501234567891,
votes: 321759,
episodes: [
{
number: 1,
episode_id: '1528116',
title: 'No Más',
aired: '2010-03-21T00:00:00Z',
avg_rating: 8.501234567891,
votes: 21788
},
{
number: 2,
episode_id: '1615186',
title: 'Caballo sin Nombre',
aired: '2010-03-28T00:00:00Z',
avg_rating: 8.601234567891,
votes: 21259
},
{
number: 3,
episode_id: '1615187',
title: 'I.F.T.',
aired: '2010-04-04T00:00:00Z',
avg_rating: 8.401234567891,
votes: 21128
},
{
number: 4,
episode_id: '1615554',
title: 'Green Light',
aired: '2010-04-11T00:00:00Z',
avg_rating: 8.201234567891,
votes: 21304
},
{
number: 5,
episode_id: '1615555',
title: 'Más',
aired: '2010-04-18T00:00:00Z',
avg_rating: 8.501234567891,
votes: 20681
},
{
number: 6,
episode_id: '1615556',
title: 'Sunset',
aired: '2010-04-25T00:00:00Z',
avg_rating: 9.301234567891,
votes: 24259
},
{
number: 7,
episode_id: '1615944',
title: 'One Minute',
aired: '2010-05-02T00:00:00Z',
avg_rating: 9.601234567891,
votes: 29760
},
{
number: 8,
episode_id: '1615557',
title: 'I See You',
aired: '2010-05-09T00:00:00Z',
avg_rating: 8.701234567891,
votes: 21246
},
{
number: 9,
episode_id: '1615558',
title: 'Kafkaesque',
aired: '2010-05-16T00:00:00Z',
avg_rating: 8.401234567891,
votes: 20956
},
{
number: 10,
episode_id: '1615550',
title: 'Fly',
aired: '2010-05-23T00:00:00Z',
avg_rating: 7.801234567891,
votes: 37113
},
{
number: 11,
episode_id: '1615551',
title: 'Abiquiu',
aired: '2010-05-30T00:00:00Z',
avg_rating: 8.401234567891,
votes: 20848
},
{
number: 12,
episode_id: '1615552',
title: 'Half Measures',
aired: '2010-06-06T00:00:00Z',
avg_rating: 9.501234567891,
votes: 28966
},
{
number: 13,
episode_id: '1615553',
title: 'Full Measure',
aired: '2010-06-13T00:00:00Z',
avg_rating: 9.601234567891,
votes: 32451
}
]
},
{
number: 4,
avg_rating: 8.962773029429462,
median_rating: 8.801234567891,
votes: 360823,
episodes: [
{
number: 1,
episode_id: '1683084',
title: 'Box Cutter',
aired: '2011-07-17T00:00:00Z',
avg_rating: 9.201234567891,
votes: 25917
},
{
number: 2,
episode_id: '1683089',
title: 'Thirty-Eight Snub',
aired: '2011-07-24T00:00:00Z',
avg_rating: 8.201234567891,
votes: 21491
},
{
number: 3,
episode_id: '1683090',
title: 'Open House',
aired: '2011-07-31T00:00:00Z',
avg_rating: 8.001234567891,
votes: 21780
},
{
number: 4,
episode_id: '1683091',
title: 'Bullet Points',
aired: '2011-08-07T00:00:00Z',
avg_rating: 8.601234567891,
votes: 20664
},
{
number: 5,
episode_id: '1683092',
title: 'Shotgun',
aired: '2011-08-14T00:00:00Z',
avg_rating: 8.601234567891,
votes: 20719
},
{
number: 6,
episode_id: '1683093',
title: 'Cornered',
aired: '2011-08-21T00:00:00Z',
avg_rating: 8.401234567891,
votes: 20950
},
{
number: 7,
episode_id: '1683094',
title: 'Problem Dog',
aired: '2011-08-28T00:00:00Z',
avg_rating: 8.801234567891,
votes: 21642
},
{
number: 8,
episode_id: '1683095',
title: 'Hermanos',
aired: '2011-09-04T00:00:00Z',
avg_rating: 9.201234567891,
votes: 24356
},
{
number: 9,
episode_id: '1683096',
title: 'Bug',
aired: '2011-09-11T00:00:00Z',
avg_rating: 8.801234567891,
votes: 21930
},
{
number: 10,
episode_id: '1683085',
title: 'Salud',
aired: '2011-09-18T00:00:00Z',
avg_rating: 9.601234567891,
votes: 30819
},
{
number: 11,
episode_id: '1683086',
title: 'Crawl Space',
aired: '2011-09-25T00:00:00Z',
avg_rating: 9.701234567891,
votes: 35874
},
{
number: 12,
episode_id: '1683087',
title: 'End Times',
aired: '2011-10-02T00:00:00Z',
avg_rating: 9.501234567891,
votes: 27683
},
{
number: 13,
episode_id: '1683088',
title: 'Face Off',
aired: '2011-10-09T00:00:00Z',
avg_rating: 9.901234567891,
votes: 66998
}
]
},
{
number: 5,
avg_rating: 9.382484567891,
median_rating: 9.451234567891,
votes: 770634,
episodes: [
{
number: 1,
episode_id: '2081647',
title: 'Live Free or Die',
aired: '2012-07-15T00:00:00Z',
avg_rating: 9.201234567891,
votes: 29240
},
{
number: 2,
episode_id: '2301457',
title: 'Madrigal',
aired: '2012-07-22T00:00:00Z',
avg_rating: 8.801234567891,
votes: 25392
},
{
number: 3,
episode_id: '2301459',
title: 'Hazard Pay',
aired: '2012-07-29T00:00:00Z',
avg_rating: 8.801234567891,
votes: 24811
},
{
number: 4,
episode_id: '2301461',
title: 'Fifty-One',
aired: '2012-08-05T00:00:00Z',
avg_rating: 8.801234567891,
votes: 25002
},
{
number: 5,
episode_id: '2301463',
title: 'Dead Freight',
aired: '2012-08-12T00:00:00Z',
avg_rating: 9.701234567891,
votes: 36260
},
{
number: 6,
episode_id: '2301465',
title: 'Buyout',
aired: '2012-08-19T00:00:00Z',
avg_rating: 9.001234567891,
votes: 25440
},
{
number: 7,
episode_id: '2301467',
title: 'Say My Name',
aired: '2012-08-26T00:00:00Z',
avg_rating: 9.501234567891,
votes: 32854
},
{
number: 8,
episode_id: '2301469',
title: 'Gliding Over All',
aired: '2012-09-02T00:00:00Z',
avg_rating: 9.601234567891,
votes: 32564
},
{
number: 9,
episode_id: '2301471',
title: 'Blood Money',
aired: '2013-08-11T00:00:00Z',
avg_rating: 9.401234567891,
votes: 31146
},
{
number: 10,
episode_id: '2301443',
title: 'Buried',
aired: '2013-08-18T00:00:00Z',
avg_rating: 9.201234567891,
votes: 27751
},
{
number: 11,
episode_id: '2301445',
title: 'Confessions',
aired: '2013-08-25T00:00:00Z',
avg_rating: 9.601234567891,
votes: 33390
},
{
number: 12,
episode_id: '2301447',
title: 'Rabid Dog',
aired: '2013-09-01T00:00:00Z',
avg_rating: 9.101234567891,
votes: 28993
},
{
number: 13,
episode_id: '2301449',
title: "To'hajiilee",
aired: '2013-09-08T00:00:00Z',
avg_rating: 9.801234567891,
votes: 49153
},
{
number: 14,
episode_id: '2301451',
title: 'Ozymandias',
aired: '2013-09-15T00:00:00Z',
avg_rating: 10.001234567891,
votes: 193236
},
{
number: 15,
episode_id: '2301453',
title: 'Granite State',
aired: '2013-09-22T00:00:00Z',
avg_rating: 9.701234567891,
votes: 48290
},
{
number: 16,
episode_id: '2301455',
title: 'Felina',
aired: '2013-09-29T00:00:00Z',
avg_rating: 9.901234567891,
votes: 127112
}
]
}
]
}
+8
View File
@@ -0,0 +1,8 @@
import Alpine from 'https://cdn.jsdelivr.net/npm/alpinejs@3.12.0/dist/module.esm.min.js'
import { search } from './components/search'
window.Alpine = Alpine
Alpine.data('search', search)
Alpine.start()
+3
View File
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;