2024-08-14 10:16:54 +02:00
|
|
|
document.body.onload=loadStatistics()
|
2024-08-14 11:03:19 +02:00
|
|
|
document.getElementById('statistics_nav').classList.add('active')
|
2024-08-14 10:16:54 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
async function create_games_over_time_chart(){
|
|
|
|
|
const gamesovertimechart = document.getElementById("gamesovertimechart")
|
|
|
|
|
|
|
|
|
|
let games_over_time_statistic = await makeRequest(api_url + '/statistics/amount_of_games_over_time?day_step=30')
|
|
|
|
|
let games_over_time_statistic_no_expanions = await makeRequest(api_url + '/statistics/amount_of_games_over_time?day_step=30&filter_expansions_out=true')
|
|
|
|
|
let games_over_time_statistic_only_expanions = await makeRequest(api_url + '/statistics/amount_of_games_over_time?day_step=30&only_expansions=true')
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
new Chart(gamesovertimechart, {
|
|
|
|
|
type: 'bar',
|
|
|
|
|
data: {
|
|
|
|
|
labels: Object.keys(games_over_time_statistic.result),
|
|
|
|
|
datasets: [{
|
|
|
|
|
label: games_over_time_statistic.name,
|
|
|
|
|
data: Object.values(games_over_time_statistic.result),
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
type: 'line'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Base games",
|
|
|
|
|
data: Object.values(games_over_time_statistic_no_expanions.result),
|
|
|
|
|
borderWidth: 1
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Expansions",
|
|
|
|
|
data: Object.values(games_over_time_statistic_only_expanions.result),
|
|
|
|
|
borderWidth: 1
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
options: {
|
|
|
|
|
scales: {
|
|
|
|
|
y: {
|
|
|
|
|
beginAtZero: true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
$("#overtimechartname").text(games_over_time_statistic.name)
|
|
|
|
|
}
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
async function create_bar_chart(url, card_to_fill){
|
2024-08-15 13:48:19 +02:00
|
|
|
|
|
|
|
|
const chart_canvas_container = document.createElement('div')
|
|
|
|
|
chart_canvas_container.classList.add('card-body')
|
|
|
|
|
chart_canvas_container.classList.add('card-img-top')
|
|
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
const chart_canvas = document.createElement('canvas')
|
|
|
|
|
chart_canvas.classList.add('chart_visual')
|
2024-08-15 13:48:19 +02:00
|
|
|
|
|
|
|
|
chart_canvas_container.appendChild(chart_canvas)
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
let statistic_data = await makeRequest(url)
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
const highest_bar_value = Math.max(...Object.values(statistic_data.result))
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
let grid_offset = 0
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
if (highest_bar_value > 10000){
|
|
|
|
|
grid_offset = 25000
|
|
|
|
|
}else if(highest_bar_value > 1000){
|
|
|
|
|
grid_offset = 2500
|
|
|
|
|
}else if(highest_bar_value > 100){
|
|
|
|
|
grid_offset = 250
|
|
|
|
|
}else{
|
|
|
|
|
grid_offset = 25
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new Chart(chart_canvas, {
|
|
|
|
|
plugins: [ChartDataLabels],
|
|
|
|
|
type: 'bar',
|
|
|
|
|
data: {
|
|
|
|
|
labels: Object.keys(statistic_data.result),
|
|
|
|
|
datasets: [{
|
|
|
|
|
label: statistic_data.name,
|
|
|
|
|
data: Object.values(statistic_data.result),
|
|
|
|
|
borderWidth: 1
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
options: {
|
|
|
|
|
scales: {
|
|
|
|
|
y: {
|
|
|
|
|
beginAtZero: true,
|
|
|
|
|
max: Math.ceil((highest_bar_value) / grid_offset) * grid_offset
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
plugins: {
|
|
|
|
|
datalabels: {
|
|
|
|
|
anchor: 'end',
|
|
|
|
|
align: 'end'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
const card_footer = document.createElement('div')
|
2024-08-16 10:14:39 +02:00
|
|
|
card_footer.classList.add('card-header')
|
2024-08-15 09:29:57 +02:00
|
|
|
card_footer.classList.add('text-muted')
|
|
|
|
|
card_footer.innerHTML = statistic_data.name
|
|
|
|
|
|
|
|
|
|
card_to_fill.appendChild(card_footer)
|
2024-08-16 10:14:39 +02:00
|
|
|
card_to_fill.appendChild(chart_canvas_container)
|
|
|
|
|
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
}
|
2024-08-14 16:16:28 +02:00
|
|
|
|
2024-08-15 13:48:19 +02:00
|
|
|
async function create_multiple_boardgame_chart(url, card_to_fill, footer_attribute = '', footer_preamble = ''){
|
|
|
|
|
function create_boardgame_image_grid_row(boardgames, footer_data = []){
|
2024-08-14 16:16:28 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
const row_container = document.createElement('div')
|
|
|
|
|
row_container.classList.add('container')
|
|
|
|
|
|
|
|
|
|
const row = document.createElement('div')
|
|
|
|
|
row.classList.add('row')
|
|
|
|
|
row.classList.add('row-cols-1')
|
|
|
|
|
row.classList.add('row-cols-md-3')
|
2024-08-16 10:14:39 +02:00
|
|
|
row.classList.add('g-4')
|
|
|
|
|
|
2024-08-14 16:16:28 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
for (let boardgame_index in boardgames){
|
|
|
|
|
let current_boardgame = boardgames[boardgame_index]
|
2024-08-14 16:16:28 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
const column = document.createElement('div')
|
|
|
|
|
column.classList.add('col')
|
2024-08-14 16:16:28 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
const boardgame_card = document.createElement('div')
|
|
|
|
|
boardgame_card.classList.add('card')
|
|
|
|
|
boardgame_card.classList.add('h-100')
|
2024-08-14 16:16:28 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
const boardgame_imaged_linked = document.createElement('a')
|
|
|
|
|
boardgame_imaged_linked.setAttribute('href', '/boardgame?id=' + current_boardgame.id)
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
const boardgame_image = document.createElement('img')
|
|
|
|
|
boardgame_image.src = current_boardgame.thumbnail_url
|
|
|
|
|
boardgame_image.classList.add('card-img-top')
|
|
|
|
|
boardgame_image.classList.add('boardgame_statistic_card_image')
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
boardgame_imaged_linked.appendChild(boardgame_image)
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
const boardgame_card_body = document.createElement('div')
|
|
|
|
|
boardgame_card_body.classList.add('card-body')
|
2024-08-16 10:14:39 +02:00
|
|
|
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-16 10:14:39 +02:00
|
|
|
const boardgame_title = document.createElement('h6')
|
2024-08-15 09:29:57 +02:00
|
|
|
boardgame_title.innerHTML = current_boardgame.name
|
|
|
|
|
boardgame_title.classList.add('card-title')
|
2024-08-14 10:16:54 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
boardgame_card_body.appendChild(boardgame_title)
|
2024-08-15 13:48:19 +02:00
|
|
|
|
|
|
|
|
if (footer_data.length > 0){
|
|
|
|
|
const boardgame_footer = document.createElement('p')
|
|
|
|
|
boardgame_footer.innerHTML = footer_data[boardgame_index]
|
|
|
|
|
boardgame_footer.classList.add('card-text')
|
|
|
|
|
boardgame_card_body.appendChild(boardgame_footer)
|
|
|
|
|
}
|
2024-08-14 13:51:07 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
boardgame_card.append(boardgame_imaged_linked)
|
|
|
|
|
boardgame_card.append(boardgame_card_body)
|
2024-08-14 13:51:07 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
column.appendChild(boardgame_card)
|
|
|
|
|
|
|
|
|
|
row.appendChild(column)
|
2024-08-14 13:51:07 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
return row
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-22 14:10:17 +02:00
|
|
|
function footer_attribute_to_value(obj, footer_attribute){
|
|
|
|
|
if (!footer_attribute) return obj;
|
|
|
|
|
const properties = footer_attribute.split('.');
|
|
|
|
|
return footer_attribute_to_value(obj[properties.shift()], properties.join('.'))
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
statistic_data = await makeRequest(url)
|
|
|
|
|
|
2024-08-16 10:14:39 +02:00
|
|
|
const card_header = document.createElement('div')
|
|
|
|
|
card_header.classList.add('card-header')
|
|
|
|
|
|
|
|
|
|
const card_footer_text = document.createElement('div')
|
|
|
|
|
card_footer_text.classList.add('text-muted')
|
|
|
|
|
card_footer_text.innerHTML = statistic_data.name
|
|
|
|
|
card_header.appendChild(card_footer_text)
|
|
|
|
|
|
|
|
|
|
card_to_fill.appendChild(card_header)
|
|
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
const boardgame_image_container = document.createElement('div')
|
2024-08-15 13:48:19 +02:00
|
|
|
boardgame_image_container.classList.add('card-body')
|
2024-08-15 09:29:57 +02:00
|
|
|
boardgame_image_container.classList.add('chart_visual')
|
|
|
|
|
boardgame_image_container.classList.add('container-fluid')
|
2024-08-16 10:14:39 +02:00
|
|
|
boardgame_image_container.classList.add('overflow-auto')
|
2024-08-15 09:29:57 +02:00
|
|
|
|
2024-08-15 13:48:19 +02:00
|
|
|
const boardgames_to_grid = statistic_data.result
|
|
|
|
|
|
|
|
|
|
footer_data = []
|
|
|
|
|
|
|
|
|
|
if (footer_attribute != ''){
|
|
|
|
|
for (boardgame_index in boardgames_to_grid){
|
2024-08-22 14:10:17 +02:00
|
|
|
let footer_string = footer_attribute_to_value(boardgames_to_grid[boardgame_index], footer_attribute)
|
2024-08-15 13:48:19 +02:00
|
|
|
if (footer_preamble != ''){
|
|
|
|
|
footer_string = footer_preamble + footer_string
|
|
|
|
|
}
|
|
|
|
|
footer_data.push(footer_string)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const row = create_boardgame_image_grid_row(boardgames_to_grid, footer_data)
|
2024-08-15 09:29:57 +02:00
|
|
|
|
|
|
|
|
boardgame_image_container.appendChild(row)
|
|
|
|
|
|
|
|
|
|
card_to_fill.appendChild(boardgame_image_container)
|
|
|
|
|
|
2024-08-15 13:48:19 +02:00
|
|
|
|
2024-08-16 10:14:39 +02:00
|
|
|
}
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-16 10:14:39 +02:00
|
|
|
async function create_basic_statistic_chard(url, card_to_fill){
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function create_statistic_card_col(){
|
|
|
|
|
const col = document.createElement('col')
|
|
|
|
|
col.classList.add('col')
|
|
|
|
|
|
|
|
|
|
const card = document.createElement('div')
|
|
|
|
|
card.classList.add('card')
|
|
|
|
|
card.classList.add('h-100')
|
|
|
|
|
|
|
|
|
|
col.appendChild(card)
|
|
|
|
|
|
|
|
|
|
return col
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function loadStatistics(){
|
|
|
|
|
|
|
|
|
|
let statistic_row = document.getElementById('statistic_row')
|
|
|
|
|
|
|
|
|
|
create_games_over_time_chart()
|
2024-08-14 15:05:40 +02:00
|
|
|
|
|
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
const games_played_per_year_card_col = create_statistic_card_col()
|
|
|
|
|
const games_played_per_year_card = games_played_per_year_card_col.firstChild
|
|
|
|
|
statistic_row.appendChild(games_played_per_year_card_col)
|
|
|
|
|
const games_played_per_year_url = api_url + '/statistics/games_played_per_year?filter_expansions_out=true'
|
|
|
|
|
create_bar_chart(games_played_per_year_url, games_played_per_year_card)
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 09:29:57 +02:00
|
|
|
const most_expensive_games_card_col = create_statistic_card_col()
|
|
|
|
|
const most_expensive_games_card = most_expensive_games_card_col.firstChild
|
|
|
|
|
statistic_row.appendChild(most_expensive_games_card_col)
|
|
|
|
|
const most_expensive_games_url = api_url + '/statistics/most_expensive_games?top_amount=6'
|
2024-08-22 14:10:17 +02:00
|
|
|
create_multiple_boardgame_chart(most_expensive_games_url, most_expensive_games_card, 'owned_info.price_paid', '\u20AC ')
|
2024-08-14 16:16:28 +02:00
|
|
|
|
2024-08-14 15:05:40 +02:00
|
|
|
|
2024-08-15 13:48:19 +02:00
|
|
|
const shelf_of_shame_card_col = create_statistic_card_col()
|
|
|
|
|
const shelf_of_shame_card= shelf_of_shame_card_col.firstChild
|
|
|
|
|
statistic_row.appendChild(shelf_of_shame_card_col)
|
2024-08-16 10:14:39 +02:00
|
|
|
const shelf_of_shame_url = api_url + '/statistics/shelf_of_shame'
|
2024-08-15 13:48:19 +02:00
|
|
|
create_multiple_boardgame_chart(shelf_of_shame_url, shelf_of_shame_card)
|
2024-08-14 13:51:07 +02:00
|
|
|
|
2024-08-14 10:16:54 +02:00
|
|
|
}
|