public EventResult(TwinRinksEvent evt) { IsPowerSkating = evt.IsPowerSkatingEvent(); IsGame = evt.EventType == TwinRinksEventType.Game; IsAway = evt.Rink == TwinRinksRink.Away; OpponentName = IsGame ? evt.AwayTeamName : ""; Description = IsGame ? "" : evt.HomeTeamName == evt.AwayTeamName ? evt.HomeTeamName : evt.HomeTeamName + " " + evt.AwayTeamName; LocationString = "@" + (IsAway ? evt.Location : evt.Rink.ToString() + " Rink"); EventTypeString = evt.EventType.ToString(); DateString = evt.EventDate.Date.ToString("ddd, MMM d").ToUpper(); TimeString = DateTime.Today.Add(evt.EventStart).ToString("h:mm tt"); }
public static TeamSnapApi.CreateEventRequest ToCreateTeamSnapEventRequest(this TwinRinksEvent evt, long teamId, bool notifyTeam = true) { TeamSnapApi.CreateEventRequest res = new TeamSnapApi.CreateEventRequest { NotifyTeam = notifyTeam, TeamId = teamId, IsGame = evt.EventType == TwinRinksEventType.Game, LocationName = evt.Location }; if (evt.Rink != TwinRinksRink.Away) { res.LocationDetails = $"{evt.Rink} Rink"; } else { res.LocationDetails = $"AWAY"; } if (res.IsGame) { res.OpponentName = evt.AwayTeamName; res.ArriveEarlyMinutes = 60; res.GameType = evt.Rink == TwinRinksRink.Away ? "Away" : "Home"; } else { res.ArriveEarlyMinutes = 30; res.Name = "Practice"; if (evt.IsPowerSkatingEvent()) { res.Label = "Power Skate"; } } res.Notes = evt.EventDescription; res.DurationMinutes = 60; res.StartDate = evt.EventDate + evt.EventStart; return(res); }
public void TestEventJsonRoundTrip() { TwinRinksEvent tr = new TwinRinksEvent(); tr.AwayTeamName = "ICE DOGS"; tr.HomeTeamName = "SQUIRT 1"; tr.EventDate = DateTime.Today.AddDays(30); tr.EventDescription = "SQUIRT 1 SQUIRT 2"; tr.EventStart = DateTime.Now.TimeOfDay; tr.EventType = TwinRinksEventType.Game; tr.Location = "HIGHLAND PARK"; tr.Rink = TwinRinksRink.Blue; var str = JsonConvert.SerializeObject(tr); var tr1 = JsonConvert.DeserializeObject <TwinRinksEvent>(str); Assert.IsFalse(tr.IsDifferentFrom(tr1, out HashSet <TwinRinksEventField> whichFields)); }
public void TestEventJson_DiffTest() { TwinRinksEvent tr = new TwinRinksEvent(); tr.AwayTeamName = "ICE DOGS"; tr.HomeTeamName = "SQUIRT 1"; tr.EventDate = DateTime.Today.AddDays(30); tr.EventDescription = "SQUIRT 1 SQUIRT 2"; tr.EventStart = DateTime.Now.TimeOfDay; tr.EventType = TwinRinksEventType.Game; tr.Location = "HIGHLAND PARK"; tr.Rink = TwinRinksRink.Blue; tr.EventEnd = DateTime.Now.TimeOfDay; TwinRinksEvent tr1 = new TwinRinksEvent(); tr1.AwayTeamName = "ICE DOGS 2"; tr1.HomeTeamName = "SQUIRT 2"; tr1.EventDate = DateTime.Today.AddDays(31); tr1.EventDescription = "SQUIRT 5 SQUIRT 4"; tr1.EventStart = DateTime.Now.TimeOfDay.Add(TimeSpan.FromDays(1)); tr1.EventType = TwinRinksEventType.Practice; tr1.Location = "HIGHLAND PARK 3"; tr1.Rink = TwinRinksRink.Away; if (tr.IsDifferentFrom(tr1, out HashSet <TwinRinksEventField> whichFields)) { Assert.IsTrue(whichFields.Contains(TwinRinksEventField.AwayTeamName)); Assert.IsTrue(whichFields.Contains(TwinRinksEventField.EventDate)); Assert.IsTrue(whichFields.Contains(TwinRinksEventField.EventDescription)); Assert.IsTrue(whichFields.Contains(TwinRinksEventField.EventEnd)); Assert.IsTrue(whichFields.Contains(TwinRinksEventField.EventStart)); Assert.IsTrue(whichFields.Contains(TwinRinksEventField.EventType)); Assert.IsTrue(whichFields.Contains(TwinRinksEventField.HomeTeamName)); Assert.IsTrue(whichFields.Contains(TwinRinksEventField.Location)); Assert.IsTrue(whichFields.Contains(TwinRinksEventField.Rink)); } }
public static IEnumerable <CompareResult> Compare(IEnumerable <TeamSnapApi.Event> tsEvents, IEnumerable <TwinRinksEvent> trEvents, HashSet <DateTime> exlusions = null) { List <CompareResult> res = new List <CompareResult>(); HashSet <long> seenTsEvents = new HashSet <long>(); foreach (TwinRinksEvent trEvent in trEvents) { if (exlusions != null && exlusions.Contains(trEvent.EventDate)) { continue; } IEnumerable <TeamSnapApi.Event> tsEventsOnDay = tsEvents.Where(x => ToCSTTime(x.StartDate).Date == trEvent.EventDate.Date && x.IsCancelled == false).ToArray(); seenTsEvents = new HashSet <long>(tsEventsOnDay.Select(e => e.Id)); if (tsEventsOnDay.Any()) { TeamSnapApi.Event foundTsEventByExactTime = tsEventsOnDay.Where(x => ToCSTTime(x.StartDate).TimeOfDay == trEvent.EventStart).FirstOrDefault(); if (foundTsEventByExactTime != null) { if (foundTsEventByExactTime.LocationName.Equals(trEvent.Location, StringComparison.InvariantCultureIgnoreCase) && foundTsEventByExactTime.IsGame == (trEvent.EventType == TwinRinksEventType.Game)) { //matched location and event type } else { res.Add(new CompareResult() { Type = DifferenceType.WrongLocOrEvtType, TR_EventTime = (trEvent.EventDate + trEvent.EventStart), TR_EventType = trEvent.EventType, TR_Location = trEvent.Location, TS_Location = foundTsEventByExactTime.LocationName, TS_EventType = foundTsEventByExactTime.IsGame ? TwinRinksEventType.Game : TwinRinksEventType.Practice, TS_NumEvents = tsEventsOnDay.Count() }); //not matched on location or event type } } else { TeamSnapApi.Event foundTsEventByEventTypeAndLocation = tsEventsOnDay.Where(x => x.LocationName.Equals(trEvent.Location, StringComparison.InvariantCultureIgnoreCase) && x.IsGame == (trEvent.EventType == TwinRinksEventType.Game)).FirstOrDefault(); if (foundTsEventByEventTypeAndLocation != null) { //time not matched res.Add(new CompareResult() { Type = DifferenceType.WrongTimeInTeamSnap, TR_EventTime = (trEvent.EventDate + trEvent.EventStart), TR_EventType = trEvent.EventType, TR_Location = trEvent.Location, TS_EventTime = ToCSTTime(foundTsEventByEventTypeAndLocation.StartDate), TS_NumEvents = tsEventsOnDay.Count(), TS_EventID = foundTsEventByEventTypeAndLocation.Id }); } else { //nothing matching res.Add(new CompareResult() { Type = DifferenceType.NotInTeamSnap, TR_EventTime = (trEvent.EventDate + trEvent.EventStart), TR_EventType = trEvent.EventType, TR_Location = trEvent.Location, TS_NumEvents = tsEventsOnDay.Count() }); } } } else { //nothing on this date res.Add(new CompareResult() { Type = DifferenceType.NotInTeamSnap, TR_EventTime = (trEvent.EventDate + trEvent.EventStart), TR_EventType = trEvent.EventType, TR_Location = trEvent.Location }); } } foreach (TeamSnapApi.Event tsEvent in tsEvents.Where(x => !x.IsCancelled && ToCSTTime(x.StartDate) > ToCSTTime(DateTime.Now.Date))) { if (exlusions != null && exlusions.Contains(ToCSTTime(tsEvent.StartDate).Date)) { continue; } if (!seenTsEvents.Contains(tsEvent.Id)) { TwinRinksEvent trEvent = trEvents.Where(x => ToCSTTime(tsEvent.StartDate).Date == x.EventDate.Date).Where(x => ToCSTTime(tsEvent.StartDate).TimeOfDay == x.EventStart).FirstOrDefault(); int cnt = trEvents.Where(x => ToCSTTime(tsEvent.StartDate).Date == x.EventDate.Date).Count(); if (trEvent == null) { res.Add(new CompareResult() { Type = DifferenceType.NotOnTwinRinksWebSite, TS_EventTime = ToCSTTime(tsEvent.StartDate), TS_Location = tsEvent.LocationName, TS_EventType = tsEvent.IsGame ? TwinRinksEventType.Game : TwinRinksEventType.Practice, TR_NumEvents = cnt, TS_EventID = tsEvent.Id }); } } } return(res); }