0
模型按不规则时间数据列表的日期进行分组,并获得日期的平均值?
public class MeterReadingsBccChartData
{
public string BranchName { get; set; }
public string TypeName { get; set; }
public string Unit { get; set; }
public List<Tuple<DateTime, double>> DateAndValue { get; set; }
public MeterReadingsBccChartData(List<Tuple<DateTime, double>> dateAndValue, string typeName, string unit, string BranchName)
{
this.DateAndValue = dateAndValue;
this.TypeName = typeName;
this.Unit = unit;
this.BranchName = BranchName;
}
}
模型到ChartSeries中方法
public static List<Series> GetBccChartData(IEnumerable<MeterReadingsBccChartData> meterReadings)
{
List<Series> series = new List<Series>();
foreach (var item in meterReadings)
{
int lenght = item.DateAndValue.Count();
object[,] data = new object[lenght, 2];
for (int i = 0; i < lenght; i++)
{
data[i, 0] = item.DateAndValue[i].Item1;
data[i, 1] = item.DateAndValue[i].Item2;
}
Series localSeries = new Series { Name = item.BranchName + " " + item.TypeName + " " + item.Unit, Data = new Data(data), Type = ChartTypes.Column };
series.Add(localSeries);
}
return series;
}
上述代码描述
我读从DB数据。数据类型是MeterReadingsBccChartData
。然后我将它转换为Series
数据类型,并将此系列存储在一个列表中。我想为此列表添加一个平均系列。但是可能没有相同日期的数据。例如我的数据看起来如下:
Series 1 : { { date : 01.01.2013, value : 5 }, { date : 02.01.2013, value : 10 } }
Series 2 : { { date : 01.01.2013, value : 11 }, { date : 03.01.2013, value : 3 } }
我要计算这些系列中,我想有些事情是这样的平均值为:
Series AVG : { { date : 01.01.2013, value : 8 }, { date : 02.01.2013, value : 10 } { date : 03.01.2013, value : 3 } }
我可以用第二个分贝取做到这一点。我获得日期之间的平均值。所以我从db获取数据两次。
有没有什么办法可以在上面的方法中计算出这个系列的avg?有小费吗?
我希望我可以解释......
谢谢...