public void PrintReport() { logger.Log(" -- Flags: {0}. Packets: {1}", Header.Flags, Packets.Count); long audioDataBytes = AudioDataBytes; long videoDataBytes = VideoDataBytes; TimeSpan start = Packets.Min(p => p.TimeStamp); TimeSpan end = Packets.Max(p => p.TimeStamp); logger.Log(" -- Audio: {0} bytes ({1:P1}) ({2} packets)", audioDataBytes, (float)audioDataBytes / Size, Packets.Count(p => p.PacketType == PacketType.AudioPayload)); logger.Log(" -- Video: {0} bytes ({1:P1}) ({2} packets)", videoDataBytes, (float)videoDataBytes / Size, Packets.Count(p => p.PacketType == PacketType.VideoPayload)); logger.Log(" -- Duration: {0} seconds (from {1} to {2})", (int)(end - start).TotalSeconds, (int)start.TotalSeconds, (int)end.TotalSeconds); }
public Bitmap drawSimulation() { if (g == null) { return(null); } if (scaleX == -1) { scaleX = ((float)g.VisibleClipBounds.Width) / Width; scaleY = ((float)g.VisibleClipBounds.Height) / Height; } PointF scale = new PointF(scaleX, scaleY); //Bitmap b = new Bitmap(1000, (int)(Height*scale)); Bitmap b = new Bitmap(1000, 1000); g = g == null?Graphics.FromImage(b) : g; g.Clear(Color.Pink); float size = 5f; Font font = new Font("Tahoma", 5 * scale.X, GraphicsUnit.World); Font font2 = new Font("Tahoma", 3 * scale.X, GraphicsUnit.World); StringBuilder sb = new StringBuilder(); string info = string.Format("Nodes Alive {0}/{1},Packets: Sent({2}), Received({3}),Dropped({4}),PDR {5}% ", NodeCount - DeadNodesCount, NodeCount, Packets.Count(), RecievedPackets.Count(), DroppedPackets.Count(), ((float)DroppedPackets.Count() * 100) / Packets.Count()); g.DrawString(info, font, Brushes.Black, 1 * scale.X, 1 * scale.Y, StringFormat.GenericDefault); sb.AppendLine(info); info = string.Format("Beacons Broadcast({0}) and received {1} times", SentBeaconsCount, RecivedBeaconsCount); sb.AppendLine(info); g.DrawString(info, font, Brushes.Black, 1 * scale.X, 15 * scale.Y, StringFormat.GenericDefault); if (RecievedPackets.Count() > 0) { float E_E_delay = RecievedPackets.Select(p => p.RecivedTime - p.SentTime).Average(); double hopCount = RecievedPackets.Select(p => p.Hubes.Count()).Average(); info = string.Format("E-E Delay:({0}),Average hub Count {1})", E_E_delay, hopCount); sb.AppendLine(info); g.DrawString(info, font, Brushes.Black, 1 * scale.X, 30 * scale.Y, StringFormat.GenericDefault); } ResultSummery = sb.ToString(); foreach (Node node in Nodes) { var speed = Math.Round(Math.Sqrt(Math.Pow(node.Speed.X, 2) + Math.Pow(node.Speed.Y, 2)), 2); if (node.IsDead) { speed = 0; g.FillRectangle(Brushes.Red, new RectangleF(node.Location.Scale(scale), new SizeF(size, size))); g.DrawString(node.Id.ToString(), font, Brushes.Red, node.Location.X * scale.X + 2 * scale.Y, node.Location.Y * scale.Y - 2 * scale.Y, StringFormat.GenericDefault); g.DrawString(speed.ToString(), font2, Brushes.Red, node.Location.X * scale.X - 2 * scale.Y, node.Location.Y * scale.Y + 2 * scale.Y, StringFormat.GenericDefault); } else { g.FillRectangle(Brushes.Yellow, new RectangleF(node.Location.Scale(scale), new SizeF(size, size))); g.DrawString(node.Id.ToString(), font, Brushes.Black, node.Location.X * scale.X + 2 * scale.Y, node.Location.Y * scale.Y - 2 * scale.Y, StringFormat.GenericDefault); g.DrawString(speed.ToString(), font2, Brushes.Yellow, node.Location.X * scale.X - 2 * scale.Y, node.Location.Y * scale.Y + 2 * scale.Y, StringFormat.GenericDefault); g.DrawString(node.Energy.ToString("0.0000"), font2, Brushes.Red, node.Location.X * scale.X - 6 * scale.Y, node.Location.Y * scale.Y + 6 * scale.Y, StringFormat.GenericDefault); } foreach (Node ne in node.RNGNeighbors) { g.DrawLine(Pens.Yellow, node.Location.Scale(scale), ne.Location.Scale(scale)); } } foreach (BeaconPacket bp in BeaconPackets) { var node = bp.Sender; RectangleF boundingRectf = new RectangleF(node.Location, new SizeF(node.Range, node.Range)); boundingRectf.Offset(-node.Range / 2, -node.Range / 2); g.DrawEllipse(Pens.YellowGreen, boundingRectf.Scale(scale)); } Pen pen = new Pen(Brushes.Black, 2.5f); foreach (Packet p in RecievedPackets.Where(p => p.SentTime == SimulationTime)) { if (p.Hubes.Count > 0) { for (int i = 0; i < p.Hubes.Count - 1; i++) { g.DrawLine(pen, p.Hubes[i].Location.Scale(scale), p.Hubes[i + 1].Location.Scale(scale)); } } } pen.Dispose(); return(b); }