?? statggspace.java
字號(hào):
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;
/**
* 統(tǒng)計(jì)gg空間的一天
* 1、 PV
* 2、 訪(fǎng)問(wèn)GG空間的獨(dú)立用戶(hù)數(shù)
* 3、 訪(fǎng)問(wèn)自己空間的獨(dú)立用戶(hù)數(shù)
* 4、 被訪(fǎng)問(wèn)的獨(dú)立空間數(shù)
* @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數(shù)
//訪(fǎng)問(wèn)GG空間的獨(dú)立用戶(hù)數(shù)
static Set vcset=new HashSet();
//訪(fǎng)問(wèn)自己GG空間的獨(dú)立用戶(hù)數(shù)
static Set vocset=new HashSet();
//被訪(fǎng)問(wèn)的獨(dú)立空間數(shù)
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]);
//插入數(shù)據(jù)
insertIntoTable();
}
/**
* 統(tǒng)計(jì)一個(gè)文件。
*/
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);//統(tǒng)計(jì)一個(gè)行
row = br.readLine();//讀下一行
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
/**
* 統(tǒng)計(jì)一行記錄。
*/
private void statLine(String row)
{
try
{
//如果行為空或者長(zhǎng)度為0,返回
if(row == null || row.trim().length() == 0)
{
return;
}
//以空格 分成3個(gè)數(shù)組 2007-07-28 09:53:35 192.168.3.52,715,65,/visitor.jsp
String[] strs = row.split(" ");//以空格 分成3個(gè)數(shù)組
dayStr = strs[0];//取出日期
//以, 分成4個(gè)數(shù)組 192.168.3.52,715,65,/visitor.jsp
String[] arr=strs[2].split(",");
//統(tǒng)計(jì)一個(gè)pv數(shù),如果在指定的頁(yè)面,那么pv就加1
for(int i=0;i<pvpage.length;i++)
{
if(arr[3].endsWith(pvpage[i]))
{
pvcount++;
}
}
//統(tǒng)計(jì)訪(fǎng)問(wèn)GG空間的獨(dú)立用戶(hù)數(shù)
vcset.add(arr[2]);
//統(tǒng)計(jì)訪(fǎng)問(wèn)自己GG空間的獨(dú)立用戶(hù)數(shù)
if(arr[1].equals(arr[2]))
{
String aa=arr[1]+" "+arr[2];
vocset.add(aa);
}
//統(tǒng)計(jì)訪(fǎng)問(wèn)的空間數(shù)
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]);
// }
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -