Exemplo n.º 1
0
        void UpdateItemRun(DataItemRun item = null)
        {
            if (item != null)
            {
                itemRun = item;
            }

            lblRunInfo.Text = GetRunInfo();

            if (btnSpeed.Image.File.Contains("active"))
            {
                CreateResultTime(SubMode.TimeSpeed, Localization.unitSecond, Localization.pageResultSpeed, Settings.GetSpeedUnit());

                if (mode.Equals(RunModeAcceleration.Mode))
                {
                    AddResultDistance(SubMode.TimeDistance, Localization.unitSecond, Localization.pageResultDistance, Settings.GetDistanceUnit());
                }
            }
            else if (btnDistance.Image.File.Contains("active"))
            {
                CreateResultTime(SubMode.Distance, Settings.GetDistanceUnit(), Localization.pageResultSpeed, Settings.GetSpeedUnit());
            }
            else
            {
                CreateResultTime(SubMode.Height, Settings.GetDistanceUnit(), Localization.pageResultSpeed, Settings.GetSpeedUnit());
            }

            ShowButtonPrevious();
            ShowButtonNext();
            ShowButtonShare();
            ShowButtonDelete();
            ShowButtonRun();
        }
Exemplo n.º 2
0
        public void Load(DataItemRun r)
        {
            mode = r.Mode;
            string data = r.Data;

            string[] eventObject = data.Split(SEPARATOR_OBJECT);

            runAdjust.PeakAcceleration = r.PeakAcceleration; // use peakA to choose proper calibration curve

            foreach (string eo in eventObject)
            {
                string[] eventMemeber = eo.Split(SEPERATOR_MEMBER);
                if (eventMemeber.Length == 5)
                {
                    Event e = new Event
                              (
                        float.Parse(eventMemeber[0]),
                        float.Parse(eventMemeber[1]),
                        float.Parse(eventMemeber[2]),
                        float.Parse(eventMemeber[3]),
                        float.Parse(eventMemeber[4])
                              );

                    events.Add(e);
                }
            }
        }
Exemplo n.º 3
0
 public void Reset()
 {
     startTime = 0;
     events.Clear();
     runDistance.Reset();
     itemRun = null;
     accelerationRecorder.Reset();
 }
Exemplo n.º 4
0
        void OnButtonNext(object sender, EventArgs args)
        {
            DataItemRun item = database.GetRunNext(mode, itemRun.Id);

            if (IsItemRunEmpty(item) == false)
            {
                UpdateItemRun(item);
                Analytics.TrackEventResult(Analytics.EVENT_RESULT_NEXT);
            }
        }
Exemplo n.º 5
0
        public int DeleteRun(DataItemRun item)
        {
            int result = 0;

            lock (locker)
            {
                result = database.Delete(item);
                Debug.LogToFileEventText("run deleted from database // id: " + item.Id + " // date: " + item.Date);
            }

            return(result);
        }
Exemplo n.º 6
0
        public int SaveRun(DataItemRun item)
        {
            int result = 0;

            lock (locker)
            {
                result = database.Insert(item);
                Debug.LogToFileEventText("run inserted to database // id: " + item.Id + " // date: " + item.Date);
            }

            return(result);
        }
Exemplo n.º 7
0
        public static DataItemRun CreateDefaultRun()
        {
            DataItemRun d = new DataItemRun
            {
                VehicleId        = -1,
                Mode             = String.Empty,
                Date             = DateTime.Now,
                PeakAcceleration = 0,
                Data             = String.Empty
            };

            return(d);
        }
Exemplo n.º 8
0
        bool IsItemRunEmpty(DataItemRun item = null)
        {
            bool result = false;

            if (item == null)
            {
                item = itemRun;
            }

            if ((item.Id <= 0) || (item.VehicleId <= 0))
            {
                result = true;
            }

            return(result);
        }
Exemplo n.º 9
0
        public PageResults(string mode)
        {
            InitializeComponent();
            Debug.LogToFileMethod();

            NavigationPage.SetHasBackButton(this, false);
            NavigationPage.SetHasNavigationBar(this, false);

            this.mode = mode;
            database  = Database.GetInstance();
            itemRun   = database.GetRunLast(mode);

            CreateListView();
            InitLayout();

            UpdateItemRun();
        }
Exemplo n.º 10
0
        public DataItemRun GetRunLast()
        {
            DataItemRun result = DataItem.CreateDefaultRun();

            lock (locker)
            {
                if (IsRunEmpty() == false)
                {
                    List <DataItemRun> runs = database.Query <DataItemRun>("SELECT * FROM [DataItemRun] ORDER BY [Id] DESC LIMIT 1;");
                    if (runs != null)
                    {
                        result = runs[0];
                    }
                }
            }

            return(result);
        }
Exemplo n.º 11
0
        public void Store()
        {
            // refuse to store empty run
            if (events.Count == 0)
            {
                return;
            }

            Database        db          = Database.GetInstance();
            DataItemVehicle itemVehicle = db.GetActiveProfile();

            if (itemRun == null)
            {
                Debug.LogToFileEventText("run insert, event count: " + events.Count);

                // this run was never stored to the database
                itemRun           = new DataItemRun();
                itemRun.VehicleId = itemVehicle.Id;
                itemRun.Date      = DateTime.Now;
                itemRun.Mode      = mode;
                itemRun.Data      = GetEventsString();

                // attach peakA to the run
                accelerationRecorder.StorePeakAcceleration(itemVehicle, itemRun);

                // insert new run
                db.SaveRun(itemRun);
            }
            else
            {
                Debug.LogToFileEventText("run update, event count: " + events.Count);

                // update run with current events
                itemRun.Data = GetEventsString();

                // attach peakA to the run
                accelerationRecorder.StorePeakAcceleration(itemVehicle, itemRun);

                // update run
                db.UpdateRun(itemRun);
            }
        }
Exemplo n.º 12
0
        void OnButtonDelete(object sender, EventArgs args)
        {
            if (IsItemRunEmpty(itemRun) == false)
            {
                database.DeleteRun(itemRun);

                DataItemRun item = database.GetRunPrevious(mode, itemRun.Id);
                if (IsItemRunEmpty(item) == true)
                {
                    item = database.GetRunNext(mode, itemRun.Id);
                    if (IsItemRunEmpty(item) == true)
                    {
                        item = database.GetRunLast(mode);
                    }
                }

                UpdateItemRun(item);
                Analytics.TrackEventResult(Analytics.EVENT_RESULT_DELETE);
            }
        }
Exemplo n.º 13
0
        public DataItemRun GetRunNext(string mode, int current)
        {
            DataItemRun result = DataItem.CreateDefaultRun();

            lock (locker)
            {
                if (IsRunEmpty() == false)
                {
                    List <DataItemRun> runs = database.Query <DataItemRun>("SELECT * FROM [DataItemRun] WHERE [Mode] = ? AND [Id] > ? ORDER BY [Id] ASC LIMIT 1;", mode, current);
                    if (runs != null)
                    {
                        if (runs.Count > 0)
                        {
                            result = runs[0];
                        }
                    }
                }
            }

            return(result);
        }
Exemplo n.º 14
0
        public void StorePeakAcceleration(DataItemVehicle itemVehicle, DataItemRun itemRun)
        {
            if (samples.Count == 0)
            {
                Debug.LogToFileMethod("peak-a: no samlpes");
                return;
            }

            if (isPeakAStored == true)
            {
                // refuse to process peakA again
                Debug.LogToFileEventText("peak-a: already found");
                return;
            }

            double peakA     = 0;
            double speed     = 0;
            double magnitude = 0;
            int    count     = samples.Count;

            // user calibrated profile before run -> get accelerometer offsets
            // to eleminate earth gravitation and slope of the device in the car mount
            double offsetX = itemVehicle.AxisOffsetX;
            double offsetY = itemVehicle.AxisOffsetY;
            double offsetZ = itemVehicle.AxisOffsetZ;

            // from collection to array with offset compensation ("normalize" to axis origin)
            ToArray(offsetX, offsetY, offsetZ);

            // apply low pass filter to each "normalized" axis
            OnlineFilter filter = OnlineFilter.CreateLowpass(ImpulseResponse.Finite,
                                                             FILTER_SAMPLE_RATE,
                                                             FILTER_CUT_OFF_RATE,
                                                             FILTER_ORDER);

            double[] filteredX = filter.ProcessSamples(samplesX);
            filter.Reset();

            double[] filteredY = filter.ProcessSamples(samplesY);
            filter.Reset();

            double[] filteredZ = filter.ProcessSamples(samplesZ);
            filter.Reset();

            // search max value of magnitude of all filtered axes
            for (int i = 0; i < count; i++)
            {
                // magnitude of all components
                magnitude = Math.Sqrt(filteredX[i] * filteredX[i] +
                                      filteredY[i] * filteredY[i] +
                                      filteredZ[i] * filteredZ[i]);

                // store if new max
                if (magnitude > peakA)
                {
                    peakA = magnitude;
                    speed = samplesS[i];
                }
            }

            // store to given run
            itemRun.PeakAcceleration = (float)peakA;

            Debug.LogToFileEventText("found peak-a [m/s^2]: " + peakA.ToString("0.00") +
                                     " at speed [m/s]: " + speed.ToString("0.00"));

            if ((count >= SIZE_MAX) && (peakA > 0))
            {
                isPeakAStored = true;
            }
        }