コード例 #1
0
        public static predictorData readXml()
        {
            predictorData dataList = new predictorData();
            XmlDocument   doc      = new XmlDocument();

            doc.Load("data.xml");

            XmlNode     restrictionListNode = doc.SelectSingleNode("/restriction");
            XmlNodeList detailNodeList      = restrictionListNode.SelectNodes("detail");

            foreach (XmlNode node in detailNodeList)
            {
                string day       = node.SelectSingleNode("day").InnerText;
                int    dayNumber = int.Parse(node.SelectSingleNode("dayNumber").InnerText);

                picoItem    pico             = new picoItem();
                XmlNode     picoListNode     = node.SelectSingleNode("pico");
                XmlNodeList scheduleNodeList = picoListNode.SelectNodes("schedule");
                foreach (XmlNode nodeSchedule in scheduleNodeList)
                {
                    string begin = nodeSchedule.SelectSingleNode("begin").InnerText;
                    string end   = nodeSchedule.SelectSingleNode("end").InnerText;
                    pico.addSchedule(new scheduleItem(begin, end));
                }

                placaItem   placa         = new placaItem();
                XmlNode     placaListNode = node.SelectSingleNode("placa");
                XmlNodeList typeNodeList  = placaListNode.SelectNodes("type");
                foreach (XmlNode nodeType in typeNodeList)
                {
                    string type = nodeType.InnerText;
                    placa.addType(type);
                }

                placaItem   exceptions         = new placaItem();
                XmlNode     exceptionsListNode = node.SelectSingleNode("exception");
                XmlNodeList exceptionsNodeList = exceptionsListNode.SelectNodes("type");
                foreach (XmlNode nodeType in exceptionsNodeList)
                {
                    string type = nodeType.InnerText;
                    exceptions.addType(type);
                }

                streetItem  streets         = new streetItem();
                XmlNode     streetListNode  = node.SelectSingleNode("street");
                XmlNodeList streetsNodeList = streetListNode.SelectNodes("streetName");
                foreach (XmlNode nodeStreet in streetsNodeList)
                {
                    string streetName = nodeStreet.InnerText;
                    streets.addStreet(streetName);
                }

                predictorItem item = new predictorItem(dayNumber, day, pico, placa, exceptions, streets);
                dataList.addPredictorItem(item);
            }
            return(dataList);
        }
コード例 #2
0
        /* Input example
         * plateNumber -- GHB-7891
         * date -- 08/31/2015
         * time -- 10:00
         * */
        public static List <string> predictProcedure(string plateNumber, string date, string time)
        {
            try
            {
                List <string>        result      = new List <string>();
                predictorData        dataList    = xmlParser.readXml();
                string               lastNumber  = plateNumber.Substring(plateNumber.Length - 1, 1);
                DateTime             predictDate = DateTime.Parse(date, new CultureInfo("en-US"));
                int                  dayNumber   = (int)predictDate.DayOfWeek;
                predictorTime        predictTime = new predictorTime(time);
                List <predictorItem> items       = dataList.getPredictorItem;
                for (int i = 0; i < items.Count; i++)
                {
                    predictorItem item = items[i];
                    if (item.getDayNumber == dayNumber)
                    {
                        if (item.getPlacas.getTypes.Contains(lastNumber))
                        {
                            if (item.getExceptions.getTypes.Contains(lastNumber) || item.getExceptions.getTypes.Contains(plateNumber))
                            {
                                return(result);
                            }
                            else
                            {
                                List <scheduleItem> listSchedules = item.getPicos.getSchedules;
                                for (int j = 0; j < listSchedules.Count; j++)
                                {
                                    predictorTime begin = listSchedules[j].getBegin;
                                    predictorTime end   = listSchedules[j].getEnd;

                                    if (predictTime.isAfter(begin) && predictTime.isBefore(end))
                                    {
                                        //List all street that the car can't circulate.
                                        return(item.getStreets.getStreets);
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
                return(result);
            }
            catch (Exception exc)
            {
                throw new Exception("Unexpected error , try again");
            }
        }
コード例 #3
0
 public void addPredictorItem(predictorItem item)
 {
     this.items.Add(item);
 }