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
净心守志:可会至道.譬如磨镜:垢去明存.断欲无求:当得宿命
随机推荐
- js实现页面跳转的几种方式
第一种: <script language="javascript" type="text/javascript"> wi ...
- hadoop2.6分布式部署时 livenodes等于1的原因
1.问题描述 在进行hadoop2.x版本的hdfs分布式部署时,遇到了一个奇怪的问题: 使用start-dfs.sh命令启动dfs之后,所有的datanode节点上均能看到datanode进程,然而 ...
- Linux下Awk详解(转载)
什么是Awk Awk是一种小巧的编程语言及命令行工具.(其名称得自于它的创始人Alfred Aho.Peter Weinberger 和 Brian Kernighan姓氏的首个字母).它非常适合服务 ...
- linux下motion摄像头监控编译与配置
利用linxu下的开源的motion搭建嵌入式视频动态监控系统 所谓移动图像监测,简单来说就是利用摄像头定点监测某个区域,当有移动物体经过时,摄像头便自动抓拍(要监测多大物体.按拍照速率都是可调的), ...
- 带有天气预报的高大上web报表制作分享
我用FineReport开发了挺多报表,但集成天气预报这样提高交互和人性化的还是第一次,所以跟大家分享下. 这个报表是综合的门店销售管理分析面板,可以查询业绩分析.店员销售分析,店铺排行分析(可以看出 ...
- 报表引擎API开发入门—简单程序数据集
小编最近接的项目是有关报表开发的,很想把这部分知识分享出来.希望大家能够支持我!不多说,马上进入我们今天的话题. API基本知识 小编最近项目所做的是关于一个报表软件—FineReport报表开发的一 ...
- poj2486Apple Tree[树形背包!!!]
Apple Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9989 Accepted: 3324 Descri ...
- vijos1334 NASA的食物计划(二维费用的背包问题)
背景 NASA(美国航空航天局)因为航天飞机的隔热瓦等其他安 全技术问题一直大伤脑筋,因此在各方压力下终止了航天 飞机的历史,但是此类事情会不会在以后发生,谁也无法 保证,在遇到这类航天问题时,解决方 ...
- vue组件的配置属性
vue组件的声明语法: Vue.component('component-name',{ template:'<p>段落{{prop1}} {{prop2}}</p>', da ...
- sublime和python
<转载> 使用 Sublime 工具时报Decode error - output not utf-8解决办法 打开Python.sublime-build文件,并添加"en ...