Workrave的historystats文件内容格式分析

作者:lizongbo 发表于:12:38. 星期二, 十一月 27th, 2007
版权声明:可以任意转载,转载时请务必以超链接形式标明文章和作者信息及本版权声明。

Workrave的historystats文件内容格式

由于Workrave没有提供导出统计信息的功能,于是通过分析统计信息文件来写了个程序来导出统计结果

(关于 Worlrave,参考 http://618119.com/archives/2007/10/31/19.html)

历史统计信息所在文件为:D:\Documents and Settings\Administrator\Application Data\\
当天的统计信息在D:\Documents and Settings\Administrator\Application Data\Workrave\todaystats
一天的统计数据如下:
D 23 10 107 8 15 23 10 107 13 6
B 0 7 21 0 9 9 0 9 2580
B 1 7 5 0 3 3 0 3 370
B 2 7 0 0 0 0 0 0 0
m 6 12927 867525 574308 4051 2006 22828
第一行表示起止时间.前五个数字是开始时间,后五个数字是结束时间,
在五个数字中,第一个是天,第二个是月(从0开始算的月),第三个是年(减去了1900后),第四个是小时,第五个是分

23 10 107 8 15 表示 2007年11月23日8点15分
23 10 107 13 6 表示 2007年11月23日13点6分

第二行到第四行的的一个数字是索引位,0,1,2,分别对应暂停,休息,每日限制,
第二个数字是表示后续的数字个数,目前均为7.

第三个数字是休息提示总数,
第四个数字是休息提示次数
第五个数字是自行休息次数
第六个数字是略过休息次数
第七个数字是休息延后次数
第八个数字是休息提示数量
第九个数字是超时时间,以秒为单位.

统计面板所显示的重复提示为 第三个数字减去第八个数字所得到的.

第五行当数据是一天的活动记录,
第二个数字表示日使用量,第三个数字表示鼠标移动距离(以像素为单位),
第四个数字表示鼠标有效移动距离(以像素为单位),第五个数字是鼠标的使用时间,
第六个是鼠标点击次数,第七个数字是当天按键盘的次数,
(像素与厘米的转换关系是1厘米为38像素)
参考: http://osdir.com/ml/misc.workrave.user/2005-01/msg00007.html

用java进行读取解析的代码为:

解析文件的代码

[code]

package com.lizongbo.workrave;

import java.io.*;

public class StatReport {
public static void main(String[] args) throws FileNotFoundException,
IOException {
String f =
"D:/Documents and Settings/Administrator/Application Data/Workrave/historystats";
if (args != null && args.length > 0) {
f = args[0];
}
//读取到以"D "开头的行,开始处理
java.io.FileInputStream fis = new FileInputStream(f);
java.io.InputStreamReader isr = new InputStreamReader(fis);
java.io.BufferedReader br = new BufferedReader(isr, 8192 * 8);
String line = null;
while ((line = br.readLine()) != null) {
if (line.startsWith("D ")) {
//需要再连读四行
String line2 = br.readLine();
String line3 = br.readLine();
String line4 = br.readLine();
String line5 = br.readLine();
DayStat ds = new DayStat();
ds.praseLine1(line);
ds.praseLine2(line2);
ds.praseLine3(line3);
ds.praseLine4(line4);
ds.praseLine5(line5);
System.out.println(ds);
}
}

}

}

[/code]

javaBean代码:

[code]
package com.lizongbo.workrave;

public class DayStat {
/** 日期 */
private String day;
/** 开始的小时 */
private int startHour;
/** 开始的分 */
private int startMin;
/** 结束的小时 */
private int endHour;
/** 结束的分 */
private int endMin;
/** 暂停 休息提示总数 */
private int pauseRestTipAll;
/** 暂停 休息提示次数 */
private int pauseRestTipTime;
/** 暂停 自行休息次数 */
private int pauseRestSelfCount;
/** 暂停 略过休息次数 */
private int pauseRestIgnoreCount;
/** 暂停 休息延后次数 */
private int pauseRestDelayCount;
/** 暂停 休息提示数量 */
private int pauseRestTipCount;
/** 暂停 超时时间,以秒为单位 */
private int pauseTimeout;
/** 休息 休息提示总数 */
private int restRestTipAll;
/** 休息 休息提示次数 */
private int restRestTipTime;
/** 休息 自行休息次数 */
private int restRestSelfCount;
/** 休息 略过休息次数 */
private int restRestIgnoreCount;
/** 休息 休息延后次数 */
private int restRestDelayCount;
/** 休息 休息提示数量 */
private int restRestTipCount;
/** 休息 超时时间,以秒为单位 */
private int restTimeout;
/** 每日限制 休息提示总数 */
private int dayLimitRestTipAll;
/** 每日限制 休息提示次数 */
private int dayLimitRestTipTime;
/** 每日限制 自行休息次数 */
private int dayLimitRestSelfCount;
/** 每日限制 略过休息次数 */
private int dayLimitRestIgnoreCount;
/** 每日限制 休息延后次数 */
private int dayLimitRestDelayCount;
/** 每日限制 休息提示数量 */
private int dayLimitRestTipCount;
/** 每日限制 超时时间,以秒为单位 */
private int dayLimitTimeout;
/** 日使用量 以秒为单位 */
private int dayUse;
/** 鼠标移动距离(以像素为单位) */
private int mouseMove;
/** 鼠标有效移动距离(以像素为单位) */
private int mouseMoveuseful;
/** 鼠标的使用时间 */
private int mouseUseTime;
/** 鼠标点击次数 */
private int mouseClick;
/** 当天按键盘的次数 */
private int keyClick;

public void praseLine1(String line1) {
String str[] = line1.split(" ");
String s = (Integer.parseInt(str[3]) + 1990) + "年" +
(Integer.parseInt(str[2]) + 1) + "月" + str[1] + "日 " +
str[4] + ":" + str[5];
String e = (Integer.parseInt(str[8]) + 1990) + "年" +
(Integer.parseInt(str[7]) + 1) + "月" + str[6] + "日 " +
str[9] + ":" + str[10];
day = "" + (Integer.parseInt(str[3]) + 1990);
int mon = (Integer.parseInt(str[2]) + 1);
if (mon < 10) {
day = day + "-" + "0" + mon;
} else {
day = day + "-" + mon;
}
int d = (Integer.parseInt(str[1]));
if (d < 10) {
day = day + "-" + "0" + d;
} else {
day = day + "-" + d;
}
startHour = Integer.parseInt(str[4]);
startMin = Integer.parseInt(str[5]);
endHour = Integer.parseInt(str[9]);
endMin = Integer.parseInt(str[10]);
}

public void praseLine2(String line2) {
String str[] = line2.split(" ");
pauseRestTipAll = Integer.parseInt(str[3]);
pauseRestTipTime = Integer.parseInt(str[4]);
pauseRestSelfCount = Integer.parseInt(str[5]);
pauseRestIgnoreCount = Integer.parseInt(str[6]);
pauseRestDelayCount = Integer.parseInt(str[7]);
pauseRestTipCount = Integer.parseInt(str[8]);
pauseTimeout = Integer.parseInt(str[9]);
}

public void praseLine3(String line3) {
String str[] = line3.split(" ");

restRestTipAll = Integer.parseInt(str[3]);
restRestTipTime = Integer.parseInt(str[4]);
restRestSelfCount = Integer.parseInt(str[5]);
restRestIgnoreCount = Integer.parseInt(str[6]);
restRestDelayCount = Integer.parseInt(str[7]);
restRestTipCount = Integer.parseInt(str[8]);
restTimeout = Integer.parseInt(str[9]);

}

public void praseLine4(String line4) {
String str[] = line4.split(" ");
restRestTipAll = Integer.parseInt(str[3]);
restRestTipTime = Integer.parseInt(str[4]);
restRestSelfCount = Integer.parseInt(str[5]);
restRestIgnoreCount = Integer.parseInt(str[6]);
restRestDelayCount = Integer.parseInt(str[7]);
restRestTipCount = Integer.parseInt(str[8]);
restTimeout = Integer.parseInt(str[9]);

}

public void praseLine5(String line5) {
String str[] = line5.split(" ");
dayUse = Integer.parseInt(str[2]);
mouseMove = Integer.parseInt(str[3]);
mouseMoveuseful = Integer.parseInt(str[4]);
mouseUseTime = Integer.parseInt(str[5]);
mouseClick = Integer.parseInt(str[6]);
keyClick = Integer.parseInt(str[7]);
}

public String toString() {
StringBuilder sb = new StringBuilder(1024);
sb.append(" 在 ");
sb.append(":");
sb.append(day);
sb.append(",从");
sb.append(startHour);
sb.append(":");
sb.append(startMin);
sb.append("到");
sb.append(endHour);
sb.append(":");
sb.append(endMin);
sb.append(", \r\n暂停- 休息提示总数: ");
sb.append(pauseRestTipAll);
sb.append(", \r\n暂停- 休息提示次数: ");
sb.append(pauseRestTipTime);
sb.append(", \r\n暂停- 自行休息次数: ");
sb.append(pauseRestSelfCount);
sb.append(", \r\n暂停- 略过休息次数: ");
sb.append(pauseRestIgnoreCount);
sb.append(", \r\n暂停- 休息延后次数: ");
sb.append(pauseRestDelayCount);
sb.append(", \r\n暂停- 休息提示数量: ");
sb.append(pauseRestTipCount);
sb.append(", \r\n暂停- 超时时间(以秒为单位): ");
sb.append(pauseTimeout);
sb.append(", \r\n休息- 休息提示总数: ");
sb.append(restRestTipAll);
sb.append(", \r\n休息- 休息提示次数: ");
sb.append(restRestTipTime);
sb.append(", \r\n休息- 自行休息次数: ");
sb.append(restRestSelfCount);
sb.append(", \r\n休息- 略过休息次数: ");
sb.append(restRestIgnoreCount);
sb.append(", \r\n休息- 休息延后次数: ");
sb.append(restRestDelayCount);
sb.append(", \r\n休息- 休息提示数量: ");
sb.append(restRestTipCount);
sb.append(", \r\n休息- 超时时间(以秒为单位): ");
sb.append(restTimeout);
sb.append(", \r\n每日限制- 休息提示总数: ");
sb.append(dayLimitRestTipAll);
sb.append(", \r\n每日限制- 休息提示次数: ");
sb.append(":");
sb.append(dayLimitRestTipTime);
sb.append(", \r\n每日限制- 自行休息次数: ");
sb.append(dayLimitRestSelfCount);
sb.append(", \r\n每日限制- 略过休息次数: ");
sb.append(dayLimitRestIgnoreCount);
sb.append(", \r\n每日限制- 休息延后次数: ");
sb.append(dayLimitRestDelayCount);
sb.append(", \r\n每日限制- 休息提示数量: ");
sb.append(dayLimitRestTipCount);
sb.append(", \r\n每日限制- 超时时间(以秒为单位): ");
sb.append(dayLimitTimeout);
sb.append(", \r\n 日使用量 以秒为单位: ");
sb.append(dayUse);
sb.append(", \r\n 鼠标移动距离(以像素为单位): ");
sb.append(mouseMove);
sb.append(", \r\n 鼠标有效移动距离(以像素为单位): ");
sb.append(mouseMoveuseful);
sb.append(", \r\n 鼠标的使用时间: ");
sb.append(mouseUseTime);
sb.append(", \r\n 鼠标点击次数: ");
sb.append(mouseClick);
sb.append(", \r\n 当天按键盘的次数: ");
sb.append(keyClick);

return sb.toString();
}
}

[/code]

有了这个JavaBean,就可以进一步将信息写到数据库进行统计分析了.

Tags: , ,

标签: , ,


分享到 Google Buzz
点此分享到QQ空间
点此分享到腾讯微博

与《Workrave的historystats文件内容格式分析》相关的搜索:

留下回复