private void cmdApplyRankList_Click(object sender, EventArgs e)
        {
            dataGridCompetitors.Columns["rank"].Visible = true;
            dataGridCompetitors.Rows.Clear();
            if (cmbRaceResults.SelectedItem != null)
            {
                race = (Race)cmbRaceResults.SelectedItem;
                {
                    List<ANR.Core.Common.TotalResult> ranklist = Common.calculateRankingList(race);
                    foreach (ANR.Core.Common.TotalResult res in ranklist)
                    {
                        Competitor c = res.Competitor;

                        bool isSetMemberOfRace;
                        if (race.Competitors.Count == 0)
                        {
                            isSetMemberOfRace = true;
                        }
                        else
                        {
                            isSetMemberOfRace = false;
                        }
                        if (race.Competitors.Contains(c))
                        {
                            isSetMemberOfRace = true;
                        }
                        int index = dataGridCompetitors.Rows.Add(new object[] { isSetMemberOfRace, res.Rank, c.CompetitionNumber, c.AcCallsign, c.PilotName, c.PilotFirstName, c.NavigatorName, c.NavigatorFirstName, c.Country });
                        dataGridCompetitors.Rows[index].Tag = c;
                        dataGridCompetitors.Sort(rank, ListSortDirection.Ascending);
                    }
                }
            }
        }
 public GroupCompetitorSelection(Competition competition, Race race)
 {
     InitializeComponent();
     this.race = race;
     this.competition = competition;
     UpdateCmbRaceResults();
     UpdateGridCompetitors(competition.CompetitorCollection);
 }
Example #3
0
 public static List<TotalResult> calculateRankingList(Race race)
 {
     List<TotalResult> rankingList = new List<TotalResult>();
     foreach (CompetitorGroup group in race.CompetitorGroups)
     {
         foreach(CompetitorRouteAssignment cra in group.CompetitorRouteAssignmentCollection)
         {
             List<int> flightPenalties = new List<int>();
             foreach (Flight flight in race.Flights.GetFlightsByCompetitor(cra.Competitor))
             {
                 flight.resetPenalties();
                 int sumOfPenaltiesPerFlight = 0;
                 foreach (Penalty penalty in flight.Penalties)
                 {
                     sumOfPenaltiesPerFlight += penalty.PenaltyPoints;
                 }
                 flightPenalties.Add(sumOfPenaltiesPerFlight);
             }
             double average = 0;
             if (flightPenalties.Count > 0)
             {
                 average = flightPenalties.Average();
             }
             rankingList.Add(new TotalResult(cra.Competitor, average));
         }
     }
     rankingList.Sort(delegate(TotalResult x, TotalResult y) { return x.Result.CompareTo(y.Result); });
     int rank = 1;
     foreach (TotalResult totalResult in rankingList)
     {
         totalResult.Rank = rank;
         rank++;
     }
        // stuffsList.Sort(delegate(MyStuff x, MyStuff y) { return Decimal.Compare(x.TheValue, y.TheValue); });
     return rankingList;
 }
Example #4
0
        /// <summary>
        /// Creates a Flight Data Sheet for the specified Flight in the PdfSharp.PdfDocument Format.
        /// </summary>
        /// <param name="competitor"></param>
        /// <param name="flight"></param>
        /// <param name="race"></param>
        /// <param name="parcours"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        public static PdfDocument createPdf(Competition competition, Competitor competitor, Flight flight, Race race, Parcours parcours)
        {
            // Create a new PDF document
            PdfDocument document = new PdfDocument();

            // Create an empty page
            PdfPage page = document.AddPage();

            // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);

            // Create a font
            XFont font = new XFont("Verdana", 14, XFontStyle.Bold);
            XFont font2 = new XFont("Verdana", 10, XFontStyle.Regular);
            XFont font3 = new XFont("Verdana", 10, XFontStyle.Regular);

            // Draw the text
            string headingText = "Results for " + race.Name + ", " + competition.Date.ToString("dd.MM.yyyy") + " in " + competition.Location;
            gfx.DrawString(headingText, font, XBrushes.DarkMagenta, new XPoint(50, 50), XStringFormat.TopLeft);

            string pilotLine = "Pilot: " + competitor.PilotName + ", " + competitor.PilotFirstName;
            gfx.DrawString(pilotLine, font2, XBrushes.Black, new XPoint(50, 90), XStringFormat.TopLeft);

            string copilotLine = "Navigator: " + competitor.NavigatorName + ", " + competitor.NavigatorFirstName;
            gfx.DrawString(copilotLine, font2, XBrushes.Black, new XPoint(50, 110), XStringFormat.TopLeft);

            string takeoffTime = "Takeoff time: " + flight.TakeOffTime.ToString("HH.mm.ss");
            gfx.DrawString(takeoffTime, font2, XBrushes.Black, new XPoint(50, 130), XStringFormat.TopLeft);

            string startTime = "Start Time: " + flight.StartGateTime.ToString("HH.mm.ss");
            gfx.DrawString(startTime, font2, XBrushes.Black, new XPoint(50, 150), XStringFormat.TopLeft);

            string finishTime = "Finish Time: " + flight.FinishGateTime.ToString("HH.mm.ss");
            gfx.DrawString(finishTime, font2, XBrushes.Black, new XPoint(250, 150), XStringFormat.TopLeft);

            Image image = Common.drawFlight(parcours.ParentMap, parcours, flight);
            int originalHeight = image.Height;
            int originalWidth = image.Width;
            XImage xImage = XImage.FromGdiPlusImage(image);
            double ratio = (double)image.Height / (double)image.Width;
            int height = (int)Math.Ceiling((page.Width.Point - 100) * ratio);
            gfx.DrawImage(xImage, 50, 180, page.Width.Point - 100, height);

            gfx.DrawString("Penalties", font2, XBrushes.Black, 50, height + 200);
            int position = height + 220;
            int i = 0;

            foreach (Penalty penalty in flight.AutomaticPenalties)
            {
                if ((position + i * 20) <= page.Height.Point - 50)
                {
                    gfx.DrawString(penalty.PenaltyPoints.ToString(), font3, XBrushes.Gray, 60, (position + i * 20));
                    gfx.DrawString(penalty.PenaltyType.ToString() + ", " + penalty.Comment, font2, XBrushes.Gray, 120, (position + i * 20));
                    i++;
                }
                else
                {
                    page = document.AddPage();
                    gfx = XGraphics.FromPdfPage(page);
                    i = 0;
                    position = 50;
                }
            }
            return document;
        }
Example #5
0
 /// <summary>
 /// saves the ranking List to the specified location
 /// </summary>
 /// <param name="race"></param>
 /// <param name="filename"></param>
 public static void saveRankingList(Race race, string filename)
 {
     List<TotalResult> rankList  = Common.calculateRankingList(race);
     StringBuilder sb = new StringBuilder();
     sb.AppendLine(String.Format("{0};{1};{2};{3};{4};{5};{6};{7};{8};",
            "Rank", "Result (Total Penalties)", "Start No", "AC-Callsign", "Pilot Firstname",
            "Pilot Name", "Navigator Firstname", "Navigator Name", "Country"));
     foreach (TotalResult res in rankList)
     {
         Competitor competitor = res.Competitor;
         sb.AppendLine(String.Format("{0};{1};{2};{3};{4};{5};{6};{7};{8};",
             res.Rank, res.Result, competitor.CompetitionNumber, competitor.AcCallsign, competitor.PilotFirstName,
             competitor.PilotName, competitor.NavigatorFirstName, competitor.NavigatorName, competitor.Country ));
     }
     StreamWriter sw = new StreamWriter(filename);
     sw.Write(sb.ToString());
     sw.Close();
 }
Example #6
0
 public static void saveRaceStartlist(Race r, string filename)
 {
     StringBuilder sb = new StringBuilder();
     sb.AppendLine(string.Format("{0};{1};{2};{3};{4};{5};{6};{7};",
            "Start Time", "Start No", "AC-Callsign", "Pilot Firstname",
            "Pilot Name", "Navigator Firstname", "Navigator Name", "Country"));
     SortedList<DateTime, Competitor> startlist = new SortedList<DateTime, Competitor>();
     foreach(CompetitorGroup cg in r.CompetitorGroups)
     {
         foreach(CompetitorRouteAssignment cra in cg.CompetitorRouteAssignmentCollection)
         {
             startlist.Add(cra.TakeoffTime, cra.Competitor);
         }
     }
     foreach (KeyValuePair<DateTime,Competitor> c in startlist)
     {
         sb.AppendLine(string.Format("{0};{1};{2};{3};{4};{5};{6};{7};",
             c.Key.ToString("HH:mm:ss"), c.Value.CompetitionNumber, c.Value.AcCallsign, c.Value.PilotFirstName,
             c.Value.PilotName, c.Value.NavigatorFirstName, c.Value.NavigatorName, c.Value.Country));
     }
     StreamWriter sw = new StreamWriter(filename);
     sw.Write(sb.ToString());
     sw.Close();
 }
Example #7
0
 /// <summary>
 /// Saves the specified PdfDocument to a specified Location.
 /// </summary>
 /// <param name="doc">PfdDocument to save</param>
 /// <param name="filename">Filepath (e.g. C:\flight.pdf). String must contain file Ending</param>
 public static void savePdf(Competition competition, Competitor competitor, Flight flight, Race race, Parcours parcours, string filename)
 {
     createPdf(competition, competitor, flight, race, parcours).Save(filename);
 }
Example #8
0
        /// <summary>
        /// Draw the Image of the flights of a Group
        /// </summary>
        /// <param name="map"></param>
        /// <param name="parcours"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        public static Image drawGroupFlights(Race race, Map map, Parcours parcours, CompetitorGroup group)
        {
            int competitorCounter = 0;

            Image img = drawParcours(parcours);
            Bitmap pg = new Bitmap(img.Width, img.Height);
            Graphics gr = Graphics.FromImage(pg);

            // clear the canvas to white
            Rectangle pgRect = new Rectangle(0, 0, pg.Width, pg.Height);
            SolidBrush solidWhite = new SolidBrush(Color.White);
            gr.FillRectangle(solidWhite, pgRect);
            // load a new image and draw it centered on our canvas

            Rectangle rc = new Rectangle(0, 0, img.Width, img.Height);
            gr.DrawImage(img, rc);
            img.Dispose();

            foreach (CompetitorRouteAssignment cra in group.CompetitorRouteAssignmentCollection)
            {
                Competitor competitor = cra.Competitor;

                Flight flight = race.Flights.GetFlightByGroupAndCompetitorId(group, competitor);
                Pen[] pens = new Pen[] { new Pen(Brushes.Blue, 3.0f), new Pen(Brushes.Aquamarine, 3.0f), new Pen(Brushes.BlueViolet, 3.0f), new Pen(Brushes.DeepSkyBlue, 3.0f) };
                Pen penInZone = new Pen(Brushes.LawnGreen, 5.0f);
                SolidBrush sb = new SolidBrush(Color.FromArgb(50, 250, 00, 20));
                double imagePointsLongitudeDifference = map.BottomRightPoint.Longitude - map.TopLeftPoint.Longitude;
                double imagePointsLatitudeDifference = map.TopLeftPoint.Latitude - map.BottomRightPoint.Latitude;

                Point[] points = new Point[flight.Track.Count];
                DateTime expectedFinishingTime = flight.StartGateTime.AddMinutes(parcours.DefaultTargetFlightDuration.TotalMinutes + 1);

                int i = 0;
                bool lastPointWasOffTrack = false;
                bool passedFinishingGate = false;
                List<Point> penaltyPoints = new List<Point>();
                List<List<Point>> penaltyPointsList = new List<List<Point>>();
                foreach (TrackPoint trackPoint in flight.Track)
                {

                    double currentPointLongitudeDifference = trackPoint.Longitude - map.TopLeftPoint.Longitude;
                    double currentPointLatitudeDifference = map.TopLeftPoint.Latitude - trackPoint.Latitude;
                    double currentPointImageX = (currentPointLongitudeDifference / imagePointsLongitudeDifference) * pg.Width;
                    double currentPointImageY = (currentPointLatitudeDifference / imagePointsLatitudeDifference) * pg.Height;

                    int mapPointX = int.Parse(Math.Ceiling(currentPointImageX).ToString());
                    int mapPointY = int.Parse(Math.Ceiling(currentPointImageY).ToString());

                    GraphicsPath p = new GraphicsPath();
                    foreach (Route route in parcours.Routes)
                    {
                        if (route.EndGate.gatePassed(trackPoint, flight.Track[i + 1]) || trackPoint.TimeStamp > expectedFinishingTime)
                        {
                            passedFinishingGate = true;
                        }
                    }
                    if (!passedFinishingGate && parcours.IsPointOffTrack(trackPoint))
                    {
                        lastPointWasOffTrack = true;
                        penaltyPoints.Add(new Point(mapPointX, mapPointY));
                    }
                    else
                    {
                        if (lastPointWasOffTrack)
                        {
                            penaltyPointsList.Add(penaltyPoints);
                            penaltyPoints = new List<Point>();
                        }
                        lastPointWasOffTrack = false;
                    }

                    points[i] = new Point(mapPointX, mapPointY);
                    if (i < flight.Track.Count - 2)
                    {
                        i++;
                    }
                }
                gr.DrawLines(pens[competitorCounter], points);

                foreach (List<Point> penaltyPts in penaltyPointsList)
                {
                    Point[] pointarray = penaltyPts.ToArray();
                    gr.DrawLines(penInZone, pointarray);
                }
                competitorCounter++;
            }
            return pg;
        }
Example #9
0
File: GUI.cs Project: helios57/anrl
 private void racesCmdAddRaceToCompetition_Click(object sender, EventArgs e)
 {
     Race newRace = new Race();
     newRace.Name = "New Race";
     newRace.Map = competition.MapCollection[0];
     newRace.Parcours = newRace.Map.ParcoursCollection[0];
     this.competition.RaceCollection.Add(newRace);
     racesCurrentRace = newRace;
     racesUpdateGrid();
 }
Example #10
0
File: GUI.cs Project: helios57/anrl
 private void resCmbRaces_SelectedIndexChanged(object sender, EventArgs e)
 {
     resCurrentRace = (Race)resCmbRaces.SelectedItem;
     UpdateResultList();
 }
Example #11
0
 public bool Contains(Race item)
 {
     return items.Contains(item);
 }
Example #12
0
File: GUI.cs Project: helios57/anrl
        private void racesUpdateGrid()
        {
            Race currentRaceLocalCopy = racesCurrentRace; //cause clearing the Rows also sets racesCurrentRace to null...

            racesDataGridViewRaces.Rows.Clear();

            foreach (Race race in competition.RaceCollection)
            {
                int index = racesDataGridViewRaces.Rows.Add(new object[] { race.Name, race.Map.MapName, race.Competitors.Count });
                racesDataGridViewRaces.Rows[index].Tag = race;
                if (race == currentRaceLocalCopy)
                {
                    racesDataGridViewRaces.Rows[index].Selected = true;
                }
            }
            racesCurrentRace = currentRaceLocalCopy;
            racesUpdateView();
        }
Example #13
0
File: GUI.cs Project: helios57/anrl
        private void raceUpdateCmbRaces()
        {
            raceCmbRaces.DisplayMember = "Name";
            raceCmbRaces.Items.Clear();
            foreach (Race race in competition.RaceCollection)
            {
                raceCmbRaces.Items.Add(race);
            }

            if (raceCmbRaces.SelectedItem != null)
            {
                raceCmbRaces.SelectedIndex = 0;
                raceCurrentRace = (Race)raceCmbRaces.SelectedItem;
            }
            raceUpdateGroupView();
        }
Example #14
0
File: GUI.cs Project: helios57/anrl
 private void racesDataGridViewRaces_SelectionChanged(object sender, EventArgs e)
 {
     if (racesDataGridViewRaces.SelectedRows.Count > 0)
     {
         racesCurrentRace = (Race)racesDataGridViewRaces.SelectedRows[0].Tag;
     }
     racesUpdateView();
 }
Example #15
0
File: GUI.cs Project: helios57/anrl
 private void racesDataGridViewRaces_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     racesCurrentRace = (Race)racesDataGridViewRaces.Rows[e.RowIndex].Tag;
     racesUpdateView();
 }
Example #16
0
File: GUI.cs Project: helios57/anrl
 private void racesCmdDeleteRace_Click(object sender, EventArgs e)
 {
     competition.RaceCollection.Remove(racesCurrentRace);
     racesCurrentRace = null;
     racesUpdateGrid();
 }
Example #17
0
 public GroupsForm(Competition competition, Race race, CompetitorGroup group)
 {
     InitializeComponent();
     this.competition = competition;
     this.race = race;
     this.competitorGroup = group;
 }
Example #18
0
File: GUI.cs Project: helios57/anrl
 void flightTreeViewGroupsAndCompetitors_AfterSelect(object sender, TreeViewEventArgs e)
 {
     if (e.Node.Tag.GetType() == typeof(Competitor))
     {
         flightCurrentCompetitor = e.Node.Tag as Competitor;
         flightCurrentGroup = e.Node.Parent.Tag as CompetitorGroup;
         flightCurrentRace = e.Node.Parent.Parent.Tag as Race;
         updateFlightView();
     }
 }
Example #19
0
 public void Add(Race item)
 {
     items.Add(item); // ToDo: key unique?!
 }
Example #20
0
File: GUI.cs Project: helios57/anrl
 private void raceCmbRaces_SelectedIndexChanged(object sender, EventArgs e)
 {
     raceCurrentRace = (Race)raceCmbRaces.SelectedItem;
     raceUpdateGroupGrid();
 }
Example #21
0
 public void Remove(Race item)
 {
     items.Remove(item);
 }
Example #22
0
 public CompetitorSelection(Race race)
 {
     InitializeComponent();
     this.race = race;
     compUpdateGrid();
 }