首页 > 其他分享 >5.19

5.19

时间:2024-05-19 23:08:12浏览次数:15  
标签:map stats HashMap month new getOrDefault 5.19

学习记录app 完结 撒花 ~~~

下面是今天一天的努力成果

统计月份 和 每个月的次数 和 各个分段等级的次数

  public Map<String, Map<String, Integer>> statistic(Integer userId) {
        List<Plan> plans = planMapper.allPlan(userId);
        Map<String, Map<String, Integer>> map = new HashMap<>();
        Map<String, Integer> monthlyStatistics = new HashMap<>();

        // Define multiple formatters for different millisecond lengths
        DateTimeFormatter[] formatters = {
                DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"),
                DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS"),
                DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"),
                DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
        };
        DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");

        for (Plan plan : plans) {
            String dateString = plan.getDate().toString();
            LocalDateTime dateTime = null;

            // Try each formatter until one succeeds
            for (DateTimeFormatter formatter : formatters) {
                try {
                    dateTime = LocalDateTime.parse(dateString, formatter);
                    break;
                } catch (DateTimeParseException e) {
                    // Ignore and try the next formatter
                }
            }

            // If none of the formatters succeeded, throw an exception
            if (dateTime == null) {
                throw new IllegalArgumentException("Invalid date format: " + dateString);
            }

            // Format to year-month
            String month = dateTime.format(monthFormatter);

//            monthlyStatistics.put(month, monthlyStatistics.getOrDefault(month, 0) + 1);
//            map.getOrDefault(month,new HashMap<>()).put("count", map.getOrDefault(month,new HashMap<>()).getOrDefault("count",0) + 1);
//            if (plan.getAnalyse() != null) {
//                switch (plan.getAnalyse()) {
//                    case "很差" ->
//                            map.getOrDefault(month,new HashMap<>()).put("1", map.getOrDefault(month,new HashMap<>()).getOrDefault("1",0) + 1);
//                    case "及格" ->
//                            map.getOrDefault(month,new HashMap<>()).put("2", map.getOrDefault(month,new HashMap<>()).getOrDefault("2",0) + 1);
//                    case "良好" ->
//                            map.getOrDefault(month,new HashMap<>()).put("3", map.getOrDefault(month,new HashMap<>()).getOrDefault("3",0) + 1);
//                    case "优秀" ->
//                            map.getOrDefault(month,new HashMap<>()).put("4", map.getOrDefault(month,new HashMap<>()).getOrDefault("4",0) + 1);
//                }
//            }

            Map<String, Integer> stats = map.computeIfAbsent(month, k -> new HashMap<>());

            // Update the count for the month
            stats.put("count", stats.getOrDefault("count", 0) + 1);

            // Update the analysis count
            if (plan.getAnalyse() != null) {
                switch (plan.getAnalyse()) {
                    case "很差" -> stats.put("1", stats.getOrDefault("1", 0) + 1);
                    case "及格" -> stats.put("2", stats.getOrDefault("2", 0) + 1);
                    case "良好" -> stats.put("3", stats.getOrDefault("3", 0) + 1);
                    case "优秀" -> stats.put("4", stats.getOrDefault("4", 0) + 1);
                }
            }

        }
        return map;
    }

标签:map,stats,HashMap,month,new,getOrDefault,5.19
From: https://www.cnblogs.com/258-333/p/18200920

相关文章

  • 5.19
    今天早上用洛天依的【数据删除】出了知更鸟,小保底79抽,赢赢赢,劳莹那么好的设计谁抽啊试玩了一下文心一言,让他给我写线段树启发式合并,写的还挺板的(?以下为AI所作(不保证准确性#include<bits/stdc++.h>usingnamespacestd;constintMAXN=1e5+5;constintMAXM......
  • 周日下 5.19
    1.斐波那契数列,变量版,变量覆盖a=1,b=1;for(inti=1;i<=n;i++){cout<<a+b<<””a=b;b=c}2.进击的奶牛前置版:变量覆盖cnt=1;pre=a[1]; for(inti=2;i<=n;i++){ if(a[i]-pre>=mid){ cnt++,pre=a[i]; } }3.分段数列:变量版,数......
  • 2024.5.19
    2024.5.19【人啊...想要保护重要东西的时候,就真的能变得很坚强。】Sunday四月十二模拟赛A.楼兰图腾在完成了分配任务之后,西部314来到了楼兰古城的西部。相传很久以前这片土地上(比楼兰古城还早)生活着两个部落,一个部落崇拜尖刀(V),一个部落崇拜铁锹(∧),他们分别用V......
  • mellanox ib card芯片型号是ConnectX-6操作系统centos 7.6升级完内核5.19 .4后,安装驱
    在升级内核后,有时候需要重新编译和安装驱动以适配新的内核版本。以下是一些可能的解决步骤:确保内核头文件已安装:在升级内核后,可能需要安装新内核版本的头文件。使用以下命令安装:bashCopycodesudoyuminstallkernel-devel-$(uname-r)kernel-headers-$(uname-r)确保......
  • 5.19
    function[x_opt,f_opt,iter]=steepest_descent()%定义目标函数f=@(x)100*(x(1)^2-x(2))^2+(x(1)-1)^2;%计算目标函数的梯度grad_f=@(x)[400*x(1)*(x(1)^2-x(2))+2*(x(1)-1);-200*(x(1)^2-x(2))];%定义终止准则epsilon=1e-5;%设置初始点x0_lis......
  • 5.19 面向对象案例分析一
    classAddress{privateStringcountry;privateStringprovince;privateStringcity;privateStringstreet;privateStringzipcode;publicAddress(){}publicAddress(Stringcountry,Stringprovince,Stringcity,Stringstr......
  • 2305.19270Learning without Forgetting for Vision-Language Models
    https://arxiv.org/pdf/2305.19270.pdf2305.19270.pd  AbstractClass-IncrementalLearning(CIL)orcontinuallearningisadesiredcapabilityintherealworld,whichrequiresalearningsystemtoadapttonewtaskswithoutforgettingformerones.Whiletradi......
  • 5.19
     #include<bits/stdc++.h>usingnamespacestd;intmain(){longn,sum,i;while(cin>>n!=EOF){cout<<"在之间的阶梯数为"<<endl;sum=0;for(i=7;i<=n;i++)if(i......
  • 2023.5.19——软件工程日报
    所花时间(包括上课):6h代码量(行):0行博客量(篇):1篇今天,上午学习,下午学习。我了解到的知识点:1.了解了一些数据库的知识;2.了解了一些python的知识;3.了解了一些英语知识;5.了解了一些Javaweb的知识;4.了解了一些数学建模的知识;6.了解了一些计算机网络的知识;......
  • 每日总结-23.5.19
    <%@pagecontentType="text/html;charset=UTF-8"language="java"%><html><head><title>添加用户</title><style>body{background-color:#f2f2f2;font-family:Aria......