Skip to content

Commit

Permalink
Get value returns HTML strings for cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
fruzyna committed Mar 15, 2024
1 parent ad64e37 commit f78c6f3
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions scripts/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ class DAL
{
keys = keys.filter(k => !k.startsWith('pit.'))
}
else
{
let cycles = keys.filter(k => k.startsWith('pit.') && dal.meta[k].cycle)
keys = keys.filter(k => !k.startsWith('pit.') || !cycles.some(c => k !== c && k.startsWith(c)))
}
if (!include_ranking)
{
keys = keys.filter(k => !k.startsWith('rank.'))
Expand Down Expand Up @@ -1744,6 +1749,32 @@ class DAL
return ''
}

/**
* Builds an HTML string representing an array of cycles.
*
* @param {Array} cycles Array of cycle data
* @returns HTML string
*/
build_cycles_string(cycles)
{
let string = ''
for (let i in cycles)
{
if (i > 0)
{
string += '<br>'
}
let cycle = cycles[i]
let keys = Object.keys(cycle)
for (let key of keys)
{
// TODO: map this value to something more human readable
string += `${this.get_name(`results.${key}`, '')}: ${cycle[key]}<br>`
}
}
return string
}

/**
* function: get_result_value
* parameters: team number, match id, value id, if it should be a friendly value
Expand Down Expand Up @@ -1771,7 +1802,7 @@ class DAL
if (map)
{
// map to option if available
if ((id === 'meta_scouter_id' || id === 'meta_note_scouter_id') && map)
if ((id === 'meta_scouter_id' || id === 'meta_note_scouter_id'))
{
return cfg.get_name(val, false)
}
Expand All @@ -1791,21 +1822,7 @@ class DAL
}
else if (typeof meta !== 'undefined' && meta.cycle === true)
{
let string = ''
for (let i in val)
{
if (i > 0)
{
string += '<br>'
}
let cycle = val[i]
let keys = Object.keys(cycle)
for (let key of keys)
{
string += `${this.get_name(`results.${key}`, '')}: ${cycle[key]}<br>`
}
}
return string
return this.build_cycles_string(val)
}
}
return val
Expand All @@ -1828,16 +1845,16 @@ class DAL
{
let category = parts[0]
let key = parts[1]
let val = 0
let val = this.teams[team][category][key]

// return stat if it exists otherwise raw value
if (this.teams[team][category].hasOwnProperty(`${key}.${stat}`))
{
val = this.teams[team][category][`${key}.${stat}`]
}
else
else if (Array.isArray(val))
{
val = this.teams[team][category][key]
val = this.build_cycles_string(val)
}

// don't return null values
Expand Down

0 comments on commit f78c6f3

Please sign in to comment.