List<string> NotCheckstationinfo = stationinfo.Where(i => i.分类 == "应用气象观测站" && i.分类 != "应用气象观测站(便捷)").Select(it => it.台站号).ToList();做出限制后,为什么还会有应用气象观测站(便捷)站点被列为异常站点
时间: 2024-03-03 07:52:20 浏览: 26
根据代码,使用LINQ语句对站点信息进行筛选时,只选取分类为"应用气象观测站"且不为"应用气象观测站(便捷)"的站点信息。因此,如果有"应用气象观测站(便捷)"的站点被列为异常站点,那么可能是因为这些站点的分类信息被错误地标记为了"应用气象观测站",或者是站点信息中没有正确地记录站点的分类信息。在这种情况下,需要检查站点信息的分类信息是否准确,并且可能需要对代码中的站点分类筛选条件进行修正。
相关问题
List<string> NotChectkstationinfo = stationinfo.Where(i => i.分类 == "应用气象观测站"&i.分类!="便携").Select(it => it.台站号).ToList();这段为什么错误
这段代码中存在两个问题:
1. `&` 应该改成 `&&`,因为 `&` 是按位与运算符,而 `&&` 才是逻辑与运算符。
2. `i.分类!="便携"` 中的感叹号 `!` 应该放在等号 `=` 前面,变成 `i.分类 != "便携"`。
修改后的代码如下:
```
List<string> NotCheckstationinfo = stationinfo.Where(i => i.分类 == "应用气象观测站" && i.分类 != "便携").Select(it => it.台站号).ToList();
```
这样就可以正确筛选出分类为“应用气象观测站”且不为“便携”的台站号了。
List<string> NotCheckstationinfo = stationinfo.Where(i => i.分类 == "应用气象观测站" || i.分类 == "应用气象观测站(便捷)").Select(it => it.台站号).ToList(); loginfo.Info($"获取{dt.ToString("yyyy-MM-dd HH:00")}区域气象站天元信息"); re = GetObservData(token, RegionalStationConfig, dt); List<string> NotChectkstationinfo = new List<string>(); //新增 re.rows = re.rows.Where(it => !NotChectkstationinfo.Contains(it.station_code)).ToArray(); re.total = re.rows.Count(); if (re.total != 0) { foreach (var item in re.rows) { Ty_Monitor monitor = new Ty_Monitor(); monitor.observtime = dt; monitor.stationumber = item.station_code; monitor.region = item.town_name; monitor.type = ObservType.区域站.ToString(); int hour = dt.Hour; int yushu = hour % 8; int group = hour / 8 + 1; string type = string.Empty; switch (group) { case 1: type = item.group1.Substring(yushu * 2, 2); break; case 2: type = item.group2.Substring(yushu * 2, 2); break; case 3: type = item.group3.Substring(yushu * 2, 2); break; } monitor.errortype = int.Parse(type); Monitors.Add(monitor); } }依旧会把应用气象站(便捷)视为异常站点是为什么
根据代码,可能是因为在获取数据之前,已经将应用气象站(便捷)的台站号添加到了NotCheckstationinfo列表中,但在筛选数据时,使用的是名为NotChectkstationinfo的空列表,所以筛选时并没有排除应用气象站(便捷)的台站数据。
解决方法是,将列表名统一改为NotCheckstationinfo,并且在获取数据之前,先清空该列表,以防之前的数据对结果造成影响。代码修改如下:
```
List<string> NotCheckstationinfo = stationinfo.Where(i => i.分类 == "应用气象观测站" || i.分类 == "应用气象观测站(便捷)").Select(it => it.台站号).ToList();
loginfo.Info($"获取{dt.ToString("yyyy-MM-dd HH:00")}区域气象站天元信息");
re = GetObservData(token, RegionalStationConfig, dt);
NotCheckstationinfo.Clear(); //清空列表
re.rows = re.rows.Where(it => !NotCheckstationinfo.Contains(it.station_code)).ToArray();
re.total = re.rows.Count();
if (re.total != 0)
{
foreach (var item in re.rows)
{
Ty_Monitor monitor = new Ty_Monitor();
monitor.observtime = dt;
monitor.stationumber = item.station_code;
monitor.region = item.town_name;
monitor.type = ObservType.区域站.ToString();
int hour = dt.Hour;
int yushu = hour % 8;
int group = hour / 8 + 1;
string type = string.Empty;
switch (group)
{
case 1: type = item.group1.Substring(yushu * 2, 2); break;
case 2: type = item.group2.Substring(yushu * 2, 2); break;
case 3: type = item.group3.Substring(yushu * 2, 2); break;
}
monitor.errortype = int.Parse(type);
Monitors.Add(monitor);
}
}
```
相关推荐
![png](https://img-home.csdnimg.cn/images/20210720083516.png)
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)