Exemplo n.º 1
0
        /// <summary>
        /// 加载boundsParams用于计算
        /// </summary>
        /// <returns></returns>
        private List <AqiParam> PermutationParams()
        {
            List <AqiParam> apList = new List <AqiParam>();
            //扩展参数
            List <AqiParam> apListTemp = AqiParam.CreateListFormJson(this, this.Tag, "Params");

            //根据 扩展参数 生成最终参数
            foreach (AqiParam apTemp in apListTemp)
            {
                Dictionary <string, string[]> data = new Dictionary <string, string[]>();

                foreach (var kv in apTemp)
                {
                    string[] v = kv.Value.Split('.');

                    data.Add(kv.Key, v);
                }
                List <Dictionary <string, string> > result = new List <Dictionary <string, string> >();
                ForPermutation(data, ref result);

                foreach (Dictionary <string, string> map in result)
                {
                    AqiParam ap = new AqiParam(apTemp, map);
                    apList.Add(ap);
                }
            }

            return(apList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 加载depthsParams用于计算
        /// </summary>
        /// <returns></returns>
        private List <AqiParam> loadDepthsParams()
        {
            List <AqiParam> apList = new List <AqiParam>();
            //扩展参数
            List <AqiParam> apListTemp = AqiParam.CreateListFormJson(this, this.Tag, "depthsParams");

            //根据 扩展参数 生成最终参数
            foreach (AqiParam apTemp in apListTemp)
            {
                int idS = Int32.Parse(apTemp["yearidStart"]);
                int idE = Int32.Parse(apTemp["yearidEnd"]);
                int idD = Int32.Parse(apTemp["yearidDepth"]);

                for (int yearid = idS; yearid <= idE; yearid++)
                {
                    int id = yearid % 100;
                    if (id > idD)
                    {
                        yearid = (yearid / 100) * 100 + 101;
                        continue;
                    }
                    AqiParam ap = new AqiParam(apTemp.Name + "\\" + yearid);
                    ap.Add("", yearid.ToString());
                    apList.Add(ap);
                }
            }

            return(apList);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 加载参数
        ///     可以重写
        /// </summary>
        /// <returns></returns>
        public virtual bool LoadParams()
        {
            switch (ParamSourceType)
            {
            case AqiConstant.ParamSourceType.JSON:
                this.listParamCache   = AqiParam.CreateListFormJson(this, this.Tag, AqiParam.PARAMS);
                this.dtParamCacheTime = AqiParam.ReadWriteTimeFormJson(this);
                break;

            case AqiConstant.ParamSourceType.ISrcUrl:
                if (this is IParseSrcUrlParam)
                {
                    IParseSrcUrlParam ipp = this as IParseSrcUrlParam;
                    this.listParamCache   = AqiParam.CreateListFormSrcUrl(ipp, ipp.ParamSrcUrl);
                    this.dtParamCacheTime = DateTime.Now;
                }
                else
                {
                    throw new ParamException("参数来源类型(ISRCUrl)与接口(IParseParam)不匹配");
                }
                break;

            default:
                throw new ParamException("参数来源类型(ParamSourceType)未知");
            }
            //TODO
            //验证参数是否匹配ParamName


            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 加载boundsParams用于计算
        /// </summary>
        /// <returns></returns>
        private List <AqiParam> loadBoundsParams()
        {
            List <AqiParam> apList = new List <AqiParam>();
            //扩展参数
            List <AqiParam> apListTemp = AqiParam.CreateListFormJson(this, this.Tag, "boundsParams");

            //根据 扩展参数 生成最终参数
            foreach (AqiParam apTemp in apListTemp)
            {
                double lonS     = double.Parse(apTemp["lonStart"]);
                double latS     = double.Parse(apTemp["latStart"]);
                double lonEnd   = double.Parse(apTemp["lonEnd"]);
                double latEnd   = double.Parse(apTemp["latEnd"]);
                double increase = double.Parse(apTemp["increase"]);

                for (double lon = lonS; lon < lonEnd; lon = lon + increase)
                {
                    for (double lat = latS; lat < latEnd; lat = lat + increase)
                    {
                        AqiParam ap = new AqiParam("[枚举图块]\\" + apTemp.Name + "\\" + lon.ToString() + "-" + lat.ToString());
                        //ap.Add("", createurlByLonLat(lon, lat, increase));

                        ap.Add("lurlv2", apTemp["lurlv2"]);
                        ap.Add("z", apTemp["z"]);
                        ap.Add("bounds", createUrlByLonLat(lon, lat, increase));

                        apList.Add(ap);
                    }
                }
            }

            return(apList);
        }
Exemplo n.º 5
0
        public List <AqiParam> ParseParam(byte[] data)
        {
            List <AqiParam> list      = AqiParam.CreateListFormJson(this, this.Tag, AqiParam.PARAMS);
            List <AqiParam> listParam = new List <AqiParam>();

            string json = Encoding.UTF8.GetString(data);

            JObject jo    = JObject.Parse(json);
            JToken  jdata = jo.GetValue("data");

            if (!(jdata is JArray))
            {
                throw new DataDifferentException("与预期的数据不一致(JSON对象应该包含data属性),可能数据源已经发生变化");
            }
            JEnumerable <JToken> je = jdata.Children();

            foreach (JToken j in je)
            {
                if (!(j is JObject))
                {
                    throw new DataDifferentException("与预期的数据不一致(JSON数组子元素应该是对象),可能数据源已经发生变化");
                }
                JObject joOne = j as JObject;
                JToken  jcity = joOne.GetValue("xzqdm");
                if (jcity == null)
                {
                    throw new DataDifferentException("与预期的数据不一致(JSON数组对象应该包含xzqdm属性),可能数据源已经发生变化");
                }
                JToken jstationname = joOne.GetValue("zdmc");
                if (jstationname == null)
                {
                    throw new DataDifferentException("与预期的数据不一致(JSON数组对象应该包含zdmc属性),可能数据源已经发生变化");
                }
                JToken jstation = joOne.GetValue("zddm");
                if (jstation == null)
                {
                    throw new DataDifferentException("与预期的数据不一致(JSON数组对象应该包含zddm属性),可能数据源已经发生变化");
                }

                foreach (AqiParam p in list)
                {
                    AqiParam ap = new AqiParam(p["pollutant"] + @"\" + jstation.ToString() + "-" + jstationname.ToString());
                    ap.Add("pollutant", p["pollutant"]);
                    ap.Add("timestart", DateTime.Now.AddDays(-1).ToString("yyyyMMddHH0000"));
                    ap.Add("timeend", DateTime.Now.ToString("yyyyMMddHH0000"));
                    ap.Add("citycode", jcity.ToString());
                    ap.Add("stationcode", jstation.ToString());
                    listParam.Add(ap);
                }
            }

            return(listParam);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 加载boundsParams用于计算
        /// </summary>
        /// <returns></returns>
        private List <AqiParam> loadBoundsParams()
        {
            List <AqiParam> apList = new List <AqiParam>();
            //扩展参数
            List <AqiParam> apListTemp = AqiParam.CreateListFormJson(this, this.Tag, "boundsParams");

            //根据 扩展参数 生成最终参数
            foreach (AqiParam apTemp in apListTemp)
            {
                int yearS = DateTime.Now.Year;
                int yearE = DateTime.Now.Year;
                if (apTemp.ContainsKey("yearStart"))
                {
                    yearS = Int32.Parse(apTemp["yearStart"]);
                }
                if (apTemp.ContainsKey("yearEnd"))
                {
                    yearE = Int32.Parse(apTemp["yearEnd"]);
                }

                if (yearS > yearE)
                {
                    //错误
                    throw new ParamException("开始年份大于结束年份");
                }

                for (int year = yearS; year <= yearE; year++)
                {
                    AqiParam ap = new AqiParam(apTemp.Name + "\\" + year.ToString());
                    ap.Group = apTemp.Group;
                    ap.Add("", year.ToString());
                    apList.Add(ap);
                }
            }

            return(apList);
        }