Пример #1
0
        public string GetKpiTypeData(List <KPIPointDataItem> pKpiDataInfo, string pLabelPrefix, string pLabelSuffix, string pKpiText, int pTypeCount, string[] pTypeName, string[] pTypeLabel, string[] pTypeIcon, string pDefaultLegend, string pDefaultIcon)
        {
            var lstData = new List <KPIPointData>();

            foreach (var kpiDataItem in pKpiDataInfo)
            {//点 KPI
                KPIPointData kpiData = new KPIPointData();
                if (!string.IsNullOrWhiteSpace(kpiDataItem.StoreID))
                {
                    kpiData.id = kpiDataItem.StoreID;
                }
                if (!string.IsNullOrWhiteSpace(kpiDataItem.StoreName))
                {
                    kpiData.title = kpiDataItem.StoreName;
                }

                if (!string.IsNullOrWhiteSpace(kpiDataItem.StoreAddress))
                {
                    kpiData.address = kpiDataItem.StoreAddress;
                }
                kpiData.xytype = kpiDataItem.GPSType;
                kpiData.x      = kpiDataItem.Longitude;
                kpiData.y      = kpiDataItem.Latitude;
                if (kpiDataItem.KPIData != null)
                {
                    kpiData.kpi = kpiDataItem.KPIData;
                    var tempKpiLabel = kpiDataItem.KPILabel;

                    if (!string.IsNullOrWhiteSpace(pLabelPrefix))
                    {
                        kpiData.kpilabel = pLabelPrefix;
                    }
                    if (string.IsNullOrWhiteSpace(tempKpiLabel))
                    {
                        kpiData.kpilabel += kpiDataItem.KPIData;
                    }
                    else
                    {
                        kpiData.kpilabel += tempKpiLabel;
                    }

                    if (!string.IsNullOrWhiteSpace(pLabelSuffix))
                    {
                        kpiData.kpilabel += pLabelSuffix;
                    }
                    ;
                }
                if (!string.IsNullOrWhiteSpace(kpiDataItem.KPIFilter1))
                {
                    kpiData.kpifilter1 = kpiDataItem.KPIFilter1;
                }
                if (!string.IsNullOrWhiteSpace(kpiDataItem.KPIFilter2))
                {
                    kpiData.kpifilter2 = kpiDataItem.KPIFilter2;
                }
                if (!string.IsNullOrWhiteSpace(kpiDataItem.KPIFilter3))
                {
                    kpiData.kpifilter3 = kpiDataItem.KPIFilter3;
                }
                if (!string.IsNullOrWhiteSpace(kpiDataItem.KPIFilter4))
                {
                    kpiData.kpifilter4 = kpiDataItem.KPIFilter4;
                }
                if (!string.IsNullOrWhiteSpace(kpiDataItem.KPIFilter5))
                {
                    kpiData.kpifilter5 = kpiDataItem.KPIFilter5;
                }

                //弹出框
                kpiData.poptype   = kpiDataItem.PopWindowType;
                kpiData.popwidth  = kpiDataItem.PopWindowWidth;
                kpiData.popheight = kpiDataItem.PopWindowHeight;
                kpiData.poptitle  = kpiDataItem.PopWindowTitle;
                kpiData.popurl    = kpiDataItem.PopWindowUrl;
                if (string.IsNullOrWhiteSpace(kpiData.popurl))
                {
                    //这些先写死
                    //kpiData.popwidth = "500";
                    //kpiData.popheight = "350";
                    //kpiData.poptitle = string.Empty;
                    kpiData.popurl = string.Format(@"/Module/MapAnalysis/Common/StoreInfo.aspx?sid={0}&kpilabel={1}&kpitext={2}", kpiData.id, kpiData.kpilabel, pKpiText);
                }
                lstData.Add(kpiData);
            }
            //设置阀值
            List <Threshold> lstThreshold = new List <Threshold>();
            Threshold        threshold1   = new Threshold();

            threshold1.level        = "4";
            threshold1.type         = "6";
            threshold1.defaultimage = pDefaultIcon;
            threshold1.defaulttext  = pDefaultLegend;
            List <ThresholdItem> lstThresholdItem = new List <ThresholdItem>();

            for (int i = 0; i < pTypeCount; i++)
            {
                ThresholdItem thresholdItem = new ThresholdItem();
                thresholdItem.image     = pTypeIcon[i];
                thresholdItem.text      = pTypeName[i];
                thresholdItem.textlabel = pTypeLabel[i];
                lstThresholdItem.Add(thresholdItem);
            }
            threshold1.threshold = lstThresholdItem.ToArray();

            lstThreshold.Add(threshold1);
            var orderedItems = lstData.OrderBy(item => item.kpi);

            KPIInformation kpiInformation = new KPIInformation();

            kpiInformation.Data       = lstData.ToArray();
            kpiInformation.Thresholds = lstThreshold.ToArray();
            var tempJsonString = kpiInformation.ToJSON();

            return(tempJsonString);
        }
Пример #2
0
        public string GetKpiData(BoundLevel pLevel, List <KPIFlatDataItem> pKpiDataInfo, string pKpiLabelPrefix, string pKpiLabelSuffix, DataValueFormat pDataValueFormat, string pStyleCode, string pStyleSubCode)
        {
            Color[] pFlatColors = GetRenderColors(pStyleCode, pStyleSubCode);
            pKpiDataInfo.Sort(KpiDataCompare);
            double dMinValue = 0;// Convert.ToDouble(pKpiDataInfo[0].KPIData);

            for (int i = 0; i < pKpiDataInfo.Count; i++)
            {
                if (pKpiDataInfo[i].KPIData != null)
                {
                    dMinValue = Convert.ToDouble(pKpiDataInfo[i].KPIData);
                    break;
                }
            }
            double dMaxValue = Convert.ToDouble(pKpiDataInfo[pKpiDataInfo.Count - 1].KPIData);

            List <Threshold> lstThreshold = new List <Threshold>();
            //分成5段
            double dInterval = (dMaxValue - dMinValue) / 5.0;

            if (dInterval < 0.01 && dInterval > 0)//最小间隔为0.1
            {
                dInterval = 0.01;
            }

            Threshold            threshold1       = new Threshold();
            List <ThresholdItem> lstThresholdItem = new List <ThresholdItem>();

            for (int i = 0; i < 5; i++)
            {
                double startValue;
                double endValue;
                if (i == 0)
                {//起始值使用最小值
                    startValue = dMinValue;
                }
                else
                {
                    startValue = dMinValue + dInterval * i;
                }
                if (i == 4)
                {//结束值使用最大值
                    endValue = dMaxValue;
                }
                else
                {
                    endValue = dMinValue + dInterval * (i + 1);
                }
                if (startValue == 0 && endValue == 0)//忽略无数据的KPI
                {
                    continue;
                }
                string startLabel = KPIBuilderUtils.GetFormatedValue(startValue.ToString(), pDataValueFormat);
                string endLabel   = KPIBuilderUtils.GetFormatedValue(endValue.ToString(), pDataValueFormat);
                //阀值处理
                ThresholdItem thresholdItem = new ThresholdItem();
                if (pFlatColors.Length > i)
                {
                    thresholdItem.color = System.Drawing.ColorTranslator.ToHtml(pFlatColors[i]).Replace("#", "0x");
                }
                else
                {
                    thresholdItem.color = "0xFF0000";
                }
                thresholdItem.start = startValue.ToString();
                thresholdItem.end   = endValue.ToString();
                if ((pDataValueFormat & DataValueFormat.Int) != 0)
                {
                    if (thresholdItem.start.IndexOf(".") > -1)
                    {
                        thresholdItem.start = thresholdItem.start.Substring(0, thresholdItem.start.IndexOf("."));
                    }
                    if (thresholdItem.end.IndexOf(".") > -1)
                    {
                        thresholdItem.end = thresholdItem.end.Substring(0, thresholdItem.end.IndexOf("."));
                    }
                }
                thresholdItem.startlabel = startLabel;
                thresholdItem.endlabel   = endLabel;
                thresholdItem.size       = (20 + i * 2).ToString();
                if (Convert.ToDouble(thresholdItem.start) >= dMaxValue && lstThresholdItem.Count > 0)
                {
                    continue;//由于误差原因,可能超过最大值。
                }
                lstThresholdItem.Add(thresholdItem);
            }
            //删除重复的分段阀值
            List <ThresholdItem> lstNewThresholdItem = new List <ThresholdItem>();

            lstNewThresholdItem.Add(lstThresholdItem[0]);
            for (int i = 1; i < lstThresholdItem.Count; i++)
            {
                if (lstThresholdItem[i - 1].start != lstThresholdItem[i].start || lstThresholdItem[i - 1].end != lstThresholdItem[i].end)
                {
                    lstNewThresholdItem.Add(lstThresholdItem[i]);
                }
            }
            threshold1.threshold = lstNewThresholdItem.ToArray();
            if (pStyleCode.ToUpper() == "SB")
            {
                threshold1.type = "3";
                //气泡渲染要添加透明效果
                foreach (var item in threshold1.threshold)
                {
                    item.alpha = "0.8";
                }

                threshold1.defaultalpha = "0.8";
            }
            else
            {
                threshold1.type = "1";
            }
            threshold1.level        = ((int)pLevel).ToString();
            threshold1.defaultcolor = "0xFFFFFF";
            threshold1.defaultimage = "";
            threshold1.defaultsize  = "20";
            threshold1.defaulttext  = "无数据";
            lstThreshold.Add(threshold1);

            //计算气泡大小
            var lstData = new List <KPIFlatData>();

            foreach (var kpiDataItem in pKpiDataInfo)
            {
                //过滤无效的数据
                if (string.IsNullOrWhiteSpace(kpiDataItem.KPIData) || kpiDataItem.Ignore)
                {
                    continue;
                }
                //lstThreshold
                double dValue = Convert.ToDouble(kpiDataItem.KPIData);
                //过滤太小的数值
                //if (dValue < 0.01)
                //    continue;
                //省市县KPI
                KPIFlatData kpiData = new KPIFlatData();
                if (!string.IsNullOrWhiteSpace(kpiDataItem.DataID))
                {
                    kpiData.id = kpiDataItem.DataID;
                }
                kpiData.kpi      = kpiDataItem.KPIData;
                kpiData.kpilabel = KPIBuilderUtils.GetFormatedValue(kpiData.kpi, pDataValueFormat);
                kpiData.kpimark  = kpiData.kpilabel;
                if (!string.IsNullOrWhiteSpace(pKpiLabelPrefix))
                {
                    kpiData.kpilabel = pKpiLabelPrefix + kpiData.kpilabel;
                }

                if (!string.IsNullOrWhiteSpace(pKpiLabelSuffix))
                {
                    kpiData.kpilabel = kpiData.kpilabel + pKpiLabelSuffix;
                }
                lstData.Add(kpiData);
            }
            KPIInformation jsonKpiData = new KPIInformation();

            jsonKpiData.Data       = lstData.ToArray();
            jsonKpiData.Thresholds = lstThreshold.ToArray();
            return(jsonKpiData.ToJSON());
        }
Пример #3
0
        public string GetKpiValueData(List <KPIPointDataItem> pKpiDataInfo, string pLabelPrefix, string pLabelSuffix, string pKpiText, string[] pValueIcon, string pDefaultLegend, string pDefaultIcon)
        {
            var lstData = new List <KPIPointData>();

            foreach (var kpiDataItem in pKpiDataInfo)
            {//点 KPI
                KPIPointData kpiData = new KPIPointData();
                if (!string.IsNullOrWhiteSpace(kpiDataItem.StoreID))
                {
                    kpiData.id = kpiDataItem.StoreID;
                }
                if (!string.IsNullOrWhiteSpace(kpiDataItem.StoreName))
                {
                    kpiData.title = kpiDataItem.StoreName;
                }

                if (!string.IsNullOrWhiteSpace(kpiDataItem.StoreAddress))
                {
                    kpiData.address = kpiDataItem.StoreAddress;
                }
                kpiData.xytype = kpiDataItem.GPSType;
                kpiData.x      = kpiDataItem.Longitude;
                kpiData.y      = kpiDataItem.Latitude;
                if (kpiDataItem.KPIData != null)
                {
                    kpiData.kpi = kpiDataItem.KPIData;
                    var tempKpiLabel = kpiDataItem.KPILabel;

                    if (!string.IsNullOrWhiteSpace(pLabelPrefix))
                    {
                        kpiData.kpilabel = pLabelPrefix;
                    }
                    if (string.IsNullOrWhiteSpace(tempKpiLabel))
                    {
                        kpiData.kpilabel += kpiDataItem.KPIData;
                    }
                    else
                    {
                        kpiData.kpilabel += tempKpiLabel;
                    }

                    if (!string.IsNullOrWhiteSpace(pLabelSuffix))
                    {
                        kpiData.kpilabel += pLabelSuffix;
                    }
                    ;
                }
                if (!string.IsNullOrWhiteSpace(kpiDataItem.KPIFilter1))
                {
                    kpiData.kpifilter1 = kpiDataItem.KPIFilter1;
                }
                if (!string.IsNullOrWhiteSpace(kpiDataItem.KPIFilter2))
                {
                    kpiData.kpifilter2 = kpiDataItem.KPIFilter2;
                }
                if (!string.IsNullOrWhiteSpace(kpiDataItem.KPIFilter3))
                {
                    kpiData.kpifilter3 = kpiDataItem.KPIFilter3;
                }
                if (!string.IsNullOrWhiteSpace(kpiDataItem.KPIFilter4))
                {
                    kpiData.kpifilter4 = kpiDataItem.KPIFilter4;
                }
                if (!string.IsNullOrWhiteSpace(kpiDataItem.KPIFilter5))
                {
                    kpiData.kpifilter5 = kpiDataItem.KPIFilter5;
                }

                //这些先写死
                kpiData.popwidth  = "500";
                kpiData.popheight = "350";
                kpiData.poptitle  = string.Empty;
                kpiData.popurl    = string.Format(@"/Module/MapAnalysis/Common/StoreInfo.aspx?sid={0}&kpilabel={1}&kpitext={2}", kpiData.id, kpiData.kpilabel, pKpiText);

                lstData.Add(kpiData);
            }
            //设置阀值
            List <Threshold>     lstThreshold     = new List <Threshold>();
            Threshold            threshold1       = new Threshold();
            List <ThresholdItem> lstThresholdItem = new List <ThresholdItem>();

            //找出最大最小值
            double dMaxValue, dMinValue;
            double dFirstValue = Convert.ToDouble(pKpiDataInfo[0].KPIData);

            dMaxValue = dFirstValue;
            dMinValue = dFirstValue;
            foreach (var pointItem in pKpiDataInfo)
            {
                //KPIPointData pointItem = (KPIPointData)item;
                double dCurrentValue = Convert.ToDouble(pointItem.KPIData);
                if (dCurrentValue > dMaxValue)
                {
                    dMaxValue = dCurrentValue;
                }
                if (dCurrentValue < dMinValue)
                {
                    dMinValue = dCurrentValue;
                }
            }
            double dInterval = (dMaxValue - dMinValue) / 5;

            for (int i = 0; i < 5; i++)
            {
                ThresholdItem thresholdItem = new ThresholdItem();
                thresholdItem.image      = pValueIcon[i];
                thresholdItem.start      = (dMinValue + dInterval * i).ToString("0.00");
                thresholdItem.startlabel = (dMinValue + dInterval * i).ToString("0.00");
                thresholdItem.end        = (dMinValue + dInterval * (i + 1)).ToString("0.00");
                thresholdItem.endlabel   = (dMinValue + dInterval * (i + 1)).ToString("0.00");
                lstThresholdItem.Add(thresholdItem);
            }

            //删除重复阀值
            List <ThresholdItem> lstNewThresholdItem = new List <ThresholdItem>();

            lstNewThresholdItem.Add(lstThresholdItem[0]);
            for (int i = 1; i < 5; i++)
            {
                if (lstThresholdItem[i - 1].start != lstThresholdItem[i].start || lstThresholdItem[i - 1].end != lstThresholdItem[i].end)
                {
                    lstNewThresholdItem.Add(lstThresholdItem[i]);
                }
            }

            threshold1.threshold    = lstNewThresholdItem.ToArray();
            threshold1.level        = "4";
            threshold1.type         = "5";
            threshold1.defaultcolor = "0x000000";
            threshold1.defaultimage = pDefaultIcon;
            threshold1.defaulttext  = pDefaultLegend;

            lstThreshold.Add(threshold1);
            var            orderedItems   = lstData.OrderBy(item => item.kpi);
            KPIInformation kpiInformation = new KPIInformation();

            kpiInformation.Data       = lstData.ToArray();
            kpiInformation.Thresholds = lstThreshold.ToArray();
            var tempJsonString = kpiInformation.ToJSON();

            return(tempJsonString);
        }
Пример #4
0
        //Create the Graph and configure is proprties
        private void CreateGraph(ZedGraphControl zgc)
        {
            GraphPane myPane = zgc.GraphPane;

            List <ThresholdItem> listCurrentThresholds = this.ReadFromDBThresholdType(cmbBoxDeviceType.SelectedItem.ToString());

            // Set the titles and axis labels per selection
            myPane.Title.Text = cmbBoxDeviceType.GetItemText(cmbBoxDeviceType.SelectedItem);

            myPane.XAxis.Title.Text = "Thresholds";
            myPane.YAxis.Title.Text = "";

            myPane.CurveList.Clear();// clear the graph

            for (int i = 0; i < listCurrentThresholds.Count(); ++i)
            {
                ThresholdItem item = listCurrentThresholds[i];
                item.name = item.name.Replace(" ", String.Empty);//remove whitespaces
                LineItem myLine = new LineItem(item.name + "Threshold",
                                               new double[] {
                    ((float)(i * 2 + 1)) / (listCurrentThresholds.Count() * 2) - (1.0 / (listCurrentThresholds.Count() * 2 + 1)),
                    ((float)(i * 2 + 1)) / (listCurrentThresholds.Count() * 2) + (1.0 / (listCurrentThresholds.Count() * 2 + 1))
                },
                                               new double[] { item.value, item.value },
                                               Color.Black,
                                               SymbolType.Diamond, 3.0f);
                myLine.IsX2Axis = true;
                myPane.CurveList.Add(myLine);
            }

            List <BarItem> listBarItems = new List <BarItem>();

            //Create Random colors to show on Graph
            Color[] barColors = new Color[] {
                //set of orange
                Color.FromArgb(49, 130, 189),
                Color.FromArgb(49, 163, 84),
                Color.FromArgb(99, 99, 99),
                Color.Azure,
                Color.Bisque,
                Color.Coral,
                Color.Crimson,
                Color.ForestGreen,
                Color.Lavender,
                Color.Navy
            };

            for (int idx = 0; idx < listDevices.SelectedItems.Count; ++idx)
            {
                DeviceItem currDevice     = (DeviceItem)listDevices.SelectedItems[idx];
                String     currDeviceName = currDevice.name;

                //Get one point for each threshold according to the device type.
                PointPairList listDeviceValues = GetDeviceData(listCurrentThresholds, currDevice.id);

                //use this to add line width 3.0F
                BarItem myCurve = new BarItem(currDeviceName, listDeviceValues, barColors[idx % barColors.Count()]);
                listBarItems.Add(myCurve);
            }


            for (int idx = 0; idx < listCurrentThresholds.Count(); ++idx)
            {
                ThresholdItem item = listCurrentThresholds[idx];
                item.name = item.name.Replace(" ", String.Empty);//remove whitespaces
                //myPane.CurveList.Average

                try
                {
                    double avg = listBarItems.Where(v => v.Points.Count > idx)
                                 .Select(v => v.Points[idx].Y).Average();

                    double stdDev = Math.Sqrt(listBarItems.Where(v => v.Points.Count > idx)
                                              .Select(v => v.Points[idx].Y)
                                              .Average(v => Math.Pow(v - avg, 2)));

                    //MessageBox.Show("i:" + idx + " stdDev: " + stdDev);
                    LineItem myLine = new LineItem(item.name + "Deviation",
                                                   new double[] {
                        ((float)(idx * 2 + 1)) / (listCurrentThresholds.Count() * 2) - (1.0 / (listCurrentThresholds.Count() * 2 + 1)),
                        ((float)(idx * 2 + 1)) / (listCurrentThresholds.Count() * 2) + (1.0 / (listCurrentThresholds.Count() * 2 + 1))
                    },
                                                   new double[] { stdDev, stdDev },
                                                   Color.FromArgb(240, 59, 32),
                                                   SymbolType.Diamond, 3.0f);
                    myLine.IsX2Axis = true;
                    myPane.CurveList.Add(myLine);
                }
                catch (InvalidOperationException)
                {
                }
                catch (NullReferenceException)
                {
                }
            }

            myPane.CurveList.AddRange(listBarItems);


            // Fill the axis background with a color gradient
            myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45F);

            // Fill the pane background with a color gradient
            myPane.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45F);

            //This informs ZedGraph to use the labels supplied by the user in Axis.Scale.TextLabels
            //Axis.Default.Type = AxisType.Text;

            //Show tooltips when the mouse hovers over a point
            zgc.IsShowPointValues = true;
            zgc.PointValueEvent  += new ZedGraphControl.PointValueHandler(MyPointValueHandler);

            // Set the XAxis to date type
            myPane.XAxis.Type = AxisType.Text;
            string[] thresholdNames = new string[listCurrentThresholds.Count];
            for (int i = 0; i < thresholdNames.Count(); ++i)
            {
                thresholdNames[i] = listCurrentThresholds[i].name;
            }

            myPane.XAxis.Scale.TextLabels = thresholdNames;
            myPane.XAxis.IsVisible        = true;

            myPane.X2Axis.Scale.Min = 0;
            myPane.X2Axis.Scale.Max = 1;
            myPane.X2Axis.IsVisible = false;

            myPane.YAxis.MajorGrid.IsVisible = true;
            myPane.YAxis.MinorGrid.IsVisible = true;


            // Calculate the Axis Scale Ranges
            axisChangeZedGraph(zgc); //refrsh the graph
        }