Ejemplo n.º 1
0
        public string GetFacts(Int16 carid, Int64 tripid)
        {
            try {
                DBController dbc = new DBController();
                List<Fact> facts = dbc.GetFactsByCarIdAndTripIdNoQuality(carid, tripid);
                dbc.Close();

                return JsonConvert.SerializeObject(facts);
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
                DBController dbc = new DBController();
                dbc.AddLog("GetFacts?carid={carid}&tripid={tripid}", carid, tripid, null, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), "");
                dbc.Close();
            }

            return "";
        }
Ejemplo n.º 2
0
        public static void UpdateRawGPS(Int16 CarId, Int64 TripId)
        {
            DBController dbc = new DBController();
            List<Fact> facts = dbc.GetFactsByCarIdAndTripIdNoQuality(CarId, TripId);
            dbc.Close();

            if (facts.Count() < 2) {
                return;
            }

            //First case - Set speed equal to second fact and set flags to false. This is essentially a freebie
            double speedFrom2ndFact = MeasureCalculator.Speed(facts[1].Spatial, facts[0].Spatial, facts[1].Temporal, facts[0].Temporal);
            facts[0].Measure = new MeasureInformation(speedFrom2ndFact, 0, 0);
            facts[0].Flag = new FlagInformation(false, false, false, false);

            for (int i = 1; i < facts.Count(); i++) {
                //Spatial
                facts[i].Spatial.DistanceToLag = MeasureCalculator.DistanceToLag(facts[i].Spatial.MPoint, facts[i - 1].Spatial.MPoint);

                //Temporal
                facts[i].Temporal.SecondsToLag = MeasureCalculator.SecondsToLag(facts[i].Temporal.Timestamp, facts[i - 1].Temporal.Timestamp);

                //MeasureInformation
                double speed = MeasureCalculator.Speed(facts[i].Spatial, facts[i - 1].Spatial, facts[i].Temporal, facts[i - 1].Temporal);
                facts[i].Measure = new MeasureInformation(speed, 0, 0);
                facts[i].Measure.Acceleration = MeasureCalculator.Acceleration(facts[i].Measure, facts[i - 1].Measure, facts[i].Temporal, facts[i - 1].Temporal);
                facts[i].Measure.Jerk = MeasureCalculator.Jerk(facts[i].Measure, facts[i - 1].Measure, facts[i].Temporal, facts[i - 1].Temporal);

                //FlagInformation
                Boolean speeding = false;
                if (facts[i].Segment != null && facts[i].Segment.MaxSpeed != -1) {
                    speeding = MeasureCalculator.Speeding(facts[i].Measure.Speed, facts[i].Segment.MaxSpeed);
                }

                Boolean accelerating = MeasureCalculator.Accelerating(facts[i].Measure);
                Boolean braking = MeasureCalculator.Braking(facts[i].Measure);
                Boolean jerking = MeasureCalculator.Jerking(facts[i].Measure);
                facts[i].Flag = new FlagInformation(speeding, accelerating, jerking, braking);
            }
            dbc = new DBController();
            try {
                dbc.UpdateGPSFactWithMeasures(facts);
            }
            catch(Exception e) {
                Console.WriteLine(e.ToString());
            }
            dbc.Close();
        }