Esempio n. 1
0
 public static Train FromBaseCSV(string row)
 {
     List<string> itemList = row.Split(new string[] { "\t" }, StringSplitOptions.None).ToList();
     Train obj = new Train();
     obj.Type = itemList[0];
     obj.Name = itemList[1];
     obj.TrainNo = itemList[2];
     obj.StartStation = AllStationList.Find(p => p.Name == itemList[3]);
     obj.EndStation = AllStationList.Find(p => p.Name == itemList[4]);
     return obj;
 }
Esempio n. 2
0
 public static Train FromRunDateCSV(string row)
 {
     List<string> itemList = row.Split(new string[] { "\t" }, StringSplitOptions.None).ToList();
     Train obj = new Train();
     obj.Type = itemList[0];
     obj.Name = itemList[1];
     obj.TrainNo = itemList[2];
     obj.StartStation = AllStationList.Find(p => p.Name == itemList[3]);
     obj.EndStation = AllStationList.Find(p => p.Name == itemList[4]);
     if (itemList[5] == "ALL")
     {
         obj.RunDateList = AllDateList;
     }
     else
     {
         obj.RunDateList = itemList[5].Split(new string[]{"|"}, StringSplitOptions.RemoveEmptyEntries).ToList();
     }
     return obj;
 }
Esempio n. 3
0
 static void Step4()
 {
     CreateDirectory(GetStepPath(STEP_4));
     List<Station> stationList = LoadBaseStation();
     //var train_list ={"2016-01-31":{"D":[{"station_train_code":"D1(北京-沈阳)","train_no":"24000000D10R"}]}}
     string text = ReadFile(GetStepFile(STEP_3, FILE_3)).Trim();
     text = text.Substring(text.IndexOf("=") + 1);
     JObject jsonObj = JObject.Parse(text);
     List<string> dateList = jsonObj.Properties().Select(p => p.Name).ToList();
     dateList.Sort();
     foreach (string date in dateList)
     {
         List<Train> trainList = new List<Train>();
         JObject dateObj = (JObject)jsonObj[date];
         List<string> typeList = dateObj.Properties().Select(p => p.Name).ToList();
         foreach (string type in typeList)
         {
             //type = "C,D,G,K,O,T,Z", we just get high speed trains. It means "C,D,G"
             if ("CDG".Contains(type))
             {
                 JArray dataArray = (JArray)dateObj[type];
                 foreach (JObject data in dataArray)
                 {
                     string trainCode = data["station_train_code"].ToString(); //D1(北京-沈阳)
                     string trainNO = data["train_no"].ToString();
                     List<string> itemList = trainCode.Split(new string[] { "(", "-", ")" }, StringSplitOptions.RemoveEmptyEntries).ToList();
                     Train train = new Train();
                     train.Type = type;
                     train.Name = itemList[0];
                     train.TrainNo = trainNO;
                     train.StartStation = stationList.Find(obj => obj.Name == itemList[1].Replace(" ", string.Empty));
                     train.EndStation = stationList.Find(obj => obj.Name == itemList[2].Replace(" ", string.Empty));
                     trainList.Add(train);
                 }
             }
         }
         trainList.Sort((obj1, obj2) =>
         {
             int c1 = obj1.Type.ToUpper().CompareTo(obj2.Type.ToUpper());
             int c2 = Convert.ToInt32(obj1.Name.Substring(1)).CompareTo(Convert.ToInt32(obj2.Name.Substring(1)));
             int c3 = obj1.TrainNo.ToUpper().CompareTo(obj2.TrainNo.ToUpper());
             return (c1 != 0) ? c1 : ((c2 != 0) ? c2 : c3);
         });
         if (trainList.Count > 0)
         {
             List<string> outputList = new List<string>();
             foreach (Train train in trainList)
             {
                 outputList.Add(train.ToBaseCSV());
             }
             WriteFile(GetStepFile(STEP_4, date + ".txt"), string.Join("\r\n", outputList.ToArray()));
             Console.WriteLine("Output " + date + ".txt");
         }
     }
 }