Skip to content

Commit

Permalink
* Fixes for RacomFileSetParser and field widths
Browse files Browse the repository at this point in the history
* Fixes for IOF XML 3 and Status Fields in relays
* Initial attempt to upload splits from OLA
* Some TestsFiles for IOF XML V3 Relays
  • Loading branch information
Peter Löfås committed Sep 25, 2016
1 parent 3cad3bd commit ad64446
Show file tree
Hide file tree
Showing 6 changed files with 346 additions and 11 deletions.
6 changes: 3 additions & 3 deletions LiveResults.Client/Parsers/IofXmlV3Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ public static Runner[] ParseXmlData(XmlDocument xmlDoc, LogMessageDelegate logit
var competitorStatusNode = teamMemberResult.SelectSingleNode("iof:Result/iof:OverallResult/iof:Status", nsMgr);
var resultTimeNode = teamMemberResult.SelectSingleNode("iof:Result/iof:OverallResult/iof:Time", nsMgr);
var startTimeNode = teamMemberResult.SelectSingleNode("iof:Result/iof:StartTime", nsMgr);
if (competitorStatusNode == null)
continue;

string status = competitorStatusNode.InnerText;
string status = "notActivated";
if (competitorStatusNode != null)
status = competitorStatusNode.InnerText;

if (status.ToLower() == "notcompeting" || status.ToLower() == "cancelled")
{
Expand Down
139 changes: 135 additions & 4 deletions LiveResults.Client/Parsers/OlaParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
using System.Globalization;
using System.Threading;
using LiveResults.Client.Model;

using System.Configuration;
using System.IO;
using System.Linq;
using System.Xml;
namespace LiveResults.Client
{

Expand Down Expand Up @@ -57,6 +60,7 @@ public void Stop()

private void Run()
{
string splitsPaths = ConfigurationManager.AppSettings["splitspath"];
while (m_continue)
{
try
Expand Down Expand Up @@ -95,7 +99,7 @@ private void Run()

int version = Convert.ToInt32(cmd.ExecuteScalar());

string baseCommand = "select results.modifyDate, results.totalTime, results.position, persons.familyname as lastname, persons.firstname as firstname, organisations.shortname as clubname, eventclasses.shortName, results.runnerStatus, results.entryid, results.allocatedStartTime, results.starttime, entries.allocationControl, entries.allocationEntryId from results, entries, Persons, organisations, raceclasses,eventclasses where raceclasses.eventClassID = eventClasses.eventClassID and results.raceClassID = raceclasses.raceclassid and raceClasses.eventRaceId = " + m_eventRaceId + " and eventclasses.eventid = " + m_eventID + " and results.entryid = entries.entryid and entries.competitorid = persons.personid and persons.defaultorganisationid = organisations.organisationid and raceClasses.raceClassStatus <> 'notUsed' and results.modifyDate > " + paramOper;
string baseCommand = "select results.bibNumber, results.individualCourseId, results.rawDataFromElectronicPunchingCardsId, results.modifyDate, results.totalTime, results.position, persons.familyname as lastname, persons.firstname as firstname, organisations.shortname as clubname, eventclasses.shortName, results.runnerStatus, results.entryid, results.allocatedStartTime, results.starttime, entries.allocationControl, entries.allocationEntryId from results, entries, Persons, organisations, raceclasses,eventclasses where raceclasses.eventClassID = eventClasses.eventClassID and results.raceClassID = raceclasses.raceclassid and raceClasses.eventRaceId = " + m_eventRaceId + " and eventclasses.eventid = " + m_eventID + " and results.entryid = entries.entryid and entries.competitorid = persons.personid and persons.defaultorganisationid = organisations.organisationid and raceClasses.raceClassStatus <> 'notUsed' and results.modifyDate > " + paramOper;
string splitbaseCommand = "select splittimes.modifyDate, splittimes.passedTime, Controls.ID, results.entryid, results.allocatedStartTime, results.starttime, persons.familyname as lastname, persons.firstname as firstname, organisations.shortname as clubname, eventclasses.shortName, splittimes.passedCount,entries.allocationControl, entries.allocationEntryId from splittimes, results, SplitTimeControls, Controls, eventClasses, raceClasses, Persons, organisations, entries where splittimes.resultraceindividualnumber = results.resultid and SplitTimes.splitTimeControlID = SplitTimeControls.splitTimeControlID and SplitTimeControls.timingControl = Controls.controlid and Controls.eventRaceId = " + m_eventRaceId + " and raceclasses.eventClassID = eventClasses.eventClassID and results.raceClassID = raceclasses.raceclassid and raceClasses.eventRaceId = " + m_eventRaceId + " and eventclasses.eventid = " + m_eventID + " and results.entryid = entries.entryid and entries.competitorid = persons.personid and persons.defaultorganisationid = organisations.organisationid and raceClasses.raceClassStatus <> 'notUsed' and splitTimes.modifyDate > " + paramOper;

RelayEventCache relayEventCache = null;
Expand Down Expand Up @@ -129,7 +133,7 @@ private void Run()
}


baseCommand = "select results.modifyDate,results.totalTime, results.position, persons.familyname as lastname, persons.firstname as firstname, entries.teamName as clubname, eventclasses.shortName, raceclasses.relayleg, results.runnerStatus, results.resultId as entryId, results.finishTime, results.allocatedStartTime, results.starttime from results, entries, Persons, raceclasses,eventclasses where raceclasses.eventClassID = eventClasses.eventClassID and results.raceClassID = raceclasses.raceclassid and raceClasses.eventRaceId = " + m_eventRaceId + " and eventclasses.eventid = " + m_eventID + " and results.entryid = entries.entryid and results.relaypersonid = persons.personid and raceClasses.raceClassStatus <> 'notUsed' and results.modifyDate > " + paramOper + " order by relayLeg";
baseCommand = "select results.bibNumber, results.individualCourseId, results.rawDataFromElectronicPunchingCardsId, results.modifyDate,results.totalTime, results.position, persons.familyname as lastname, persons.firstname as firstname, entries.teamName as clubname, eventclasses.shortName, raceclasses.relayleg, results.runnerStatus, results.resultId as entryId, results.finishTime, results.allocatedStartTime, results.starttime from results, entries, Persons, raceclasses,eventclasses where raceclasses.eventClassID = eventClasses.eventClassID and results.raceClassID = raceclasses.raceclassid and raceClasses.eventRaceId = " + m_eventRaceId + " and eventclasses.eventid = " + m_eventID + " and results.entryid = entries.entryid and results.relaypersonid = persons.personid and raceClasses.raceClassStatus <> 'notUsed' and results.modifyDate > " + paramOper + " order by relayLeg";
splitbaseCommand = "select splittimes.modifyDate, splittimes.passedTime, Controls.ID, results.resultId as entryId, results.allocatedStartTime, persons.familyname as lastname, persons.firstname as firstname, entries.teamName as clubname, eventclasses.shortName,raceclasses.relayleg, splittimes.passedCount,results.allocatedStartTime, results.starttime from splittimes, results, SplitTimeControls, Controls, eventClasses, raceClasses, Persons, entries where splittimes.resultraceindividualnumber = results.resultid and SplitTimes.splitTimeControlID = SplitTimeControls.splitTimeControlID and SplitTimeControls.timingControl = Controls.controlid and Controls.eventRaceId = " + m_eventRaceId + " and raceclasses.eventClassID = eventClasses.eventClassID and results.raceClassID = raceclasses.raceclassid and raceClasses.eventRaceId = " + m_eventRaceId + " and eventclasses.eventid = " + m_eventID + " and results.entryid = entries.entryid and results.relaypersonid = persons.personid and raceClasses.raceClassStatus <> 'notUsed' and splitTimes.modifyDate > " + paramOper;
}

Expand All @@ -140,6 +144,7 @@ private void Run()

cmd.CommandText = baseCommand;
IDbCommand cmdSplits = m_connection.CreateCommand();
IDbCommand cmdSplitTimes = m_connection.CreateCommand();
cmdSplits.CommandText = splitbaseCommand;
IDbDataParameter param = cmd.CreateParameter();
param.ParameterName = "date";
Expand Down Expand Up @@ -197,6 +202,9 @@ private void Run()
(cmdSplits.Parameters["date"] as IDbDataParameter).Value = lastSplitDateTime;
}

List<object[]> splitsToRead = null;
if (!string.IsNullOrEmpty(splitsPaths))
splitsToRead = new List<object[]>();

cmd.Prepare();
reader = cmd.ExecuteReader();
Expand Down Expand Up @@ -245,7 +253,17 @@ private void Run()
iStartTime = (int)(startTime.TimeOfDay.TotalSeconds * 100);
}


if (splitsToRead != null && reader["bibNumber"] != null && reader["bibNumber"] != DBNull.Value && reader["rawDataFromElectronicPunchingCardsId"] != null && reader["rawDataFromElectronicPunchingCardsId"] != DBNull.Value)
{
int bibNumber = Convert.ToInt32(reader["bibNumber"]);
if (!File.Exists(Path.Combine(splitsPaths, bibNumber + ".xml")))
{
int courseId = Convert.ToInt32(reader["individualCourseId"]);
int rawCardId = Convert.ToInt32(reader["rawDataFromElectronicPunchingCardsId"]);
splitsToRead.Add(new object[] { bibNumber, courseId, rawCardId, startTime, time });
}
}


}
catch (Exception ee)
Expand Down Expand Up @@ -333,6 +351,119 @@ time is seconds * 100
}
reader.Close();

if (splitsToRead != null && splitsToRead.Count > 0)
{
while (splitsToRead.Count > 0)
{
object[] toRead = splitsToRead[0];
splitsToRead.RemoveAt(0);
int bibNumber = (int)toRead[0];
int courseId = (int)toRead[1];
int rawDataId = (int)toRead[2];
DateTime startTime = (DateTime)toRead[3];
int time = (int)toRead[4];

cmdSplitTimes.CommandText = @"select ordered, punchingCode from punchingUnits pu, controlspunchingunits cpu, coursesWayPointControls cwp where
cwp.controlId = cpu.control and cpu.punchingUnit=pu.punchingUnitId and cwp.courseId=" + courseId + " order by ordered";

List<int[]> courseWayPointCodes = new List<int[]>();
using (var splreader = cmdSplitTimes.ExecuteReader())
{
int lastOrder = -1;
while (splreader.Read())
{
int code = Convert.ToInt32(splreader["punchingCode"]);
int order = Convert.ToInt32(splreader["ordered"]);
if (courseWayPointCodes.Count == 0 || order > lastOrder)
{
courseWayPointCodes.Add(new int[] { code });
}
else
{
var l = new List<int>(courseWayPointCodes[courseWayPointCodes.Count-1]);
l.Add( code);
courseWayPointCodes[courseWayPointCodes.Count - 1] = l.ToArray();
}
}
splreader.Close();
}

DateTime cardReadTime = DateTime.MinValue;
cmdSplitTimes.CommandText = @"select readInTime from rawdatafromelectronicpunchingcards where Id=" + rawDataId;
using (var splreader = cmdSplitTimes.ExecuteReader())
{
int lastOrder = -1;
if (splreader.Read())
{
cardReadTime = Convert.ToDateTime(splreader["readInTime"]);
}
splreader.Close();
}

cmdSplitTimes.CommandText = @"select punchingCode, punchingTime from rawpunches where rawCardId=" + rawDataId + " order by controlNUmber";
List<int[]> punches = new List<int[]>();
using (var splreader = cmdSplitTimes.ExecuteReader())
{
while (splreader.Read())
{
punches.Add(new int[] { Convert.ToInt32(splreader["punchingCode"]), Convert.ToInt32(splreader["punchingTime"]) });
}
splreader.Close();
}


int curIdx = punches.Count - 1;
int timeAtReadOut = -1;
while (curIdx > 0)
{
if (punches[curIdx][0] >= 250 && punches[curIdx][0] <= 254)
{
timeAtReadOut = punches[curIdx][1];
break;
}
curIdx--;
}

DateTime[] splits = new DateTime[courseWayPointCodes.Count];

int wayPointIx = courseWayPointCodes.Count - 1;
if (timeAtReadOut > 0)
{
curIdx--;
while (curIdx >= 0 && wayPointIx >= 0)
{
int punch = punches[curIdx][0];
if (Array.IndexOf<int>(courseWayPointCodes[wayPointIx], punch) >= 0)
{
DateTime punchTime = cardReadTime.AddSeconds(-1*(timeAtReadOut - punches[curIdx][1]));
//splits.Add(new object[] { punches[curIdx]);
splits[wayPointIx] = punchTime;
wayPointIx--;
}
curIdx--;
}
}

using (var xml = XmlWriter.Create(Path.Combine(splitsPaths, bibNumber + ".xml"), new XmlWriterSettings() { Indent = true }))
{
xml.WriteStartDocument();
xml.WriteStartElement("splits");
xml.WriteAttributeString("bibNumber",bibNumber.ToString());
xml.WriteAttributeString("startTime", startTime.ToString("yyyy-MM-dd HH:mm:ss"));
xml.WriteAttributeString("totalTimeSeconds", time.ToString());
for (int i = 0; i < splits.Length; i++)
{
xml.WriteStartElement("split");
xml.WriteAttributeString("control", (i+1).ToString());
xml.WriteAttributeString("punchTime", splits[i].ToString("yyyy-MM-dd HH:mm:ss"));
xml.WriteAttributeString("splitTimeSeconds", ((int)(i > 0 ? (splits[i] - splits[i - 1]).TotalSeconds : 0)).ToString());
xml.WriteEndElement();
}
xml.WriteEndElement();
}
}
}

reader = cmdSplits.ExecuteReader();
while (reader.Read())
{
Expand Down
4 changes: 2 additions & 2 deletions LiveResults.Client/Parsers/RacomFileSetParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ private void ReadStartList(DateTime zeroTime, string startlistFile, List<Runner>
string tmp;
while ((tmp = sr.ReadLine()) != null)
{
string stnr = tmp.Substring(0, 3).Trim();
string sinr = tmp.Substring(4, 10).Trim();
string stnr = tmp.Substring(0, 5).Trim();
string sinr = tmp.Substring(6, 8).Trim();
string className = tmp.Substring(15, 7).Trim();
string name = tmp.Substring(31, 23).Trim();
string start = tmp.Substring(54).Trim();
Expand Down
4 changes: 2 additions & 2 deletions LiveResults.Client/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.2.2.0")]
[assembly: AssemblyFileVersion("1.2.2.0")]
[assembly: AssemblyVersion("1.2.3.0")]
[assembly: AssemblyFileVersion("1.2.3.0")]
79 changes: 79 additions & 0 deletions testfiles/IOFXMLV3/OS2010/nuorisoviesti.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="windows-1252"?>
<ResultList xmlns="http://www.orienteering.org/datastandard/3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
iofVersion="3.0"
createTime="2016-09-25T21:21:32.305"
creator="SportSoftware OS2010 V.11.0">
<Event>
<Name>XXV Nuorisoviesti Raisiossa 1.10.2016</Name>
</Event>
<ClassResult>
<Class>
<Id>10</Id>
<Name>A</Name>
<ShortName>A</ShortName>
<Leg><!-- SplitTimeControls: 80,82,100,999 --></Leg>
<Leg/>
<Leg/>
<Leg/>
<Leg/>
<Leg/>
<Leg/>
<TeamFee>
<Name>Default</Name>
<Amount>90.00</Amount>
</TeamFee>
<TeamFee>
<Name>Startfee 2</Name>
<Amount>180.00</Amount>
</TeamFee>
<RaceClass>
<FirstStart>2016-10-01T12:00:00.000</FirstStart>
</RaceClass>
</Class>
<TeamResult>
<Name>Espoon Akilles 2</Name>
<Organisation>
<Id>482</Id>
<Name>Espoon Akilles</Name>
<ShortName>Espoon Akilles</ShortName>
<Country code="FIN">FIN</Country>
</Organisation>
<BibNumber>2</BibNumber>
<TeamMemberResult>
<Person sex="M">
<Name>
<Family>Vaherlehto</Family>
<Given>Eemi</Given>
</Name>
</Person>
<Result>
<Leg>1</Leg>
<LegOrder>1</LegOrder>
<StartTime>2016-10-01T12:00:00.000</StartTime>
<Status>OK</Status>
<Course>
<Id>9001</Id>
<Name>#1 AAA</Name>
<Length>3525</Length>
<NumberOfControls>10</NumberOfControls>
</Course>
<SplitTime>
<ControlCode>80</ControlCode>
<Time>31087</Time>
</SplitTime>
<SplitTime>
<ControlCode>82</ControlCode>
</SplitTime>
<SplitTime>
<ControlCode>100</ControlCode>
</SplitTime>
<SplitTime>
<ControlCode>999</ControlCode>
</SplitTime>
<ControlCard>76657</ControlCard>
</Result>
</TeamMemberResult>
</TeamResult>
</ClassResult>
</ResultList>
Loading

0 comments on commit ad64446

Please sign in to comment.