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
净心守志:可会至道.譬如磨镜:垢去明存.断欲无求:当得宿命
随机推荐
- [20140117]疑似checkpoint堵塞数据库连接
注:这个说法是不成立的,问题已经解决,但是无法正确的定位到具体什么原因:[20140702]奇怪的应用程序超时 背景: 开发通过应用程序的日志发现间歇性的出现,数据库连接超时 原因: 只能大概猜测,没 ...
- Sql Server之旅——第三站 解惑那些背了多年聚集索引的人
说到聚集索引,我想每个码农都明白,但是也有很多像我这样的猥程序员,只能用死记硬背来解决这个问题,什么表中只能建一个聚集索引, 然后又扯到了目录查找来帮助读者记忆....问题就在这里,我们不是学文科,, ...
- python爬取并下载麦子学院所有视频教程
一.主要思路 scrapy爬取是有课程地址及名称 使用multiprocessing进行下载 就是为了爬点视频,所以是简单的代码堆砌 想而未实行,进行共享的方式 二.文件说明 itemsscray字段 ...
- spring中各jar功能及jar包之间的依赖关系
(1) spring-core.jar 这个jar文件包含Spring框架基本的核心工具类,Spring其它组件要都要使用到这个包里的类,是其它组件的基本核心,当然你也可以在自己的应用系统中使用这些工 ...
- Macbook无法上网,访问不了appstore、safria、网易云等,但QQ、谷歌浏览器可以用--解决方案
---------------------我是分割线 update 2016-09-22 20:55:22----------------------------- 发现之前那个方法也是不稳定,后来 ...
- LeetCode #303. Range Sum Query
问题: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclu ...
- X264库直接压缩BITMAP格式数据
最近帮朋友看了下X264压缩视频,主要参考了雷霄骅(leixiaohua1020)的专栏的开源代码: http://blog.csdn.net/leixiaohua1020/article/detai ...
- hw 要的是螺丝钉
日前突然接到华为HR的电话,叫我去面试。本来我的工作和工资收入等各方面在本地也还算可以,没有想要跳槽。但是本着去看看有没有更好机会的想法就去了。 9:30到了现场后,在那里等了很久,一个考官上来问了 ...
- 瘟疫公司中国版(Android)手动破解内购
前言 洒家近日下载了个瘟疫公司中国版(安卓版)(com.easymobi.plagueinc.mi ,版本 1.1.2(5)(.mi 小米版)),发现游戏需要内购而且价格不菲. 需求 root权限 文 ...
- POJ 1724 ROADS【最短路/搜索/DP】
一道写法多样的题,很具有启发性. 具体参考:http://www.cnblogs.com/scau20110726/archive/2013/04/28/3050178.html http://blo ...