Esempio n. 1
0
        public async Task <IEnumerable <Code> > GetAll([FromRoute] Guid deviceId)
        {
            Device dev = await GetDeviceAsync(deviceId);

            if (dev == null)
            {
                return(null);
            }
            var t = _repository.GetAll(dev);

            return(t);
        }
Esempio n. 2
0
        public async Task <object> GetAll()
        {
            List <Code> listCode = new List <Code>();

            try
            {
                listCode = _codeRepository.GetAll();
            }
            catch (Exception ex)
            {
                result = false;
                error  = ex.Message;
            }

            return(new SingleResponse <List <Code> >
            {
                Message = "Get all code execute successfully",
                DidError = false,
                ErrorMessage = string.Empty,
                Token = string.Empty,
                Model = listCode
            });
        }
Esempio n. 3
0
        public IEnumerable <Code> GetCodes()
        {
            var codes = codeRepository.GetAll();

            return(codes);
        }
Esempio n. 4
0
        private List <ChartJSCore.Models.Chart> CreateCharts(Device device)
        {
            int binNum = 6;

            IEnumerable <Code> codes = _repository.GetAll(device);
            var freq = codes.GroupBy(x => x.Action).ToDictionary(x => x.Key, x => x.Count());
            IEnumerable <double> compl = codes.Where(x => x.DateArrived != DateTime.MinValue && x.DateCompleted != DateTime.MinValue &&
                                                     x.DateExecuted != DateTime.MinValue).Select(x => (x.DateCompleted - x.DateArrived).TotalSeconds);

            ChartJSCore.Models.Chart frequency      = new ChartJSCore.Models.Chart();
            ChartJSCore.Models.Chart timeToComplete = new ChartJSCore.Models.Chart();

            frequency.Type      = "bar";
            timeToComplete.Type = "bar";


            ChartJSCore.Models.Data freqData = new ChartJSCore.Models.Data();
            freqData.Labels = freq.Keys.Select(x => x.ToString()).ToList();

            double lowerCompl;
            double upperCompl;

            if (compl.Any())
            {
                lowerCompl = compl.Min();
                upperCompl = compl.Max();
            }
            else
            {
                lowerCompl = 0;
                upperCompl = 0;
            }

            double complRange = (upperCompl - lowerCompl) / binNum;

            List <string> complBins = new List <string>();

            for (int i = 0; i < binNum; i++)
            {
                complBins.Add($"{lowerCompl + i * complRange:f1}-{lowerCompl + (i + 1) * complRange:f1}");
            }

            int[] complPoints = new int[binNum];
            foreach (var value in compl)
            {
                int bucketIndex = 0;
                if (complRange > 0.0)
                {
                    bucketIndex = (int)((value - lowerCompl) / complRange);
                    if (bucketIndex == binNum)
                    {
                        bucketIndex--;
                    }
                }
                complPoints[bucketIndex]++;
            }


            ChartJSCore.Models.Data completeData = new ChartJSCore.Models.Data();
            completeData.Labels = complBins;

            BarDataset freqDataset = new BarDataset()
            {
                Label           = "Frequency of Actions",
                Data            = freq.Values.Select(x => (double)x).ToList(),
                BackgroundColor = new List <string>(),
                BorderWidth     = new List <int>()
                {
                    1
                }
            };

            freqData.Datasets = new List <Dataset>();
            freqData.Datasets.Add(freqDataset);

            BarDataset complDateDataset = new BarDataset()
            {
                Label           = "Complete time in seconds",
                Data            = complPoints.Select(x => (double)x).ToList(),
                BackgroundColor = new List <string>(),
                BorderWidth     = new List <int>()
                {
                    1
                }
            };

            completeData.Datasets = new List <Dataset>();
            completeData.Datasets.Add(complDateDataset);

            frequency.Data      = freqData;
            timeToComplete.Data = completeData;

            BarOptions options = new BarOptions()
            {
                Scales        = new Scales(),
                BarPercentage = 0.7
            };

            Scales scales = new Scales()
            {
                YAxes = new List <Scale>()
                {
                    new CartesianScale()
                    {
                        Ticks = new CartesianLinearTick()
                        {
                            BeginAtZero = true
                        }
                    }
                }
            };

            options.Scales = scales;

            frequency.Options      = options;
            timeToComplete.Options = options;

            return(new List <ChartJSCore.Models.Chart>
            {
                frequency,
                timeToComplete
            });
        }