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> }
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; }
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> }
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> }
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> }
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> }
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> }
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; }