Exemplo n.º 1
0
 public DataItem Type3Relation(DataItem di, RelationTable rt)
 {
     //<Time, VID, Xway, QID, Day, InTime(DateTime)>
     di.AddCapacity(1);
     object[] keys = { di[1] };
     lock (rt)
     {
         DataRow drow = rt.Find(keys);
         if (drow == null)
         {
             drow = rt.GetRow();
             drow["VID"] = Convert.ToInt32(di[1]);
             drow["Bal"] = 0;
             drow["Time"] = DateTime.Now.Subtract(di.TimeStamp).TotalSeconds;
             rt.Add(drow);
             //Console.WriteLine("We had to make a new balance for a type 3 query");
         }
         di.AddValue(drow["Bal"]);
     }
     return di;
     //<Time, VID, Xway, QID, Day, Bal>
 }
Exemplo n.º 2
0
            private void initTables()
            {
                NSSTable = new Dictionary<uint, uint>();
                IsDupTable = new List<int>((int)MAXVID);

                string[] accNames = {"VID", "Bal", "Time"};
                Type[] accTypes = { typeof(Int32), typeof(Int32), typeof(Int32) };
                int[] accIndexes = { 0 };
                accountBalances = new RelationTable(accNames, accTypes, accIndexes);

                DataRow drow;
                for (uint i = 0; i < MAXVID; i++)
                {
                    drow = accountBalances.GetRow();
                    drow["VID"] = i;
                    drow["Bal"] = 0;
                    drow["Time"] = 0;
                    accountBalances.Add(drow);
                }

                string[] acdntNames = { "Xway", "Dir", "Seg" };
                Type[] acdntTypes = { typeof(Int32), typeof(Int32), typeof(Int32) };
                int[] acdntIndexes = { 0, 1, 2};
                accidents = new RelationTable(acdntNames, acdntTypes, acdntIndexes);

                string[] tqNames = { "VID", "Seg", "LAV", "Toll" };
                Type[] tqTypes = { typeof(Int32), typeof(Int32), typeof(Int32), typeof(Int32) };
                int[] tqIndexes = { 0, 1 };
                tollQuotes = new RelationTable(tqNames, tqTypes, tqIndexes);

                string[] ssNames = { "Seg", "Xway", "Dir", "LAV", "Count", "LAVWID", "CountWID" };
                Type[] ssTypes = { typeof(Int32), typeof(Int32), typeof(Int32), typeof(Int32), typeof(Int32), typeof(UInt64), typeof(UInt64) };
                int[] ssIndexes = { 0, 1, 2 };
                segStats = new RelationTable(ssNames, ssTypes, ssIndexes);
            }
Exemplo n.º 3
0
 public DataItem Type2Relation(DataItem di, RelationTable rt)
 {
     //<Time, VID, QID>
     if (!(di is Punctuation))
     {
         object[] keys = { di[1] }; //VID
         int bal, time;
         di.AddCapacity(2);
         lock (rt)
         {
             DataRow drow = rt.Find(keys);
             if (drow == null)
             {
                 drow = rt.GetRow();
                 drow["VID"] = Convert.ToInt32(di[1]);
                 drow["Bal"] = 0;
                 drow["Time"] = DateTime.Now.Subtract(di.TimeStamp).TotalSeconds;
                 rt.Add(drow);
                 //Console.WriteLine("We had to make a new balance for a type 2 query");
             }
             bal = drow["Bal"];
             time = drow["Time"];
         }
         di.AddValue(bal);
         di.AddValue(time);
         return di;
     }
     else
         return di;
     //<Time, VID, QID, Bal, UTime>
 }
Exemplo n.º 4
0
 public DataItem SStatsLAVInsertion(DataItem di, RelationTable rt)
 {
     if (!(di is Punctuation))
     {
         object[] keys = { di[2], di[0], di[1] }; //Seg, Xway, Dir
         lock (rt)
         {
             DataRow drow = rt.Find(keys);
             if (drow != null)
             {
                 drow["LAV"] = di[4];
                 drow["LAVWID"] = di[3];
             }
             else
             {
                 drow = rt.GetRow();
                 drow["Seg"] = di[2];
                 drow["Xway"] = di[0];
                 drow["Dir"] = di[1];
                 drow["LAV"] = di[4];
                 drow["LAVWID"] = di[3];
                 drow["Count"] = -1; //we have no idea what it might be
                 drow["CountWID"] = di[3];
                 rt.Add(drow);
             }
         }
     }
     else //we need to check every segment
     {
         Punctuation p = di as Punctuation;
         ulong WID = (ulong)((Punctuation.LiteralPattern)p[3]).Value;
         for (int s = 0; s < SEGMENTS; s++)
         {
             for (int x = 0; x < EXPRESSWAYS; x++)
             {
                 for (int d = 0; d < DIRECTIONS; d++)
                 {
                     object[] keys = { s, x, d };
                     lock (rt)
                     {
                         DataRow drow = rt.Find(keys);
                         if (drow != null)
                         {
                             if ((ulong)drow["LAVWID"] < WID)
                             {
                                 drow["LAV"] = -1;
                                 drow["LAVWID"] = WID;
                             }
                         }
                         else
                         {
                             drow = rt.GetRow();
                             drow["Seg"] = s;
                             drow["Xway"] = x;
                             drow["Dir"] = d;
                             drow["LAV"] = -1;
                             drow["LAVWID"] = 0;
                             drow["Count"] = -1;
                             drow["CountWID"] = 0;
                             rt.Add(drow);
                         }
                     }
                 }
             }
         }
     }
     return di;
 }
Exemplo n.º 5
0
            public DataItem QuoteTolls(DataItem di, RelationTable rt)
            {
                //<Time, VID, Xway, Lane, Dir, Seg, ?isNSS, ?isAIR, LAV, Count>
                if (!(di is Punctuation))
                {
                    uint toll,
                        LAV = Convert.ToUInt32(di[8]),
                        Count = Convert.ToUInt32(di[9]);
                    int isAccident = Convert.ToInt32(di[7]);

                    if (isAccident != -1 || Count <= 50 || LAV >= 40)
                        toll = 0;
                    else
                    {
                        toll = 2 * (uint)Math.Pow((Count - 50), 2.0);
                        //Console.WriteLine("Toll Quote: {0}, Count: {1}, LAV: {2}", toll, Count, LAV);
                        lock (rt)
                        {
                            DataRow drow = rt.GetRow();
                            drow["VID"] = di[1];
                            drow["Seg"] = di[5];
                            drow["LAV"] = LAV;
                            drow["Toll"] = toll;
                            rt.Add(drow);
                        }
                    }
                }
                //<Time, VID, Xway, Lane, Dir, Seg, ?isNSS, ?isAIR, LAV, Count>
                return di;
            }
Exemplo n.º 6
0
 public DataItem ChargeToll(DataItem di, RelationTable rt)
 {
     //<Time, VID, Xway, Lane, Dir, Seg, ?isNSS, Toll, LAV>
     if (!(di is Punctuation))
     {
         object[] keys = { di[1] }; //VID
         lock (rt)
         {
             DataRow drow = rt.Find(keys);
             if (drow == null)
             {
                 drow = rt.GetRow();
                 drow["Vid"] = di[1];
                 drow["Bal"] = di[7];
                 drow["Time"] = di[0];
                 rt.Add(drow);
             }
             else
             {
                 drow["Bal"] = Convert.ToUInt32(di[7]) + (uint)drow["Bal"];
                 drow["Time"] = di[0];
             }
         }
     }
     return di;
     //<Time, VID, Xway, Lane, Dir, Seg, ?isNSS, Toll, LAV>
 }
Exemplo n.º 7
0
            public DataItem AccidentDetection(DataItem di, RelationTable rt)
            {
                if (!(di is Punctuation))
                {
                    uint count = Convert.ToUInt32(di[6]);

                    if (count == 4)
                    {
                        object[] keys = { di[1], di[2], di[3] }; //Xway, Dir, Seg
                        lock (rt)
                        {
                            DataRow drow = rt.Find(keys);
                            if (drow == null)
                            {
                                drow = rt.GetRow();
                                drow["Xway"] = di[1];
                                drow["Dir"] = di[2];
                                drow["Seg"] = di[3];
                                rt.Add(drow);
                            }
                            //Console.WriteLine("Accidents: {0} - From Insertion", rt.Rows);
                        }
                    }
                    else //4 > count > 1
                    {
                        object[] keys = { di[1], di[2], di[3] }; //Xway, Dir, Seg
                        lock (rt)
                        {
                            DataRow drow = rt.Find(keys); //assumes that there will only be one accident per Xway/dir
                            if (drow != null)
                                rt.Drop(drow);
                            //Console.WriteLine("Accidents: {0} - From Deletion", rt.Rows);
                        }
                    }
                }
                return di;
            }