From 238fb7123e02f0e4f564234549aaf7e765e515f0 Mon Sep 17 00:00:00 2001 From: Trygve Date: Sat, 17 Oct 2020 21:11:03 +0200 Subject: [PATCH] Added splittimes and made general improvements. --- common/main.css | 153 +++++++++++++++++++++----- index.php | 244 +----------------------------------------- liveresults.js | 278 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 411 insertions(+), 264 deletions(-) create mode 100644 liveresults.js diff --git a/common/main.css b/common/main.css index 778e8ec..ceb50f1 100644 --- a/common/main.css +++ b/common/main.css @@ -21,14 +21,15 @@ body{ --table-border: #e0e0e0; --table-highlight: #c5cae9;; --tr-nth-color: #f2f2f2; - --tr-color: none; + --tr-color: #ffffff; --background-color: #ffffff; --text-color: #000000; font-family: "Noto Sans", "Liberation Sans","Trebuchet MS", Arial, Helvetica, sans-serif; background-color: var(--background-color); color: var(--text-color); - font-size: 1.2rem; + font-size: 1.1rem; + min-height: 100vw; } header { @@ -40,12 +41,12 @@ header { color: white; grid-gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); - box-shadow: 0 .5rem 1.2rem rgba(0,0,0,.15) !important; } .header-brand{ font-weight: 700; + font-size: 1.4rem; } header div{ display: inline-block; @@ -63,8 +64,6 @@ table { font-weight: 410; margin: 0.8rem; border-radius: 0.4rem; - overflow: hidden; - box-shadow: 0 .5rem 1.2rem rgba(0,0,0,.15) !important; } td, th { @@ -80,11 +79,16 @@ tr:nth-child(even){background-color: var(--tr-nth-color);} tr:hover { background-color: var(--table-highlight); - box-shadow: 0 .8rem 1.8rem rgba(0,0,0,.15) !important; } tr:visited { background-color:var(--table-highlight); } +td:first-child{ + padding-left: 2rem; +} +td:last-child{ + padding-right: 2rem; +} th { padding-top: 12px; padding-bottom: 12px; @@ -96,45 +100,70 @@ h4 { font-size: 20px; margin-bottom: 6px; margin-top: 20px; - margin-left: 0.9rem; + margin-left: 1rem; font-weight: 600; } +.shadow-strong { + box-shadow: 0 1px 1px rgba(0,0,0,0.11), + 0 2px 2px rgba(0,0,0,0.11), + 0 4px 4px rgba(0,0,0,0.11), + 0 8px 8px rgba(0,0,0,0.11), + 0 16px 16px rgba(0,0,0,0.11), + 0 32px 32px rgba(0,0,0,0.11); +} + +.shadow-0{box-shadow:0px 0px 0px 0px rgba(0, 0, 0, 0.2),0px 0px 0px 0px rgba(0, 0, 0, 0.14),0px 0px 0px 0px rgba(0,0,0,.12)}.shadow-1{box-shadow:0px 2px 1px -1px rgba(0, 0, 0, 0.2),0px 1px 1px 0px rgba(0, 0, 0, 0.14),0px 1px 3px 0px rgba(0,0,0,.12)}.shadow-2{box-shadow:0px 3px 1px -2px rgba(0, 0, 0, 0.2),0px 2px 2px 0px rgba(0, 0, 0, 0.14),0px 1px 5px 0px rgba(0,0,0,.12)}.shadow-3{box-shadow:0px 3px 3px -2px rgba(0, 0, 0, 0.2),0px 3px 4px 0px rgba(0, 0, 0, 0.14),0px 1px 8px 0px rgba(0,0,0,.12)}.shadow-4{box-shadow:0px 2px 4px -1px rgba(0, 0, 0, 0.2),0px 4px 5px 0px rgba(0, 0, 0, 0.14),0px 1px 10px 0px rgba(0,0,0,.12)}.shadow-5{box-shadow:0px 3px 5px -1px rgba(0, 0, 0, 0.2),0px 5px 8px 0px rgba(0, 0, 0, 0.14),0px 1px 14px 0px rgba(0,0,0,.12)}.shadow-6{box-shadow:0px 3px 5px -1px rgba(0, 0, 0, 0.2),0px 6px 10px 0px rgba(0, 0, 0, 0.14),0px 1px 18px 0px rgba(0,0,0,.12)}.shadow-7{box-shadow:0px 4px 5px -2px rgba(0, 0, 0, 0.2),0px 7px 10px 1px rgba(0, 0, 0, 0.14),0px 2px 16px 1px rgba(0,0,0,.12)}.shadow-8{box-shadow:0px 5px 5px -3px rgba(0, 0, 0, 0.2),0px 8px 10px 1px rgba(0, 0, 0, 0.14),0px 3px 14px 2px rgba(0,0,0,.12)}.shadow-9{box-shadow:0px 5px 6px -3px rgba(0, 0, 0, 0.2),0px 9px 12px 1px rgba(0, 0, 0, 0.14),0px 3px 16px 2px rgba(0,0,0,.12)}.shadow-10{box-shadow:0px 6px 6px -3px rgba(0, 0, 0, 0.2),0px 10px 14px 1px rgba(0, 0, 0, 0.14),0px 4px 18px 3px rgba(0,0,0,.12)}.shadow-11{box-shadow:0px 6px 7px -4px rgba(0, 0, 0, 0.2),0px 11px 15px 1px rgba(0, 0, 0, 0.14),0px 4px 20px 3px rgba(0,0,0,.12)}.shadow-12{box-shadow:0px 7px 8px -4px rgba(0, 0, 0, 0.2),0px 12px 17px 2px rgba(0, 0, 0, 0.14),0px 5px 22px 4px rgba(0,0,0,.12)}.shadow-13{box-shadow:0px 7px 8px -4px rgba(0, 0, 0, 0.2),0px 13px 19px 2px rgba(0, 0, 0, 0.14),0px 5px 24px 4px rgba(0,0,0,.12)}.shadow-14{box-shadow:0px 7px 9px -4px rgba(0, 0, 0, 0.2),0px 14px 21px 2px rgba(0, 0, 0, 0.14),0px 5px 26px 4px rgba(0,0,0,.12)}.shadow-15{box-shadow:0px 8px 9px -5px rgba(0, 0, 0, 0.2),0px 15px 22px 2px rgba(0, 0, 0, 0.14),0px 6px 28px 5px rgba(0,0,0,.12)}.shadow-16{box-shadow:0px 8px 10px -5px rgba(0, 0, 0, 0.2),0px 16px 24px 2px rgba(0, 0, 0, 0.14),0px 6px 30px 5px rgba(0,0,0,.12)}.shadow-17{box-shadow:0px 8px 11px -5px rgba(0, 0, 0, 0.2),0px 17px 26px 2px rgba(0, 0, 0, 0.14),0px 6px 32px 5px rgba(0,0,0,.12)}.shadow-18{box-shadow:0px 9px 11px -5px rgba(0, 0, 0, 0.2),0px 18px 28px 2px rgba(0, 0, 0, 0.14),0px 7px 34px 6px rgba(0,0,0,.12)}.shadow-19{box-shadow:0px 9px 12px -6px rgba(0, 0, 0, 0.2),0px 19px 29px 2px rgba(0, 0, 0, 0.14),0px 7px 36px 6px rgba(0,0,0,.12)}.shadow-20{box-shadow:0px 10px 13px -6px rgba(0, 0, 0, 0.2),0px 20px 31px 3px rgba(0, 0, 0, 0.14),0px 8px 38px 7px rgba(0,0,0,.12)}.shadow-21{box-shadow:0px 10px 13px -6px rgba(0, 0, 0, 0.2),0px 21px 33px 3px rgba(0, 0, 0, 0.14),0px 8px 40px 7px rgba(0,0,0,.12)}.shadow-22{box-shadow:0px 10px 14px -6px rgba(0, 0, 0, 0.2),0px 22px 35px 3px rgba(0, 0, 0, 0.14),0px 8px 42px 7px rgba(0,0,0,.12)}.shadow-23{box-shadow:0px 11px 14px -7px rgba(0, 0, 0, 0.2),0px 23px 36px 3px rgba(0, 0, 0, 0.14),0px 9px 44px 8px rgba(0,0,0,.12)}.shadow-24{box-shadow:0px 11px 15px -7px rgba(0, 0, 0, 0.2),0px 24px 38px 3px rgba(0, 0, 0, 0.14),0px 9px 46px 8px rgba(0,0,0,.12)} + + .all-result{ - display: -ms-flexbox; - -ms-flex-direction: column; - -ms-flex-wrap: wrap; - display: flex; - flex-direction: column; - flex-wrap: wrap; - height: 50vw; - gap: 1rem; - font-size: 1rem; + display: flex; + flex-flow: column wrap; + align-content: space-between; + /* Your container needs a fixed height, and it + * needs to be taller than your tallest column. */ + height: 700rem; +} +.all-result::before, +.all-result::after { + content: ""; + flex-basis: 100%; + width: 0; + order: 2; } .all-result-div{ - max-width: 25%; - padding: 0 4px; + width: 32%; + margin-bottom: 2%; /* Optional */ } +.all-result-div:nth-child(3n+1) { order: 1; } +.all-result-div:nth-child(3n+2) { order: 2; } +.all-result-div:nth-child(3n) { order: 3; } + .all-result-div h4{ margin-left: auto; font-size: 1.4rem; } -@media only screen and (max-width: 1200px){ +@media only screen and (max-width: 1500px){ .all-result{ display: flex; - flex-direction: row; + flex-direction: column; flex-wrap: wrap; height: auto; gap: 1rem; + align-content: center; } .all-result-div{ - max-width: 100%; + width: max-content; + max-width: max-content; padding: 0px; margin-left: auto; margin-right: auto; + } body{ font-size: 1rem; } + .all-result-div:nth-child(2n+1) { order: 1; } + .all-result-div:nth-child(2n) { order: 2; } } .hiddendiv { display:none; @@ -151,7 +180,7 @@ h4 { background-color: #e7e7e7; } -.StatusDiv{ +.status-div{ color: #ffffffa2; } .nav-pills .nav-link{ @@ -165,18 +194,72 @@ h4 { .result-div{ width: max-content; margin: auto; + overflow-x:auto; + max-width: 100vw; } .table-labels{ font-weight: 900; font-size: 1.2rem; } +.splits-labels{ + font-weight: bolder; +} +.splits-table{ + display: none; +} +.splits-table td:first-child{ + position: sticky; + left: 0; + background-color: var(--tr-color); +} +.splits-table tr:nth-child(even) td:first-child{ + background-color: var(--tr-nth-color); +} +.result-header{ + display: flex; + justify-content: space-between; + align-items: center; + width: 25vw; + min-width: 600px; + margin: auto; +} +.fancy-button { + background-color: transparent; + color: var(--text-accent-color); + text-align: center; + display: inline-block; + border: 4px solid var(--button-color); + font-weight: 700; + border-radius: 0.25rem; + transition: 0.05s; + margin: 0.4rem; +} +.fancy-button:link, +.fancy-button:visited { + color: #7986cb; + padding: 10px 20px; + text-align: center; + text-decoration: underline; + display: inline-block; + border: 4px solid var(--button-color); + font-weight: 700; +} + +.fancy-button:hover, +.fancy-button:active { + color: white; + background-color: var(--button-color); + border: 4px solid var(--button-color); + font-weight: 700; + box-shadow: 0 .5rem 1rem rgba(0,0,0,.15) !important; +} @media only screen and (max-width: 600px) { header { flex-wrap: wrap; padding-left: 0.2rem; padding-right: 0.2rem; } - .StatusDiv{ + .status-div{ margin-left: auto; } .header-brand { @@ -186,20 +269,42 @@ h4 { .ResultTable{ width: 100%; margin: 0px; + border-radius: .4rem; } .result-div{ width: 100%; margin: 0px; + overflow-x: auto; } .result-div h4{ margin: 0px; + width: 100%; + } + .all-result{ + flex-direction: column; + width: 100vw; + align-content: unset; } .all-result-div{ - width: 100%; + width: 100vh; + max-width: 100%; + padding: 0px; + margin-left: 0; + margin-right: 0; } .club-collum{ display: none; } + td:first-child{ + padding-left: 0.6rem; + } + td:last-child{ + padding-right: 0.3rem; + } + .result-header{ + width: 100%; + min-width: 0; + } } @media (prefers-color-scheme: dark) { body.theme-auto { diff --git a/index.php b/index.php index ffa57f2..70aa498 100755 --- a/index.php +++ b/index.php @@ -12,36 +12,16 @@ -
+
Liveresultater
-
status
-
status
+
status
+
status
- - @@ -61,224 +41,8 @@
- + diff --git a/liveresults.js b/liveresults.js new file mode 100644 index 0000000..c511468 --- /dev/null +++ b/liveresults.js @@ -0,0 +1,278 @@ +var tabsCreated = false; + +function createTabs(tabArray, tabNameArray) { + for (let i = 0; i < tabArray.length; i++) { + let startStrTab = ''; + let StrCont = '
' + document.getElementById("classes-tabs").innerHTML += StrTab; + document.getElementById("classes-tab-content").innerHTML += StrCont; + tabsCreated = true; + } +} + +function TimeFormater(stamp) { + //diff /= 60; + let hours = Math.floor(stamp / 3600); + let minutes = Math.floor((stamp - hours * 3600) / 60); + let seconds = stamp - minutes * 60; + let hourString; + if(hours!==0){ + hourString = ("0" + hours).slice(-2) + ':'; + } + else{ + hourString = ''; + } + + return hourString +("0" + minutes).slice(-2) + ":" + ("0" + seconds).slice(-2); +} + +function sortTable(tableToCheck) { + var table, rows, switching, i, x, y, shouldSwitch; + table = document.getElementById(tableToCheck); + switching = true; + /* Make a loop that will continue until + no switching has been done: */ + while (switching) { + // Start by saying: no switching is done: + switching = false; + rows = table.rows; + /* Loop through all table rows (except the + first, which contains table headers): */ + for (i = 1; i < (rows.length - 1); i++) { + // Start by saying there should be no switching: + shouldSwitch = false; + /* Get the two elements you want to compare, + one from current row and one from the next: */ + x = rows[i].getElementsByTagName("td")[2]; + y = rows[i + 1].getElementsByTagName("td")[2]; + // Check if the two rows should switch place: + if (parseInt(x.persTime, 10) > parseInt(y.persTime, 10)) { + // If so, mark as a switch and break the loop: + shouldSwitch = true; + break; + } + } + if (shouldSwitch) { + /* If a switch has been marked, make the switch + and mark that a switch has been done: */ + rows[i].parentNode.insertBefore(rows[i + 1], rows[i]); + switching = true; + } + } + for (i = 1; i < (rows.length); i++) { + rows[i].getElementsByTagName("td")[0].innerHTML = i+1+"."; + } +} + + +function loadresults() { + var xmlhttp = new XMLHttpRequest(); + xmlhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + let xmlObj = JSON.parse(this.responseText); + var classesArray = []; + for (let i = 0; i < xmlObj.ClassResult.length; i++) { + classesArray[i] = xmlObj.ClassResult[i].Class.Name.replace(/ |\//g, "_");; + } + console.log(classesArray); + if (tabsCreated == false) { + createTabs(classesArray, xmlObj.ClassResult); + } + document.getElementById("alle-cont").innerHTML = ""; + + console.log(xmlObj); + + //create tables + for (let i = 0; i < xmlObj.ClassResult.length; i++) { + let resultTable = ""; + let splitTimes = '' + ''; + let winnerTime; + + + if(typeof(xmlObj.ClassResult[i].PersonResult[0])!== 'undefined' && typeof(xmlObj.ClassResult[i].PersonResult[0].Result.SplitTime)!== 'undefined'){ + splitTimes += '' + for (let s = 0; s < xmlObj.ClassResult[i].PersonResult[0].Result.SplitTime.length; s++){ + splitTimes += ''; + } + + } + + splitTimes += '' + + for (let k = 0; k < xmlObj.ClassResult[i].PersonResult.length; k++) { + resultTable += ''; + //add name + resultTable += "" + //add club + if (xmlObj.ClassResult[i].PersonResult[k].Organisation.Name!='[object Object]'){ + resultTable += '' + } + else{ + resultTable += '' + } + + + let timeUsedStamp = xmlObj.ClassResult[i].PersonResult[k].Result.Time; + let timeUsed = TimeFormater(timeUsedStamp); + console.log(xmlObj.ClassResult[i].PersonResult[k].Result.Status ); + //Check if person is dsq and add time + let persStatus = xmlObj.ClassResult[i].PersonResult[k].Result.Status; + if (persStatus == 'OK') { + resultTable += '' + } + else if (persStatus == 'Disqualified') { + resultTable += ''; + } + else if (persStatus == 'Active'){ + resultTable += ''; + } + else if (persStatus == 'DidNotStart'){ + resultTable += ''; + } + else { + resultTable += ''; + } + + //add time difference to winner + if (!xmlObj.ClassResult[i].PersonResult[k].Result.Position){ + resultTable += '' + } + else if(xmlObj.ClassResult[i].PersonResult[k].Result.Time==0){ + resultTable += '' + } + else if (xmlObj.ClassResult[i].PersonResult[k].Result.Position!=1){ + let timeDiff = xmlObj.ClassResult[i].PersonResult[k].Result.Time-winnerTime; + resultTable += '' + } + else if (xmlObj.ClassResult[i].PersonResult[k].Result.Position=1){ + winnerTime = xmlObj.ClassResult[i].PersonResult[k].Result.Time; + resultTable += '' + } + + resultTable += ""; + + + + if (typeof(xmlObj.ClassResult[i].PersonResult[0])!== 'undefined' && typeof(xmlObj.ClassResult[i].PersonResult[0].Result.SplitTime)!== 'undefined' && persStatus == 'OK'){ + splitTimes += '"; + let controlTime = 0; + let controlTimeDelta = 0; + for (let t = 0; t < xmlObj.ClassResult[i].PersonResult[k].Result.SplitTime.length; t++) { + controlTime = parseInt(xmlObj.ClassResult[i].PersonResult[k].Result.SplitTime[t].Time, 10)-controlTimeDelta + controlTimeDelta += controlTime; + splitTimes += '' + } + } + splitTimes += ''; + + } + resultTable += "
' + (s+1) + '-' + xmlObj.ClassResult[i].PersonResult[0].Result.SplitTime[s].ControlCode +'
" + xmlObj.ClassResult[i].PersonResult[k].Person.Name.Given + " " + xmlObj.ClassResult[i].PersonResult[k].Person.Name.Family + "' + xmlObj.ClassResult[i].PersonResult[k].Organisation.Name + '' + "" + '' + timeUsed + '' + 'DSQ' +'' + 'Ikke i mål' +'' + 'Ikke startet' +'' + persStatus +'' + "" + '' + "" + '+' + TimeFormater(timeDiff) + '' + "" + '
' + xmlObj.ClassResult[i].PersonResult[k].Person.Name.Given + " " + xmlObj.ClassResult[i].PersonResult[k].Person.Name.Family + "'+ TimeFormater(controlTime) +'
'+ TimeFormater(xmlObj.ClassResult[i].PersonResult[k].Result.SplitTime[t].Time)+'
" + splitTimes += "" + console.log(splitTimes) + + let pClassName = classesArray[i].replace(/ |\//g, "_"); + + resultTableA = '

'+xmlObj.ClassResult[i].Class.Name+'

'+''+resultTable; + let resultTableB = '

'+xmlObj.ClassResult[i].Class.Name+'

LøperKlubbTidDiff
'+''+resultTable; + splitTimes = '
'+splitTimes; + + document.getElementById(pClassName).innerHTML = resultTableB+splitTimes; + sortTable(pClassName+'-table'); + + document.getElementById("alle-cont").innerHTML += '
'+resultTableA.replace(/-table/g, "-all-table")+'
'; + resultTable = ""; + splitTimes = ""; + } + + //console.log(xmlObj) + } + }; + xmlhttp.open("GET", "xmlToJson.php", true); + xmlhttp.send(); +} + +loadresults() + +function mkTimeStr(timestmp) { + var date = new Date(timestmp * 1000); + // Hours part from the timestamp + var hours = date.getHours(); + // Minutes part from the timestamp + var minutes = "0" + date.getMinutes(); + // Seconds part from the timestamp + var seconds = "0" + date.getSeconds(); + + // Will display time in 10:30:23 format + var formattedTime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2); + return formattedTime; +} + + +var lastUpdate; + +if (typeof(EventSource) !== "undefined") { + var source = new EventSource("updater.php"); + source.onmessage = function(event) { + //console.log(event); + statusArray = event.data.split(","); + lastMessage = parseInt(statusArray[3], 10); + console.log(statusArray); + document.getElementById("lastUpdate").innerHTML = "Siste oppdatering: " + mkTimeStr(statusArray[1]); + document.getElementById("lastMessage").innerHTML = "Siste sjekket: " + mkTimeStr(statusArray[2]); + updateInt = parseInt(statusArray[0], 10); + console.log(updateInt); + //check if update has accured + if (parseInt(statusArray[1], 10) + 6 > parseInt(statusArray[2], 10)) { + updateInt = 1; + } + if (lastUpdate == undefined) { + window.lastUpdate == parseInt(statusArray[1], 10) + } + console.log(statusArray); + + //update results + if (updateInt == 1) { + loadresults() + console.log("Update!!!!! :=)"); + window.lastUpdate = parseInt(statusArray[1], 10); + + var jdata = JSON.parse(statusArray[3]); + console.log(jdata); + } else { + console.log("No update"); + } + + }; +} else { + document.getElementById("serverStatus").innerHTML = "Sorry, your browser does not support server-sent events..."; +} + +const checkConnection = async function() { + cTime = Math.round(Date.now() / 1000); + + if (cTime > lastMessage + 30) { + //mistet tilkobling + var element = document.getElementById("ConnectionAlert"); + element.classList.remove("hiddendiv"); + + } else { + //fortsatt tilkoblet + var element = document.getElementById("ConnectionAlert"); + element.classList.add("hiddendiv"); + } +} +function showHideSplits(className) { + let x = document.getElementById(className+'-table'); + let y = document.getElementById(className+'-splits'); + if (x.style.display === "none") { + x.style.display = "block"; + y.style.display = "none"; + } else { + x.style.display = "none"; + y.style.display = "block"; + } +} + +var interval = setInterval(checkConnection, 10000);
LøperKlubbTidDiff