Ejemplo n.º 1
0
 public Fact(Int64 EntryId, SegmentInformation Segment, TemporalInformation Temporal, MeasureInformation Measure)
 {
     this._EntryId = EntryId;
     this._Segment = Segment;
     this.Temporal = Temporal;
     this.Measure = Measure;
 }
Ejemplo n.º 2
0
 public Fact(QualityInformation Quality, SegmentInformation Segment, TemporalInformation Temporal, SpatialInformation Spatial, MeasureInformation Measure)
 {
     this._Quality = Quality;
     this._Segment = Segment;
     this.Temporal = Temporal;
     this.Spatial = Spatial;
     this.Measure = Measure;
 }
Ejemplo n.º 3
0
 public Fact(Int64 EntryId, int CarId, Int64 TripId, QualityInformation Quality, SegmentInformation Segment, TemporalInformation Temporal, SpatialInformation Spatial, MeasureInformation Measure, FlagInformation Flag)
 {
     this._EntryId = EntryId;
     this.CarId = CarId;
     this._TripId = TripId;
     this._Quality = Quality;
     this._Segment = Segment;
     this.Temporal = Temporal;
     this.Spatial = Spatial;
     this.Measure = Measure;
     this.Flag = Flag;
 }
Ejemplo n.º 4
0
        public int AddSegment(SegmentInformation segment, int speedlimitForward, int speedlimitBackward, string lineString)
        {
            string sql = @"INSERT INTO segmentinformation(segmentid, osmid, roadname, roadtype, oneway, speedbackward, speedforward, segmentline)
                           VALUES (@segmentid, @osmid, @roadname, @roadtype, @oneway, @speedbackward, @speedforward, ST_GeomFromText(@lineString, 4326))";

            NpgsqlCommand command = new NpgsqlCommand(sql, Connection);
            command.Parameters.AddWithValue("@segmentid", segment.SegmentId);
            command.Parameters.AddWithValue("@osmid", segment.OSMId);
            command.Parameters.AddWithValue("@roadname", segment.RoadName);
            command.Parameters.AddWithValue("@roadtype", segment.RoadType);
            command.Parameters.AddWithValue("@oneway", segment.Oneway);
            command.Parameters.AddWithValue("@speedforward", (Int16)speedlimitForward);
            command.Parameters.AddWithValue("@speedbackward", (Int16)speedlimitBackward);
            command.Parameters.AddWithValue("@lineString", lineString);

            //lineString will be added this way
            //http://www.bostongis.com/postgis_geomfromtext.snippet
            //referring to this link.

            try {
                return NonQuery(command, "segmentinformation");
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
            }

            return 0;
        }
Ejemplo n.º 5
0
        public static void LoadMap()
        {
            //Open file from path
            StreamReader file = new StreamReader(Global.Batch.INFATI.Path + "\\map.csv");

            //Discard data header
            file.ReadLine();

            //Read remaining file, split every row into its columns
            string entry;
            List<List<string>> rows = new List<List<string>>();

            while ((entry = file.ReadLine()) != null) {
                List<string> elements = entry.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();

                //Add to list of entries
                rows.Add(elements);
            }

            file.Close();

            //Assemble the entries into SegmentInformation
            List<Fact> facts = new List<Fact>();
            DBController dbc = new DBController();

            foreach (List<string> row in rows) {
                //(Int64 SegmentId, Int64 OSMId, string RoadName, Int16 RoadType, Int16 Oneway, Int16 Bridge, Int16 Tunnel, Int16 MaxSpeed, bool Direction, PostgisLineString RoadLine)
                //segmentkey0;segmentid1;name2;category3;startpoint4;endpoint5;direction6;speedlimit_forward7;speedlimit_backward8;meters9;geom10
                if (row.Count != 11) {
                    Int64 segmentIdC12 = Int64.Parse(row[0]);
                    Int64 osmIdC12 = Int64.Parse(row[1]);
                    string RoadNameC12 = row[2] + ";" + row[3];

                    Int16 RoadTypeC12 = (Int16)(Global.Enums.RoadType)Enum.Parse(typeof(Global.Enums.RoadType), row[4]);
                    Int16 OneWayC12 = (Int16)(Global.Enums.Direction)Enum.Parse(typeof(Global.Enums.Direction), row[7]);

                    SegmentInformation segmentC12 = new SegmentInformation(segmentIdC12, osmIdC12, RoadNameC12, RoadTypeC12, OneWayC12, 0, 0, 0, false, null);

                    Int16 speedlimitForwardC12 = Int16.Parse(row[8]);
                    Int16 speedlimitBackwardC12 = Int16.Parse(row[9]);
                    string lineStringC12 = row[11];

                    dbc.AddSegment(segmentC12, speedlimitForwardC12, speedlimitBackwardC12, lineStringC12);
                    //REFACTOR POTENTIAL BECAUSE approx 165 cases has length 12... the code is just copy-pasted in again and adjusted the index-keys
                    continue;
                }

                Int64 segmentId = Int64.Parse(row[0]);
                Int64 osmId = Int64.Parse(row[1]);
                string RoadName = row[2];

                Int16 RoadType = (Int16)(Global.Enums.RoadType)Enum.Parse(typeof(Global.Enums.RoadType), row[3]);
                Int16 OneWay = (Int16)(Global.Enums.Direction)Enum.Parse(typeof(Global.Enums.Direction), row[6]);

                SegmentInformation segment = new SegmentInformation(segmentId, osmId, RoadName, RoadType, OneWay, 0, 0, 0, false, null);

                Int16 speedlimitForward = Int16.Parse(row[7]);
                Int16 speedlimitBackward = Int16.Parse(row[8]);
                string lineString = row[10];

                dbc.AddSegment(segment, speedlimitForward, speedlimitBackward, lineString);
            }

            dbc.Close();
        }
Ejemplo n.º 6
0
        public Fact(DataRow row)
        {
            if (row.Table.Columns.Contains("entryid")) {
                this._EntryId = row.Field<Int64>("entryid");
            }
            if (row.Table.Columns.Contains("carid")) {
                this.CarId = row.Field<int>("carid");
            }
            if (row.Table.Columns.Contains("tripid")) {
                this._TripId = row.Field<Int64>("tripid");
            }
            /*
            if (row.Table.Columns.Contains("localtripid")) {
                this._LocalTripId = row.Field<Int64>("localtripid");
            }
            */
            //Spatial Information
            if (row.Table.Columns.Contains("distancetolag") && row.Table.Columns.Contains("pathline")) {
                row["distancetolag"] = row["distancetolag"] is DBNull ? -1.0 : row["distancetolag"];
                row["pathline"] = row["pathline"] is DBNull ? null : row["pathline"];

                this.Spatial = new SpatialInformation(new GeoCoordinate(row.Field<double>("latitude"), row.Field<double>("longitude")), (double)row.Field<Single>("distancetolag"), row.Field<PostgisLineString>("pathline"));

            } else if (row.Table.Columns.Contains("pointlatitude")) {
                this.Spatial = new SpatialInformation(new GeoCoordinate(row.Field<double>("pointlatitude"), row.Field<double>("pointlongitude")), this._TripId);

            } else {
                this.Spatial = new SpatialInformation(new GeoCoordinate(row.Field<double>("latitude"), row.Field<double>("longitude")));
            }

            //Temporal Information
            if (row.Table.Columns.Contains("secondstolag")) {
                row["secondstolag"] = row["secondstolag"] is DBNull ? 0 : row["secondstolag"];
                this.Temporal = new TemporalInformation(DateTimeHelper.ConvertToDateTime(row.Field<int>("dateid"), row.Field<int>("timeid")), new TimeSpan(0, 0, row.Field<Int16>("secondstolag")));
            } else {
                this.Temporal = new TemporalInformation(DateTimeHelper.ConvertToDateTime(row.Field<int>("dateid"), row.Field<int>("timeid")));
            }

            //Measure Information
            if (row.Table.Columns.Contains("speed") && row.Table.Columns.Contains("acceleration") && row.Table.Columns.Contains("jerk")) {
                row["speed"] = row["speed"] is DBNull ? 0 : row["speed"];
                row["acceleration"] = row["acceleration"] is DBNull ? 0 : row["acceleration"];
                row["jerk"] = row["jerk"] is DBNull ? 0 : row["jerk"];
                this.Measure = new MeasureInformation((double)row.Field<Single>("speed"), (double)row.Field<Single>("acceleration"), (double)row.Field<Single>("jerk"));
            }

            //Flag Information
            if (row.Table.Columns.Contains("speeding")) {
                row["speeding"] = row["speeding"] is DBNull ? false : row["speeding"];
                row["accelerating"] = row["accelerating"] is DBNull ? false : row["accelerating"];
                row["jerking"] = row["jerking"] is DBNull ? false : row["jerking"];
                row["braking"] = row["braking"] is DBNull ? false : row["braking"];
                row["steadyspeed"] = row["steadyspeed"] is DBNull ? false : row["steadyspeed"];
                this.Flag = new FlagInformation(row.Field<bool>("speeding"), row.Field<bool>("accelerating"), row.Field<bool>("jerking"), row.Field<bool>("braking"), row.Field<bool>("steadyspeed"));
            }

            //Segment Information
            if (row.Table.Columns.Contains("segmentid") && row.Table.Columns.Contains("maxspeed")) {
                row["segmentid"] = row["segmentid"] is DBNull ? -1 : row["segmentid"];
                row["maxspeed"] = row["maxspeed"] is DBNull ? -1 : row["maxspeed"];
                this._Segment = new SegmentInformation(row.Field<int>("segmentid"), row.Field<Int16>("maxspeed"));
            }

            //Quality Information
            if (row.Table.Columns.Contains("qualityid") && row.Table.Columns.Contains("satellites") && row.Table.Columns.Contains("hdop")) {
                row["qualityid"] = row["qualityid"] is DBNull ? -1 : row["qualityid"];
                row["satellites"] = row["satellites"] is DBNull ? -1 : row["satellites"];
                row["hdop"] = row["hdop"] is DBNull ? -1 : row["hdop"];
                this._Quality = new QualityInformation(row.Field<Int16>("qualityid"), row.Field<Int16>("satellites"), (double)row.Field<Single>("hdop"));
            } else if (row.Table.Columns.Contains("qualityid")) {
                this._Quality = new QualityInformation(-1, -1, -1);
            }
        }
 public static SegmentInformation CreateWithMaxSpeed(Int16 MaxSpeed)
 {
     SegmentInformation segment = new SegmentInformation();
     segment.MaxSpeed = MaxSpeed;
     return segment;
 }
 public static SegmentInformation CreateWithId(Int64 SegmentId)
 {
     SegmentInformation segment = new SegmentInformation();
     segment.SegmentId = SegmentId;
     return segment;
 }