public static void GenerateListOfRoutesForSimulator(DublinBus jsonDublinDataset)
        {
            var listOfRoutes = FilterByDublinRoutes(jsonDublinDataset).OrderBy(x => PadNumbers(x)).ToList();

            using (StreamWriter fileWriter = new StreamWriter(@"ListOfRoutesSimulator.txt"))
            {
                foreach (var route in listOfRoutes)
                {
                    var filteredbylistOfRoutes = jsonDublinDataset.results
                                                 .Where(x => x.operators.First().routes.Contains(route) && x.operators.First().name == "bac")
                                                 .Select(obj =>
                                                         new { obj.latitude, obj.longitude, obj.stopid, obj.operators.First().routes }).ToArray();

                    filteredbylistOfRoutes.ToList()
                    .ForEach(s =>
                             FileWriter.RouteRecordInfoSimulatorFormat(fileWriter, s.stopid, s.latitude, s.longitude));

                    var total     = filteredbylistOfRoutes.ToList().Count;
                    var duplicate = filteredbylistOfRoutes.ToList().GroupBy(x => x.stopid)
                                    .Where(g => g.Count() > 1)
                                    .Select(y => y.Key).Count();

                    FileWriter.RouteInfo(fileWriter, route, total, duplicate);
                }
                FileWriter.RoutesCompleteReport(fileWriter, listOfRoutes.Count);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            using (StreamReader file = new StreamReader(AppDomain.CurrentDomain.BaseDirectory.Replace(@"\bin\Debug\", @"\Dataset\jsonDublinDataset.json")))
            {
                string    json = file.ReadToEnd();
                DublinBus jsonDublinDataset = JsonConvert.DeserializeObject <DublinBus>(json);

                DataProcessor.GenerateListOfStops(jsonDublinDataset);
                DataProcessor.GenerateListOfRoutes(jsonDublinDataset);
                DataProcessor.GenerateListOfRoutesForSimulator(jsonDublinDataset);
            }
        }
        public static void GenerateListOfStops(DublinBus jsonDublinDataset)
        {
            var filteredbylistOfStops = jsonDublinDataset.results
                                        .Where(x => x.operators.First().name == "bac")
                                        .Select(obj =>
                                                new { obj.latitude, obj.longitude, obj.stopid });

            using (StreamWriter fileWriter = new StreamWriter(@"ListOfStops.txt"))
            {
                filteredbylistOfStops.ToList()
                .ForEach(s =>
                         FileWriter.StopsRecord(fileWriter, s.stopid, s.latitude, s.longitude));

                FileWriter.StopsCompleteReport(fileWriter, filteredbylistOfStops.Count());
            }
        }
        private static List <string> FilterByDublinRoutes(DublinBus jsonDublinDataset)
        {
            var distinctRoutes = new List <string>();

            foreach (var result in jsonDublinDataset.results)
            {
                foreach (var op in result.operators)
                {
                    if (op.name == "bac")
                    {
                        foreach (var route in op.routes)
                        {
                            distinctRoutes.Add(route);
                        }
                    }
                }
            }
            distinctRoutes = distinctRoutes.Distinct().ToList();

            var removedNARoutes = RemoveNotApplicableRoutes;

            return(distinctRoutes.Where(x => !removedNARoutes.ToList().Contains(x.ToUpper())).ToList());
        }