91 lines
2.3 KiB
C#
91 lines
2.3 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using ScoreboardApi.Objects;
|
|
using System.Net;
|
|
|
|
namespace ScoreboardApi.Controllers
|
|
{
|
|
//[Route("competition")]
|
|
//[ApiController]
|
|
public class CompetitionController
|
|
{
|
|
[HttpPost]
|
|
public IActionResult Create(Competition comp, bool generateFixtures = true) =>
|
|
new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
|
}
|
|
|
|
public class Competition
|
|
{
|
|
public Format format { get; set; }
|
|
public List<Team> Teams { get; set; }
|
|
public List<Fixture> Fixtures { get; set; }
|
|
public int MatchDurationMinutes { get; set; }
|
|
}
|
|
|
|
public class Fixture
|
|
{
|
|
public Team Home { get; set; }
|
|
public Team Away { get; set; }
|
|
public int Round { get; set; }
|
|
public DateTimeOffset KickOffTime { get; set; }
|
|
}
|
|
|
|
public enum Format
|
|
{
|
|
RoundRobin = 1,
|
|
Elimination = 2
|
|
}
|
|
}
|
|
|
|
/*
|
|
|
|
/ko
|
|
/toff
|
|
/ton
|
|
|
|
/halftime
|
|
/secondhalf
|
|
|
|
|
|
/end
|
|
|
|
//get all match events from start point (second half/firsthalf)
|
|
//iterate
|
|
// if no event, use .now
|
|
// else calculate diff from initial to event time.
|
|
// iterate next
|
|
|
|
|
|
self.calculateRemainingTime = ko.computed(function(){
|
|
if(halftime){return '40:00';}
|
|
if(matchend){return '80:00';}
|
|
|
|
var matchEvts = eventList.Filter(x=>x.category === 'Match');
|
|
var initialTime = self.kickOffTime(); //IF FIRST HALF, WORK OUT FOR IF SECOND HALF
|
|
|
|
if(!matchEvts){
|
|
return calcDiff(initialTime, new Date());
|
|
}
|
|
var totalMins = 0;
|
|
var totalSecs = 0;
|
|
|
|
matchEvts.forEach((evt)=>{
|
|
if(evt.eventType === 'timeOff'){
|
|
var t = calcDiff(initialTime, timeoff.timestamp);
|
|
totalMins += t.minutes;
|
|
totalSecs += t.seconds;
|
|
}
|
|
if(evt.eventType === 'timeOn'){
|
|
initialTime = timeon.timestamp;
|
|
}
|
|
});
|
|
|
|
return `${String(totalMins).padStart(2, "0")}:${String(totalSecs).padStart(2, "0")}`;
|
|
});
|
|
|
|
var calcDiff = function (startTimeStamp, endTimeStamp){
|
|
var diff = endTimeStamp - startTimeStamp;
|
|
const minutes = Math.floor(remainingTime / 60000);
|
|
const seconds = Math.floor((remainingTime % 60000) / 1000);
|
|
return new {mins: minutes, secs:seconds}
|
|
}
|
|
*/ |