/// <summary> /// 从闪电序列中找出制定地名的闪电数据 /// </summary> /// <param name="_strikes"></param> /// <returns></returns> private int CalculateNumber(IEnumerable <BaseStrikeChina> _strikes, AdministrativeLevel _administrativeLevelEnum, string _areaName) { int resultNum = 0; switch (_administrativeLevelEnum) { case AdministrativeLevel.Country: resultNum = _strikes.Where(r => r.Province == _areaName).Count(); break; case AdministrativeLevel.Province: resultNum = _strikes.Where(r => r.City == _areaName).Count(); break; case AdministrativeLevel.City: resultNum = _strikes.Where(r => r.City == _areaName).Count(); break; case AdministrativeLevel.Village: throw new ArgumentOutOfRangeException("不存在比县更小的行政级别"); default: throw new ArgumentOutOfRangeException("未知的行政区划级别"); } return(resultNum); }
/// <summary> /// 根据行政区划和 /// </summary> /// <param name="_strikes"></param> /// <param name="_administrativeLevelEnum"></param> /// <returns></returns> private List <string> ProcessAreaList(IEnumerable <BaseStrikeChina> _strikes, AdministrativeLevel _administrativeLevelEnum) { List <string> areaList = new List <string>(); if (_administrativeLevelEnum == AdministrativeLevel.Country) { areaList = _strikes.Select(r => r.Province).Distinct().ToList(); } else if (_administrativeLevelEnum == AdministrativeLevel.Province) { areaList = _strikes.Select(r => r.City).Distinct().ToList(); } else if (_administrativeLevelEnum == AdministrativeLevel.City) { areaList = _strikes.Select(r => r.City).Distinct().ToList(); } else if (_administrativeLevelEnum == AdministrativeLevel.County) { return(null); //无下级单位 throw new ArgumentOutOfRangeException("县无下级行政区划单位"); } else//默认为市级 { areaList = _strikes.Select(r => r.City).Distinct().ToList(); } return(areaList); }
/// <summary> /// 计算下级地区闪电分布情况。 /// </summary> /// <param name="_strikes"></param> /// <returns></returns> public Dictionary <string, int> ProcessAreaDistribution(IEnumerable <BaseStrikeChina> _strikes, AdministrativeLevel _administrativeLevelEnum) { //if (_administrativeLevelEnum) //{ Dictionary <string, int> resultDic = new Dictionary <string, int>(); List <string> areaList = new List <string>(); if (_strikes != null && _strikes.Any()) { areaList = ProcessAreaList(_strikes, _administrativeLevelEnum); if (areaList != null) { foreach (var tmp in areaList) { int resultNum = CalculateNumber(_strikes, _administrativeLevelEnum, tmp); resultDic.Add(tmp, resultNum); } return(resultDic); } else { return(null); } } else { throw new ArgumentException("下级地区分布描述处理,序列中不包含闪电。"); } }