test2
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的更多相关文章
- python 装饰器--对有无参数的函数进行装饰
# 使用装饰器无参数的函数进行装饰# def func(funcionName): # print('-----1------') # def func_in(): # print('--func_i ...
- 如果是多个 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 是两个源代码文件.
- VS2010 正在创建“Debug\test2.unsuccessfulbuild”,因为已指定“AlwaysCreate”。
问题一:VS2010 正在创建“Debug\test2.unsuccessfulbuild”,因为已指定“AlwaysCreate”. 方法解决: The relevant setting is i ...
- python遍历目录os.walk(''d:\\test2",topdown=False)
os.walk(top, topdown=True, onerror=None, followlinks=False)遍历目录,topdown=false表示先返回目录,后返回文件 参数说明: top ...
- 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 ...
- 2016/3/30 ①投票checkbox ②进度条两个div套起百分比控制内div(width) <div><div></div></div> ③数据库test2 表 diaoyan... 35岁发展方向投票
分两个页面,要点:提交form 相连action method 两个页面可以合成一个页面action传到自身页面 但分开较清晰 第一个页面vote.php <!DOCTYPE html P ...
- 5、数组的复制(test2.java、test3.java)
对于数组的复制,在最开始的时候最容易犯的一个错误,那就是自己认为的申请一个数组,然后将已存在的数组赋值到新申请数组名上,这样是错误的,这样仅仅是将数组的地址复制了过去,并不是,将数组内的元素拷贝过去, ...
- 还可以使用 -c 参数来显示全部内容,并标出不同之处 diff -c test2.txt test1.txt
二.实例 在test目录下存放了两个文本文件,test1.txt test2.txt . 比较这两个文件的异同. diff test1.txt test2.txt "5c5& ...
- 20150706 test2
净心守志:可会至道.譬如磨镜:垢去明存.断欲无求:当得宿命
随机推荐
- Sql Server之旅——第十三站 对锁的初步认识
终于这个系列快结束了,马上又要过年了,没什么心情写博客...作为一个开发人员,锁机制也是我们程序员必须掌握的东西,很久之前 在学习锁的时候,都是教科书上怎么说,然后我怎么背,缺少一个工具让我们眼见为实 ...
- Android搭建junit测环境
在AndroidManifest.xml文件中增加两个东西,分别是: 1.uses-library ,位于application里面. 2.instrumentation,与application同级 ...
- 【SQL篇章--基于MySQL5.7--创建用户】
SQL: 创建用户:>=MySQL5.7.6 查看用户: mysql> select user,host,authentication_string from mysql.user; ...
- 初次体验VS2015正式版,安装详细过程。
本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceLink 阅读目录 介绍 安装 其他 本文版权归mephi ...
- SQLServer 数据修复命令DBCC一览
1. DBCC CHECKDB 重启服务器后,在没有进行任何操作的情况下,在SQL查询分析器中执行以下SQL进行数据库的修复,修复数据库存在的一致性错误与分配错误. use master decla ...
- oracle存储过程、函数、序列、包
一. 存储过程 1. 语法 create or replace procedure procedureName(seqName varchar2) is /*声明变量*/ n ); cursor cu ...
- dpkg
dpkg是debian最早提出的一个软件包管理工具,因为早期并没有考虑到当下软件包之间这么复杂的依赖关系,所以并不能自动解决软件包的依赖问题,这个命令多用于安装本地的.deb软件包,也可以进行软件包的 ...
- iNeedle产品介绍
一.产品简介 1.产品背景 1.您曾经遇到过下面的问题和烦恼吗?2.当网站上线以后,如何实时的了解网站的运行状况?3.当网站访问速度慢,是升级服务器?还是升级带宽?还是优化网站代码?4.当网站新上线一 ...
- android 导入数据(通讯录)
接着android 中导出数据 一文,下面介绍在android中导入数据的思路: 1.将数据从文本中读取出来 2.封装处理成自己想要的对象或模型 3.将处理好的数据对象插入自己应用的数据库中 4.更新 ...
- [转]C#网络编程(同步传输字符串) - Part.2
本文转自:http://www.tracefact.net/CSharp-Programming/Network-Programming-Part2.aspx 服务端客户端通信 在与服务端的连接建立以 ...