CalcGXCSendTime.java 2.77 KB
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by liuchong on 2017/11/22.
 * Copyright(c) 2017 quanmincai Co., Ltd.
 * All right reserved.
 */
public class CalcGXCSendTime {

    public static String filePath = "/Users/liuchong/Downloads/guoxinsend";
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

    public static void main(String[] args) throws Exception {
        int count500 = 0;
        int count1000 = 0;
        int count2000 = 0;
        int count5000 = 0;
        int countAll = 0;
        int countError = 0;
        File file = new File(filePath);
        File[] files = file.listFiles();
        Map<String, Long> timeMap = new HashMap<String, Long>();
        System.out.println("需要解析的文件个数是 :" + files.length);
        for (File file1 : files) {
            BufferedReader fileRead = new BufferedReader(new FileReader(file1));
            String info = "";
            while ((info = fileRead.readLine()) != null) {
                String[] line = info.substring(0, 100).split("\\|");
                //System.out.println(line);
                String time = line[0];
                String id = line[4];
                if (info.contains("|ERR|")) {
                    countAll++;
                    countError++;
                    System.out.println("id" + id + "   " + time);
                    continue;
                }
                long currentTime = sdf.parse(time).getTime();
                if (timeMap.containsKey(id)) {
                    countAll++;
                    // 送票时间
                    long startTime = timeMap.get(id);
                    long dis = currentTime - startTime;
                    if (dis <= 500) {
                        count500++;
                    }
                    if (dis <= 1000 && dis > 500) {
                        count1000++;
                    }
                    if (dis <= 5000 && dis > 1000) {
                        count2000++;
                    }
                    if (dis > 5000) {
                        count5000++;
                        //System.out.println(id+"  "+dis);
                    }
                    timeMap.remove(id);
                } else {
                    timeMap.put(id, currentTime);
                }
            }

        }
        System.out.println(timeMap.size());
        System.out.println("all      :" + countAll);
        System.out.println("<500     :" + count500);
        System.out.println("500-1000 :" + count1000);
        System.out.println("1000-2000:" + count2000);
        System.out.println(">5000    :" + count5000);
        System.out.println("Error    :" + countError);
    }

}