/// <summary>
 /// Check the data returned by Wind is correct
 /// </summary>
 /// <param name="wd">Wind Data Format</param>
 public static void windEnsureNoErr(WindData wd)
 {
     if (wd.errorCode != 0)
     {
         throw new Exception("windEnsureConnect: " + wd.GetErrorMsg());
     }
 }
        private static int checkError(WindData wd)
        {
            string s = string.Empty;

            if (wd.errorCode != 0)
            {
                s += wd.GetErrorMsg() + Environment.NewLine;
                return(-1);
            }
            return(0);
        }
Exemple #3
0
        public static string WindDataToString(WindData wd, string strFuncName)
        {
            if (null == wd)
            {
                return(string.Empty);
            }

            string s   = string.Empty;
            string str = string.Empty;

            //请求出错,获取错误信息
            if (wd.errorCode != 0)
            {
                s += wd.GetErrorMsg() + Environment.NewLine;

                return(s);
            }

            if (null != wd.codeList)
            {
                s += "Windcode = " + Environment.NewLine;
                foreach (String code in wd.codeList)
                {
                    s += "  " + code + "\t";
                }
                s += Environment.NewLine;
            }
            if (null != wd.fieldList)
            {
                s += "Indicators = " + Environment.NewLine;
                foreach (String field in wd.fieldList)
                {
                    s += "  " + field + "\t";
                }
                s += Environment.NewLine;
            }
            if (null != wd.timeList)
            {
                s += "Times = " + Environment.NewLine;
                foreach (DateTime time in wd.timeList)
                {
                    s += "  " + time.ToString() + "\t";
                }
                s += Environment.NewLine;
            }

            s += "Data = " + Environment.NewLine;
            object getData = wd.getDataByFunc(strFuncName, false);

            if (getData is object[, ])//转化为2维数组
            {
                object[,] odata = (object[, ])getData;

                switch (strFuncName)
                {
                case "wsd":
                {
                    string strColHead = string.Empty;
                    strColHead += "Time" + "\t\t";
                    foreach (String field in wd.fieldList)
                    {
                        strColHead += field + "\t";
                    }
                    strColHead += Environment.NewLine;

                    s = strColHead;

                    int nTimeLength  = wd.timeList.Length;
                    int nCodeLength  = wd.codeList.Length;
                    int nFieldLength = wd.fieldList.Length;
                    for (int i = 0; i < nTimeLength; i++)
                    {
                        s += wd.timeList[i].ToString("yyyy-MM-dd") + "\t";
                        for (int j = 0; j < nCodeLength * nFieldLength; j++)
                        {
                            str = odata[i, j].ToString();
                            s  += str + "\t";
                        }
                        s += Environment.NewLine;
                    }
                }
                break;

                case "wsi":
                case "wst":
                {
                    string strColHead      = string.Empty;
                    bool   bNeedOutputTime = true;
                    foreach (String field in wd.fieldList)
                    {
                        if (field == "time")
                        {
                            strColHead     += field + "\t\t\t";
                            bNeedOutputTime = false;
                        }
                        else
                        {
                            strColHead += field + "\t";
                        }
                    }
                    if (bNeedOutputTime)
                    {
                        strColHead = "time" + "\t\t\t" + strColHead;
                    }
                    strColHead += Environment.NewLine;

                    s = strColHead;

                    int nTimeLength  = wd.timeList.Length;
                    int nCodeLength  = wd.codeList.Length;
                    int nFieldLength = wd.fieldList.Length;
                    for (int i = 0; i < nTimeLength; i++)
                    {
                        if (bNeedOutputTime)
                        {
                            s += wd.timeList[i].ToString() + "\t";
                        }

                        for (int j = 0; j < nCodeLength * nFieldLength; j++)
                        {
                            str = odata[i, j].ToString();
                            s  += str + "\t";
                        }
                        s += Environment.NewLine;
                    }
                }
                break;

                case "wsq":
                case "wss":
                case "wset":
                case "wpf":
                {
                    string strColHead = string.Empty;
                    foreach (String field in wd.fieldList)
                    {
                        strColHead += field + "\t";
                    }

                    s = strColHead + Environment.NewLine;

                    int nTimeLength  = wd.timeList.Length;
                    int nCodeLength  = wd.codeList.Length;
                    int nFieldLength = wd.fieldList.Length;
                    for (int i = 0; i < nCodeLength; i++)
                    {
                        if (i > 100)
                        {
                            break;
                        }
                        s += wd.codeList[i] + "\t";
                        for (int j = 0; j < nTimeLength * nFieldLength; j++)
                        {
                            if (null != odata[i, j])
                            {
                                str = odata[i, j].ToString();
                                s  += str + "\t";
                            }
                        }
                        s += Environment.NewLine;
                    }
                }
                break;

                default:
                {
                    foreach (object o in odata)
                    {
                        str = o.ToString();
                        s  += str + "\t";
                    }
                    s += Environment.NewLine;
                }
                break;
                }
            }
            else if (getData is object[])//一维数组
            {
                object[] odata = (object[])getData;
                foreach (object o in odata)
                {
                    str = o.ToString();
                    s  += str + Environment.NewLine;
                }
            }
            else//简单对象
            {
                s += getData.ToString() + Environment.NewLine;
            }

            return(s);
        }
Exemple #4
0
        static string WindDataToSerialize(WindData wd, string windFuncName)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            serializer.MaxJsonLength = Int32.MaxValue;
            serializer.RegisterConverters(new JavaScriptConverter[] { new ExpandoJSONConverter() });

            //请求出错,获取错误信息
            if (wd.errorCode != 0)
            {
                return(serializer.Serialize(wd.GetErrorMsg()));
            }

            // OutputWindData(wd, "wsd");
            // OutputWindData(wd, "edb");
            // Console.WriteLine(serializer.Serialize(wd.data));

            object[,] odata = (object[, ])wd.getDataByFunc(windFuncName, false);
            int nTimeLength  = wd.timeList.Length;
            int nCodeLength  = wd.codeList.Length;
            int nFieldLength = wd.fieldList.Length;
            int nDataLength  = wd.GetDataLength();

            // Console.WriteLine(string.Format("nTimeLength={0} nCodeLength={1} nFieldLength={2}", nTimeLength, nCodeLength, nFieldLength));

            // for (int i = 0; i < odata.GetLength(0);i++ )
            // {
            //     for (int j = 0; j < odata.GetLength(1); j++)
            //     {
            //          Console.WriteLine("维度 {0} {1} 的值为 {2}", i, j, odata[i, j]);
            //     }
            // }
            // Console.WriteLine(nDataLength);

            dynamic[] rows       = new ExpandoObject[nDataLength];
            int       indexTime  = 0;
            int       indexCode  = 0;
            int       indexField = 0;

            for (int i = 0; i < nDataLength; i++)
            {
                indexTime  = (int)Math.Ceiling((float)(i + 1) / (float)(nCodeLength * nFieldLength)) - 1;
                indexCode  = (i) % nCodeLength;
                indexField = (i) % nFieldLength;
                // MAC_IND_API Urban;
                // Urban.END_DATE = wd.timeList[i].ToString("yyyy-MM-dd");
                // Urban.DATA_FREQ_PAR = 5;
                // Urban.MAC_IDX_PAR = 1001;
                // Urban.PRC_UNIT = "万人";
                // Urban.IDX_VAL = Convert.ToSingle(odata[i, 0].ToString());
                // Console.WriteLine(Urban.ToString());

                dynamic o = new ExpandoObject();
                o.time  = wd.timeList[indexTime].ToString("yyyy-MM-dd");
                o.code  = wd.codeList[indexCode];
                o.field = wd.fieldList[indexField];
                o.value = odata[indexTime, indexCode *nFieldLength + indexField];
                // o.value = Double.IsNaN((double)odata[indexTime, indexCode]) ? 0 : odata[indexTime, indexCode];
                rows[i] = o;
                // Console.WriteLine(string.Format("{0} {1} {2} {3}", o.time, o.code, o.field, o.value));
            }
            String serialization = serializer.Serialize(rows);

            return(serialization);
        }