Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 每周的组和平均时间跨度_C#_Asp.net_Charts_Grouping_Timespan - Fatal编程技术网

C# 每周的组和平均时间跨度

C# 每周的组和平均时间跨度,c#,asp.net,charts,grouping,timespan,C#,Asp.net,Charts,Grouping,Timespan,我有许多不同日期时间的记录,但我需要以图形布局跟踪这些记录。我目前已设法检索到每条记录的时间跨度 List<myclass> recs = context.myclass.Where(c => c.RequestedTimestamp >= start & c.DeliveredTimestamp <= end).ToList(); foreach (var item in recs) { TimeSpan diff = (TimeSpan)(i

我有许多不同日期时间的记录,但我需要以图形布局跟踪这些记录。我目前已设法检索到每条记录的时间跨度

List<myclass> recs = context.myclass.Where(c => c.RequestedTimestamp >= start & c.DeliveredTimestamp <= end).ToList();

foreach (var item in recs) 
{
    TimeSpan diff = (TimeSpan)(item.DeliveredTimestamp - item.RequestedTimestamp);

    //more to come, this is where I realized I have issues
}

List recs=context.myclass.Where(c=>c.RequestedTimestamp>=start&c.DeliveredTimestamp这可能不是可用的最佳解决方案,并且逻辑中存在一些明确的漏洞,但是目前这是一个工作到所需程度的解决方案(低优先级系统因此不需要高精度)。
另外,很抱歉这里有很多被删的变量,比如类名等等,我知道读起来更痛苦

public static List<ChartPoint> RenderWeeklyAverageChart(List<myclass> myclass, DateTime start, DateTime end)
        {
            DateTime datePointer = start; //1st date in list
            List<ChartPoint> points = new List<ChartPoint>();
            double average = 0;

            if (myclass!= null && myclass.Count > 0)
            {
                while (datePointer < DateTime.Now)
                {
                    //Filter By Selected Week
                    List<myclass> Weekmyclass = myclass.Where(c => c.RequestedTimestamp >= datePointer &&
                        c.RequestedTimestamp < datePointer.AddDays(7)).ToList();
                    //If there are records, find the average timespan of the records
                    if (Weekmyclass != null && Weekmyclass.Count > 0)
                    {
                        long ticks = (long)WeekSlabs.Average(c => (c.DeliveredTimestamp.Value - c.RequestedTimestamp.Value).Ticks);
                        average = TimeSpan.FromTicks(ticks).TotalHours;

                        points.Add(new ChartPoint
                        {
                            PointValue = average,
                            AxisXText = datePointer.ToShortDateString() + " - "
                                        + datePointer.AddDays(7).ToShortDateString()
                        });
                    }
                    else
                    {
                        //Otherwise Add a Zero Record
                        points.Add(new ChartPoint
                        {
                            PointValue = 0,
                            AxisXText = datePointer.ToShortDateString() + " - "
                                        + datePointer.AddDays(7).ToShortDateString()
                        });
                    }
                    datePointer = datePointer.AddDays(7);
                }
            }
            return points;
        }
公共静态列表RenderWeeklyAverageChart(列出myclass、DateTime开始、DateTime结束)
{
DateTime datePointer=start;//列表中的第一个日期
列表点=新列表();
双平均=0;
if(myclass!=null&&myclass.Count>0)
{
while(datePointerc.RequestedTimestamp>=datePointer&&
c、 RequestedTimestamp0)
{
长滴答声=(长)周实验室.Average(c=>(c.DeliveredTimestamp.Value-c.RequestedTimestamp.Value).ticks);
平均=TimeSpan.FromTicks(ticks).TotalHours;
添加(新图表点)
{
PointValue=平均值,
AxisXText=datePointer.ToSortDateString()+“-”
+datePointer.AddDays(7.ToSortDateString())
});
}
其他的
{
//否则,添加一个零记录
添加(新图表点)
{
PointValue=0,
AxisXText=datePointer.ToSortDateString()+“-”
+datePointer.AddDays(7.ToSortDateString())
});
}
datePointer=datePointer.AddDays(7);
}
}
返回点;
}

目前您的问题尚不清楚。您在
foreach
中计算的
时间跨度有什么问题?您没有创建列表,因此我不理解“将返回一个时间跨度列表”.你在foreach做什么,为什么它不能按预期工作?或者你实际上想要实现什么?这里不清楚。
TimeSpan
不允许你按周或月平均值分组,因为
TimeSpan
只是一个任意的时间量。我想你真正要求的是分组你的
rec
不知何故,每周都会得到每一组中每一项的时间跨度。我忘了在foreach中列出我的清单,因为我排到了一半,被难住了,意识到我所想的并不是我所希望的。至于时间跨度,我提到我意识到它只是一个没有参考点的数字。但是,是的,jonesy,我想按周/月分组,然后找到该组的平均时间跨度。这里也可能存在时区问题。我假设可以在许多不同的时区进行交付。您的时间戳是UTC还是当地时间?您根据谁的角度分组-收到交付的人?还是查看报告的人T?你也可以考虑使用,而不是<代码>日期时间>代码>时区不是问题,时间戳都在一个本地时区内。IM认为这些组将来自交付的时间戳,然而实际上,这些时间戳都应该在一天内真正存在,除非有问题。的应用程序只能在一个区域中访问