Esempio n. 1
0
        public string GetChartData(List <DevicesListModel> DevicesDataList)
        {
            ChartController chart = new ChartController();

            //chart color
            List <string> Color = new List <string>();
            //sensor log


            List <CurrentDataModel> DevicesCurrentList = new List <CurrentDataModel>();
            //only ts

            DateTime today = DateTime.Now;


            //end set time
            List <string> labelss = new List <string>();
            List <double> data    = new List <double>();

            List <object> datasets = new List <object>();
            List <object> datas    = new List <object>();

            foreach (DevicesListModel get in DevicesDataList)
            {
                Color.Add(chart.GetRandomColor());
                labelss.Add(get.devicesId);
                DevicesCurrentList = GetChartDataList(get.devicesId).Where(x => x.latest_checking_time > today.AddDays(-1)).OrderBy(x => x.latest_checking_time).ToList();
                //Debug.WriteLine(get.devicesId+" line 596 :" + DevicesCurrentList.ToJson().ToString());

                DateTime ca = today;
                //TimeSpan catime = ca - ca.AddDays(-1);
                TimeSpan catime = ca - ca.AddHours(-6);


                int counttime = Convert.ToInt32(catime.TotalMinutes / 5);

                for (int x = 0; x <= counttime; x++)
                {
                    data.Add(0);
                }
                //Debug.WriteLine("line 603 : " + DevicesCurrentList.Count());

                if (DevicesCurrentList.Count() != 0)
                {
                    foreach (CurrentDataModel getCurrent in DevicesCurrentList)
                    {
                        //Debug.WriteLine("line 615 : "+ DevicesCurrentList.ToJson().ToString());

                        var value = Convert.ToDouble(Convert.ToDouble(getCurrent.current).ToString("0.00"));

                        ca = today.AddHours(-6);

                        for (int x = 0; x <= counttime; x++)
                        {
                            var bo = getCurrent.latest_checking_time >= ca && getCurrent.latest_checking_time <= ca.AddMinutes(5);

                            ca = ca.AddMinutes(5);
                            if (getCurrent.latest_checking_time > ca && getCurrent.latest_checking_time < ca.AddMinutes(5))
                            {
                                data[x] = value;
                            }
                        }
                    }
                }
                else
                {
                }
                datas.Add(data.ToArray());
            }

            for (int i = 0; i < DevicesDataList.Count; i++)
            {
                labelss.Add(DevicesDataList[i].devicesId);
            }

            foreach (var get in datas)
            {
                //Debug.WriteLine(get.ToJson());
            }
            return(chart.LineChart(DevicesDataList.Count, labelss, datas));
        }