📄 statggspace.java
字号:
package com.jb;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;
/**
* 统计gg空间的一天
* 1、 PV
* 2、 访问GG空间的独立用户数
* 3、 访问自己空间的独立用户数
* 4、 被访问的独立空间数
* @author chenhaibin
*
*/
public class StatGGSpace
{
private static final String INSERT_STAT = "insert into ggspacestat(Date,PV,visit_count,visit_own_count,space_visit) values(?,?,?,?,?)";
static private String dayStr=null;
private static int pvcount=0;//PV数
//访问GG空间的独立用户数
static Set vcset=new HashSet();
//访问自己GG空间的独立用户数
static Set vocset=new HashSet();
//被访问的独立空间数
static Set spaceset=new HashSet();
private String[] pvpage={"/favor_list.jsp","/friends.jsp","/index.jsp","/mb_deleteall.jsp","/mb_main.jsp","/mb_reply.jsp","/mood.jsp",
"/send_favor.jsp","/send_share.jsp","/send_share3.jsp","/send_share2.jsp","/send_whisper.jsp","/setcity.jsp","/setfri.jsp",
"/share.jsp","/spoor.jsp","/visitor.jsp","/whisper.jsp"};
public StatGGSpace(String[] args)
{
//读入文件
statFile(args[0]);
//插入数据
insertIntoTable();
}
/**
* 统计一个文件。
*/
private void statFile(String file)
{
try
{
File f = new File(file);
FileInputStream fis = new FileInputStream(f);//文件输入流
InputStreamReader isr = new InputStreamReader(fis);//读入文件
BufferedReader br = new BufferedReader(isr);//放入缓冲
String row = br.readLine();//读入行
while(row != null)//如果行不为空
{
statLine(row);//统计一个行
row = br.readLine();//读下一行
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
/**
* 统计一行记录。
*/
private void statLine(String row)
{
try
{
//如果行为空或者长度为0,返回
if(row == null || row.trim().length() == 0)
{
return;
}
//以空格 分成3个数组 2007-07-28 09:53:35 192.168.3.52,715,65,/visitor.jsp
String[] strs = row.split(" ");//以空格 分成3个数组
dayStr = strs[0];//取出日期
//以, 分成4个数组 192.168.3.52,715,65,/visitor.jsp
String[] arr=strs[2].split(",");
//统计一个pv数,如果在指定的页面,那么pv就加1
for(int i=0;i<pvpage.length;i++)
{
if(arr[3].endsWith(pvpage[i]))
{
pvcount++;
}
}
//统计访问GG空间的独立用户数
vcset.add(arr[2]);
//统计访问自己GG空间的独立用户数
if(arr[1].equals(arr[2]))
{
String aa=arr[1]+" "+arr[2];
vocset.add(aa);
}
//统计访问的空间数
spaceset.add(arr[1]);
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
private void insertIntoTable()
{
Connection conn = MysqlDriver.getConnection();
PreparedStatement pstmt = null;
try{
//保存记录
pstmt = conn.prepareStatement(INSERT_STAT);
pstmt.setString(1, dayStr);
pstmt.setInt(2, pvcount);
pstmt.setInt(3, vcset.size());
pstmt.setInt(4, vocset.size());
pstmt.setInt(5, spaceset.size());
pstmt.executeUpdate();
pstmt.close();
}
catch (SQLException se)
{
System.out.println(se.toString());
}
clear();
DbConnectionGrobals.closeConnection(pstmt, conn);
}
public void clear()
{
if(dayStr!=null)
dayStr=null;
if(vcset!=null)
vcset=null;
if(vocset!=null)
vocset=null;
if(spaceset!=null)
spaceset=null;
}
public static void main(String[] args)
{
new StatGGSpace(args);
// Object[] aa=vocset.toArray();
// for(int i=0;i<aa.length;i++)
// {
// System.out.println((String)aa[i]);
// }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -