zoukankan      html  css  js  c++  java
  • 统计每个季度的数据

     private object GetSeasonDataByYear(DateTime thisTime,
                List<DailyDialysisWayStatistic> baseStatisticsList, List<string> dialysisWayList)
            {
                //源格式:透析方式-季度数组
                List<Tuple<string, object>> tupleList = new List<Tuple<string, object>>();
    
                var seasonGroups = new[] { "第一季度", "第二季度", "第三季度", "第四季度" };
                dialysisWayList.ForEach(y =>
                {
                    int[] countGroups = new int[4];
                    for (int i = 1; i <= seasonGroups.Length; i++)
                    {
                        DateTime[] seasonDate = GetSeasonDate(thisTime.Year, i);
                        var count = baseStatisticsList
                            .Where(z => z.DialysisWay == y && z.DialysisDate >= seasonDate.First() &&
                                        z.DialysisDate <= seasonDate.Last())
                            .Sum(x => x.Frequency);
                        countGroups[i - 1] = count;
                    }
                    tupleList.Add(new Tuple<string, object>(y, countGroups));
                });
    
                return new { seasonGroups, tupleList };
            }
    
    
    
     /// <summary>
            /// 获取输入年-季度的第一天与最后一天
            /// </summary>
            /// <param name="thisYear">当前年</param>
            /// <param name="seasonNum">季度序号</param>
            /// <returns></returns>
            private DateTime[] GetSeasonDate(int thisYear, int seasonNum = 1)
            {
                var firstDate = new DateTime(thisYear, (seasonNum - 1) * 3 + 1, 1);
    
                //季度最后一天默认30号,1-4季度为31号.
                var day = seasonNum == 1 || seasonNum == 4 ? 31 : 30;
                var lastDate = new DateTime(thisYear, (seasonNum - 1) * 3 + 3, day);
    
                return new[] { firstDate, lastDate };
            }
  • 相关阅读:
    shell学习(三)
    shell学习(四)
    自定义yum源
    fpm制作rpm包
    shell学习(三)
    shell学习(二)
    linux系统下创建lvm挂载到指定目录
    nginx做代理安装docker
    df -h命令卡死解决办法
    docker安装
  • 原文地址:https://www.cnblogs.com/shiruina/p/9355096.html
Copyright © 2011-2022 走看看