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. Sql Server之旅——第九站 看公司这些DBA们设计的这些复合索引

    这一篇再说下索引的最后一个主题,索引覆盖,当然学习比较好的捷径是看看那些大师们设计的索引,看从中能提取些什么营养的东西,下面我们看 看数据库中一个核心的Orders表. 一:查看表的架构 <1& ...

  2. Linux Gitlab

    一.简介 GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目.它拥有与Github类似的功能,能够浏览源 ...

  3. Mac brew命令

    一.简介 Brew又叫Homebrew,是MAC中的一款软件包管理工具,通过brew可以很方便的在MAC中安装软件或者是卸载软件. 二.安装 ruby -e "$(curl -fsSL ht ...

  4. URL tailing slash

    Without tailing slash request header GET /snippets HTTP/1.1 User-Agent: Fiddler Host: 192.168.128.13 ...

  5. [转]ASP.Net篇之Session与Cookie

    本文转自:http://www.cnblogs.com/japanbbq/archive/2011/08/31/2160494.html Session: Session是“会话”的意思,然而,因为h ...

  6. windows 10 & Office 2016 安装

    Office 2016 VOL版    http://blog.sina.com.cn/s/blog_470614a90102vtmc.html 专业版合集: magnet:?xt=urn:btih: ...

  7. Java的cmd配置(也即Java的JDK配置及相关常用命令)——找不到或无法加载主类 的解决方法

    Java的cmd配置(也即Java的JDK配置及相关常用命令) ——找不到或无法加载主类  的解决方法 这段时间一直纠结于cmd下Java无法编译运行的问题.主要问题描述如下: javac 命令可以正 ...

  8. Student管理系统

    使用三层架构实现Student管理系统,分为Studrnt.Model层,Student.DAL层,Student.BLL层和Student.UI层 步骤分析: 1.在Student.Model添加S ...

  9. Winform窗体基本属性

    窗体是程序与用户交互的可视界面,窗体也是对象,窗体类定义了生成窗体的模版,实例化一个窗体类就产生了一个窗体..NET框架类库的System.Windows.Forms命名空间中定义的Form类是所有窗 ...

  10. 嵌入式Linux 修改启动LOGO

    1.嵌入式 Linux LOGO显示原理      嵌入式Linux是直接在FrameBuffer的基础上.直接显示一个ppm格式的图象.     它 kernel/drivers/video/fbc ...