Ejemplo n.º 1
0
        public string ExportServiceDirectionTable()
        {
            List <ServiceDirectionModel> serviceDirections =
                ServiceDirectionDataAccess.GetAllServiceDirectionsPerRoute(RouteId);

            return(WriteServiceDirectionHeader() + WriteServiceDirectionData(serviceDirections));
        }
        private void ImportServiceDirection(string[] fields)
        {
            var serviceDirection = new ServiceDirectionModel();

            serviceDirection.Id = int.Parse(fields[1]);
            serviceDirection.ServiceDirectionName         = fields[2];
            serviceDirection.ServiceDirectionAbbreviation = fields[3];
            serviceDirection.IsDescending = bool.Parse(fields[5]);
            serviceDirection.RouteId      = newRouteId;
            var newServiceDirectionId = ServiceDirectionDataAccess.InsertServiceDirection(serviceDirection);

            ServiceDirectionKeys.Add(serviceDirection.Id, newServiceDirectionId);
        }
Ejemplo n.º 3
0
        public static TimetableMatrixModel ReadTimetableMatrix(int timetableId, bool csvTarget)
        {
            // TODO wrap this all in a transaction, for better performance
            TimetableMatrixModel matrixModel = new TimetableMatrixModel();

            // Get TimetableMode to retrieve name

            var timetable = TimetableDataAccess.GetTimetableById(timetableId);

            matrixModel.TimetableName = timetable.TimetableName;
            matrixModel.TimetableId   = timetable.Id;
            matrixModel.RouteId       = timetable.RouteId;
            var direction = ServiceDirectionDataAccess.GetServiceDirectionById(timetable.ServiceDirectionId);

            matrixModel.IsDescending = direction.IsDescending;

            // Now get a view, representing Services

            List <ServiceModel> serviceList = ServicesDataAccess.GetServicesPerTimetable(timetable.Id);

            serviceList = serviceList.OrderBy(x => x.StartTime).ToList();

            var locationsList = LocationDataAccess.GetAllLocationsPerRoute(matrixModel.RouteId);

            if (matrixModel.IsDescending)
            {
                locationsList = locationsList.OrderByDescending(x => x.Order).ToList();
            }
            else
            {
                locationsList = locationsList.OrderBy(x => x.Order).ToList();
            }

            var locationsCount = locationsList.Count;

            matrixModel.Matrix = new string[locationsList.Count + 1][];
            var columncount = serviceList.Count + 1;

            string[] columnheaders = new string[columncount];
            columnheaders[0] = "---";
            for (int i = 0; i < columncount - 1; i++)
            {
                columnheaders[i + 1] = serviceList[i].ServiceAbbreviation;
            }
            matrixModel.Matrix[0] = columnheaders;
            for (int i = 0; i < locationsCount; i++)
            {
                string[] row = new string[columncount];
                row[0] = locationsList[i].LocationName;
                matrixModel.Matrix[i + 1] = row;
            }

            for (int index = 0; index < serviceList.Count; index++)
            {
                int actualTime = serviceList[index].StartTime;
                List <ServiceTimingModel> Timing;
                if (matrixModel.IsDescending)
                {
                    Timing = GetServiceTiming(serviceList[index].Id, locationsList).OrderByDescending(x => x.LocationsOrder).ToList();
                }
                else
                {
                    Timing = GetServiceTiming(serviceList[index].Id, locationsList);
                }
                int j = 0;
                for (int i = 0; i < locationsCount;)
                {
                    if (j < Timing.Count && locationsList[i].Order == Timing[j].LocationsOrder)
                    {
                        i++;
                        j++;
                    }
                    else
                    {
                        var Insert = new ServiceTimingModel();
                        Insert.LocationId     = locationsList[i].Id;
                        Insert.LocationName   = locationsList[i].LocationName;
                        Insert.LocationAbbrev = locationsList[i].LocationAbbreviation;
                        Insert.EventType      = "";
                        Insert.ArrivalTime    = 0;
                        Insert.WaitTime       = 0;
                        Insert.TimeString     = "--";
                        Insert.LocationsOrder = locationsList[i].Order;
                        Insert.TimeEventId    = -1;                      // TimeEvent is not valid!
                        Timing.Insert(j, Insert);
                        i++;
                        j++;
                    }
                }
                matrixModel.TimingList.Add(Timing);
            }

            for (int i = 0; i < columncount - 1; i++)             // for each service
            {
                int actualTime = serviceList[i].StartTime;
                var timing     = matrixModel.TimingList[i];
                for (int j = 0; j < locationsCount; j++)                 // for each location
                {
                    if (timing[j].TimeEventId > 0)
                    {
                        actualTime          += timing[j].ArrivalTime;
                        timing[j].TimeString = TimeConverters.TimeEventToString(actualTime, timing[j].WaitTime, csvTarget);
                        actualTime          += timing[j].WaitTime;
                    }
                    matrixModel.Matrix[j + 1][i + 1] = timing[j].TimeString;
                }
            }
            return(matrixModel);
        }
        public static List <DepartureArrivalTimetableModel> GetDeparturesAndArrivals(int timetableId,
                                                                                     int locationId)
        {
            List <DepartureArrivalTimetableModel> output = new List <DepartureArrivalTimetableModel>();
            var serviceList = ServicesDataAccess.GetServicesPerTimetable(timetableId);

            foreach (var service in serviceList)
            {
                var departureArrival = new DepartureArrivalTimetableModel();
                departureArrival.ServiceName   = service.ServiceName;
                departureArrival.ServiceAbbrev = service.ServiceAbbreviation;
                departureArrival.ServiceId     = service.Id;
                departureArrival.StartTime     = service.StartTime;
                departureArrival.EndTime       = service.EndTime;
                var found            = false;
                var serviceDirection = ServiceDirectionDataAccess.GetServiceDirectionByServiceTemplateId(service.ServiceTemplateId);
                var timeEventList    =
                    FullTimeEventDataAccess.GetAllFullTimeEventsPerServiceTemplate(service.ServiceTemplateId);

                if (serviceDirection.IsDescending)
                {
                    timeEventList = timeEventList.OrderByDescending(x => x.LocationOrder).ToList();
                }
                else
                {
                    timeEventList = timeEventList.OrderBy(x => x.LocationOrder).ToList();
                }

                int arrivalTime   = departureArrival.StartTime;
                int departureTime = departureArrival.StartTime;
                foreach (var timeEvent in timeEventList)
                {
                    departureArrival.ArrivalTime   += timeEvent.ArrivalTime;
                    departureArrival.DepartureTime += timeEvent.ArrivalTime + timeEvent.WaitTime;
                    if (timeEvent.LocationId == locationId)
                    {
                        found = true;                         // need to filter, if the location is not included in the service, do not show it.
                        departureArrival.LocationName   = timeEvent.LocationName;
                        departureArrival.LocationAbbrev = timeEvent.LocationAbbreviation;
                        departureArrival.EventType      = timeEvent.EventType;
                        departureArrival.ArrivalTime    = arrivalTime;
                        departureArrival.DepartureTime  = departureTime;
                    }

                    if (timeEvent.EventType == "S")
                    {
                        departureArrival.OriginName   = timeEvent.LocationName;
                        departureArrival.OriginAbbrev = timeEvent.LocationAbbreviation;
                    }

                    if (timeEvent.EventType == "E")
                    {
                        departureArrival.DestinationName   = timeEvent.LocationName;
                        departureArrival.DestinationAbbrev = timeEvent.LocationAbbreviation;
                    }
                }

                if (found)
                {
                    output.Add(departureArrival);
                }
            }
            return(output);
        }