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 };
            }
  • 相关阅读:
    关于全景漫游
    webgl圈中物体
    css3の极限
    reactjs弹幕视频播放
    数值积分I
    显出你的h5逼格
    奇葩のbeforeunload
    面试问题搜集及解析
    TCP拥塞控制(滑动窗口机制)
    如何使CPU占用率为50%
  • 原文地址:https://www.cnblogs.com/shiruina/p/9355096.html
Copyright © 2011-2022 走看看