Beispiel #1
0
        public async void onUploadAllClicked(View view)
        {
            TextView codeView = FindViewById <TextView>(Resource.Id.mainCodeTV);

            codeView.Visibility = ViewStates.Invisible;

            HeartDebugHandler.debugLog("Getting json string");
            string jsonStringSteps = await HeartFileHandler.getJSONString(HeartFileHandler.FILENAME_STEPS);

            string jsonStringRate = await HeartFileHandler.getJSONString(HeartFileHandler.FILENAME_HEARTRATE);

            string jsonStringBeat = await HeartFileHandler.getJSONString(HeartFileHandler.FILENAME_HEARTBEAT);

            //HeartDebugHandler.debugLog(jsonString.Substring(jsonString.Length-30));
            //HeartDebugHandler.debugLog("String got, length: " + jsonString.Length);

            HeartDebugHandler.debugLog("Sending data");

            //HeartNetworkHandler.sendPostRequest(this, jsonString, codeView);
            //HeartNetworkHandler.sendPostRequest(this, jsonStringSteps, jsonStringRate, jsonStringBeat, codeView);
            HeartPostSender hps = new HeartPostSender(this, codeView, jsonStringSteps, jsonStringRate, jsonStringBeat);

            hps.SendData();
        }
Beispiel #2
0
        public void onSaveToFileClicked(View view)
        {
            HeartDebugHandler.debugLog("Save to file clicked");

            if (hdata_Steps.Count > 0)
            {
                HeartFileHandler.saveData(hdata_Steps, HeartFileHandler.FILENAME_STEPS, dataStatusHandler);
            }

            if (hdata_Rate.Count > 0)
            {
                HeartFileHandler.saveData(hdata_Rate, HeartFileHandler.FILENAME_HEARTRATE, dataStatusHandler);
            }

            if (hdata_Beat.Count > 0)
            {
                HeartFileHandler.saveData(hdata_Beat, HeartFileHandler.FILENAME_HEARTBEAT, dataStatusHandler);
            }

            if (hdata_Steps.Count == 0 && hdata_Beat.Count == 0 && hdata_Rate.Count == 0)
            {
                dataStatusHandler.updateStatus("No unsaved data");
            }
        }
Beispiel #3
0
 public void onPurgeStepsData(View view)
 {
     HeartDebugHandler.debugLog("Purge Steps data clicked!");
     HeartFileHandler.DeleteStepsData();
 }
Beispiel #4
0
 public void onPurgeHeartRateData(View view)
 {
     HeartDebugHandler.debugLog("Purge Heart Rate data clicked!");
     HeartFileHandler.DeleteHeartRateData();
 }
Beispiel #5
0
 public void onPurgeAllData(View view)
 {
     HeartDebugHandler.debugLog("Purge all data clicked!");
     HeartFileHandler.DeleteAllData();
 }
Beispiel #6
0
        public async void onToggleChartClicked(View view)
        {
            if (imageView.Visibility == ViewStates.Visible)
            {
                imageView.Visibility = ViewStates.Gone;
                chartView.Visibility = ViewStates.Visible;
                List <HeartDataPoint> dataPoints = await HeartFileHandler.getData(HeartFileHandler.FILENAME_STEPS);

                List <Entry> orderedSummarizedList = new List <Entry>();
                if (dataPoints != null && dataPoints.Count > 0)
                {
                    dataPoints.Sort((x, y) => x.timestamp.CompareTo(y.timestamp));    //ordering list by time

                    HeartDataPoint currentPoint = dataPoints[0];
                    //DateTime currentDate = currentPoint.timestamp;
                    //int currentHour = currentPoint.timestamp.Hour;
                    int currentTotal = 0;
                    int colorCount   = 0;
                    for (int i = 0; i < dataPoints.Count; i++)
                    {
                        HeartDataPoint examinePoint = dataPoints[i];
                        if (currentPoint.timestamp.Date == examinePoint.timestamp.Date &&
                            currentPoint.timestamp.Hour == examinePoint.timestamp.Hour &&
                            currentPoint.timestamp.Minute == examinePoint.timestamp.Minute)
                        {
                            currentTotal += examinePoint.amount;
                        }
                        else
                        {
                            //create entry here
                            Entry entry = new Entry(currentTotal)
                            {
                                Label      = currentPoint.timestamp.Date.ToString("d") + ", Hour: " + currentPoint.timestamp.Hour,
                                ValueLabel = currentTotal.ToString(),
                                Color      = SKColor.Parse(getColor(colorCount))
                            };
                            colorCount++;
                            orderedSummarizedList.Add(entry);

                            currentPoint = dataPoints[i];
                            currentTotal = currentPoint.amount;//since it won't be examined against it self, like the first will
                        }
                    }
                    //Adding the last iteration of the list(also helps when list only contains one member)
                    Entry lastEntry = new Entry(currentTotal)
                    {
                        Label      = currentPoint.timestamp.Date.ToString("d") + ", Hour: " + currentPoint.timestamp.Hour + "Min: " + currentPoint.timestamp.Minute,
                        ValueLabel = currentTotal.ToString(),
                        Color      = SKColor.Parse(getColor(colorCount))
                    };
                    orderedSummarizedList.Add(lastEntry);

                    var entriesLC = orderedSummarizedList.ToArray();
                    var chart     = new LineChart()
                    {
                        Entries = entriesLC
                    };
                    chartView.Chart = chart;
                }
                else
                {
                    chartView.Visibility = ViewStates.Gone;
                    imageView.Visibility = ViewStates.Visible;
                    Toast.MakeText(this, "No data currently available", ToastLength.Short).Show();
                }
            }
            else
            {
                chartView.Visibility = ViewStates.Gone;
                imageView.Visibility = ViewStates.Visible;
            }
        }
Beispiel #7
0
        /// <summary>
        /// get's called when data from the wearable is received
        /// needs to be different from earlier data, which is why you need the timestamps as part of the data if you want each data point
        /// </summary>
        /// <param name="dataEvents"></param>
        public void OnDataChanged(DataEventBuffer dataEvents)
        {
            HeartDebugHandler.debugLog("Data changed");

            var dataEvent = Enumerable.Range(0, dataEvents.Count)
                            .Select(i => dataEvents.Get(i).JavaCast <IDataEvent>())
                            .FirstOrDefault(x => x.Type == DataEvent.TypeChanged && x.DataItem.Uri.Path.Equals(DataPointsPath));

            if (dataEvent == null)
            {
                return;
            }
            else
            {
                var    dataMapItem = DataMapItem.FromDataItem(dataEvent.DataItem);
                var    map         = dataMapItem.DataMap;
                string message     = dataMapItem.DataMap.GetString("Message");
                HeartDebugHandler.debugLog("Data received! message: " + message);

                string[] allDataPoints;
                if (message.Contains("|"))
                {
                    allDataPoints = message.Split("|");
                }
                else
                {
                    allDataPoints = new[] { message };
                }

                int  teller       = 0;
                bool stepReceived = false;
                bool hbReceived   = false;
                bool hrReceived   = false;
                foreach (string pointData in allDataPoints)
                {
                    HeartDataPoint p = decodeDataPoint(pointData);
                    if (p != null)
                    {
                        teller++;
                    }

                    if (p.heartType == HeartDataType.HeartBeat)
                    {
                        if (!hbReceived)
                        {
                            hbReceived = true;
                        }
                        hdata_Beat.Enqueue(p);

                        if (hdata_Beat.Count > 50)
                        {
                            HeartFileHandler.saveData(hdata_Beat, HeartFileHandler.FILENAME_HEARTBEAT, dataStatusHandler);
                        }
                    }
                    else if (p.heartType == HeartDataType.HeartRate)
                    {
                        if (!hrReceived)
                        {
                            hrReceived = true;
                        }
                        hdata_Rate.Enqueue(p);

                        if (hdata_Rate.Count > 50)
                        {
                            HeartFileHandler.saveData(hdata_Rate, HeartFileHandler.FILENAME_HEARTRATE, dataStatusHandler);
                        }
                    }
                    else if (p.heartType == HeartDataType.StepCount)
                    {
                        if (!stepReceived)
                        {
                            stepReceived = true;
                        }
                        hdata_Steps.Enqueue(p);
                        if (hdata_Steps.Count > 50)
                        {
                            HeartFileHandler.saveData(hdata_Steps, HeartFileHandler.FILENAME_STEPS, dataStatusHandler);
                        }
                    }
                }

                if (teller > 0)
                {
                    string types = "";
                    if (hrReceived)
                    {
                        types += "HR,";
                    }
                    if (hbReceived)
                    {
                        types += "HB,";
                    }
                    if (stepReceived)
                    {
                        types += "St";
                    }
                    //updateStatusString("Data received, Types: {"+ types + "}, Amount: " + teller + ".");
                    connectionStatusHandler.updateStatus("Data received, Types: {" + types + "}, Amount: " + teller + ".");
                    //saveStepData();//bør nok kjøres på en mer intelligent måte
                }
                else
                {
                    //updateStatusString("Invalid data received.");
                    connectionStatusHandler.updateStatus("Invalid data received.");
                }
            }
        }