Example #1
0
        public void setupGraph(deviceReadings startData, List <deviceReadings> totalData, double cellWidth, double cellHeight, double trackerHeight, UIView parentView, UITableView tableView)
        {
            cellData = startData;

            var combineName = cellData.serialNumber + "/" + cellData.sensorIndex;

            //Console.WriteLine("Looking at device " + combineName);
            allData = totalData;

            graphTable             = tableView;
            this.BackgroundColor   = UIColor.Clear;
            this.Layer.BorderWidth = 1f;

            deviceName      = new UILabel(new CGRect(0, 0, .8 * cellWidth, .2 * cellHeight));
            deviceName.Text = cellData.serialNumber + "     " + cellData.type;
            deviceName.AdjustsFontSizeToFitWidth = true;
            deviceName.TextAlignment             = UITextAlignment.Left;

            if (cellData.type.Equals("Temperature"))
            {
                deviceName.BackgroundColor = UIColor.FromRGB(247, 148, 29);
                deviceName.TextColor       = UIColor.Black;
            }
            else if (cellData.type.Equals("Vacuum"))
            {
                deviceName.BackgroundColor = UIColor.FromRGB(123, 38, 34);
                deviceName.TextColor       = UIColor.White;
            }
            else
            {
                deviceName.BackgroundColor = UIColor.FromRGB(46, 49, 146);
                deviceName.TextColor       = UIColor.White;
            }

            plotView = new PlotView(new CGRect(0, .2 * cellHeight, .8 * cellWidth, .8 * cellHeight))
            {
                Model           = CreatePlotModel(trackerHeight, parentView),
                BackgroundColor = UIColor.Clear,
            };

            includeButton = new UIButton(new CGRect(.799 * cellWidth, 0, .2 * cellWidth, 1.17 * cellHeight));
            includeButton.SetTitleColor(UIColor.White, UIControlState.Normal);
            includeButton.Layer.BorderWidth = 1f;

            includeLabel = new UILabel(new CGRect(.8 * cellWidth, 0, includeButton.Bounds.Width, .25 * includeButton.Bounds.Height));
            includeLabel.TextAlignment             = UITextAlignment.Center;
            includeLabel.Text                      = Util.Strings.INCLUDE;
            includeLabel.AdjustsFontSizeToFitWidth = true;
            includeLabel.Layer.BorderWidth         = 1f;
            includeLabel.BackgroundColor           = UIColor.Black;
            includeLabel.TextColor                 = UIColor.White;

            buttonImage = new UIView(new CGRect(.8 * cellWidth, .25 * includeButton.Bounds.Height, includeButton.Bounds.Width, .75 * includeButton.Bounds.Height));
            buttonImage.BackgroundColor        = UIColor.Yellow;
            buttonImage.UserInteractionEnabled = true;
            var image = new UIImageView(new CGRect(.25 * buttonImage.Bounds.Width, .25 * buttonImage.Bounds.Height, .5 * buttonImage.Bounds.Width, .5 * buttonImage.Bounds.Width));

            image.Layer.CornerRadius = 12;
            image.BackgroundColor    = UIColor.White;
            if (ChosenDates.includeList.Contains(combineName))
            {
                image.Image = UIImage.FromBundle("ic_checkbox");
            }
            else
            {
                image.Image = UIImage.FromBundle("ic_unchecked");
            }
            buttonImage.AddSubview(image);

            includeButton.TouchUpInside += (sender, e) => {
                if (ChosenDates.includeList.Contains(combineName))
                {
                    ChosenDates.includeList.Remove(combineName);
                    image.Image = UIImage.FromBundle("ic_unchecked");
                }
                else
                {
                    ChosenDates.includeList.Add(combineName);
                    image.Image = UIImage.FromBundle("ic_checkbox");
                }
            };

            this.AddSubview(plotView);
            this.AddSubview(deviceName);
            this.AddSubview(includeLabel);
            this.AddSubview(buttonImage);
            this.AddSubview(includeButton);
            this.BringSubviewToFront(includeButton);
            this.BringSubviewToFront(deviceName);
        }
Example #2
0
        public async void setupGraphing()
        {
            await Task.Delay(TimeSpan.FromMilliseconds(2));

            graphingSection = new ChooseGraphing(containerView, checkData);

            containerView.AddSubview(graphingSection.graphingType);

            if (activityLoadingGraphs != null)
            {
                activityLoadingGraphs = null;
            }

            activityLoadingGraphs       = new UIActivityIndicatorView(new CGRect(0, 0, containerView.Bounds.Width, containerView.Bounds.Height));
            activityLoadingGraphs.Alpha = .4f;
            activityLoadingGraphs.Layer.CornerRadius = 8;
            activityLoadingGraphs.BackgroundColor    = UIColor.DarkGray;

            containerView.AddSubview(activityLoadingGraphs);
            containerView.BringSubviewToFront(activityLoadingGraphs);

            activityLoadingGraphs.StartAnimating();

            ChosenDates.includeList = new List <string>();
            ChosenDates.allTimes    = new Dictionary <string, int>();
            ChosenDates.allIndexes  = new Dictionary <int, string>();
            var paramList = new List <string>();

            foreach (var num in checkData.selectedSessions)
            {
                paramList.Add('"' + num.ToString() + '"');
            }

            var graphResult = ion.database.Query <ION.Core.Database.SessionRow>("SELECT SID, sessionStart, sessionEnd, frn_JID FROM SessionRow WHERE SID in (" + string.Join(",", paramList.ToArray()) + ") ORDER BY SID");

            var tempResults   = new List <deviceReadings>();
            var holderList    = new List <string>();
            var sessionBreaks = new string[graphResult.Count];

            ChosenDates.breakPoints = graphResult.Count;
            for (int s = 0; s < graphResult.Count; s++)
            {
                //Console.WriteLine("Going through session " + graphResult[s].SID);
                var deviceCount = ion.database.Query <ION.Core.Database.SensorMeasurementRow>("SELECT DISTINCT serialNumber, sensorIndex FROM SensorMeasurementRow WHERE frn_SID = ? ORDER BY serialNumber ASC", graphResult[s].SID);
                //Console.WriteLine("Grabbed " + deviceCount.Count + " device results");

                for (int m = 0; m < deviceCount.Count; m++)
                {
                    var activeDevice = new deviceReadings();
                    activeDevice.times        = new List <DateTime>();
                    activeDevice.readings     = new List <double>();
                    activeDevice.SID          = graphResult[s].SID;
                    activeDevice.frnJID       = graphResult[s].frn_JID;
                    activeDevice.serialNumber = deviceCount[m].serialNumber;
                    activeDevice.sensorIndex  = deviceCount[m].sensorIndex;

                    var measurementCount = ion.database.Query <ION.Core.Database.SensorMeasurementRow>("SELECT * FROM SensorMeasurementRow WHERE serialNumber = ? AND frn_SID = ? AND sensorIndex = ? ORDER BY MID ASC", activeDevice.serialNumber, graphResult[s].SID, deviceCount[m].sensorIndex);
                    //Console.WriteLine("Using sensor index: " + measurementCount[0].sensorIndex + " for device: " + measurementCount[0].serialNumber);
                    var df    = ion.deviceManager.deviceFactory;
                    var tempD = df.GetDeviceDefinition(SerialNumberExtensions.ParseSerialNumber(activeDevice.serialNumber)) as GaugeDeviceDefinition;
                    activeDevice.type = tempD.sensorDefinitions[measurementCount[0].sensorIndex].sensorType.ToString();

                    foreach (var meas in measurementCount)
                    {
                        activeDevice.times.Add(meas.recordedDate.ToLocalTime());
                        if (!holderList.Contains(meas.recordedDate.ToLocalTime().ToString()))
                        {
                            holderList.Add(meas.recordedDate.ToLocalTime().ToString());
                        }
                        var measurement = Convert.ToDouble(meas.measurement);
                        activeDevice.readings.Add(measurement);
                    }

                    tempResults.Add(activeDevice);
                    //Console.WriteLine("Added package for serial " + activeDevice.serialNumber);
                }
                if (holderList.Count > 0)
                {
                    sessionBreaks[s] = holderList[holderList.Count - 1];
                    //Console.WriteLine("Added a session break @ " + holderList[holderList.Count - 1]);
                }
            }
            holderList.Sort((x, y) => DateTime.Parse(x).CompareTo(DateTime.Parse(y)));

            ChosenDates.extraPlots = holderList.Count;

            ChosenDates.extraPlots = (ChosenDates.extraPlots + (int)(ChosenDates.extraPlots * .05)) - holderList.Count;

            if (ChosenDates.extraPlots == 0)
            {
                ChosenDates.extraPlots = 1;
            }

            var indexes    = 0;
            var breakPoint = 0;

            foreach (var time in holderList)
            {
                //Console.WriteLine("Adding index " +indexes);
                ChosenDates.allTimes.Add(time, indexes);
                ChosenDates.allIndexes.Add(indexes, time);
                if (breakPoint < sessionBreaks.Length && sessionBreaks[breakPoint].Equals(time))
                {
                    //Console.WriteLine("hit a breakpoint");
                    indexes    = indexes + ChosenDates.extraPlots;
                    breakPoint = breakPoint + 1;
                }
                else
                {
                    indexes = indexes + 1;
                }
            }

            graphingSection.graphingView = new GraphingView(graphingSection.graphingType, this.root, tempResults, selectedSessions);
            graphingSection.legendView   = new LegendView(graphingSection.graphingType, tempResults, this);
            graphingSection.graphingType.AddSubview(graphingSection.graphingView.gView);
            graphingSection.graphingType.AddSubview(graphingSection.legendView.lView);
            graphingSection.graphingType.BringSubviewToFront(graphingSection.legendView.lView);

            if (holderList.Count > 0)
            {
                containerView.AddSubview(graphingSection.graphingView.resetButton);
                containerView.AddSubview(graphingSection.graphingView.exportGraph);
            }
            activityLoadingGraphs.StopAnimating();
            graphingSection.graphingView.graphTab.TouchUpInside   += showGraphTable;
            graphingSection.graphingView.numericTab.TouchUpInside += showNumericTable;
            graphingSection.graphingView.menuButton.TouchUpInside += showLegendView;

            graphingSection.legendView.pressureUnits.TouchUpInside    += changePressureDefault;
            graphingSection.legendView.temperatureUnits.TouchUpInside += changeTemperatureDefault;
            graphingSection.legendView.vacuumUnits.TouchUpInside      += changeVacuumDefault;
        }
Example #3
0
        public void setupTable(UITableView tableView, deviceReadings deviceData, List <deviceReadings> allData)
        {
            double highestMeasurement = -9999;
            double lowestMeasurement  = 9999999;
            var    combineName        = deviceData.serialNumber + "/" + deviceData.sensorIndex;

            var cellHeight = .25 * tableView.Bounds.Height;

            header = new UILabel(new CGRect(0, 0, .8 * tableView.Bounds.Width, .2 * cellHeight));
            header.BackgroundColor           = UIColor.Black;
            header.TextColor                 = UIColor.White;
            header.TextAlignment             = UITextAlignment.Left;
            header.AdjustsFontSizeToFitWidth = true;
            header.Text = deviceData.serialNumber + "    " + deviceData.type;

            if (deviceData.type.Equals("Temperature"))
            {
                header.BackgroundColor = UIColor.FromRGB(247, 148, 29);
                header.TextColor       = UIColor.Black;
            }
            else if (deviceData.type.Equals("Vacuum"))
            {
                header.BackgroundColor = UIColor.FromRGB(123, 38, 34);
                header.TextColor       = UIColor.White;
            }
            else
            {
                header.BackgroundColor = UIColor.FromRGB(46, 49, 146);
                header.TextColor       = UIColor.White;
            }

            includeLabel = new UILabel(new CGRect(.8 * tableView.Bounds.Width, 0, .2 * tableView.Bounds.Width, .2 * cellHeight));
            includeLabel.TextAlignment             = UITextAlignment.Center;
            includeLabel.Text                      = Util.Strings.INCLUDE;
            includeLabel.AdjustsFontSizeToFitWidth = true;
            includeLabel.Layer.BorderWidth         = 1f;
            includeLabel.BackgroundColor           = UIColor.Black;
            includeLabel.TextColor                 = UIColor.White;

            includeButton = new UIButton(new CGRect(.799 * tableView.Bounds.Width, 0, .2 * tableView.Bounds.Width, cellHeight));
            includeButton.SetTitleColor(UIColor.White, UIControlState.Normal);
            includeButton.Layer.BorderWidth = 1f;

            buttonImage = new UIView(new CGRect(.8 * tableView.Bounds.Width, .25 * includeButton.Bounds.Height, includeButton.Bounds.Width, .75 * includeButton.Bounds.Height));
            buttonImage.BackgroundColor        = UIColor.Yellow;
            buttonImage.UserInteractionEnabled = true;

            var image = new UIImageView(new CGRect(.25 * buttonImage.Bounds.Width, .25 * buttonImage.Bounds.Height, .5 * buttonImage.Bounds.Width, .5 * buttonImage.Bounds.Width));

            image.Layer.CornerRadius = 12;
            image.BackgroundColor    = UIColor.White;
            if (ChosenDates.includeList.Contains(combineName))
            {
                image.Image = UIImage.FromBundle("ic_checkbox");
            }
            else
            {
                image.Image = UIImage.FromBundle("ic_unchecked");
            }

            buttonImage.AddSubview(image);

            includeButton.TouchUpInside += (sender, e) => {
                if (ChosenDates.includeList.Contains(combineName))
                {
                    ChosenDates.includeList.Remove(combineName);
                    image.Image = UIImage.FromBundle("ic_unchecked");
                }
                else
                {
                    ChosenDates.includeList.Add(combineName);
                    image.Image = UIImage.FromBundle("ic_checkbox");
                }
            };

            information = new UILabel(new CGRect(0, .2 * cellHeight, .8 * tableView.Bounds.Width, .8 * cellHeight));
            information.Layer.BorderWidth         = 1f;
            information.Lines                     = 0;
            information.AdjustsFontSizeToFitWidth = true;

            var    totalMeasurements = 0;
            double totalValue        = 0;

            var defaultUnit = NSUserDefaults.StandardUserDefaults.StringForKey("settings_units_default_pressure");

            if (deviceData.type.Equals("Temperature"))
            {
                defaultUnit = NSUserDefaults.StandardUserDefaults.StringForKey("settings_units_default_temperature");
                if (defaultUnit == null)
                {
                    defaultUnit = "18";
                    NSUserDefaults.StandardUserDefaults.SetInt(18, "settings_units_default_temperature");
                }
            }
            else if (deviceData.type.Equals("Vacuum"))
            {
                defaultUnit = NSUserDefaults.StandardUserDefaults.StringForKey("settings_units_default_vacuum");
            }
            var lookup       = ION.Core.Sensors.UnitLookup.GetUnit(Convert.ToInt32(defaultUnit));
            var standardUnit = lookup.standardUnit;

            foreach (var device in allData)
            {
                if (device.serialNumber.Equals(deviceData.serialNumber) && device.sensorIndex.Equals(deviceData.sensorIndex))
                {
                    for (int i = 0; i < device.readings.Count; i++)
                    {
                        var baseValue = standardUnit.OfScalar(device.readings[i]);
                        var coverted  = baseValue.ConvertTo(lookup);
                        if (device.readings[i] < lowestMeasurement)
                        {
                            lowestMeasurement = device.readings[i];
                        }
                        if (device.readings[i] > highestMeasurement)
                        {
                            highestMeasurement = device.readings[i];
                        }
                        totalValue += device.readings[i];
                        totalMeasurements++;
                    }
                }
            }

            var workingValue = standardUnit.OfScalar(highestMeasurement);

            var finalHighest = workingValue.ConvertTo(lookup);

            workingValue = standardUnit.OfScalar(lowestMeasurement);
            var finalLowest = workingValue.ConvertTo(lookup);

            workingValue = standardUnit.OfScalar((totalValue / totalMeasurements));
            var finalAverage = workingValue.ConvertTo(lookup);

            information.Text = Util.Strings.Measure.LOWESTMEASUREMENT + ": " + finalLowest.amount.ToString("N") + " " + lookup.ToString() + "\n" + Util.Strings.Measure.HIGHESTMEASUREMENT + ": " + finalHighest.amount.ToString("N") + " " + lookup.ToString() + "\n" + Util.Strings.Measure.AVERAGEMEASUREMENT + ": " + finalAverage.amount.ToString("N") + " " + lookup.ToString();

            this.AddSubview(header);
            this.AddSubview(information);

            this.AddSubview(includeLabel);
            this.AddSubview(buttonImage);
            this.AddSubview(includeButton);
            this.BringSubviewToFront(includeButton);
        }