/// <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(); foreach (TotalResult res in rankList) { Competitor competitor = res.Competitor; sb.AppendLine(String.Format("{0};{1};{2};{3};{4};{5};{6};{7};", 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(); }
/// <summary> /// returns the DateTime when a TakeOffGate was passed /// </summary> /// <param name="race"></param> /// <param name="flight"></param> /// <returns></returns> public static DateTime takeoffGatePassingTime(Race race, Flight flight) { for (int i = 0; i < flight.Track.Count - 2; i++) { if (Common.gatePassed(race.TakeOffGate, flight.Track[i], flight.Track[i + 1])) { return flight.Track[i + 1].TimeStamp; } } return new DateTime(0); }
/// <summary> /// Saves the Race to the specified Location on the local Computer using a BinaryFormatter. The File contains the binary representation of a Race Object, including all Child-Objects (= all collected data) /// </summary> /// <param name="filename">Filename for the File. The Ending must be .anrx, elsewise the file will not work!</param> /// <param name="race">Race Object to save.</param> public static void saveRace(string filename, Race race) { BinaryFormatter binaryFormatter = new BinaryFormatter(); Stream fStream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None); binaryFormatter.Serialize(fStream, race); }
/// <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(Competitor competitor, Flight flight, Race race, Parcours parcours, string filename) { createPdf(competitor, flight, race, parcours).Save(filename); }
/// <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(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 + ", " + race.Date.ToString("dd.MM.yyyy") + " in " + race.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: " + Common.startingGatePassingTime(parcours, flight).ToString("HH.mm.ss"); gfx.DrawString(takeoffTime, font2, XBrushes.Black, new XPoint(50, 130), XStringFormat.TopLeft); string startTime = "Start Time: " + Common.startingGatePassingTime(parcours, flight).ToString("HH.mm.ss"); gfx.DrawString(startTime, font2, XBrushes.Black, new XPoint(50, 150), XStringFormat.TopLeft); string finishTime = "Finish Time: " + Common.finishingGatePassingTime(parcours, flight).ToString("HH.mm.ss"); gfx.DrawString(finishTime, font2, XBrushes.Black, new XPoint(250, 150), XStringFormat.TopLeft); Image image = Common.drawFlight(race.Map, 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.Penalties) { 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; }
public static List<TotalResult> calculateRankingList(Race race) { List<TotalResult> rankingList = new List<TotalResult>(); foreach (Competitor competitor in race.Competitors) { //int[] flightPenalties = new int[competitor.Flights.Count]; List<int> flightPenalties = new List<int>(); foreach (Flight flight in competitor.Flights.Values) { 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(competitor,average)); } rankingList.Sort(delegate(TotalResult x, TotalResult y) { return x.Result.CompareTo(y.Result); }); // stuffsList.Sort(delegate(MyStuff x, MyStuff y) { return Decimal.Compare(x.TheValue, y.TheValue); }); return rankingList; }
static void Main(string[] args) { Console.WriteLine("Import Test, testparcours.dxf"); Race r = new Race(); r.Location = "Birrfeld"; r.Date = DateTime.Now; r.Name = "Schweizermeisterschaft"; r.TargetFlightDuration = new TimeSpan(0); Parcours p = new Parcours(@"..\..\testparcours2.dxf"); Competitor comp = new Competitor(); comp.AcCallsign = "gibb"; comp.Country = "Switzerland"; comp.PilotFirstName = "Quack"; comp.PilotName = "Crashpilot"; comp.NavigatorFirstName = "Christopher"; comp.NavigatorName = "Columbus"; r.Competitors.Add(comp); Competitor newComp = new Competitor(); comp.AcCallsign = "HellouHellou"; comp.Country = "Switzerland"; comp.PilotFirstName = "Emilio"; comp.PilotName = "Sigrist"; comp.NavigatorFirstName = "Gartenzwerg"; comp.NavigatorName = "Mutzli"; r.Competitors.Add(newComp); CompetitorGroup group = new CompetitorGroup(); group.Competitors.Add(comp); r.ImportFlight(group, comp, @"..\..\Track1_c172.GAC"); Flight f = r.Flights.GetFlightByGroupAndCompetitorId(group.Id, comp.Id); Console.WriteLine(f.Track[0].ToString(GpsPointFormatString.Swiss, GpsPointComponent.Latitude)); Console.WriteLine(f.Track[0].ToString(GpsPointFormatString.Swiss, GpsPointComponent.Longitude)); Map m = new Map(new Bitmap(Image.FromFile(@"..\..\635320_251980_668600_230020.jpg")), new GpsPoint(251980, 635320, GpsPointFormatImport.Swiss), new GpsPoint(230020, 668600, GpsPointFormatImport.Swiss)); r.Map = m; r.SetMap(@"..\..\635320_251980_668600_230020.jpg"); Image img = Common.drawParcours(m,p); img.Save(@"C:\p.bmp", System.Drawing.Imaging.ImageFormat.Bmp); Process.Start(@"C:\p.bmp"); Flight flight = r.Flights.GetFlightByGroupAndCompetitorId(group.Id, comp.Id); Image img2 = Common.drawFlight(m, p, flight); #region ////img.Save(@"C:\test.bmp", System.Drawing.Imaging.ImageFormat.Bmp); //// Save object to a file named CarData.dat in binary. //BinaryFormatter binFormat = new BinaryFormatter(); //Stream fStream = new FileStream(@"C:\tRace.anrx", FileMode.Create, FileAccess.Write, FileShare.None); //binFormat.Serialize(fStream, r); //Stream fStream2 = new FileStream(@"C:\tParcours.anrx", FileMode.Create, FileAccess.Write, FileShare.None); //binFormat.Serialize(fStream2, p); //Stream fStream3 = new FileStream(@"C:\tGroup.anrx", FileMode.Create, FileAccess.Write, FileShare.None); //binFormat.Serialize(fStream3, group); //Console.WriteLine("Number of forbidden Zones" + p.ForbiddenZones.Count); //foreach(ForbiddenZone f in p.ForbiddenZones) //{ // Console.WriteLine("Zone: \n"); // foreach (GpsPoint pt in f.GpsPoints) // { // Console.WriteLine("\t Point: " + pt.Longitude + " / " + pt.Latitude + "\n"); // } //} //for(int i =0;i<p.Gates.Length / 2; i++) //{ // Console.WriteLine("Track: \n"); // Console.WriteLine("Starting Gate: \n"); // Console.WriteLine("\t Point: " + p.Gates[i,0].LeftPoint.Longitude + " / " + p.Gates[i,0].LeftPoint.Latitude + "\n"); // Console.WriteLine("\t Point: " + p.Gates[i,0].RightPoint.Longitude + " / " + p.Gates[i,0].RightPoint.Latitude + "\n"); // Console.WriteLine("Finishing Gate:"); // Console.WriteLine("\t Point: " + p.Gates[i, 1].LeftPoint.Longitude + " / " + p.Gates[i, 1].LeftPoint.Latitude + "\n"); // Console.WriteLine("\t Point: " + p.Gates[i, 1].RightPoint.Longitude + " / " + p.Gates[i, 1].RightPoint.Latitude + "\n"); // Console.WriteLine("\t Point in CH Coord " + m.TopLeftPoint.ToString(GpsPointFormatString.Swiss, GpsPointComponent.Longitude)); // Console.WriteLine("\t Point in CH Coord " + m.TopLeftPoint.ToString(GpsPointFormatString.Swiss, GpsPointComponent.Latitude)); //} //Console.WriteLine("NbLine: \n"); //try //{ // Console.WriteLine("\t Point: " + p.NbLine.LeftPoint.Longitude + " / " + p.NbLine.LeftPoint.Latitude + "\n"); // Console.WriteLine("\t Point: " + p.NbLine.RightPoint.Longitude + " / " + p.NbLine.RightPoint.Latitude + "\n"); //} //catch //{ // Console.WriteLine("No NbLine defined!"); //} //Console.Write("Total Forbidden Zones: \t" + p.ForbiddenZones.Count + " \n"); //Console.Write("Total Gates : \t\t" + p.Gates.Length / 2 + " \n"); //int v = 0; //int w = 0; //foreach (TrackPoint point in comp.getFlight(group).Track) //{ // if (p.isPointOffTrack(point)) // { // Console.WriteLine("Point was off Track: " + point.Latitude.ToString() + " / " + point.Longitude.ToString() + " Timestamp: " + point.TimeStamp.ToString()); // v++; // } // else // { // Console.WriteLine("Point was NOT off Track: " + point.Latitude.ToString() + " / " + point.Longitude.ToString() + " Timestamp: " + point.TimeStamp.ToString()); // w++; // } //} //Console.WriteLine("Total Points: " + comp.getFlight(group).Track.Count + "off track: " + v.ToString() + "in track: " + w.ToString()); //Console.WriteLine("Passed Gate at: " + comp.getFlight(group).PassedGate(p).ToString()); #endregion foreach (Penalty penalty in flight.Penalties) { Console.WriteLine(penalty.PenaltyPoints.ToString() + " " + penalty.PenaltyType.ToString() + " " + penalty.Comment.ToString()); } for (int i = 0; i < flight.Track.Count - 2; i++) { for(int j = 0; j<4;j++) { for (int k = 0; k <= 1; k++) { //Gate gate = p.Gates[j, k]; // ToDo: get flights //if (Common.gatePassed(gate, comp.getFlight(group).Track[i], comp.getFlight(group).Track[i + 1])) //{ // if (k == 0) // { // Console.WriteLine("passed Start Gate " + j + " at :" + comp.getFlight(group).Track[i].TimeStamp.ToString()); // } // else // { // Console.WriteLine("passed finishing Gate " + j + " at :" +comp.getFlight(group).Track[i].TimeStamp.ToString()); // } //} } } } // ToDo: get flight //comp.getFlight(group).Penalties.AddRange(list); //PdfSharp.Pdf.PdfDocument doc = Common.createPdf(comp, comp.getFlight(group), r, p); //doc.Save("C:\\test.pdf"); Process.Start("C:\\test.pdf"); Console.ReadLine(); }