Esempio n. 1
0
        public double getEstatistica(object startItem, object destinationItem) // Replicado método que monta as estatísticas da aplicação, com a diferença de que este retorna o tempo médio de viagem
        {
            ignoreUpdateEvent = true;

            BunchOfNodes start       = startItem as BunchOfNodes;
            BunchOfNodes destination = destinationItem as BunchOfNodes;

            editStartNodeTitle.Text       = start.title;
            m_mainForm.fromLineNodes      = start.nodes;
            editDestinationNodeTitle.Text = destination.title;
            m_mainForm.toLineNodes        = destination.nodes;

            if (start != null && destination != null)
            {
                m_currentVolume = m_steuerung.GetOrCreateTrafficVolume(start, destination);

                spinCarsVolume.Value    = m_currentVolume.trafficVolumeCars;
                spinTruckVolume.Value   = m_currentVolume.trafficVolumeTrucks;
                spinBusVolume.Value     = m_currentVolume.trafficVolumeBusses;
                spinTramVolume.Value    = m_currentVolume.trafficVolumeTrams;
                spinCarsVolume.Enabled  = true;
                spinTruckVolume.Enabled = true;
                spinBusVolume.Enabled   = true;
                spinTramVolume.Enabled  = true;
                ignoreUpdateEvent       = false;

                double milage = (m_currentVolume.statistics.sumMilage / m_currentVolume.statistics.numVehiclesReachedDestination) / 10;
                double tt     = m_currentVolume.statistics.sumTravelTime / m_currentVolume.statistics.numVehiclesReachedDestination;
                if (m_currentVolume.statistics.numVehicles == 0)
                {
                    milage = 0;
                    tt     = 1;
                }
                lblNumVehicles.Text = "Total Vehicles: " + m_currentVolume.statistics.numVehicles + " (" + m_currentVolume.statistics.numVehiclesReachedDestination + " reached Destination)";
                lblMilage.Text      = "Average Milage: " + milage + "m";
                lblTravelTime.Text  = "Average Travel Time: " + tt + "s";
                lblVelocity.Text    = "Average Milage: " + (milage / tt) + "m/s";
                lblNumStops.Text    = "Average Number of Stops: " + ((float)m_currentVolume.statistics.numStops / m_currentVolume.statistics.numVehicles);

                return(tt);
            }
            else
            {
                m_currentVolume         = null;
                spinCarsVolume.Enabled  = false;
                spinTruckVolume.Enabled = false;
                spinBusVolume.Enabled   = false;
                spinTramVolume.Enabled  = false;
                lblNumVehicles.Text     = "Total Vehicles: 0";
                lblMilage.Text          = "Average Milage: 0m";
                lblTravelTime.Text      = "Average Travel Time: 0s";
                lblVelocity.Text        = "Average Milage: 0m/s";
                lblNumStops.Text        = "Average Number of Stops: 0";
            }

            ignoreUpdateEvent = false;

            return(0);
        }
        /// <summary>
        /// Gets the TrafficVolume record to the corresponding start and destination nodes and updates the SpinEdit values.
        /// </summary>
        private void GetTrafficVolume()
        {
            ignoreUpdateEvent = true;
            BunchOfNodes start       = lbStartNodes.SelectedItem as BunchOfNodes;
            BunchOfNodes destination = lbDestinationNodes.SelectedItem as BunchOfNodes;

            if (start != null && destination != null)
            {
                m_currentVolume = m_steuerung.GetOrCreateTrafficVolume(start, destination);

                spinCarsVolume.Value    = m_currentVolume.trafficVolumeCars;
                spinTruckVolume.Value   = m_currentVolume.trafficVolumeTrucks;
                spinBusVolume.Value     = m_currentVolume.trafficVolumeBusses;
                spinTramVolume.Value    = m_currentVolume.trafficVolumeTrams;
                spinCarsVolume.Enabled  = true;
                spinTruckVolume.Enabled = true;
                spinBusVolume.Enabled   = true;
                spinTramVolume.Enabled  = true;
                ignoreUpdateEvent       = false;

                double milage = (m_currentVolume.statistics.sumMilage / m_currentVolume.statistics.numVehiclesReachedDestination) / 10;
                double tt     = m_currentVolume.statistics.sumTravelTime / m_currentVolume.statistics.numVehiclesReachedDestination;
                if (m_currentVolume.statistics.numVehicles == 0)
                {
                    milage = 0;
                    tt     = 1;
                }
                lblNumVehicles.Text = "Total Vehicles: " + m_currentVolume.statistics.numVehicles + " (" + m_currentVolume.statistics.numVehiclesReachedDestination + " reached Destination)";
                lblMilage.Text      = "Average Milage: " + milage + "m";
                lblTravelTime.Text  = "Average Travel Time: " + tt + "s";
                lblVelocity.Text    = "Average Milage: " + (milage / tt) + "m/s";
                lblNumStops.Text    = "Average Number of Stops: " + ((float)m_currentVolume.statistics.numStops / m_currentVolume.statistics.numVehicles);
            }
            else
            {
                m_currentVolume         = null;
                spinCarsVolume.Enabled  = false;
                spinTruckVolume.Enabled = false;
                spinBusVolume.Enabled   = false;
                spinTramVolume.Enabled  = false;
                lblNumVehicles.Text     = "Total Vehicles: 0";
                lblMilage.Text          = "Average Milage: 0m";
                lblTravelTime.Text      = "Average Travel Time: 0s";
                lblVelocity.Text        = "Average Milage: 0m/s";
                lblNumStops.Text        = "Average Number of Stops: 0";
            }
            ignoreUpdateEvent = false;
        }