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. Java Se:Java Security

    Java API中有很多都使用了SecurityManager,这到底是什么玩意?最近看公司的产品的源码,也有不少SecurityManager.AccessControlContext等相关的代码, ...

  2. Javascript之旅——第十站:为什么都说闭包难理解呢?

    研究过js的朋友大多会说,理解了js的原型和闭包就可以了,然后又说这些都是js的高级内容,然后就又扯到了各种神马的作用域...然后不少 人就会被忽悠的云里雾里...下面我也试着来说说闭包,看我说的这个 ...

  3. (转,有改动)测试网页响应时间的shell脚本[需要curl支持]

    用法及返回结果如下: [root@myserver01 tmp]# sh test_web.sh -n500 http://www.baidu.com Request url: http://www. ...

  4. IO系统性能之一:衡量性能的几个指标

    作为一个数据库管理员,关注系统的性能是日常最重要的工作之一,而在所关注的各方面的性能只能IO性能却是最令人头痛的一块,面对着各种生涩的参数和令人眼花缭乱的新奇的术语,再加上存储厂商的忽悠,总是让我们有 ...

  5. C+命令行+方向键=简易版扫雷

    前言: 想起来做这个是因为那时候某天知道了原来黑框框里面的光标是可以控制的,而且又经常听人说起这个,就锻炼一下好了. 之前就完成了那1.0的版本,现在想放上来分享却发现有蛮多问题的,而且最重要的是没什 ...

  6. subversion 1.8.5好像不是很成熟

    加:--enable-all-static1. 没找到libneon库支持,不得不用libserf。2. libserf编译要用到scons.py,所有要有python工具支持。3. 当遇到链接少ss ...

  7. 荒芜的周六-PHP之面向对象(三)

    hi 又是开森的周六了.积攒的两周的衣服,终于是差不多洗完了.大下午的才来学点东西~~ 1.PHP面向对象(三) 四.OOP的高级实践 4.3 Static-静态成员 <?phpdate_def ...

  8. Android开发快速入门(环境配置、Android Studio安装)

    Android是一种激动人心的开源移动平台,它像手机一样无处不在,得到了Google以及其他一些开放手机联盟成员(如三星.HTC.中国移动.Verizon和AT&T等)的支持,因而不能不加以学 ...

  9. NOIP2004合并果子

    题目描述 在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合成一堆. 每一次合并,多多可以把两堆果子合并到一起,消耗的体力等于两堆果子的重量之和.可 ...

  10. Quantum Bogo sort浅谈

    1.普通的猴子排序(bogo sort) 猴子排序百科 en.wikipedia.org/wiki/Bogosort 不停的随机打乱序列,然后检查,直到排好序 复杂度O(n*n!) while not ...