2019-07-04 09:03:39 +02:00
|
|
|
import QtQuick 2.10
|
|
|
|
import QtQuick.Controls 2.4
|
2019-07-05 14:06:09 +02:00
|
|
|
import QtQuick.Layouts 1.3
|
2019-07-04 09:03:39 +02:00
|
|
|
import QtQuick.Controls.Material 2.1
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
id: control
|
|
|
|
|
|
|
|
property var flowchartData
|
|
|
|
property var allFlowchartData
|
|
|
|
property int rounds
|
|
|
|
property int tileSize: app.height / 8 * 0.8
|
|
|
|
|
2019-07-04 23:00:43 +02:00
|
|
|
property int refreshes: 0
|
|
|
|
property int roundRefreshes: 1
|
|
|
|
|
2019-07-04 09:03:39 +02:00
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: 10
|
|
|
|
model: rounds + 2
|
|
|
|
|
|
|
|
spacing: app.width * 0.1
|
|
|
|
|
|
|
|
orientation: ListView.LeftToRight
|
|
|
|
boundsBehavior: ListView.StopAtBounds
|
|
|
|
|
|
|
|
onFlowchartDataChanged: {
|
|
|
|
prepareData()
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareData() {
|
2019-07-04 23:00:43 +02:00
|
|
|
if(!control.enabled)
|
|
|
|
return
|
|
|
|
/*refreshes += 1
|
|
|
|
|
|
|
|
if(refreshes > 2){
|
|
|
|
roundRefreshes += 1
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("refreshes: " + refreshes + " rounds: " + roundRefreshes)
|
|
|
|
|
|
|
|
// create competition like data (just testing)
|
|
|
|
for(var part in flowchartData['participants']){
|
|
|
|
if(flowchartData['participants'].hasOwnProperty(part)){
|
|
|
|
|
|
|
|
for(var r = 2 + roundRefreshes; r < 7; r++){
|
|
|
|
delete flowchartData['participants'][part]["result"+r]
|
|
|
|
delete flowchartData['participants'][part]["result_rank"+r]
|
|
|
|
}
|
|
|
|
|
|
|
|
if(parseInt(flowchartData['participants'][part]["result_rank0"]) > 14 + refreshes) {
|
|
|
|
delete flowchartData['participants'][part]["result_rank2"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete flowchartData['route_names'][2]
|
|
|
|
delete flowchartData['route_names'][3]
|
|
|
|
delete flowchartData['route_names'][4]
|
|
|
|
delete flowchartData['route_names'][5]
|
|
|
|
delete flowchartData['route_names'][6]
|
|
|
|
*/
|
|
|
|
|
|
|
|
//flowchartData['route_names'] = flowchartData['route_names'].slice(0,)
|
2019-07-04 09:03:39 +02:00
|
|
|
|
|
|
|
// array to store the restructured data
|
|
|
|
var allData = []
|
|
|
|
|
2019-07-04 23:00:43 +02:00
|
|
|
//console.log(JSON.stringify(flowchartData['route_names']))
|
|
|
|
|
2019-07-04 09:03:39 +02:00
|
|
|
for(var round in flowchartData['route_names']){
|
2019-07-04 23:00:43 +02:00
|
|
|
//console.log(round)
|
2019-07-04 09:03:39 +02:00
|
|
|
if(flowchartData['route_names'].hasOwnProperty(round) && parseInt(round) >= 0){
|
2019-07-04 23:00:43 +02:00
|
|
|
//console.log(round)
|
2019-07-04 09:03:39 +02:00
|
|
|
|
2019-07-04 23:00:43 +02:00
|
|
|
/*if(allData.length > 0){
|
2019-07-04 09:03:39 +02:00
|
|
|
allData[allData.length-1].push(round)
|
|
|
|
allData[allData.length-1].push(flowchartData['route_names'][round])
|
2019-07-04 23:00:43 +02:00
|
|
|
}*/
|
2019-07-04 09:03:39 +02:00
|
|
|
|
|
|
|
if(parseInt(round) === 0){
|
|
|
|
// this is the first round
|
|
|
|
|
|
|
|
// find pairs (always wors vs. best (1-16; 1-15; ...)) (they are sorted by the rank of the better athlete (1-2-3-4-5-6-7-8)
|
|
|
|
|
|
|
|
var qualificationResults = []
|
|
|
|
|
|
|
|
for(var x = 0; x < flowchartData['participants'].length; x++){
|
|
|
|
qualificationResults.push(flowchartData['participants'][x])
|
|
|
|
}
|
|
|
|
|
|
|
|
qualificationResults.sort(function(a, b) {
|
|
|
|
return parseInt(a["result_rank0"]) - parseInt(b["result_rank0"]);
|
|
|
|
});
|
|
|
|
|
|
|
|
var nextRoundPairs = []
|
|
|
|
var nextRoundMatches = Math.pow(2, control.model-1)
|
|
|
|
|
|
|
|
for(var i = 0; i < nextRoundMatches; i++){
|
|
|
|
nextRoundPairs.push([qualificationResults[i], qualificationResults[nextRoundMatches*2-i-1]])
|
|
|
|
}
|
|
|
|
|
|
|
|
// build second round pairs (sorted by the rank of the better athlete and worst vs. best (1-8; 2-7; ... ))
|
|
|
|
|
|
|
|
var sortedFirstRoundPairs = []
|
|
|
|
|
|
|
|
for(i = 0; i < nextRoundMatches; i += 1){
|
|
|
|
sortedFirstRoundPairs.push([nextRoundPairs.shift(), nextRoundPairs.pop()])
|
|
|
|
}
|
|
|
|
|
|
|
|
// sort these pairs (containing two pairs of athletes) by the rank of the better athlete (1-4;2-3)
|
|
|
|
|
|
|
|
var finalSortedFirstRoundPairs = []
|
|
|
|
|
|
|
|
for(i=0; i < nextRoundMatches/4; i++){
|
|
|
|
finalSortedFirstRoundPairs.push(sortedFirstRoundPairs[i])
|
|
|
|
finalSortedFirstRoundPairs.push(sortedFirstRoundPairs[nextRoundMatches/2-i-1])
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert the list of pairs of pairs of athletes back to a single list of pairs of athletes
|
|
|
|
|
|
|
|
var finalFirstRoundPairs = []
|
|
|
|
|
|
|
|
for(i=0; i < finalSortedFirstRoundPairs.length; i++){
|
|
|
|
finalFirstRoundPairs.push(finalSortedFirstRoundPairs[i][0])
|
|
|
|
finalFirstRoundPairs.push(finalSortedFirstRoundPairs[i][1])
|
|
|
|
}
|
|
|
|
|
|
|
|
// push the first round to all data
|
2019-07-04 23:00:43 +02:00
|
|
|
finalFirstRoundPairs.push(2)
|
|
|
|
finalFirstRoundPairs.push(flowchartData['route_names'][2])
|
2019-07-04 09:03:39 +02:00
|
|
|
allData.push(finalFirstRoundPairs)
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(parseInt(round) > 0 ){
|
|
|
|
// this is not the first round
|
|
|
|
|
|
|
|
var nextRound = []
|
|
|
|
|
|
|
|
// only used when the current round is the 1/2 final
|
|
|
|
var smallFinal = []
|
|
|
|
var Final = []
|
|
|
|
|
|
|
|
for(var i = 0; i < allData[allData.length-1].length-2; i+=1){
|
|
|
|
|
|
|
|
var thisPair = allData[allData.length-1][i]
|
|
|
|
var thisWinner
|
|
|
|
var thisLooser
|
|
|
|
var thisWinnerIsFirstOfNewPair = i%2 === 0
|
|
|
|
|
2019-07-04 23:00:43 +02:00
|
|
|
if(thisPair[0] === undefined || thisPair[1] === undefined){
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-07-04 09:03:39 +02:00
|
|
|
if(thisWinnerIsFirstOfNewPair){
|
|
|
|
nextRound.push([])
|
|
|
|
}
|
|
|
|
|
|
|
|
//thisPair[0]["result_rank"] = thisPair[0]["result_rank"+round]
|
|
|
|
//thisPair[1]["result_rank"] = thisPair[1]["result_rank"+round]
|
|
|
|
|
|
|
|
if(parseInt(thisPair[0]["result_rank"+round]) < parseInt(thisPair[1]["result_rank"+round])){
|
|
|
|
thisWinner = thisPair[0]
|
|
|
|
thisLooser = thisPair[1]
|
|
|
|
}
|
2019-07-04 23:00:43 +02:00
|
|
|
else if(parseInt(thisPair[0]["result_rank"+round]) > parseInt(thisPair[1]["result_rank"+round])) {
|
2019-07-04 09:03:39 +02:00
|
|
|
thisWinner = thisPair[1]
|
|
|
|
thisLooser = thisPair[0]
|
|
|
|
}
|
2019-07-04 23:00:43 +02:00
|
|
|
else {
|
|
|
|
// no result yet!!
|
2019-07-05 13:31:54 +02:00
|
|
|
//console.log("got no winner yet, rank 0: " + thisPair[0]["result_rank"+round] + " rank 1: " + thisPair[1]["result_rank"+round])
|
2019-07-04 23:00:43 +02:00
|
|
|
continue
|
|
|
|
}
|
2019-07-04 09:03:39 +02:00
|
|
|
|
2019-07-04 23:00:43 +02:00
|
|
|
//console.log(thisWinner['firstname']+" has won in round " + round)
|
2019-07-04 09:03:39 +02:00
|
|
|
|
|
|
|
if(round - control.rounds === 2){
|
|
|
|
// if we are in the 1/2 final
|
|
|
|
|
|
|
|
Final.push(thisWinner)
|
|
|
|
smallFinal.push(thisLooser)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nextRound[nextRound.length-1].push(thisWinner)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(smallFinal.length > 0 && Final.length > 0){
|
|
|
|
|
|
|
|
// Final
|
|
|
|
allData.push([Final, parseInt(round)+2, flowchartData['route_names'][String(parseInt(round)+2)] + " / " + flowchartData['route_names'][String(parseInt(round)+1)] ])
|
|
|
|
// small Final
|
|
|
|
allData.push([smallFinal, parseInt(round)+1])
|
|
|
|
|
2019-07-04 23:00:43 +02:00
|
|
|
//break
|
2019-07-04 09:03:39 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-07-04 23:00:43 +02:00
|
|
|
nextRound.push(parseInt(round) + 1 )
|
|
|
|
nextRound.push(flowchartData['route_names'][parseInt(round) + 1])
|
2019-07-04 09:03:39 +02:00
|
|
|
allData.push(nextRound)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
control.allFlowchartData = allData
|
2019-07-04 23:00:43 +02:00
|
|
|
//console.log(JSON.stringify(allData))
|
|
|
|
}
|
|
|
|
|
|
|
|
function getWinner(part1, part2){
|
|
|
|
|
2019-07-04 09:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
delegate: Column {
|
|
|
|
id: roundCol
|
|
|
|
|
|
|
|
property int thisIndex: index
|
2019-07-04 23:00:43 +02:00
|
|
|
property int thisRound: thisRoundIsValid ? control.allFlowchartData[roundCol.thisIndex][control.allFlowchartData[roundCol.thisIndex].length-2]:-1
|
|
|
|
property bool thisRoundIsValid: control.allFlowchartData !== undefined && control.allFlowchartData[roundCol.thisIndex] !== undefined && control.allFlowchartData[roundCol.thisIndex].length > 2
|
2019-07-04 09:03:39 +02:00
|
|
|
property bool thisIsLastRound: thisIndex === control.model - 1
|
|
|
|
|
|
|
|
width: app.width * 0.5
|
|
|
|
height: control.height
|
|
|
|
|
|
|
|
//spacing: app.width * 0.1
|
|
|
|
|
|
|
|
Label {
|
|
|
|
id: roundNameLa
|
|
|
|
width: parent.width
|
2019-07-04 23:00:43 +02:00
|
|
|
height: control.height * 0.05
|
2019-07-04 09:03:39 +02:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
2019-07-04 23:00:43 +02:00
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
fontSizeMode: Text.Fit
|
|
|
|
font.pixelSize: height * 0.6
|
2019-07-04 09:03:39 +02:00
|
|
|
font.bold: true
|
2019-07-04 23:00:43 +02:00
|
|
|
text: roundCol.thisRoundIsValid && control.allFlowchartData[roundCol.thisIndex][control.allFlowchartData[roundCol.thisIndex].length-1] !== undefined ? control.allFlowchartData[roundCol.thisIndex][control.allFlowchartData[roundCol.thisIndex].length-1] : "-"
|
2019-07-04 09:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
id: rectRep
|
|
|
|
model: Math.max( Math.pow(2, control.model-1) * Math.pow(0.5, (index)), 2)
|
|
|
|
delegate: Item {
|
|
|
|
id: matchItm
|
|
|
|
|
|
|
|
property bool lowerPart: (index%2 > 0)
|
|
|
|
|
2019-07-04 23:00:43 +02:00
|
|
|
property var matchData: roundCol.thisRoundIsValid ? control.allFlowchartData[ thisIsSmallFinal ? roundCol.thisIndex+1 : roundCol.thisIndex][ thisIsSmallFinal ? 0:matchItm.thisIndex]:undefined
|
|
|
|
|
2019-07-04 09:03:39 +02:00
|
|
|
property int thisIndex: index
|
2019-07-04 23:00:43 +02:00
|
|
|
property int thisRound: parseInt(roundCol.thisRound) - (thisIsSmallFinal ? 1:0)
|
|
|
|
property var thisMatchData: thisMatchDataIsValid ? matchData:[]
|
|
|
|
|
|
|
|
property bool thisMatchDataIsValid: (matchData !== undefined && matchData !== null && typeof matchData === "object" && matchData.length > 0)
|
|
|
|
property bool thisMatchIsOver: thisMatchDataIsValid && thisMatchData[0]['result_rank'+thisRound] !== undefined && thisMatchData[1]['result_rank'+thisRound] !== undefined
|
|
|
|
|
2019-07-04 09:03:39 +02:00
|
|
|
property bool thisIsFinal: roundCol.thisIsLastRound && thisIndex === rectRep.model - 2
|
2019-07-04 23:00:43 +02:00
|
|
|
property bool thisIsSmallFinal: roundCol.thisIsLastRound && thisIndex === rectRep.model - 1
|
2019-07-04 09:03:39 +02:00
|
|
|
|
2019-07-04 23:00:43 +02:00
|
|
|
property int winnerIndex: thisMatchIsOver ? (parseInt(thisMatchData[0]['result_rank'+thisRound]) < parseInt(thisMatchData[1]['result_rank'+thisRound]) ? 0:1) : -1
|
2019-07-04 09:03:39 +02:00
|
|
|
|
|
|
|
height: !roundCol.thisIsLastRound ? (roundCol.height - roundNameLa.height) / rectRep.model - roundCol.spacing : (thisIsFinal ? (roundCol.height - roundNameLa.height) * 0.5 + control.tileSize * 0.5 : (roundCol.height - roundNameLa.height) - (roundCol.height - roundNameLa.height) * 0.5 + control.tileSize * 0.5 )
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
Canvas {
|
|
|
|
id: lineCanvas
|
|
|
|
width: app.width; height: app.height
|
|
|
|
contextType: "2d"
|
|
|
|
|
|
|
|
visible: !roundCol.thisIsLastRound
|
|
|
|
|
|
|
|
property int targetX: matchItm.width + control.spacing
|
|
|
|
property int targetY: matchItm.lowerPart ? 0:matchItm.height
|
|
|
|
|
|
|
|
Path {
|
|
|
|
id: myPath
|
|
|
|
startX: matchRect.x + matchRect.width * matchRect.scale ; startY: matchRect.y + matchRect.height * 0.5
|
|
|
|
|
|
|
|
PathCurve { x: lineCanvas.targetX ; y: lineCanvas.targetY }
|
|
|
|
}
|
|
|
|
|
|
|
|
onPaint: {
|
|
|
|
context.strokeStyle = Qt.rgba(.4,.6,.8);
|
|
|
|
context.path = myPath;
|
|
|
|
context.stroke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: matchRect
|
|
|
|
|
|
|
|
anchors {
|
|
|
|
centerIn: !matchItm.thisIsFinal ? parent:undefined
|
|
|
|
bottom: matchItm.thisIsFinal ? parent.bottom:undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
//anchors.verticalCenterOffset: matchItm.lowerPart ? 10:10
|
|
|
|
width: parent.width
|
|
|
|
height: control.tileSize
|
|
|
|
//scale: 0.9
|
|
|
|
color: "white"
|
|
|
|
border.color: "lightgrey"
|
|
|
|
border.width: 1
|
|
|
|
radius: height * 0.2
|
|
|
|
Material.elevation: 10
|
|
|
|
|
|
|
|
Grid {
|
|
|
|
columns: app.landscape() ? 2:0
|
|
|
|
rows: app.landscape() ? 0:2
|
|
|
|
|
2019-07-05 14:06:09 +02:00
|
|
|
spacing: app.landscape() ? height * 0.4:0
|
2019-07-05 13:31:54 +02:00
|
|
|
|
2019-07-04 09:03:39 +02:00
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: matchRect.radius * 0.5
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
// for the two athletes
|
|
|
|
model: 2
|
|
|
|
|
2019-07-05 14:06:09 +02:00
|
|
|
delegate: RowLayout {
|
2019-07-04 23:00:43 +02:00
|
|
|
|
2019-07-05 14:06:09 +02:00
|
|
|
height: app.landscape() ? parent.height:parent.height / 2 - parent.spacing
|
|
|
|
width: app.landscape() ? parent.width / 2 - parent.spacing : parent.width
|
2019-07-04 09:03:39 +02:00
|
|
|
|
2019-07-05 14:06:09 +02:00
|
|
|
spacing: app.landscape() ? height * 0.1:height * 0.1
|
2019-07-04 09:03:39 +02:00
|
|
|
|
|
|
|
Label {
|
2019-07-05 14:06:09 +02:00
|
|
|
Layout.preferredHeight: parent.height
|
|
|
|
//Layout.preferredWidth: parent.width * 0.1
|
|
|
|
|
2019-07-04 09:03:39 +02:00
|
|
|
height: parent.height
|
|
|
|
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2019-07-05 14:06:09 +02:00
|
|
|
font.pixelSize: height * 0.7
|
2019-07-04 09:03:39 +02:00
|
|
|
fontSizeMode: Text.Fit
|
|
|
|
minimumPixelSize: 1
|
|
|
|
|
2019-07-05 14:06:09 +02:00
|
|
|
Layout.alignment: Layout.Left
|
|
|
|
|
|
|
|
text: matchItm.thisMatchData[index] !== undefined ? (parseInt(matchItm.thisMatchData[index]['result_rank0']) < 10 ?matchItm.thisMatchData[index]['result_rank0'] + " ":matchItm.thisMatchData[index]['result_rank0']): ""
|
2019-07-04 09:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
2019-07-05 14:06:09 +02:00
|
|
|
Layout.preferredHeight: parent.height
|
|
|
|
|
2019-07-04 09:03:39 +02:00
|
|
|
height: parent.height
|
|
|
|
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2019-07-05 14:06:09 +02:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
//horizontalAlignment: app.landscape() ? Text.AlignLeft : Text.AlignLeft
|
|
|
|
font.pixelSize: app.landscape() ? height * 0.4 : height * 0.6
|
|
|
|
minimumPixelSize: app.landscape() ? height * 0.35 : height * 0.5
|
|
|
|
fontSizeMode: Text.Fit
|
2019-07-05 13:31:54 +02:00
|
|
|
font.bold: matchItm.winnerIndex === index
|
|
|
|
elide: "ElideRight"
|
2019-07-04 09:03:39 +02:00
|
|
|
|
2019-07-05 14:06:09 +02:00
|
|
|
Layout.fillWidth: true
|
|
|
|
|
2019-07-04 23:00:43 +02:00
|
|
|
color: matchItm.winnerIndex === index ? "green":"black"
|
2019-07-04 09:03:39 +02:00
|
|
|
|
2019-07-04 23:00:43 +02:00
|
|
|
text: matchItm.thisMatchData[index] !== undefined ? matchItm.thisMatchData[index]['firstname'] + " " + matchItm.thisMatchData[index]['lastname'] :"-"
|
2019-07-04 09:03:39 +02:00
|
|
|
}
|
|
|
|
|
2019-07-05 13:31:54 +02:00
|
|
|
Label {
|
2019-07-05 14:06:09 +02:00
|
|
|
Layout.preferredHeight: parent.height
|
|
|
|
//Layout.preferredWidth: parent.width * 0.2
|
|
|
|
|
2019-07-05 13:31:54 +02:00
|
|
|
height: parent.height
|
|
|
|
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2019-07-05 14:06:09 +02:00
|
|
|
font.pixelSize: app.landscape() ? height * 0.35 : height * 0.5
|
|
|
|
|
|
|
|
Layout.alignment: Layout.Right
|
2019-07-05 13:31:54 +02:00
|
|
|
|
2019-07-05 14:06:09 +02:00
|
|
|
text: matchItm.thisMatchData[index] !== undefined ? ( parseFloat(matchItm.thisMatchData[index]['result'+matchItm.thisRound]) ? (parseFloat(matchItm.thisMatchData[index]['result'+matchItm.thisRound]).toFixed(2)) : matchItm.thisMatchData[index]['result'+matchItm.thisRound] ): "-"
|
2019-07-05 13:31:54 +02:00
|
|
|
}
|
|
|
|
|
2019-07-04 09:03:39 +02:00
|
|
|
/*Rectangle {
|
|
|
|
id: hasWonRect
|
|
|
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
|
|
height: width
|
|
|
|
width: parent.width * 0.1
|
|
|
|
|
|
|
|
scale: 0.7
|
|
|
|
|
|
|
|
radius: width * 0.5
|
|
|
|
|
|
|
|
color: "green"
|
|
|
|
|
|
|
|
visible: (parseInt(matchItm.thisMatchData[0]["result_rank" + roundCol.thisRound ]) < parseInt(matchItm.thisMatchData[1]["result_rank" + roundCol.thisRound])) === (index === 0 ? true:false)
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|