示例#1
0
            internal void GBFinal(List<DataItem> ldi)
            {
                if (fComplete)
                    return;

                fComplete = true;

                DataItem di;
                if (attrs == null)
                {
                    di = new DataItem(1, ReleaseDataItem);
                    di.AddValue(gTotal.oResult);
                    ldi.Add(di);
                }
                else
                {
                    foreach (int o in ht.Keys)
                    {
                        List<Group> al = (List<Group>)ht[o];
                        for (int i = 0; i < al.Count; i++)
                        {
                            Group g = al[i];
                            BuildGroupResult(g, out di);
                            ldi.Add(di);
                        }
                    }
                    ht.Clear();
                }
            }
示例#2
0
 private void BuildGroupResult(Group g, out DataItem di)
 {
     di = GetDataItem(1)[0];
     foreach (object v in g.keys)
         di.AddValue(v);
     di.AddValue(g.oResult);
 }
示例#3
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>
 }
示例#4
0
 /// <summary>
 /// Generic Map function that outputs results based on given attribute list
 /// </summary>
 /// <returns>Projected data item</returns>
 /// <seealso cref="UnaryOp.Map"/>
 private DataItem mapGeneric(DataItem di)
 {
     DataItem diRet = new DataItem(attrs.Length, null);
     foreach (int i in attrs)
         diRet.AddValue(di[i]);
     return diRet;
 }
示例#5
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>
 }
示例#6
0
 public DataItem Type3MapConvert(DataItem di)
 {
     //<Time, VID, Xway, QID, Day, Bal>
     di.AddCapacity(1);
     di.AddValue(Convert.ToInt32(di[0]) + (int)(DateTime.Now.Subtract(di.TimeStamp).TotalSeconds));
     return di;
     //<Time, VID, Xway, QID, Day, Bal, Emit>
 }
示例#7
0
 public DataItem IsDupCheckVID(DataItem di)
 {
     //<Time, VID, Spd, Xway, Lane, Dir, Seg, Pos, WID(List)>
     di.AddCapacity(1);
     if (di is Punctuation)
     {
         Punctuation p = di as Punctuation;
         p.AddValue(new Punctuation.WildcardPattern());
         IsDupTable.Clear();
         return p;
     }
     else
     {
         int VID = (int)di[1];
         if (IsDupTable.Contains(VID))
         {
             di.AddValue((int)1);
         }
         else
         {
             di.AddValue((int)0);
             IsDupTable.Add(VID);
         }
         return di;
     }
     //<Time, VID, Spd, Xway, Lane, Dir, Seg, Pos, WID(List), ?isDup>
 }
示例#8
0
            public DataItem NSSCheckSeg(DataItem di)
            {
                //<Time, VID, Spd, Xway, Lane, Dir, Seg, Pos>
                int[] attrs = { 0, 1, 3, 4, 5, 6 };
                if (di is Punctuation)
                {
                    Punctuation pRet = new Punctuation(attrs.Length + 1);
                    foreach (int i in attrs)
                        pRet.AddValue(di[i]);

                    if (pRet[1] is Punctuation.LiteralPattern) //an end of vehicle punctuation
                    {
                        NSSTable.Remove(Convert.ToUInt32(((Punctuation.LiteralPattern)pRet[1]).Value));
                    }
                    pRet.AddValue(new Punctuation.WildcardPattern());
                    return pRet;
                }
                else
                {
                    DataItem diRet = new DataItem(attrs.Length + 1, null);
                    foreach (int i in attrs)
                        diRet.AddValue(di[i]);
                    diRet.EOF = di.EOF;
                    diRet.TimeStamp = di.TimeStamp;

                    uint VID = Convert.ToUInt32(diRet[1]);
                    uint Seg = Convert.ToUInt32(diRet[5]);
                    if (NSSTable.ContainsKey(VID))
                    {
                        uint OldSeg = NSSTable[VID];
                        if (OldSeg == Seg)
                            diRet.AddValue((int)0);
                        else
                        {
                            diRet.AddValue((int)1);
                            NSSTable[VID] = Seg;
                        }
                    }
                    else
                    {
                        NSSTable.Add(VID, Seg);
                        diRet.AddValue((uint)1);
                    }
                    return diRet;
                }
                //<Time, VID, Xway, Lane, Dir, Seg, ?isNSS>
            }
示例#9
0
 public DataItem FindToll(DataItem di, RelationTable rt)
 {
     //<Time, VID, Xway, Lane, Dir, Seg, ?isNSS>
     di.AddCapacity(2);
     if (di is Punctuation)
     {
         Punctuation p = di as Punctuation;
         p.AddValue(new Punctuation.WildcardPattern());
         p.AddValue(new Punctuation.WildcardPattern());
         return p;
     }
     else
     {
         uint seg = Convert.ToUInt32(di[5]);
         if (Convert.ToUInt32(di[4]) == 0) //find the seg before this one
             seg--;
         else
             seg++;
         object[] keys = { di[1], seg }; //VID
         lock (rt)
         {
             DataRow drow = rt.Find(keys);
             if (drow == null) //there's no toll, we can drop it
             {
                 di.AddValue((int)0);
                 di.AddValue((int)0);
             }
             else
             {
                 di.AddValue(drow["Toll"]);
                 di.AddValue(drow["LAV"]);
                 rt.Drop(drow);
                 //Console.WriteLine("We found a toll");
             }
         }
         return di;
     }
     //<Time, VID, Xway, Lane, Dir, Seg, ?isNSS, Toll, LAV>
 }
示例#10
0
 public DataItem ConvertTimeStamp(DataItem di)
 {
     //<Time, VID, Xway, Lane, Dir, Seg, ?isNSS, ...>
     if (!(di is Punctuation))
     {
         di.AddCapacity(1);
         di.AddValue(Convert.ToUInt32(di[0]) + ((DateTime.Now.Subtract(di.TimeStamp)).TotalSeconds));
         return di;
     }
     return di;
     //<Time, VID, Xway, Lane, Dir, Seg, ?isNSS, ...>
 }
示例#11
0
 public DataItem AttachStats(DataItem di, RelationTable rt)
 {
     //<Time, VID, Xway, Lane, Dir, Seg, InTime(DateTime), ?isNSS, isAIR>
     di.AddCapacity(2);
     if (!(di is Punctuation))
     {
         try
         {
             object[] keys = { di[5], di[2], di[4] }; //Seg, Xway, Dir
             lock (rt)
             {
                 DataRow drow = rt.Find(keys);
                 if (drow == null)
                 {
                     di.AddValue((uint)0);
                     di.AddValue((uint)0);
                 }
                 else
                 {
                     di.AddValue(drow["LAV"]);
                     di.AddValue(drow["Count"]);
                 }
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
         }
     }
     return di;
     //<Time, VID, Xway, Lane, Dir, Seg, InTime(DateTime), ?isNSS, ?isAIR, LAV, Count>
 }
示例#12
0
            public DataItem AccidentInRange(DataItem di, RelationTable rt)
            {
                //<Time, VID, Xway, Lane, Dir, Seg, ?isNSS>
                di.AddCapacity(1);
                if (di is Punctuation)
                {
                    Punctuation p = di as Punctuation;
                    p.AddValue(new Punctuation.WildcardPattern());
                    return p;
                }
                else
                {
                    int Xway = (int)di[2],
                        dir = (int)di[4],
                        seg = (int)di[5];
                    lock (rt)
                    {
                        DataRow[] drows = rt.Find("[Xway] = " + Xway + " AND [Dir] = " + dir);
                        if (drows.Length > 0)
                        {
                            int accseg = (int)drows[0]["Seg"],
                                lbound, hbound;
                            if (dir == 0)//segs are increasing
                            {
                                lbound = accseg - 4;
                                hbound = accseg;
                            }
                            else
                            {
                                lbound = accseg;
                                hbound = accseg + 4;
                            }

                            if (seg <= hbound && seg >= lbound) //between the bounds
                                di.AddValue(accseg);
                            else
                                di.AddValue((int)-1);
                        }
                        else
                            di.AddValue((int)-1);
                    }
                    return di;
                }
                //<Time, VID, Xway, Lane, Dir, Seg, ?isNSS, isAIR>
            }
示例#13
0
        protected void StrReader()
        {
            bool eof = false, tagMonitor;
            BinaryFormatter bf = new BinaryFormatter();
            DataItem di;
            DateTime sysTime = new DateTime(0); //The "System Time"
            int fiter = 0, type = 0;
            do
            {
                di = new DataItem(TYPE0, null); //TYPE0 has the most ints we'll need
                tagMonitor = false;
                try
                {
                    while (fiter < NUMBEROFINTS && !eof)
                    {
                        if (sysTime.Ticks == 0) //initialize the time
                            sysTime = DateTime.Now;
                        byte[] inbytes = new byte[4];
                        nsClient.Read(inbytes, 0, 4); //read in the bytes
                        int inint = BitConverter.ToInt32(inbytes, 0);
                        if (inint != -1)
                        {
                            if (fiter == 0)
                                type = inint;

                            if (fiter == INDEXOFTIME && inint > lastTime) //change in the time
                            {
                                InsertPuncts(sysTime.AddSeconds(lastTime));
                                lastTime = (uint)inint;
                            }

                            if (fiter == INDEXOFLANE && inint == 4) //there is a car in the exit lane
                                tagMonitor = true;

                            if (fiter == INDEXOFTIME)
                                di.AddValue((ulong)TimeSpan.FromTicks(sysTime.AddSeconds(lastTime).Ticks).TotalSeconds);
                            else
                                di.AddValue(Convert.ToUInt32(inint));
                        }
                        fiter++;
                    }
                }
                catch (System.IO.IOException ex)
                {
                    //Assume that the connection was closed (though I have no way of knowing...)
                    Console.WriteLine("Something bad happened when we tried to read from the stream: {0} ({1})",
                        ex.Message, ((ex.InnerException != null) ? ex.InnerException.Message : ""));
                    eof = true;
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine("Something bad happened when we tried to read from the stream: {0} ({1})",
                        ex.Message, ((ex.InnerException != null) ? ex.InnerException.Message : ""));
                    eof = true;
                }
                if (tagMonitor)
                {
                    if (type == 0)
                    {
                        uint VID = Convert.ToUInt32(di[INDEXOFVID]);
                        if (!vids.ContainsKey(VID))
                        {
                            vids.Add(VID, sysTime.AddSeconds(lastTime));
                        }
                        else
                        {
                            vids[VID] = sysTime.AddSeconds(lastTime);
                        }
                    }
                }
                switch (type) //send the data item
                {
                    case 0:
                        //st.Start();
                        lrcs[0].sendData(di);
                        //st.Stop();
                        break;
                    case 2:
                        lrcs[1].sendData(di);
                        break;
                    case 3:
                        lrcs[2].sendData(di);
                        break;
                    case 4:
                        //lrcs[3].sendData(di);
                        break;
                    default:
                        throw new System.Exception("The stream provided a type we don't know how to handle");
                }
                fiter = 0;
            } while (!eof);
            nsClient.Close();
        }