Ejemplo n.º 1
0
        private void UpdateTimeStatistics(DateTime bTime, DateTime aTime, BusLineStatistics st)
        {
            int board  = bTime.Hour;
            int alight = aTime.Hour;

            for (int i = board; i <= alight; i++)
            {
                st.TimeStatistics[i]++;
            }
        }
Ejemplo n.º 2
0
        public void Analyse()
        {
            DataTable table = records.Tables["TripRecord"];

            foreach (DataRow row in table.Rows)
            {
                int      userID  = (int)row["CellPhoneAddr"];
                string   busLine = (string)row["BusLine"];
                DateTime BTime   = (DateTime)row["BoardTime"];
                DateTime ATime   = (DateTime)row["AlightTime"];

                Dictionary <string, BusLineStatistics> userSt;
                if (results.TryGetValue(userID, out userSt))
                {
                    BusLineStatistics busSt;
                    if (userSt.TryGetValue(busLine, out busSt))
                    {
                        busSt.Count++;
                        if (busSt.EarlestBoardTime.CompareTo(BTime) > 0)
                        {
                            busSt.EarlestBoardTime = BTime;
                        }
                        if (busSt.LatestAlightTime.CompareTo(ATime) < 0)
                        {
                            busSt.LatestAlightTime = ATime;
                        }
                        UpdateTimeStatistics(BTime, ATime, busSt);
                    }
                    else
                    {
                        busSt = new BusLineStatistics()
                        {
                            Count = 1, EarlestBoardTime = BTime, LatestAlightTime = ATime
                        };
                        UpdateTimeStatistics(BTime, ATime, busSt);
                        userSt.Add(busLine, busSt);
                    }
                }
                else
                {
                    userSt = new Dictionary <string, BusLineStatistics>();
                    BusLineStatistics busSt = new BusLineStatistics()
                    {
                        Count = 1, EarlestBoardTime = BTime, LatestAlightTime = ATime
                    };
                    UpdateTimeStatistics(BTime, ATime, busSt);
                    userSt.Add(busLine, busSt);
                    results.Add(userID, userSt);
                }
            }
        }