public async Task <IActionResult> GetStatistic([FromRoute] int id)
        {
            var query  = new GetStatistic(id);
            var result = await _mediator.Send(query);

            return(Ok(result));
        }
Exemple #2
0
        public PassageData GetCoordinates(string authToken, string passageGuid)
        {
            if (authToken != null)
            {
                var pkg = new GetStatistic {
                    token = authToken, passage_guid = passageGuid
                };
                var httpClient = new HttpClient {
                    Timeout = new TimeSpan(0, 0, 10, 0)
                };
                var json                = JsonConvert.SerializeObject(pkg);
                var httpContent         = new StringContent(json, Encoding.UTF8, "application/json");
                var httpResponseMessage = httpClient.PostAsync(PPConfig.EndPointAdress + "statistics", httpContent).Result;
                if (httpResponseMessage.StatusCode == HttpStatusCode.OK)
                {
                    string contents = httpResponseMessage.Content.ReadAsStringAsync().Result;
                    var    result   = JsonConvert.DeserializeObject <PassageData>(contents);
                    _sensors = result;
                    //var res = new PassageData();
                    //double step = result.LocationTimestamp.Count / 500.0;
                    //if (step <= 1)
                    //{
                    //    res.LocationTimestamp = result.LocationTimestamp;
                    //    res.LocationLat = result.LocationLat;
                    //    res.LocationLng = result.LocationLng;
                    //}
                    //else
                    //{
                    //    for (double i = 0; i < result.LocationTimestamp.Count; i += step)
                    //    {
                    //        res.LocationTimestamp.Add(result.LocationTimestamp[(int)i]);
                    //        res.LocationLat.Add(result.LocationLat[(int)i]);
                    //        res.LocationLng.Add(result.LocationLng[(int)i]);
                    //    }
                    //}

                    //step = result.AccTimestamp.Count / 500.0;
                    //if (step <= 1)
                    //{
                    //    res.AccTimestamp = result.AccTimestamp;
                    //    res.AccX = result.AccX;
                    //    res.AccY = result.AccY;
                    //    res.AccZ = result.AccZ;
                    //}
                    //else
                    //{
                    //    for (double i = 0; i < result.AccTimestamp.Count; i += step)
                    //    {
                    //        res.AccTimestamp.Add(result.AccTimestamp[(int)i]);
                    //        res.AccX.Add(result.AccX[(int)i]);
                    //        res.AccY.Add(result.AccY[(int)i]);
                    //        res.AccZ.Add(result.AccZ[(int)i]);
                    //    }
                    //}

                    //step = result.GyroTimestamp.Count / 500.0;
                    //if (step <= 1)
                    //{
                    //    res.GyroTimestamp = result.GyroTimestamp;
                    //    res.GyroX = result.GyroX;
                    //    res.GyroY = result.GyroY;
                    //    res.GyroZ = result.GyroZ;
                    //}
                    //else
                    //{
                    //    for (double i = 0; i < result.GyroTimestamp.Count; i += step)
                    //    {
                    //        res.GyroTimestamp.Add(result.GyroTimestamp[(int)i]);
                    //        res.GyroX.Add(result.GyroX[(int)i]);
                    //        res.GyroY.Add(result.GyroY[(int)i]);
                    //        res.GyroZ.Add(result.GyroZ[(int)i]);
                    //    }
                    //}

                    //step = result.LightTimestamp.Count / 500.0;
                    //if (step <= 1)
                    //{
                    //    res.LightTimestamp = result.LightTimestamp;
                    //    res.LightIntensity = result.LightIntensity;
                    //}
                    //else
                    //{
                    //    for (double i = 0; i < result.LightTimestamp.Count; i += step)
                    //    {
                    //        res.LightTimestamp.Add(result.LightTimestamp[(int)i]);
                    //        res.LightIntensity.Add(result.LightIntensity[(int)i]);
                    //    }
                    //}
                    return(result);
                }
            }

            return(new PassageData());
        }
Exemple #3
0
 public PassageData GetStatistic(GetStatistic pkg)
 {
     return(repository.GetStatistic(pkg.token, pkg.passage_guid));
 }
Exemple #4
0
        public async Task <IActionResult> Index(GetStatistic getStatistic = null)
        {
            if (getStatistic.Start == default || getStatistic.End == default)
            {
                getStatistic = new GetStatistic {
                    Start = DateTime.Now.AddYears(-1), End = DateTime.Now
                };
            }
            else if (!ModelState.IsValid)
            {
                return(View(getStatistic));
            }
            var user = await userManager.GetUserAsync(User);

            getStatistic.SumCosts = await costsRepository.GetSumCostsAsync(user, getStatistic.Start, getStatistic.End);

            var groupCostsByProduct = await costsRepository.GroupCostsByProductAsync(user, getStatistic.Start, getStatistic.End, take : 20);

            List <string>         productLabels    = new();
            List <ChartJSDataset> productsDatasets = new();

            foreach (var cbp in groupCostsByProduct)
            {
                productLabels.Add(cbp.GroupName);
                ChartJSDataset dataset = new(cbp.GroupName);
                dataset.Add(Convert.ToDouble(cbp.Sum), NextChartColor);
                productsDatasets.Add(dataset);
            }

            var groupCostsByCategory = await costsRepository.GroupCostsByCategoryAsync(user, getStatistic.Start, getStatistic.End);

            List <string>  categoryLabels = new();
            ChartJSDataset costsDataset   = new("Расходы по категориям");

            foreach (var cbc in groupCostsByCategory)
            {
                categoryLabels.Add(cbc.GroupName);
                costsDataset.Add(Convert.ToDouble(cbc.Sum), NextChartColor);
            }

            List <string>  monthLabels      = new();
            ChartJSDataset costsSumDataset  = new("Расходы за месяц", NextChartColor);
            List <string>  top5ProductNames = new();

            for (int i = 0; i < 5 && i < productLabels.Count; i++)
            {
                top5ProductNames.Add(productLabels[i]);
            }
            int countTopProducts    = productLabels.Count >= 5 ? 5 : productLabels.Count;
            var top5ProductsDataset = new ChartJSDataset[countTopProducts];

            for (int i = 0; i < top5ProductsDataset.Length; i++)
            {
                top5ProductsDataset[i] = new ChartJSDataset(top5ProductNames[i], NextChartColor);
            }
            DateTime tempDate = getStatistic.Start;

            while (tempDate < getStatistic.End)
            {
                monthLabels.Add(tempDate.ToString("MMMM") + $" {tempDate.Year}");
                decimal sumCostsPerMonth = await costsRepository.GetSumCostsPerMonthAsync(user, tempDate);

                costsSumDataset.AddValue(Convert.ToDouble(sumCostsPerMonth));

                for (int i = 0; i < top5ProductsDataset.Length; i++)
                {
                    decimal productSumPerMonth = await costsRepository.GetSumCostsPerMonthAsync(user, top5ProductNames[i], tempDate);

                    top5ProductsDataset[i].AddValue(Convert.ToDouble(productSumPerMonth));
                }

                tempDate = tempDate.AddMonths(1);
            }

            ViewData["productsBarChart"]     = GenerateBarChart(productsDatasets);
            ViewData["categoriesPieChart"]   = GeneratePieChart(costsDataset, categoryLabels);
            ViewData["costsLineChart"]       = GenerateLineChart(costsSumDataset, monthLabels);
            ViewData["topProductsLineChart"] = GenerateLineChart(top5ProductsDataset, monthLabels);
            getStatistic.IsCompleteStatistic = true;

            return(View(getStatistic));
        }