c# - 获取响应规则的日期列表
问题描述
我有一个日期列表,例如:
- 21/12/2019
- 22/12/2019
- 22/12/2019
- 2019 年 12 月 24 日
- 2019 年 12 月 26 日
- 2019 年 12 月 26 日
- 27/12/2019
我将规则模型定义为:
public class Timing
{
public int PeriodNbMinutes { get; set; }
public int NbTimes { get; set; }
public bool IsConsecutive { get; set; }
public int Multiplicity { get; set; }
}
现在我有这样的规则:我想找到所有日期:
在 2 天内出现 3 次和出现两次的日期
所以我应该得到两组(我不想重复使用组中已经存在的日期):
第一的
第一天:21/12/2019 - 22/12/2019 - 22/12/2019
第二
第二次:26/12/2019 - 26/12/2019 - 27/12/2019
然后我有这样的规则:
this.PeriodMinutes = 2680;
this.NbTimes = 2;
this.Multiplicity = 2;
this.IsConsecutive=true;
已编辑
public int PeriodNbMinutes { get; set; }
public int NbTimes { get; set; }
public bool IsConsecutive { get; set; }
public int Multiplicity { get; set; }
internal bool Test(List<DateTime> metrics)
{
bool res = false;
int times = 0;
int multiple=0;
TimeSpan ts = new TimeSpan(0, PeriodNbMinutes, 0);
for (int i = 0; i < metrics.Count; i++)
{
var dates = metrics.Skip(i);
var selectedDts = metrics.Zip(dates, (dtFirst, dtNext) => (dtNext - dtFirst).Ticks < ts.Ticks);
if (selectedDts.Count() > 0)
{
res = true;
times++;
if (times == Multiplicity)
{
multiple++;
if (multiple == Multiplicity)
return true;
// Consecutive???
}
else res = false;
}
else
{
res = false;
times = 0;
}
}
return res;
}
如何使用 Linq 找到这些组?我尝试使用 TimeSpan 但无法正常工作。
此外,在所选的两组中,我需要知道它们是否连续。
我尝试了很多不同的解决方案,但没有什么好处。我怎样才能简单地做到这一点?
谢谢,
解决方案
推荐阅读
- java - OpenJDK 和 update-alternatives 命令
- git - Git 从 fork master 推送到远程上游分支
- python - 使用 python、BeautifulSoup 和 pandas 'read_html' 进行网络抓取的问题
- laravel - Laravel - 从第二个表中获取两个日期之间的记录
- javascript - 逐点更新单个值,无需突变和重建对象的初始结构JS
- r - R分位数函数因小值而失败
- flutter - 如何在加载应用程序之前避免图像区域显示蓝色
- python - 通过referrer header找出网络流量来源
- python - 多个绘图子图的单个滑块
- javascript - Firebase Web 登录,检查自定义值