某一天,24小时统计数据的整理。

public List getForStatisticDayToTimeList(String day) {
  List newList = new ArrayList();  //组建新的List
  List list = this.getStatisticDao().getForStatisticDayToTimeList(day);  //查询统计List;
  Iterator iterator = list.iterator(); 
  String time[] = new String[] { "0:00 - 1:00", "1:00 - 2:00",
    "2:00 - 3:00", "3:00 - 4:00", "4:00 - 5:00", "5:00 - 6:00",
    "6:00 - 7:00", "7:00 - 8:00", "8:00 - 9:00", "9:00 - 10:00",
    "10:00 - 11:00", "11:00 - 12:00", "12:00 - 13:00",
    "13:00 - 14:00", "14:00 - 15:00", "15:00 - 16:00",
    "16:00 - 17:00", "17:00 - 18:00", "18:00 - 19:00",
    "19:00 - 20:00", "20:00 - 21:00", "21:00 - 22:00",
    "22:00 - 23:00", "23:00 - 24:00" };  //时间数组
  int i = 0;
  StatisticDayObj statisticTimeIsNull = null;
        while (iterator.hasNext()) {
   StatisticDayObj statisticTime = (StatisticDayObj) iterator.next(); // 每个时间段统计的数据
   int TimeForClock = Integer.parseInt(statisticTime.getVisitTime()); // 统计时间
   if (TimeForClock != i) {//填充空的时间段数据
              while (true) {
     if (TimeForClock == i) {
      break;
     } else {
      statisticTimeIsNull = new StatisticDayObj();
      statisticTimeIsNull.setVisitTime(time[i]);
      statisticTimeIsNull.setVisiterAvgCount(0.0);
      statisticTimeIsNull.setVisiterCount(0);
      statisticTimeIsNull.setPageCount(0);
      statisticTimeIsNull.setIpCount(0);
      newList.add(statisticTimeIsNull);
      i++;
     }

    }

   }
            if (statisticTime.getVisiterCount() != 0){ // 除数不能为0 
    statisticTime.setVisiterAvgCount(statisticTime.getPageCount()/ (double) statisticTime.getVisiterCount());
   }
    statisticTime.setVisitTime(time[TimeForClock]);  //格式化时间
   newList.add(statisticTime);
   i++;
  }
       return newList;
 }

 

 

测试,打印如下:

0:00 - 1:00
0
0.0
0
0
1:00 - 2:00
0
0.0
0
0
2:00 - 3:00
0
0.0
0
0
3:00 - 4:00
0
0.0
0
0
4:00 - 5:00
0
0.0
0
0
5:00 - 6:00
2
1.0
2
1
6:00 - 7:00
0
0.0
0
0
7:00 - 8:00
1
1.0
1
1
8:00 - 9:00
0
0.0
0
0
9:00 - 10:00
0
0.0
0
0
10:00 - 11:00
0
0.0
0
0
11:00 - 12:00
1
1.0
1
1
12:00 - 13:00
0
0.0
0
0
13:00 - 14:00
1
1.0
1
1
14:00 - 15:00
0
0.0
0
0
15:00 - 16:00
2
1.0
2
1
16:00 - 17:00
0
0.0
0
0
17:00 - 18:00
1
13.0
13
1
18:00 - 19:00
2
1.0
2
1
19:00 - 20:00
0
0.0
0
0
20:00 - 21:00
1
1.0
1
1
21:00 - 22:00
0
0.0
0
0
22:00 - 23:00
1
1.0
1
1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值