private void Generate(int part) { int partsSize = (int)(q) / (parts); int ost = (q) - partsSize * parts; int st = part * partsSize; if (part < ost) { st += part; } else { st += ost; } int fn = (part + 1) * partsSize; if (part + 1 < ost) { fn += part; } else { fn += ost - 1; } for (int i = st; i <= fn; i++) { if (r == null) { r = new Random(DateTime.UtcNow.Millisecond); } Point t = new Point(r.NextDouble() * (b - a) + a, r.NextDouble() * ((int)max + 1)); points.Add(t); EventPoints?.Invoke(t.GetX(), t.GetY(), max + 1); } }
public void TestToStringMethod() { Console.WriteLine("Inside " + GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name); EventPoints myEventPoints = new EventPoints(5.0m, 0.0m, "AthleteName", "ABR", "4:25"); string strEventPoints = myEventPoints.ToString(); Console.WriteLine("My string:" + Environment.NewLine + Environment.NewLine); Console.WriteLine(strEventPoints + Environment.NewLine); Console.WriteLine("Expecting:" + Environment.NewLine + Environment.NewLine); Console.WriteLine("Athlete: AthleteName" + Environment.NewLine + "School: ABR" + Environment.NewLine + "Performance: 4:25" + Environment.NewLine + "Team 1 Points: 5" + Environment.NewLine + "Team 2 Points: 0"); Assert.AreEqual(strEventPoints, "Athlete: AthleteName" + Environment.NewLine + "School: ABR" + Environment.NewLine + "Performance: 4:25" + Environment.NewLine + "Team 1 Points: 5" + Environment.NewLine + "Team 2 Points: 0", GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name + " Failed"); Console.WriteLine(GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name + " Passed"); }
public void TestDefaultConstructor() { Console.WriteLine("Inside " + GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name); EventPoints blankEventPoints = new EventPoints(); Assert.AreEqual(blankEventPoints != null, true, GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name + " Failed"); Console.WriteLine(GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name + " Passed"); }
public void TestEqualsMethod() { Console.WriteLine("Inside " + GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name); bool test = true; EventPoints control = new EventPoints(5.0m, 0.0m, "AthleteName", "ABR", "4:25"); EventPoints equal = new EventPoints(5.0m, 0.0m, "AthleteName", "ABR", "4:25"); EventPoints diffTeam1Pts = new EventPoints(4.0m, 0.0m, "AthleteName", "ABR", "4:25"); EventPoints diffTeam2Pts = new EventPoints(5.0m, 1.0m, "AthleteName", "ABR", "4:25"); EventPoints diffAthleteName = new EventPoints(5.0m, 0.0m, "Donald Trump", "ABR", "4:25"); EventPoints diffSchoolName = new EventPoints(5.0m, 0.0m, "AthleteName", "WHS", "4:25"); EventPoints diffPerformance = new EventPoints(5.0m, 0.0m, "AthleteName", "ABR", "4:23"); if (!control.Equals(equal)) { test = false; Console.WriteLine("equal object was not equal to the control"); } if (control.Equals(diffTeam1Pts)) { test = false; Console.WriteLine("diffTeam1Pts was equal to the control"); } if (control.Equals(diffTeam2Pts)) { test = false; Console.WriteLine("diffTeam2Pts was equal to the control"); } if (control.Equals(diffAthleteName)) { test = false; Console.WriteLine("diffAthleteName was equal to the control"); } if (control.Equals(diffSchoolName)) { test = false; Console.WriteLine("diffSchoolName was equal to the control"); } if (control.Equals(diffPerformance)) { test = false; Console.WriteLine("diffPerformance was equal to the control"); } Assert.True(test, GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name + " Failed"); Console.WriteLine(GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name + " Passed"); }
public EventPoints GetNearestEventMarkers(string userID) { var eventMarkers = new EventPoints(); try { var markerObject = mTrackSvc.getNearestEventMakers(userID, Constants.SPEC_GROUP_TYPE); eventMarkers = JsonConvert.DeserializeObject <EventPoints>(markerObject.ToString()); } catch (Exception ex) { //ShowMessageBox(null, ex.Message); return(null); } return(eventMarkers); }
void SetNearestEventMarkers() { System.Threading.ThreadPool.QueueUserWorkItem(delegate { ShowLoadingView(PortableLibrary.Constants.MSG_LOADING_ALL_MARKERS); MemberModel.rootMember = GetUserObject(); mEventMarker = GetNearestEventMarkers(AppSettings.UserID); //mEventMarker = GetAllMarkers("58aafae816528b16d898a1f3"); HideLoadingView(); InvokeOnMainThread(() => { var boundPoints = new List <CLLocationCoordinate2D>(); if (mEventMarker != null && mEventMarker.markers.Count > 0) { for (int i = 0; i < mEventMarker.markers.Count; i++) { var point = mEventMarker.markers[i]; var imgPin = GetPinIconByType(point.type); var pointLocation = new CLLocationCoordinate2D(point.lat, point.lng); boundPoints.Add(pointLocation); AddMapPin(pointLocation, imgPin, i); } } if (boundPoints.Count > 0) { var mapBounds = new CoordinateBounds(); var myLocation = LocationHelper.GetLocationResult(); var myLocation2D = new CLLocationCoordinate2D(myLocation.Latitude, myLocation.Longitude); boundPoints.Add(myLocation2D); foreach (var bound in boundPoints) { mapBounds = mapBounds.Including(bound); } mMapView.MoveCamera(CameraUpdate.FitBounds(mapBounds, 50.0f)); } }); }); }
void SetNearestEventMarkers(Location currentLocation) { System.Threading.ThreadPool.QueueUserWorkItem(delegate { ShowLoadingView(Constants.MSG_LOADING_ALL_MARKERS); mEventMarker = GetNearestEventMarkers(AppSettings.UserID); //mEventMarker = GetAllMarkers("58aafae816528b16d898a1f3"); HideLoadingView(); if (mEventMarker == null || mEventMarker.markers.Count == 0) { return; } try { var mapBounds = new LatLngBounds.Builder(); mapBounds.Include(new LatLng(currentLocation.Latitude, currentLocation.Longitude)); pointIDs = new List <string>(); RunOnUiThread(() => { for (int i = 0; i < mEventMarker.markers.Count; i++) { var point = mEventMarker.markers[i]; var pointLocation = new LatLng(point.lat, point.lng); mapBounds.Include(pointLocation); AddMapPin(pointLocation, point.type); } mMapView.MoveCamera(CameraUpdateFactory.NewLatLngBounds(mapBounds.Build(), 50)); }); } catch (Exception err) { Toast.MakeText(this, err.ToString(), ToastLength.Long).Show(); } }); }
public void TestParameterizedConstructor() { Console.WriteLine("Inside " + GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name); bool test = true; EventPoints ep = new EventPoints(5.0m, 0.0m, "AthleteName", "ABR", "4:25"); if (ep == null) { test = false; Console.WriteLine("ep is null"); } if (ep.team1Pts != 5.0m) { test = false; Console.WriteLine("team1Pts does not have the correct value"); } if (ep.team2Pts != 0.0m) { test = false; Console.WriteLine("team2Pts does not have the correct value"); } if (ep.athleteName != "AthleteName") { test = false; Console.WriteLine("athleteName does not have the correct value"); } if (ep.schoolName != "ABR") { test = false; Console.WriteLine("schoolName does not have the correct value"); } if (ep.performance != "4:25") { test = false; Console.WriteLine("performance does not have the correct value"); } Assert.True(test, GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name + " Failed"); Console.WriteLine(GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name + " Passed"); }
/// <summary> /// Implementation for calculating points (1st, and 2nd) for a relay event /// </summary> /// <param name="team1Abbr">Abbr for team 1</param> /// <param name="team2Abbr">Abbr for team 2</param> /// <param name="perf"></param> /// <returns>RelayEvent, which holds all information ragarding this event's points</returns> public RelayEvent CalculateRelayEvent(string team1Abbr, string team2Abbr, List <Performance> perf) { Console.WriteLine("Inside " + GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name); // //gather performances from only teams 1 and 2 // List <Performance> teams1and2 = new List <Performance>(); foreach (Performance i in perf) //Iterate through entire list of performances { //A name stands for A relays. Only A relays count towards points. B and above are scrimmage relays if ((i.schoolName == team1Abbr && i.athleteName == "A Relay") || (i.schoolName == team2Abbr && i.athleteName == "A Relay")) //check if the performance is for Team 1 or 2 { teams1and2.Add(i); //Add performance to working List } } // //sort performances from best to worst // teams1and2 = teams1and2.OrderBy(o => o.performance).ToList(); RelayEvent eventToReturn = new RelayEvent(); eventToReturn.team1 = team1Abbr; eventToReturn.team2 = team2Abbr; EventPoints[] points = new EventPoints[2]; points[0] = new EventPoints(); points[1] = new EventPoints(); //Use this to convert into strings for EventPoints objects DataEntrySvcImpl DESI = new DataEntrySvcImpl(); //First Place if (teams1and2.Count > 0) { if (teams1and2[0].schoolName == team1Abbr) { points[0] = new EventPoints(5.0m, 0.0m, teams1and2[0].athleteName, teams1and2[0].schoolName, DESI.ConvertToTimedData(teams1and2[0].performance)); } else if (teams1and2[0].schoolName == team2Abbr) { points[0] = new EventPoints(0.0m, 5.0m, teams1and2[0].athleteName, teams1and2[0].schoolName, DESI.ConvertToTimedData(teams1and2[0].performance)); } else { Console.WriteLine("ERROR! This code should be unreachable!"); throw new TeamNotFoundException(teams1and2[0].schoolName + " does not equal " + team1Abbr + " or " + team2Abbr); } } //Second Place if (teams1and2.Count > 1) { if (teams1and2[1].schoolName == team1Abbr) { points[1] = new EventPoints(0.0m, 0.0m, teams1and2[1].athleteName, teams1and2[1].schoolName, DESI.ConvertToTimedData(teams1and2[1].performance)); } else if (teams1and2[1].schoolName == team2Abbr) { points[1] = new EventPoints(0.0m, 0.0m, teams1and2[1].athleteName, teams1and2[1].schoolName, DESI.ConvertToTimedData(teams1and2[1].performance)); } else { Console.WriteLine("ERROR! This code should be unreachable!"); throw new TeamNotFoundException(teams1and2[1].schoolName + " does not equal " + team1Abbr + " or " + team2Abbr); } } //Add Points data to returning object eventToReturn.points = points; //Calculate Totals eventToReturn.team1Total = points[0].team1Pts + points[1].team1Pts; eventToReturn.team2Total = points[0].team2Pts + points[1].team2Pts; //return object return(eventToReturn); }
/// <summary> /// Helper Method for Calculating Individual Event (Not Relay) /// </summary> /// <param name="team1Abbr">Abbreviation for Team #1</param> /// <param name="team2Abbr">Abbreviation for Team #2</param> /// <param name="teams1and2">Sorted List (Ascending or Descending, depending on event) of Performances for Teams 1 & 2</param> /// <returns>IndEvent, which holds all information ragarding this event's points</returns> /// <remarks>Does NOT include a way to determine Ties for Field Events. This must be implemented later by another Method</remarks> public static IndEvent CalculateIndEventInOrder(string team1Abbr, string team2Abbr, List <Performance> teams1and2) { // //gather info for 1st 2nd and 3rd // IndEvent eventToReturn = new IndEvent(); eventToReturn.team1 = team1Abbr; eventToReturn.team2 = team2Abbr; List <int> firstPlaceHeats = new List <int>(); List <int> secondPlaceHeats = new List <int>(); List <int> thirdPlaceHeats = new List <int>(); decimal firstPlacePerf = 0; decimal secondPlacePerf = 0; decimal thirdPlacePerf = 0; //First place performance if (teams1and2.Count > 0) { firstPlacePerf = teams1and2[0].performance; firstPlaceHeats.Add(teams1and2[0].heatNum); for (int i = 1; i < teams1and2.Count; i++) { if (teams1and2[i].performance == firstPlacePerf) { //check heatnum if (firstPlaceHeats.Contains(teams1and2[i].heatNum)) //check if it is already a 2nd item { if (secondPlaceHeats.Contains(teams1and2[i].heatNum)) //check if it is already a 3rd item { if (!thirdPlaceHeats.Contains(teams1and2[i].heatNum)) { thirdPlaceHeats.Add(teams1and2[i].heatNum); thirdPlacePerf = teams1and2[0].performance; } } else { secondPlaceHeats.Add(teams1and2[i].heatNum); secondPlacePerf = teams1and2[0].performance; } } else { firstPlaceHeats.Add(teams1and2[i].heatNum); } } } //Check if 3 or more firsts //Should have no 2nds or 3rds if (firstPlaceHeats.Count >= 3) { secondPlaceHeats.Clear(); thirdPlaceHeats.Clear(); secondPlacePerf = 0; thirdPlacePerf = 0; } //Check if 2 firsts //Should have no 2nd, its should become third if (firstPlaceHeats.Count == 2) { thirdPlaceHeats.Clear(); thirdPlaceHeats.AddRange(secondPlaceHeats); secondPlaceHeats.Clear(); thirdPlacePerf = secondPlacePerf; secondPlacePerf = 0; } //Check if 2 or more seconds //Should have no 3rds if (secondPlaceHeats.Count >= 2) { thirdPlaceHeats.Clear(); thirdPlacePerf = 0; } //Check if second place was not already found, at least 2 performances, and not more than one firstPlace if (!(secondPlaceHeats.Count > 0 || teams1and2.Count <= 1 || firstPlaceHeats.Count > 1)) { secondPlacePerf = teams1and2[1].performance; secondPlaceHeats.Add(teams1and2[1].heatNum); for (int i = 2; i < teams1and2.Count; i++) { if (teams1and2[i].performance == secondPlacePerf) { //check heatnum if (secondPlaceHeats.Contains(teams1and2[i].heatNum)) //check if it is already a 3rd item { if (!thirdPlaceHeats.Contains(teams1and2[i].heatNum)) { thirdPlaceHeats.Add(teams1and2[i].heatNum); thirdPlacePerf = teams1and2[i].performance; } } else { secondPlaceHeats.Add(teams1and2[i].heatNum); secondPlacePerf = teams1and2[i].performance; } } } } else { //This means that there were either 2 or more firsts, or second place was already found (same time + same heat) } //Check if third place was not already found and at least 3 performances if (!(thirdPlaceHeats.Count > 0 || teams1and2.Count <= 2 || secondPlaceHeats.Count + firstPlaceHeats.Count > 2)) { thirdPlacePerf = teams1and2[2].performance; thirdPlaceHeats.Add(teams1and2[2].heatNum); for (int i = 3; i < teams1and2.Count; i++) { if (teams1and2[i].performance == thirdPlacePerf) { //check heatnum if (!thirdPlaceHeats.Contains(teams1and2[i].heatNum)) { thirdPlaceHeats.Add(teams1and2[i].heatNum); thirdPlacePerf = teams1and2[i].performance; } } } } else { //Third place should not be calculated because of ties with 1st and/or 2nd } } else //No performances for either team. Uncontested Event { //null object. needs created here Console.WriteLine("No performances for this event. Returning null IndEvent"); eventToReturn = new IndEvent(); //Console.WriteLine("Leaving " + GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name); Console.WriteLine("Leaving " + MethodBase.GetCurrentMethod().DeclaringType + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name); return(eventToReturn); } //Check for redundancy, or in wrong place. //This code is also above. MAY be needed again. //Check if 3 or more firsts //Should have no 2nds or 3rds /*if (firstPlaceHeats.Count >= 3) * { * secondPlaceHeats.Clear(); * thirdPlaceHeats.Clear(); * secondPlacePerf = 0; * thirdPlacePerf = 0; * } * * //Check if 2 firsts * //Should have no 2nd, its should become third * if (firstPlaceHeats.Count == 2) * { * thirdPlaceHeats.Clear(); * thirdPlaceHeats.AddRange(secondPlaceHeats); * secondPlaceHeats.Clear(); * thirdPlacePerf = secondPlacePerf; * secondPlacePerf = 0; * } * * //Check if 2 or more seconds * //Should have no 3rds * if (secondPlaceHeats.Count >= 2) * { * thirdPlaceHeats.Clear(); * thirdPlacePerf = 0; * }*/ //End code check // //Populate IndEvent object // //Algorithm used to resort list if multiple same performances in same and different heats //Assumes list was originally organized by heats bool stopLoop = false; do { stopLoop = false; for (int i = 1; i < teams1and2.Count - 1; i++) { if (teams1and2[i - 1].performance == teams1and2[i].performance && teams1and2[i - 1].heatNum == teams1and2[i].heatNum && teams1and2[i].performance == teams1and2[i + 1].performance && teams1and2[i].heatNum != teams1and2[i + 1].heatNum) { Performance temp = teams1and2[i]; teams1and2[i] = teams1and2[i + 1]; teams1and2[i + 1] = temp; stopLoop = true; } } } while (stopLoop); //ints used if dividing by them near the end of the method //Avoids Divide by zero errors because the ints in the Lists are about to be removed int numFirstPlaces = firstPlaceHeats.Count; int numSecondPlaces = secondPlaceHeats.Count; int numThirdPlaces = thirdPlaceHeats.Count; //Use this to convert into strings for EventPoints objects DataEntrySvcImpl DESI = new DataEntrySvcImpl(); EventPoints firstEventPoints = new EventPoints(); EventPoints secondEventPoints = new EventPoints(); EventPoints thirdEventPoints = new EventPoints(); //first place EventPoints if (firstPlacePerf != 0) { firstEventPoints.performance = DESI.ConvertToTimedData(firstPlacePerf); if (firstPlaceHeats.Count > 1) { Console.WriteLine(numFirstPlaces + "-Way Tie for 1st"); firstEventPoints.athleteName = "TIE"; firstEventPoints.schoolName = "TIE"; //Calculate Tie info //Two-Way Tie if (firstPlaceHeats.Count == 2) { foreach (Performance p in teams1and2) { if (p.performance == firstPlacePerf && firstPlaceHeats.Contains(p.heatNum)) { //test taking out p.heatNum here //Not sure if this is correct firstPlaceHeats.Remove(p.heatNum); if (p.schoolName == team1Abbr) { firstEventPoints.team1Pts += 4; } else if (p.schoolName == team2Abbr) { firstEventPoints.team2Pts += 4; } else { Console.WriteLine("ERROR! This code should be unreachable!"); throw new TeamNotFoundException(p.schoolName + " does not equal " + team1Abbr + " or " + team2Abbr); } } } } //More than Two-Way Tie else if (firstPlaceHeats.Count >= 2) { foreach (Performance p in teams1and2) { if (p.performance == firstPlacePerf && firstPlaceHeats.Contains(p.heatNum)) { //test taking out p.heatNum here //Not sure if this is correct firstPlaceHeats.Remove(p.heatNum); if (p.schoolName == team1Abbr) { firstEventPoints.team1Pts += (9.0m / numFirstPlaces); } else if (p.schoolName == team2Abbr) { firstEventPoints.team2Pts += (9.0m / numFirstPlaces); } else { Console.WriteLine("ERROR! This code should be unreachable!"); throw new TeamNotFoundException(p.schoolName + " does not equal " + team1Abbr + " or " + team2Abbr); } } } } } else { //Populate regular non-tie info firstEventPoints.athleteName = teams1and2[0].athleteName; firstEventPoints.schoolName = teams1and2[0].schoolName; if (firstEventPoints.schoolName == team1Abbr) { firstEventPoints.team1Pts = 5; firstEventPoints.team2Pts = 0; } else if (firstEventPoints.schoolName == team2Abbr) { firstEventPoints.team1Pts = 0; firstEventPoints.team2Pts = 5; } else { Console.WriteLine("ERROR! This code should be unreachable!"); throw new TeamNotFoundException(firstEventPoints.schoolName + " does not equal " + team1Abbr + " or " + team2Abbr); } } } else { firstEventPoints.performance = ""; firstEventPoints.athleteName = ""; firstEventPoints.schoolName = ""; firstEventPoints.team1Pts = 0; firstEventPoints.team2Pts = 0; } //secondplace EventPoints if (secondPlacePerf != 0) { secondEventPoints.performance = DESI.ConvertToTimedData(secondPlacePerf); if (secondPlaceHeats.Count > 1) { Console.WriteLine(numSecondPlaces + "-Way Tie for 2nd"); secondEventPoints.athleteName = "TIE"; secondEventPoints.schoolName = "TIE"; //Calculate Tie info foreach (Performance p in teams1and2) { if (p.performance == secondPlacePerf && secondPlaceHeats.Contains(p.heatNum)) { //test taking out p.heatNum here //Not sure if this is correct secondPlaceHeats.Remove(p.heatNum); if (p.schoolName == team1Abbr) { secondEventPoints.team1Pts += (4.0m / numSecondPlaces); } else if (p.schoolName == team2Abbr) { secondEventPoints.team2Pts += (4.0m / numSecondPlaces); } else { Console.WriteLine("ERROR! This code should be unreachable!"); throw new TeamNotFoundException(p.schoolName + " does not equal " + team1Abbr + " or " + team2Abbr); } } } } else { //Populate regular non-tie info for (int i = 1; i < teams1and2.Count; i++) { if (teams1and2[i].performance == secondPlacePerf) { secondEventPoints.athleteName = teams1and2[i].athleteName; secondEventPoints.schoolName = teams1and2[i].schoolName; break; //break added, same perf same heat error without } } if (secondEventPoints.schoolName == team1Abbr) { secondEventPoints.team1Pts = 3; secondEventPoints.team2Pts = 0; } else if (secondEventPoints.schoolName == team2Abbr) { secondEventPoints.team1Pts = 0; secondEventPoints.team2Pts = 3; } else { Console.WriteLine("ERROR! Second Place Points being assigned to an incorrect team name"); throw new TeamNotFoundException(secondEventPoints.schoolName + " does not equal " + team1Abbr + " or " + team2Abbr); } } } else { secondEventPoints.performance = ""; secondEventPoints.athleteName = ""; secondEventPoints.schoolName = ""; secondEventPoints.team1Pts = 0; secondEventPoints.team2Pts = 0; } //thirdplace EventPoints if (thirdPlacePerf != 0 && numFirstPlaces + numSecondPlaces < 3) { thirdEventPoints.performance = DESI.ConvertToTimedData(thirdPlacePerf); if (thirdPlaceHeats.Count > 1) { Console.WriteLine(numThirdPlaces + "-Way Tie for 3rd"); thirdEventPoints.athleteName = "TIE"; thirdEventPoints.schoolName = "TIE"; //Calculate Tie info foreach (Performance p in teams1and2) { if (p.performance == thirdPlacePerf && thirdPlaceHeats.Contains(p.heatNum)) { //test taking out p.heatNum here //Not sure if this is correct thirdPlaceHeats.Remove(p.heatNum); if (p.schoolName == team1Abbr) { thirdEventPoints.team1Pts += (1.0m / numThirdPlaces); } else if (p.schoolName == team2Abbr) { thirdEventPoints.team2Pts += (1.0m / numThirdPlaces); } else { Console.WriteLine("ERROR! This code should be unreachable!"); throw new TeamNotFoundException(p.schoolName + " does not equal " + team1Abbr + " or " + team2Abbr); } } } } else { //Populate regular non-tie info for (int i = 2; i < teams1and2.Count; i++) { if (teams1and2[i].performance == thirdPlacePerf) //if (teams1and2[i].performance == thirdPlacePerf && thirdPlaceHeats.Contains(teams1and2[i].heatNum)) //Changed { thirdEventPoints.athleteName = teams1and2[i].athleteName; thirdEventPoints.schoolName = teams1and2[i].schoolName; break; //break added, same perf same heat error without } } if (thirdEventPoints.schoolName == team1Abbr) { thirdEventPoints.team1Pts = 1; thirdEventPoints.team2Pts = 0; } else if (thirdEventPoints.schoolName == team2Abbr) { thirdEventPoints.team1Pts = 0; thirdEventPoints.team2Pts = 1; } else { Console.WriteLine("ERROR! Third Place Points being assigned to an incorrect team name"); throw new TeamNotFoundException(thirdEventPoints.schoolName + " does not equal " + team1Abbr + " or " + team2Abbr); } } } else { thirdEventPoints.performance = ""; thirdEventPoints.athleteName = ""; thirdEventPoints.schoolName = ""; thirdEventPoints.team1Pts = 0; thirdEventPoints.team2Pts = 0; } //Populate points totals eventToReturn.points[0] = firstEventPoints; eventToReturn.points[1] = secondEventPoints; eventToReturn.points[2] = thirdEventPoints; eventToReturn.team1Total = firstEventPoints.team1Pts + secondEventPoints.team1Pts + thirdEventPoints.team1Pts; eventToReturn.team2Total = firstEventPoints.team2Pts + secondEventPoints.team2Pts + thirdEventPoints.team2Pts; // //return IndEvent Object // Console.WriteLine("Leaving " + MethodBase.GetCurrentMethod().DeclaringType + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name); return(eventToReturn); }
void GetMarkersAndPoints() { System.Threading.ThreadPool.QueueUserWorkItem(delegate { ShowLoadingView(PortableLibrary.Constants.MSG_LOADING_ALL_MARKERS); mEventMarker = GetAllMarkers(eventID); var trackPoints = GetTrackPoints(eventID); HideLoadingView(); InvokeOnMainThread(() => { var boundPoints = new List <CLLocationCoordinate2D>(); if (mEventMarker != null && mEventMarker.markers.Count > 0) { for (int i = 0; i < mEventMarker.markers.Count; i++) { var point = mEventMarker.markers[i]; var imgPin = GetPinIconByType(point.type); var pointLocation = new CLLocationCoordinate2D(point.lat, point.lng); boundPoints.Add(pointLocation); AddMapPin(pointLocation, imgPin, i); } } if (trackPoints != null && trackPoints.Count > 0) { if (trackPoints[0].Count > 0) { var startPoint = trackPoints[0][0]; var endPoint = trackPoints[trackPoints.Count - 1][trackPoints[trackPoints.Count - 1].Count - 1]; var startLocation = new CLLocationCoordinate2D(startPoint.Latitude, startPoint.Longitude); var endLocation = new CLLocationCoordinate2D(endPoint.Latitude, endPoint.Longitude); AddMapPin(startLocation, GetPinIconByType("pSTART"), -1); AddMapPin(endLocation, GetPinIconByType("pFINISH"), -1); } for (int i = 0; i < trackPoints.Count; i++) { var tPoints = trackPoints[i]; var path = new MutablePath(); var polyline = new Polyline(); for (int j = 0; j < tPoints.Count; j++) { var tPoint = tPoints[j]; var tLocation = new CLLocationCoordinate2D(tPoint.Latitude, tPoint.Longitude); if (j < tPoints.Count - 1) { var distance = DistanceAtoB(tPoint, tPoints[j + 1]); if (PortableLibrary.Constants.AVAILABLE_DISTANCE_MAP > distance) { var nPoint = tPoints[j + 1]; path.AddCoordinate(tLocation); } else { polyline.Path = path; polyline.StrokeColor = GetRandomColor(i); polyline.StrokeWidth = 5; polyline.Geodesic = true; polyline.Map = mMapView; path = new MutablePath(); polyline = new Polyline(); } } polyline.Path = path; polyline.StrokeColor = GetRandomColor(i); polyline.StrokeWidth = 5; polyline.Geodesic = true; polyline.Map = mMapView; boundPoints.Add(tLocation); } } } if (boundPoints.Count == 0) { var camera = CameraPosition.FromCamera(PortableLibrary.Constants.LOCATION_ISURAEL[0], PortableLibrary.Constants.LOCATION_ISURAEL[1], zoom: PortableLibrary.Constants.MAP_ZOOM_LEVEL); mMapView = MapView.FromCamera(RectangleF.Empty, camera); } else { var mapBounds = new CoordinateBounds(); foreach (var bound in boundPoints) { mapBounds = mapBounds.Including(bound); } mMapView.MoveCamera(CameraUpdate.FitBounds(mapBounds, 50.0f)); } }); }); }
void GetMarkersAndPoints() { System.Threading.ThreadPool.QueueUserWorkItem(delegate { ShowLoadingView(Constants.MSG_LOADING_ALL_MARKERS); mEventMarker = GetAllMarkers(AppSettings.selectedEvent._id); var trackPoints = GetTrackPoints(AppSettings.selectedEvent._id); HideLoadingView(); var boundPoints = new List <LatLng>(); pointIDs = new List <string>(); RunOnUiThread(() => { try { if (mEventMarker != null && mEventMarker.markers.Count > 0) { for (int i = 0; i < mEventMarker.markers.Count; i++) { var point = mEventMarker.markers[i]; var pointLocation = new LatLng(point.lat, point.lng); boundPoints.Add(pointLocation); AddMapPin(pointLocation, point.type); } } if (trackPoints != null && trackPoints.Count > 0) { if (trackPoints[0].Count > 0) { var startPoint = trackPoints[0][0]; var endPoint = trackPoints[trackPoints.Count - 1][trackPoints[trackPoints.Count - 1].Count - 1]; var startLocation = new LatLng(startPoint.Latitude, startPoint.Longitude); var endLocation = new LatLng(endPoint.Latitude, endPoint.Longitude); AddMapPin(startLocation, "pSTART"); AddMapPin(endLocation, "pFINISH"); } for (int i = 0; i < trackPoints.Count; i++) { var tPoints = trackPoints[i]; List <LatLng> paths = new List <LatLng>(); LatLng[] arrPath; for (int j = 0; j < tPoints.Count; j++) { var tPoint = tPoints[j]; var tLocation = new LatLng(tPoint.Latitude, tPoint.Longitude); if (j < tPoints.Count - 1) { var distance = DistanceAtoB(tPoint, tPoints[j + 1]); if (PortableLibrary.Constants.AVAILABLE_DISTANCE_MAP > distance) { var nPoint = tPoints[j + 1]; paths.Add(tLocation); } else { arrPath = new LatLng[paths.Count]; for (var k = 0; k < paths.Count; k++) { arrPath[k] = paths[k]; } mMapView.AddPolyline(new PolylineOptions().Add(arrPath).InvokeColor(GetRandomColor(i)).InvokeWidth(5f)); paths = new List <LatLng>(); } } boundPoints.Add(tLocation); } arrPath = new LatLng[paths.Count]; for (var k = 0; k < paths.Count; k++) { arrPath[k] = paths[k]; } mMapView.AddPolyline(new PolylineOptions().Add(arrPath).InvokeColor(GetRandomColor(i)).InvokeWidth(5f)); paths = new List <LatLng>(); } } if (boundPoints.Count == 0) { var location = new LatLng(Constants.LOCATION_ISURAEL[0], Constants.LOCATION_ISURAEL[1]); CameraUpdate cu_center = CameraUpdateFactory.NewLatLngZoom(location, Constants.MAP_ZOOM_LEVEL); mMapView.MoveCamera(cu_center); } else { var mapBounds = new LatLngBounds.Builder(); foreach (var bound in boundPoints) { mapBounds.Include(bound); } mMapView.MoveCamera(CameraUpdateFactory.NewLatLngBounds(mapBounds.Build(), 50)); } } catch (Exception err) { Toast.MakeText(this, err.ToString(), ToastLength.Long).Show(); } }); }); }
public static List <CompetitorChampionship> MergeClassResults(List <CompetitorChampionship> previousClassResults, List <CompetitorChampionship> currentClassResults, int events) { // Nothing to update if (currentClassResults.Count() == 0) { if (previousClassResults == null) { return(new List <CompetitorChampionship>()); } else { //Iterate over results list and add null points to competitors that did not attend the current event foreach (var currentResult in previousClassResults) { var eventPoints = new EventPoints(); for (int j = currentResult.Points.Count(); j < events; j++) { currentResult.Points.Add(eventPoints); } } //Iterate over results list and recalculate the competitors points foreach (var competitor in previousClassResults) { // Sum points but remove the worst result competitor.Total = CalculateTotalPoints(competitor.Points); } //Reorder list by points previousClassResults = previousClassResults.OrderByDescending(o => o.Total).ToList(); return(previousClassResults); } } List <int> competitorNumberList = new List <int>(); bool found = false; foreach (var currentResult in currentClassResults) { competitorNumberList.Add(currentResult.Number); int i = 0; // Attempt to find drivers with same number within class only if the previous count is greather than zero if (previousClassResults != null) { while (i < previousClassResults.Count()) { if (currentResult.Number == previousClassResults[i].Number) { // Names match, so it can proceed if (currentResult.Name == previousClassResults[i].Name) { found = true; break; } else { //Throw message to verify if the competitors are the same var dr = MessageBox.Show("A competitor with same car number was found (#" + currentResult.Number + "). Previous competitor: " + previousClassResults[i].Name + ", current competitor: " + currentResult.Name + ".\nDo you want to merge results?", "Attention required", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { // If yes, stop the search and merge the results. Otherwise keep looking until another competitor is found (if found). Duplicated numbers will be created found = true; break; } } } i++; } if (i < previousClassResults.Count() && found) { // Found competitor // Add event points to the championship results previousClassResults[i].Points.Add(currentResult.Points.First()); // Sum points but remove the worst result //previousClassResults[i].Total = CalculateTotalPoints(previousClassResults[i].Points); // Sum the penalties from the current result previousClassResults[i].Penalties += currentResult.Penalties; continue; } else { // Not found. Add another competitor to the results or continue searching (different number?) var eventPoints = new EventPoints(); for (int j = 0; j < events - 1; j++) { currentResult.Points.Insert(0, eventPoints); } previousClassResults.Add(currentResult); } } else { // Add first competitor to the results var eventPoints = new EventPoints(); for (int j = 0; j < events - 1; j++) { currentResult.Points.Insert(0, eventPoints); } previousClassResults = new List <CompetitorChampionship>(); previousClassResults.Add(currentResult); } } //Iterate over results list and add null points to competitors that did not attend the current event foreach (var currentResult in previousClassResults) { if (!competitorNumberList.Contains(currentResult.Number)) { var eventPoints = new EventPoints(); for (int j = currentResult.Points.Count(); j < events; j++) { currentResult.Points.Add(eventPoints); } } } //Iterate over results list and recalculate the competitors points foreach (var competitor in previousClassResults) { // Sum points but remove the worst result competitor.Total = CalculateTotalPoints(competitor.Points); } //Reorder list by points previousClassResults = previousClassResults.OrderByDescending(o => o.Total).ToList(); return(previousClassResults); }
public static Championship Calculate(List <CompetitorResult> overallCompetitors, List <CompetitorResult> n2Competitors, List <CompetitorResult> n4Competitors, List <CompetitorResult> e2Competitors, List <CompetitorResult> e4Competitors, List <CompetitorResult> proCompetitors, List <CompetitorResult> truckCompetitors) { // First event of the season var championship = new Championship { Events = 1, OverallCompetitors = overallCompetitors.Count(), N2Competitors = n2Competitors.Count(), N4Competitors = n4Competitors.Count(), E2Competitors = e2Competitors.Count(), E4Competitors = e4Competitors.Count(), ProCompetitors = proCompetitors.Count(), TruckCompetitors = truckCompetitors.Count() }; // Overall results championship.Overall = new List <CompetitorChampionship>(); foreach (var competitor in overallCompetitors) { var competitorChampionship = new CompetitorChampionship() { Number = competitor.Number, Car = competitor.Car, Name = competitor.Name, Points = new List <EventPoints>(), Total = competitor.PositionPoints + competitor.CompetitorsInClassPoints + competitor.FastestLapPoints, Penalties = competitor.Penalties }; EventPoints ep = new EventPoints() { Position = competitor.PositionPoints, CompetitorsInClass = competitor.CompetitorsInClassPoints, FastestLap = competitor.FastestLapPoints }; competitorChampionship.Points.Add(ep); championship.Overall.Add(competitorChampionship); } ; // N2 results championship.N2 = new List <CompetitorChampionship>(); foreach (var competitor in n2Competitors) { var competitorChampionship = new CompetitorChampionship { Number = competitor.Number, Car = competitor.Car, Name = competitor.Name, Points = new List <EventPoints>(), Total = competitor.PositionPoints + competitor.CompetitorsInClassPoints + competitor.FastestLapPoints, Penalties = competitor.Penalties }; EventPoints ep = new EventPoints() { Position = competitor.PositionPoints, CompetitorsInClass = competitor.CompetitorsInClassPoints, FastestLap = competitor.FastestLapPoints }; competitorChampionship.Points.Add(ep); championship.N2.Add(competitorChampionship); } ; // N4 results championship.N4 = new List <CompetitorChampionship>(); foreach (var competitor in n4Competitors) { var competitorChampionship = new CompetitorChampionship { Number = competitor.Number, Car = competitor.Car, Name = competitor.Name, Points = new List <EventPoints>(), Total = competitor.PositionPoints + competitor.CompetitorsInClassPoints + competitor.FastestLapPoints, Penalties = competitor.Penalties }; EventPoints ep = new EventPoints() { Position = competitor.PositionPoints, CompetitorsInClass = competitor.CompetitorsInClassPoints, FastestLap = competitor.FastestLapPoints }; competitorChampionship.Points.Add(ep); championship.N4.Add(competitorChampionship); } ; // E2 results championship.E2 = new List <CompetitorChampionship>(); foreach (var competitor in e2Competitors) { var competitorChampionship = new CompetitorChampionship { Number = competitor.Number, Car = competitor.Car, Name = competitor.Name, Points = new List <EventPoints>(), Total = competitor.PositionPoints + competitor.CompetitorsInClassPoints + competitor.FastestLapPoints, Penalties = competitor.Penalties }; EventPoints ep = new EventPoints() { Position = competitor.PositionPoints, CompetitorsInClass = competitor.CompetitorsInClassPoints, FastestLap = competitor.FastestLapPoints }; competitorChampionship.Points.Add(ep); championship.E2.Add(competitorChampionship); } ; // E4 results championship.E4 = new List <CompetitorChampionship>(); foreach (var competitor in e4Competitors) { var competitorChampionship = new CompetitorChampionship { Number = competitor.Number, Car = competitor.Car, Name = competitor.Name, Points = new List <EventPoints>(), Total = competitor.PositionPoints + competitor.CompetitorsInClassPoints + competitor.FastestLapPoints, Penalties = competitor.Penalties }; EventPoints ep = new EventPoints() { Position = competitor.PositionPoints, CompetitorsInClass = competitor.CompetitorsInClassPoints, FastestLap = competitor.FastestLapPoints }; competitorChampionship.Points.Add(ep); championship.E4.Add(competitorChampionship); } ; // Pro results championship.Pro = new List <CompetitorChampionship>(); foreach (var competitor in proCompetitors) { var competitorChampionship = new CompetitorChampionship { Number = competitor.Number, Car = competitor.Car, Name = competitor.Name, Points = new List <EventPoints>(), Total = competitor.PositionPoints + competitor.CompetitorsInClassPoints + competitor.FastestLapPoints, Penalties = competitor.Penalties }; EventPoints ep = new EventPoints() { Position = competitor.PositionPoints, CompetitorsInClass = competitor.CompetitorsInClassPoints, FastestLap = competitor.FastestLapPoints }; competitorChampionship.Points.Add(ep); championship.Pro.Add(competitorChampionship); } ; // Truck results championship.Truck = new List <CompetitorChampionship>(); foreach (var competitor in truckCompetitors) { var competitorChampionship = new CompetitorChampionship { Number = competitor.Number, Car = competitor.Car, Name = competitor.Name, Points = new List <EventPoints>(), Total = competitor.PositionPoints + competitor.CompetitorsInClassPoints + competitor.FastestLapPoints, Penalties = competitor.Penalties }; EventPoints ep = new EventPoints() { Position = competitor.PositionPoints, CompetitorsInClass = competitor.CompetitorsInClassPoints, FastestLap = competitor.FastestLapPoints }; competitorChampionship.Points.Add(ep); championship.Truck.Add(competitorChampionship); } ; return(championship); }