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 };
            }
  • 相关阅读:
    接口测试如何在json中引用mock变量
    接口测试--接口文档规范
    接口测试和性能测试的区别
    接口测试和功能测试的区别
    接口请求(get、post、head等)详解
    软件测试流程
    软件测试系统学习流程和常见面试题
    接口测试之json中的key获取
    正则表达式解析
    Jmeter使用HTTPS协议
  • 原文地址:https://www.cnblogs.com/shiruina/p/9355096.html
Copyright © 2011-2022 走看看