Esempio n. 1
0
        /// <summary>
        /// Determine if the train is approaching, leaving or within a loop.
        /// </summary>
        /// <param name="train">The train object containing the journey details.</param>
        /// <param name="targetLocation">The specific location being considered.</param>
        /// <returns>True, if the train is within the boundaries of teh loop window.</returns>
        public bool isTrainInLoopBoundary(Train train, double targetLocation)
        {
            /* Find the indecies of the boundaries of the loop. */
            double lookBack       = targetLocation - Settings.loopBoundaryThreshold;
            double lookForward    = targetLocation + Settings.loopBoundaryThreshold;
            int    lookBackIdx    = train.indexOfgeometryKm(train.TrainJourney, lookBack);
            int    lookForwardIdx = train.indexOfgeometryKm(train.TrainJourney, lookForward);

            /* Check the indecies are valid */
            if (lookBack < Settings.startKm && lookBackIdx == -1)
            {
                lookBackIdx = 0;
            }
            if (lookForward > Settings.endKm && lookForwardIdx == -1)
            {
                lookForwardIdx = train.TrainJourney.Count() - 1;
            }

            /* Determine if a loop is within the loop window of the current position. */
            if (lookBackIdx >= 0 && lookForwardIdx >= 0)
            {
                for (int journeyIdx = lookBackIdx; journeyIdx < lookForwardIdx; journeyIdx++)
                {
                    TrainDetails journey = train.TrainJourney[journeyIdx];

                    if (journey.isLoopHere)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
        public ActionResult EditTrainDetails(int trainId)       //Editing Train details
        {
            TrainDetails          trainDetails          = trainDetailsBL.GetTrainByNo(trainId);
            TrainDetailsViewModel trainDetailsViewModel = AutoMapper.Mapper.Map <TrainDetails, TrainDetailsViewModel>(trainDetails);

            return(View(trainDetailsViewModel));
        }
 public void UpdateTrainDetails(TrainDetails trainDetails)   //Method to update train details
 {
     using (TrainTicketBookingDbContext dbContext = new TrainTicketBookingDbContext())
     {
         TrainDetails details = GetTrainByNo(trainDetails.TrainId);
         dbContext.Entry(trainDetails).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
Esempio n. 4
0
 public ActionResult EditTrainDetails(TrainDetailsViewModel trainDetailsViewModel)   //Post method for editing train details
 {
     if (ModelState.IsValid)
     {
         TrainDetails trainDetails = AutoMapper.Mapper.Map <TrainDetailsViewModel, TrainDetails>(trainDetailsViewModel);
         trainDetailsBL.UpdateTrainDetails(trainDetails);
         TempData["TrainId"] = trainDetails.TrainId;
         return(RedirectToAction("DisplayTrainCategories", "TrainClass"));
     }
     return(View(trainDetailsViewModel));
 }
 public bool AddTrainDetails(TrainDetails trainDetails)      //Method to add train details to Database
 {
     try
     {
         using (TrainTicketBookingDbContext dbContext = new TrainTicketBookingDbContext())
         {
             dbContext.TrainDetails.Add(trainDetails);
             //dbContext.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [dbo].[TrainDetails] ON");
             dbContext.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 6
0
 public ActionResult Create(TrainDetailsViewModel trainDetailsViewModel)
 {
     if (ModelState.IsValid)
     {
         TrainDetails trainDetails = AutoMapper.Mapper.Map <TrainDetailsViewModel, TrainDetails>(trainDetailsViewModel);
         //trainDetails.TrainClassDetails = new List<TrainClassDetails>();
         //foreach(int detail in trainDetailsViewModel.TrainClass)
         //{
         //    TrainClassDetails trainClassDetails = new TrainClassDetails();
         //    trainClassDetails.ClassId = detail;
         //    trainDetails.TrainClassDetails.Add(trainClassDetails);
         //}
         trainDetailsBL.AddTrainDetails(trainDetails);                       //Creating Train Details
         TempData["TrainId"] = trainDetails.TrainId;
         return(RedirectToAction("AddTrainClass", "TrainClass"));
         //TempData["Message"] = "Added Successfully!!!";
         //return RedirectToAction("Index");
     }
     //ViewBag.TrainClass = new SelectList(TrainClassRepository.GetClassDetails(), "ClassId", "ClassName");
     return(View(trainDetailsViewModel));
 }
Esempio n. 7
0
        /// <summary>
        /// Determine the properties of the TSR if one applies.
        /// </summary>
        /// <param name="train">The train object containing the journey details.</param>
        /// <param name="targetLocation">The specific location being considered.</param>
        /// <returns>TSR object containting the TSR flag and the associated speed. </returns>
        public TSRObject temporarySpeedRestrictionParameters(Train train, double targetLocation)
        {
            TSRObject TSR = new TSRObject();

            /* Find the indecies of the boundaries of the loop. */
            double lookBack       = targetLocation - Settings.TSRwindowBounday;
            double lookForward    = targetLocation + Settings.TSRwindowBounday;
            int    lookBackIdx    = train.indexOfgeometryKm(train.TrainJourney, lookBack);
            int    lookForwardIdx = train.indexOfgeometryKm(train.TrainJourney, lookForward);

            /* Check the indecies are valid */
            if (lookBack < Settings.startKm && lookBackIdx == -1)
            {
                lookBackIdx = 0;
            }
            if (lookForward > Settings.endKm && lookForwardIdx == -1)
            {
                lookForwardIdx = train.TrainJourney.Count() - 1;
            }

            /* Determine if a loop is within the loop window of the current position. */
            if (lookBackIdx >= 0 && lookForwardIdx >= 0)
            {
                for (int journeyIdx = lookBackIdx; journeyIdx < lookForwardIdx; journeyIdx++)
                {
                    TrainDetails journey = train.TrainJourney[journeyIdx];

                    if (journey.isTSRHere)
                    {
                        TSR.isTSRHere = true;
                        TSR.TSRSpeed  = journey.TSRspeed;
                    }
                }
            }
            return(TSR);
        }
Esempio n. 8
0
        /// <summary>
        /// Determine the average speed of all trains in a specified direction given a power to weight range.
        /// </summary>
        /// <param name="trains">All train data containig each train journey details.</param>
        /// <param name="simulation">The journey of the simulated train.</param>
        /// <param name="lowerBound">The lower bound of the acceptable power to weight ratio.</param>
        /// <param name="upperBound">The upper bound of the acceptable power to weight ratio.</param>
        /// <param name="direction">The direction of the km of the train journey.</param>
        /// <returns>A list for the average speed of trains within the power to weight range.</returns>
        public List <double> powerToWeightAverageSpeed(List <Train> trains, List <InterpolatedTrain> simulation, double lowerBound, double upperBound, direction direction)
        {
            int    size = (int)((Settings.endKm - Settings.startKm) / (Settings.interval / 1000));
            double sum  = 0;

            /* Place holders for the included speeds and teh resulting average speed at each location. */
            List <double> speed        = new List <double>();
            List <double> averageSpeed = new List <double>();

            TrainDetails journey = new TrainDetails();

            /* Loop through each interpoalted location. */
            for (int journeyIdx = 0; journeyIdx <= size; journeyIdx++)
            {
                sum = 0;
                speed.Clear();

                /* Loop through each train. */
                foreach (Train train in trains)
                {
                    journey = train.TrainJourney[journeyIdx];

                    if (journey.trainDirection == direction)
                    {
                        /* Is there a TSR that applies */
                        if (!temporarySpeedRestrictionParameters(train, journey.geometryKm).isTSRHere)
                        {
                            /* Check train is not within the loop boundaries */
                            if (!isTrainInLoopBoundary(train, journey.geometryKm))
                            {
                                if (journey.powerToWeight > lowerBound && journey.powerToWeight <= upperBound)
                                {
                                    speed.Add(journey.speed);
                                    sum = sum + journey.speed;
                                }
                            }
                            else
                            {
                                /* Train is within the loop boundaries */
                                if (journey.speed > (simulation[journeyIdx].speed * Settings.loopSpeedThreshold))
                                {
                                    speed.Add(journey.speed);
                                    sum = sum + journey.speed;
                                }
                            }
                        }
                        else
                        {
                            /* A TSR applies to the current position of the train. */
                        }
                    }
                }

                if (speed.Count == 0)
                {
                    averageSpeed.Add(0);       // This might have to be the simulated speed
                }
                else
                {
                    if (sum == 0)
                    {
                        averageSpeed.Add(0);
                    }
                    else
                    {
                        averageSpeed.Add(speed.Where(x => x > 0.0).Average(x => x));
                    }
                }
            }

            return(averageSpeed);
        }
Esempio n. 9
0
        public TrainDetails GetTrainDetails(int trainId)
        {
            TrainDetails details = mapper.Map <TrainDetails>(db.Trains.Find(trainId));

            return(details);
        }
Esempio n. 10
0
 public void UpdateTrainDetails(TrainDetails trainDetails)   //Method to update train details
 {
     trainDetailsRepository.UpdateTrainDetails(trainDetails);
 }
Esempio n. 11
0
 public bool AddTrainDetails(TrainDetails trainDetails)      //Method to Add train details
 {
     return(trainDetailsRepository.AddTrainDetails(trainDetails));
 }