Made changes to the board game statistic according to API change, no more attribute fidgeting
This commit is contained in:
parent
d6b05ea986
commit
b2a6a0f7e1
1 changed files with 30 additions and 27 deletions
|
|
@ -312,8 +312,8 @@ async function create_bar_chart(statistic_data, name=''){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function create_multiple_boardgame_chart(statistic_data, name = '', footer_attribute = '', footer_preamble = ''){
|
async function create_multiple_boardgame_chart(statistic_data, name = '', include_footer = false, footer_preamble = ''){
|
||||||
function create_boardgame_image_grid_row(boardgames, footer_data = []){
|
function create_boardgame_image_grid_row(boardgames, include_footer, footer_data, footer_preamble){
|
||||||
|
|
||||||
const row_container = document.createElement('div')
|
const row_container = document.createElement('div')
|
||||||
row_container.classList.add('container')
|
row_container.classList.add('container')
|
||||||
|
|
@ -355,9 +355,9 @@ async function create_multiple_boardgame_chart(statistic_data, name = '', footer
|
||||||
|
|
||||||
boardgame_card_body.appendChild(boardgame_title)
|
boardgame_card_body.appendChild(boardgame_title)
|
||||||
|
|
||||||
if (footer_data.length > 0){
|
if (include_footer){
|
||||||
const boardgame_footer = document.createElement('p')
|
const boardgame_footer = document.createElement('p')
|
||||||
boardgame_footer.innerHTML = footer_data[boardgame_index]
|
boardgame_footer.innerHTML = footer_preamble + footer_data[current_boardgame.id]
|
||||||
boardgame_footer.classList.add('card-text')
|
boardgame_footer.classList.add('card-text')
|
||||||
boardgame_card_body.appendChild(boardgame_footer)
|
boardgame_card_body.appendChild(boardgame_footer)
|
||||||
}
|
}
|
||||||
|
|
@ -375,12 +375,6 @@ async function create_multiple_boardgame_chart(statistic_data, name = '', footer
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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('.'))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name == ""){
|
if (name == ""){
|
||||||
statistic_name = statistic_data.name
|
statistic_name = statistic_data.name
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -405,22 +399,24 @@ async function create_multiple_boardgame_chart(statistic_data, name = '', footer
|
||||||
boardgame_image_container.classList.add('container-fluid')
|
boardgame_image_container.classList.add('container-fluid')
|
||||||
boardgame_image_container.classList.add('overflow-auto')
|
boardgame_image_container.classList.add('overflow-auto')
|
||||||
|
|
||||||
const boardgames_to_grid = statistic_data.result
|
const boardgames_to_grid = statistic_data.games
|
||||||
|
|
||||||
footer_data = []
|
const footer_data = statistic_data.result
|
||||||
|
|
||||||
if (footer_attribute != ''){
|
|
||||||
for (boardgame_index in boardgames_to_grid){
|
|
||||||
let footer_string = footer_attribute_to_value(boardgames_to_grid[boardgame_index], footer_attribute)
|
|
||||||
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)
|
// if (footer_attribute != ''){
|
||||||
|
// for (boardgame_index in boardgames_to_grid){
|
||||||
|
// let footer_string = footer_attribute_to_value(boardgames_to_grid[boardgame_index], footer_attribute)
|
||||||
|
// if (footer_preamble != ''){
|
||||||
|
// footer_string = footer_preamble + footer_string
|
||||||
|
// }
|
||||||
|
// footer_data.push(footer_string)
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
const row = create_boardgame_image_grid_row(boardgames_to_grid, include_footer, footer_data, footer_preamble)
|
||||||
|
|
||||||
boardgame_image_container.appendChild(row)
|
boardgame_image_container.appendChild(row)
|
||||||
|
|
||||||
|
|
@ -429,7 +425,7 @@ async function create_multiple_boardgame_chart(statistic_data, name = '', footer
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function create_basic_statistic_chart(statistic_data, name=''){
|
async function create_basic_statistic_chart(statistic_data, name='', preamble=''){
|
||||||
|
|
||||||
if (name == ""){
|
if (name == ""){
|
||||||
statistic_name = statistic_data.name
|
statistic_name = statistic_data.name
|
||||||
|
|
@ -451,7 +447,7 @@ async function create_basic_statistic_chart(statistic_data, name=''){
|
||||||
|
|
||||||
const card_title = document.createElement('h5')
|
const card_title = document.createElement('h5')
|
||||||
card_title.classList.add('card-title')
|
card_title.classList.add('card-title')
|
||||||
card_title.innerHTML = statistic_data.result
|
card_title.innerHTML = preamble + statistic_data.result
|
||||||
|
|
||||||
card_body.appendChild(card_title)
|
card_body.appendChild(card_title)
|
||||||
|
|
||||||
|
|
@ -466,7 +462,7 @@ async function loadStatistics(){
|
||||||
create_basic_statistic_chart(amount_of_games_statistic_data, 'Spellen in bezit')
|
create_basic_statistic_chart(amount_of_games_statistic_data, 'Spellen in bezit')
|
||||||
|
|
||||||
const total_collection_cost_statistic_data = await makeRequest(api_url+'/statistics/total_collection_cost')
|
const total_collection_cost_statistic_data = await makeRequest(api_url+'/statistics/total_collection_cost')
|
||||||
create_basic_statistic_chart(total_collection_cost_statistic_data, 'Totale kost van spellen in bezit')
|
create_basic_statistic_chart(total_collection_cost_statistic_data, 'Totale kost van spellen in bezit', '\u20AC ')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -495,15 +491,22 @@ async function loadStatistics(){
|
||||||
delete winrate_statistic_data.result[player_name]
|
delete winrate_statistic_data.result[player_name]
|
||||||
}else{
|
}else{
|
||||||
winrate_statistic_data.result[player_name] *= 100
|
winrate_statistic_data.result[player_name] *= 100
|
||||||
|
winrate_statistic_data.result[player_name] = winrate_statistic_data.result[player_name].toFixed(2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
create_bar_chart(winrate_statistic_data, 'Winrate van spelers')
|
create_bar_chart(winrate_statistic_data, 'Winrate van spelers')
|
||||||
|
|
||||||
const most_expensive_games_statistic_data = await makeRequest(api_url+'/statistics/most_expensive_games?top_amount=6')
|
const most_expensive_games_statistic_data = await makeRequest(api_url+'/statistics/most_expensive_games?top_amount=6')
|
||||||
create_multiple_boardgame_chart(most_expensive_games_statistic_data, 'Duurste spellen', 'owned_info.price_paid', '\u20AC ')
|
create_multiple_boardgame_chart(most_expensive_games_statistic_data, 'Duurste spellen', true, '\u20AC ')
|
||||||
|
|
||||||
|
const cheapest_per_play_games_statistic_data = await makeRequest(api_url+'/statistics/cheapest_per_play?top_amount=6')
|
||||||
|
for (let boardgame_id_result in cheapest_per_play_games_statistic_data.result){
|
||||||
|
cheapest_per_play_games_statistic_data.result[boardgame_id_result] = cheapest_per_play_games_statistic_data.result[boardgame_id_result].toFixed(2)
|
||||||
|
}
|
||||||
|
create_multiple_boardgame_chart(cheapest_per_play_games_statistic_data, 'Goedkoopste per sessie', true, '\u20AC ')
|
||||||
|
|
||||||
const shelf_of_shame_statistic_data = await makeRequest(api_url + '/statistics/shelf_of_shame')
|
const shelf_of_shame_statistic_data = await makeRequest(api_url + '/statistics/shelf_of_shame')
|
||||||
create_multiple_boardgame_chart(shelf_of_shame_statistic_data)
|
create_multiple_boardgame_chart(shelf_of_shame_statistic_data, 'Shelf of Shame', false)
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue