package com.analysis.code;

import org.apache.commons.lang3.StringUtils;

import java.io.*;
import java.net.URL;
import java.util.*;

/**
 * Created by Zephery on 2016/9/26.
 */
public class ThirdTest {
    public static boolean judgeURL(String line) throws Exception {         //判断来源的主域名
        String lineformat = java.net.URLDecoder.decode(line, "utf-8");
        URL url = new URL(lineformat);
        String host = url.getHost();
        //System.out.println(host);
        if (host != null) {
            if (!host.equals("api.app.happyjuzi.com") && !host.equals("m.happyjuzi.com") && !host.equals("a.happyjuzi.com")) {
                //System.out.println(host);
                return false;
            }
            if (lineformat.contains("&uid=")) {
                //System.out.println(lineformat);
                return false;
            }
        }
        return true;
    }
//
//    public static List<String> getFileList(File file) {
//        List<String> result = new ArrayList<String>();
//        if (!file.isDirectory()) {
//            System.out.println(file.getAbsolutePath());
//            result.add(file.getAbsolutePath());
//        } else {
//            File[] directoryList = file.listFiles(new FileFilter() {
//                public boolean accept(File file) {
//                    if (file.isFile() && file.getName().indexOf("log") > -1) {
//                        return true;
//                    } else {
//                        return false;
//                    }
//                }
//            });
//            for (int i = 0; i < directoryList.length; i++) {
//                result.add(directoryList[i].getPath());
//            }
//        }
//        return result;
//    }

    public static List<String> getFileList(String path, String pathtodate) {     //fu wu qi tiao shi
        List<String> pathlist = new ArrayList<>();
        Iterator it = pathlist.iterator();
        for (int i = 0; i <= 2; i++) {
            for (int j = 0; j <= 9; j++) {
                String hour = i + "" + j;
                pathlist.add(path + "/logstat-" + pathtodate + "-" + hour + ".log");
                if (Integer.parseInt(hour) > 22) {
                    break;
                }
            }
        }
        return pathlist;
    }

    public static void main(String args[]) {
        Long programstarttime = System.currentTimeMillis();
        try {
            int repeatecount = 0;

            String path = args[0];               //fuwuqi
            String pathsplit[] = path.split("/");
            String pathtodate = pathsplit[pathsplit.length - 1];
            List<String> pathlist = getFileList(path, pathtodate);
            String line = null;
//            String path = "src/log/2016-09-26";
//            String pathsplit[] = path.split("/");
//            String pathtodate = "2016-09-26";
//            File file = new File(path);
//            List<String> pathlist = getFileList(file);
//            String line = null;
            int count = 0;
            Map<String, List<Map<String, String>>> originmap = new HashMap<>();          //声明一个全局的map
            Map<String, Long> timemap = new HashMap<>();             //用来存储时间的map
            for (String l : pathlist) {
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(
                        new FileInputStream(l)));
                while ((line = bufferedReader.readLine()) != null) {
                    try {
                        String[] data = line.split("&");
                        Map<String, String> tojson = new HashMap<>();
                        //List<Map> list = new ArrayList<>();

                        String iphost = data[0].split("=")[1].split(",")[0];
                        String usi = data[1].split("=")[1];
//                List<Map> list = originmap.get(iphost);
                        for (String da : data) {
                            String source[] = da.split("=");
                            if (source.length < 2) {
                                tojson.put(source[0], null);
                            } else {
                                tojson.put(source[0], source[1].equals("null") ? null : source[1]);
                            }
                        }
                        tojson.put("ip", iphost);
                        tojson.put("comefrom", "");
                        if (!judgeURL(tojson.get("u"))) {
                            continue;
                        }
                        String key = "";
                        if (originmap.get(usi) != null) {
                            key = usi;
                        } else if (originmap.get(iphost) != null) {
                            key = iphost;
                        }
                        if (StringUtils.isNotBlank(key) && originmap.containsKey(key)) {
                            long starttime = Long.parseLong(timemap.get(key).toString().substring(0, 10));
                            long endtime = Long.parseLong(tojson.get("ipt").substring(0, 10));
                            //大于30秒的情况
                            if ((endtime - starttime) < 300) {
                                originmap.get(key).add(tojson);
                            } else {
                                //数据库处理
                                new JudgeFrom(pathtodate).judgeoneip(originmap.get(key));
                                repeatecount++;
                                List<Map<String, String>> list = new ArrayList<>();
                                list.add(tojson);
                                originmap.put(key, list);
                            }
                        } else {
                            //###
                            List<Map<String, String>> list = new ArrayList<>();
                            list.add(tojson);
                            originmap.put(iphost, list);
                        }

                        timemap.put(iphost, Long.parseLong(tojson.get("ipt")));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    //System.out.println(data[0].split("=")[1].split(",")[0]);

                    //只判断100条数据
                    count++;
//                    if (count > 1999) {
//                        break;
//                    }
                    System.out.println(count);
                }
            }

            System.out.println("end");
            JudgeFrom judgeFrom = new JudgeFrom(pathtodate);
            judgeFrom.judgefromwhere(originmap);

            System.out.println(repeatecount);
            //System.out.println("PV:" + (PV + originmap.size()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(System.currentTimeMillis() - programstarttime);
    }
}

test

test2的更多相关文章

  1. python 装饰器--对有无参数的函数进行装饰

    # 使用装饰器无参数的函数进行装饰# def func(funcionName): # print('-----1------') # def func_in(): # print('--func_i ...

  2. 如果是多个 c 代码的源码文件,编译方法如下: $ gcc test1.c test2.c -o main.out $ ./main.out test1.c 与 test2.c 是两个源代码文件。

    如果是多个 c 代码的源码文件,编译方法如下: $ gcc test1.c test2.c -o main.out $ ./main.out test1.c 与 test2.c 是两个源代码文件.

  3. VS2010 正在创建“Debug\test2.unsuccessfulbuild”,因为已指定“AlwaysCreate”。

    问题一:VS2010  正在创建“Debug\test2.unsuccessfulbuild”,因为已指定“AlwaysCreate”. 方法解决: The relevant setting is i ...

  4. python遍历目录os.walk(''d:\\test2",topdown=False)

    os.walk(top, topdown=True, onerror=None, followlinks=False)遍历目录,topdown=false表示先返回目录,后返回文件 参数说明: top ...

  5. load data infile出现“ERROR 13 (HY000): Can't get stat of '/tmp/test2.txt' (Errcode: 2)”问题

    用load data infile导数据到mysql数据库出现这个该问题,解决方法如下: 安全起见,连接mysql的语句需要添加–local-infile, mysql -hlocalhost -ur ...

  6. 2016/3/30 ①投票checkbox ②进度条两个div套起百分比控制内div(width) <div><div></div></div> ③数据库test2 表 diaoyan... 35岁发展方向投票

    分两个页面,要点:提交form 相连action method  两个页面可以合成一个页面action传到自身页面   但分开较清晰 第一个页面vote.php <!DOCTYPE html P ...

  7. 5、数组的复制(test2.java、test3.java)

    对于数组的复制,在最开始的时候最容易犯的一个错误,那就是自己认为的申请一个数组,然后将已存在的数组赋值到新申请数组名上,这样是错误的,这样仅仅是将数组的地址复制了过去,并不是,将数组内的元素拷贝过去, ...

  8. 还可以使用 -c 参数来显示全部内容,并标出不同之处 diff -c test2.txt test1.txt

    二.实例 在test目录下存放了两个文本文件,test1.txt  test2.txt . 比较这两个文件的异同. diff  test1.txt   test2.txt     "5c5& ...

  9. 20150706 test2

    净心守志:可会至道.譬如磨镜:垢去明存.断欲无求:当得宿命

随机推荐

  1. 【hadoop】——压缩工具比较

    文件压缩主要有两个好处,一是减少了存储文件所占空间,另一个就是为数据传输提速.在hadoop大数据的背景下,这两点尤为重要,那么我现在就先来了解下hadoop中的文件压缩. hadoop里支持很多种压 ...

  2. 烂泥:学习ssh之ssh密钥随身携带

    本文由秀依林枫提供友情赞助,首发于烂泥行天下 在上一篇文章<烂泥:学习ssh之ssh无密码登陆>中,我们讲解了如何使用ssh密钥,免密码登陆服务器. 这篇文章我们再来讲解,如何把已经生成的 ...

  3. Altium Designer 出现错误提示(警告)adding items to hidden net GND/VCC

    一般出现这个提示,不是错误. 可以取消net 网格标号 这样就不会报这个警告了. 还可以设置规则,不让它报告. 点击确定,但是再次打开工程时有得警告这个错误了.我想,还是取消NET标注.

  4. html5移动端Meta设置

    1.   强制让文档的宽度与设备的宽度保持1:1,并且文档最大的宽度比例是1.0,且不允许用户点击屏幕放大浏览. <meta name="viewport" content= ...

  5. KVM 介绍(8):使用 libvirt 迁移 QEMU/KVM 虚机和 Nova 虚机 [Nova Libvirt QEMU/KVM Live Migration]

    学习 KVM 的系列文章: (1)介绍和安装 (2)CPU 和 内存虚拟化 (3)I/O QEMU 全虚拟化和准虚拟化(Para-virtulizaiton) (4)I/O PCI/PCIe设备直接分 ...

  6. BZOJ4152The Captain[DIjkstra]

    4152: [AMPPZ2014]The Captain Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 700  Solved: 266[Submit ...

  7. 第5章 绘图基础_5.1-5.4 GDI绘图

    5.1 GDI的原理和结构 (1)提供一种特殊机制彻底隔离应用程序与不同输出设备(eg.显示器或打印机),以便支持 与设备无关的图形. 光栅设备(如显示器.激光打印机):图像是由点构成的矩阵 图形输出 ...

  8. netty5和4.x,3.x的一些区别

    http://item.congci.com/item/netty-5-0-4-0-xin-bianhua-he-zhuyi-dian

  9. 云计算之路-阿里云上:RDS用户的烦恼

    http://www.cnblogs.com/cmt/p/3586029.html *博主注:阿里云数据库真的这么可笑?

  10. 关于OAUTH2.0的极品好文

    Web Server Flow: web ServerFlow是把oauth1.0的三个步骤缩略为两个步骤 首先这个是适合有server的第三方使用的. 1客户端http请求authorize 2服务 ...