From ad64446d7ca46fd914cb5072223b6ecb1d6683ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20L=C3=B6f=C3=A5s?= Date: Sun, 25 Sep 2016 23:28:32 +0200 Subject: [PATCH] * Fixes for RacomFileSetParser and field widths * Fixes for IOF XML 3 and Status Fields in relays * Initial attempt to upload splits from OLA * Some TestsFiles for IOF XML V3 Relays --- LiveResults.Client/Parsers/IofXmlV3Parser.cs | 6 +- LiveResults.Client/Parsers/OlaParser.cs | 139 +++++++++++++++++- .../Parsers/RacomFileSetParser.cs | 4 +- LiveResults.Client/Properties/AssemblyInfo.cs | 4 +- testfiles/IOFXMLV3/OS2010/nuorisoviesti.xml | 79 ++++++++++ testfiles/IOFXMLV3/OS2010/nuorisoviesti_2.xml | 125 ++++++++++++++++ 6 files changed, 346 insertions(+), 11 deletions(-) create mode 100644 testfiles/IOFXMLV3/OS2010/nuorisoviesti.xml create mode 100644 testfiles/IOFXMLV3/OS2010/nuorisoviesti_2.xml diff --git a/LiveResults.Client/Parsers/IofXmlV3Parser.cs b/LiveResults.Client/Parsers/IofXmlV3Parser.cs index 812cabb3..37695c45 100644 --- a/LiveResults.Client/Parsers/IofXmlV3Parser.cs +++ b/LiveResults.Client/Parsers/IofXmlV3Parser.cs @@ -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") { diff --git a/LiveResults.Client/Parsers/OlaParser.cs b/LiveResults.Client/Parsers/OlaParser.cs index c58c269c..45bf2ce0 100644 --- a/LiveResults.Client/Parsers/OlaParser.cs +++ b/LiveResults.Client/Parsers/OlaParser.cs @@ -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 { @@ -57,6 +60,7 @@ public void Stop() private void Run() { + string splitsPaths = ConfigurationManager.AppSettings["splitspath"]; while (m_continue) { try @@ -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; @@ -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; } @@ -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"; @@ -197,6 +202,9 @@ private void Run() (cmdSplits.Parameters["date"] as IDbDataParameter).Value = lastSplitDateTime; } + List splitsToRead = null; + if (!string.IsNullOrEmpty(splitsPaths)) + splitsToRead = new List(); cmd.Prepare(); reader = cmd.ExecuteReader(); @@ -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) @@ -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 courseWayPointCodes = new List(); + 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(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 punches = new List(); + 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(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()) { diff --git a/LiveResults.Client/Parsers/RacomFileSetParser.cs b/LiveResults.Client/Parsers/RacomFileSetParser.cs index 1c1d9925..59e043a3 100644 --- a/LiveResults.Client/Parsers/RacomFileSetParser.cs +++ b/LiveResults.Client/Parsers/RacomFileSetParser.cs @@ -250,8 +250,8 @@ private void ReadStartList(DateTime zeroTime, string startlistFile, List 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(); diff --git a/LiveResults.Client/Properties/AssemblyInfo.cs b/LiveResults.Client/Properties/AssemblyInfo.cs index 18597603..9dbf8d11 100644 --- a/LiveResults.Client/Properties/AssemblyInfo.cs +++ b/LiveResults.Client/Properties/AssemblyInfo.cs @@ -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")] diff --git a/testfiles/IOFXMLV3/OS2010/nuorisoviesti.xml b/testfiles/IOFXMLV3/OS2010/nuorisoviesti.xml new file mode 100644 index 00000000..6b22b94b --- /dev/null +++ b/testfiles/IOFXMLV3/OS2010/nuorisoviesti.xml @@ -0,0 +1,79 @@ + + + +XXV Nuorisoviesti Raisiossa 1.10.2016 + + + +10 +A +A + + + + + + + + +Default +90.00 + + +Startfee 2 +180.00 + + +2016-10-01T12:00:00.000 + + + +Espoon Akilles 2 + +482 +Espoon Akilles +Espoon Akilles +FIN + +2 + + + +Vaherlehto +Eemi + + + +1 +1 +2016-10-01T12:00:00.000 +OK + +9001 +#1 AAA +3525 +10 + + +80 + + + +82 + + +100 + + +999 + +76657 + + + + + diff --git a/testfiles/IOFXMLV3/OS2010/nuorisoviesti_2.xml b/testfiles/IOFXMLV3/OS2010/nuorisoviesti_2.xml new file mode 100644 index 00000000..43cc0825 --- /dev/null +++ b/testfiles/IOFXMLV3/OS2010/nuorisoviesti_2.xml @@ -0,0 +1,125 @@ + + + +XXV Nuorisoviesti Raisiossa 1.10.2016 + + + +10 +A +A + + + + + + + + +Default +90.00 + + +Startfee 2 +180.00 + + +2016-10-01T12:00:00.000 + + + +Espoon Akilles 2 + +482 +Espoon Akilles +Espoon Akilles +FIN + +2 + + + +Vaherlehto +Eemi + + + +1 +1 +2016-10-01T12:00:00.000 +OK + +9001 +#1 AAA +3525 +10 + + +80 + + + +82 + + + +100 + + +999 + +76657 + + + + +Espoon Akilles 1 + +482 +Espoon Akilles +Espoon Akilles +FIN + +1 + + + +Vuorela +Joona + + + +1 +1 +2016-10-01T12:00:00.000 +OK + +9001 +#1 AAA +3525 +10 + + +80 + + +82 + + + +100 + + + +999 + +57960 + + + + +