[srvx-commits] CVS: services/src helpserv.c,1.67,1.68
Brought to you by:
entrope
|
From: Adrian D. <sai...@us...> - 2003-06-02 20:10:50
|
Update of /cvsroot/srvx/services/src
In directory sc8-pr-cvs1:/tmp/cvs-serv31187
Modified Files:
helpserv.c
Log Message:
Track all helper information for the previous 4 weeks
Modify cmd_stats to show some of the extra information
Convert all helper time stats to "x hours, y minutes"
Add number of requests picked up + reassigned to the helper in cmd_statsreport (Featreq #690260)
Index: helpserv.c
===================================================================
RCS file: /cvsroot/srvx/services/src/helpserv.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -C2 -r1.67 -r1.68
*** helpserv.c 2 Jun 2003 01:32:10 -0000 1.67
--- helpserv.c 2 Jun 2003 20:10:44 -0000 1.68
***************
*** 439,448 ****
/* statistics */
time_t join_time; /* when they joined, or 0 if not in channel */
! unsigned int time_per_week[4]; /* how long they've were in the channel the past 4 weeks */
! /* These statistics are kept both per-week (in [0]) and total (in [1]). */
! unsigned int picked_up[2]; /* how many requests they have picked up */
! unsigned int closed[2]; /* how many requests they have closed */
! unsigned int reassigned_from[2]; /* how many requests reassigned from them to others */
! unsigned int reassigned_to[2]; /* how many requests reassigned from others to them */
};
--- 439,448 ----
/* statistics */
time_t join_time; /* when they joined, or 0 if not in channel */
! /* [0] through [3] are n weeks ago, [4] is the total of everything before that */
! unsigned int time_per_week[5]; /* how long they've were in the channel the past 4 weeks */
! unsigned int picked_up[5]; /* how many requests they have picked up */
! unsigned int closed[5]; /* how many requests they have closed */
! unsigned int reassigned_from[5]; /* how many requests reassigned from them to others */
! unsigned int reassigned_to[5]; /* how many requests reassigned from others to them */
};
***************
*** 558,561 ****
--- 558,567 ----
};
+ static void helpserv_interval(char *output, time_t interval) {
+ int num_hours = interval / 3600;
+ int num_minutes = (interval % 3600) / 60;
+ sprintf(output, "%u hour%s, %u minute%s", num_hours, num_hours == 1 ? "" : "s", num_minutes, num_minutes == 1 ? "" : "s");
+ }
+
static const char * helpserv_level2str(enum helpserv_level level) {
if (level <= HlOper) {
***************
*** 1450,1454 ****
hs_user->closed[0]++;
! hs_user->closed[1]++;
/* Set these to keep track of the lists after the request is gone, but
--- 1456,1460 ----
hs_user->closed[0]++;
! hs_user->closed[4]++;
/* Set these to keep track of the lists after the request is gone, but
***************
*** 1648,1658 ****
helpserv_notice(user, HSMSG_REQ_REASSIGNED, req->id, old_helper->handle->handle);
req->helper->reassigned_to[0]++;
! req->helper->reassigned_to[1]++;
old_helper->reassigned_from[0]++;
! old_helper->reassigned_from[1]++;
} else {
helpserv_notice(user, HSMSG_REQ_ASSIGNED_YOU, req->id);
req->helper->picked_up[0]++;
! req->helper->picked_up[1]++;
}
helpserv_show(from_opserv, hs, user, req);
--- 1654,1664 ----
helpserv_notice(user, HSMSG_REQ_REASSIGNED, req->id, old_helper->handle->handle);
req->helper->reassigned_to[0]++;
! req->helper->reassigned_to[4]++;
old_helper->reassigned_from[0]++;
! old_helper->reassigned_from[4]++;
} else {
helpserv_notice(user, HSMSG_REQ_ASSIGNED_YOU, req->id);
req->helper->picked_up[0]++;
! req->helper->picked_up[4]++;
}
helpserv_show(from_opserv, hs, user, req);
***************
*** 1813,1817 ****
int i;
char weekstr[32]; /* "September 10" should be the longest, but with other locales, who knows */
! char intervalstr[INTERVALLEN];
char buf[12];
struct tm *week_tm;
--- 1819,1823 ----
int i;
char weekstr[32]; /* "September 10" should be the longest, but with other locales, who knows */
! char intervalstr[32]; /* Should be at least 1 more than enough */
char buf[12];
struct tm *week_tm;
***************
*** 1849,1853 ****
helpserv_notice(user, HSMSG_STATS_TOP, hs->helpserv->nick, target->handle->handle);
! tbl.length = 5;
tbl.width = 2;
tbl.flags = TABLE_NO_FREE;
--- 1855,1859 ----
helpserv_notice(user, HSMSG_STATS_TOP, hs->helpserv->nick, target->handle->handle);
! tbl.length = 6;
tbl.width = 2;
tbl.flags = TABLE_NO_FREE;
***************
*** 1858,1872 ****
week_tm = localtime(&last_stats_update);
week_tm->tm_mday -= week_tm->tm_wday; /* Ensure it'll start on Sunday */
! for (i=0; i < 4; i++) {
unsigned int week_time = target->time_per_week[i];
tbl.contents[i+1] = alloca(tbl.width * sizeof(**tbl.contents));
! mktime(week_tm); /* To fix up other stuff after messing with tm_mday */
! if (!strftime(weekstr, 32, "%B %d", week_tm)) {
! tbl.contents[i+1][0] = strdup("(Error)");
} else {
! tbl.contents[i+1][0] = strdup(weekstr);
}
! if ((i == 0) && target->join_time) week_time += now - target->join_time;
! intervalString(intervalstr, week_time);
tbl.contents[i+1][1] = strdup(intervalstr);
week_tm->tm_mday -= 7;
--- 1864,1882 ----
week_tm = localtime(&last_stats_update);
week_tm->tm_mday -= week_tm->tm_wday; /* Ensure it'll start on Sunday */
! for (i=0; i < 5; i++) {
unsigned int week_time = target->time_per_week[i];
tbl.contents[i+1] = alloca(tbl.width * sizeof(**tbl.contents));
! if (i == 4) {
! tbl.contents[i+1][0] = strdup("Total");
} else {
! mktime(week_tm); /* To fix up other stuff after messing with tm_mday */
! if (!strftime(weekstr, 32, "%B %d", week_tm)) {
! tbl.contents[i+1][0] = strdup("(Error)");
! } else {
! tbl.contents[i+1][0] = strdup(weekstr);
! }
}
! if ((i == 0 || i == 4) && target->join_time) week_time += now - target->join_time;
! helpserv_interval(intervalstr, week_time);
tbl.contents[i+1][1] = strdup(intervalstr);
week_tm->tm_mday -= 7;
***************
*** 1882,1886 ****
tbl.length = 5;
! tbl.width = 3;
tbl.flags = TABLE_NO_FREE;
tbl.contents = alloca(tbl.length * sizeof(*tbl.contents));
--- 1892,1896 ----
tbl.length = 5;
! tbl.width = 4;
tbl.flags = TABLE_NO_FREE;
tbl.contents = alloca(tbl.length * sizeof(*tbl.contents));
***************
*** 1892,1915 ****
tbl.contents[0][0] = "Category";
tbl.contents[0][1] = "This week";
! tbl.contents[0][2] = "Total";
tbl.contents[1][0] = "Requests picked up";
! for (i=0; i < 2; i++) {
! sprintf(buf, "%u", target->picked_up[i]);
tbl.contents[1][i+1] = strdup(buf);
}
tbl.contents[2][0] = "Requests closed";
! for (i=0; i < 2; i++) {
! sprintf(buf, "%u", target->closed[i]);
tbl.contents[2][i+1] = strdup(buf);
}
tbl.contents[3][0] = "Reassigned from";
! for (i=0; i < 2; i++) {
! sprintf(buf, "%u", target->reassigned_from[i]);
tbl.contents[3][i+1] = strdup(buf);
}
tbl.contents[4][0] = "Reassigned to";
! for (i=0; i < 2; i++) {
! sprintf(buf, "%u", target->reassigned_to[i]);
tbl.contents[4][i+1] = strdup(buf);
}
--- 1902,1926 ----
tbl.contents[0][0] = "Category";
tbl.contents[0][1] = "This week";
! tbl.contents[0][2] = "Last week";
! tbl.contents[0][3] = "Total";
tbl.contents[1][0] = "Requests picked up";
! for (i=0; i < 3; i++) {
! sprintf(buf, "%u", target->picked_up[(i == 2 ? 4 : i)]);
tbl.contents[1][i+1] = strdup(buf);
}
tbl.contents[2][0] = "Requests closed";
! for (i=0; i < 3; i++) {
! sprintf(buf, "%u", target->closed[(i == 2 ? 4 : i)]);
tbl.contents[2][i+1] = strdup(buf);
}
tbl.contents[3][0] = "Reassigned from";
! for (i=0; i < 3; i++) {
! sprintf(buf, "%u", target->reassigned_from[(i == 2 ? 4 : i)]);
tbl.contents[3][i+1] = strdup(buf);
}
tbl.contents[4][0] = "Reassigned to";
! for (i=0; i < 3; i++) {
! sprintf(buf, "%u", target->reassigned_to[(i == 2 ? 4 : i)]);
tbl.contents[4][i+1] = strdup(buf);
}
***************
*** 1921,1924 ****
--- 1932,1936 ----
free((char *)tbl.contents[i][1]);
free((char *)tbl.contents[i][2]);
+ free((char *)tbl.contents[i][3]);
}
***************
*** 1942,1951 ****
tbl.length = dict_size(hs->users)+1;
! tbl.width = 2;
tbl.flags = TABLE_NO_FREE;
tbl.contents = alloca(tbl.length * sizeof(*tbl.contents));
tbl.contents[0] = alloca(tbl.width * sizeof(**tbl.contents));
! tbl.contents[0][0] = "Handle";
! tbl.contents[0][1] = "Time helping";
for (it=dict_first(hs->users), line=0; it; it=iter_next(it)) {
--- 1954,1964 ----
tbl.length = dict_size(hs->users)+1;
! tbl.width = 3;
tbl.flags = TABLE_NO_FREE;
tbl.contents = alloca(tbl.length * sizeof(*tbl.contents));
tbl.contents[0] = alloca(tbl.width * sizeof(**tbl.contents));
! tbl.contents[0][0] = "Account";
! tbl.contents[0][1] = "Requests";
! tbl.contents[0][2] = "Time helping";
for (it=dict_first(hs->users), line=0; it; it=iter_next(it)) {
***************
*** 1954,1958 ****
tbl.contents[++line] = alloca(tbl.width * sizeof(**tbl.contents));
tbl.contents[line][0] = hs_user->handle->handle;
! tbl.contents[line][1] = malloc(INTERVALLEN);
}
--- 1967,1972 ----
tbl.contents[++line] = alloca(tbl.width * sizeof(**tbl.contents));
tbl.contents[line][0] = hs_user->handle->handle;
! tbl.contents[line][1] = malloc(12);
! tbl.contents[line][2] = malloc(32); /* A bit more than needed */
}
***************
*** 1960,1970 ****
week_tm.tm_mday -= week_tm.tm_wday; /* Ensure it'll start on Sunday */
week_tm.tm_mday -= 7 * 3; /* Oldest to newest */
! /* 4 to 1 because it's unsigned */
for (i=4; i > 0; i--, week_tm.tm_mday += 7) {
for (it=dict_first(hs->users), line=0; it; it=iter_next(it)) {
struct helpserv_user *hs_user=iter_data(it);
unsigned int week_time = hs_user->time_per_week[i-1];
if ((i==1) && hs_user->join_time) week_time += now - hs_user->join_time;
! intervalString((char *)tbl.contents[++line][1], week_time);
}
mktime(&week_tm); /* To fix up stuff after messing with tm_mday */
--- 1974,1988 ----
week_tm.tm_mday -= week_tm.tm_wday; /* Ensure it'll start on Sunday */
week_tm.tm_mday -= 7 * 3; /* Oldest to newest */
! /* 4 to 1 instead of 3 to 0 because it's unsigned */
for (i=4; i > 0; i--, week_tm.tm_mday += 7) {
for (it=dict_first(hs->users), line=0; it; it=iter_next(it)) {
struct helpserv_user *hs_user=iter_data(it);
+ /* Time */
unsigned int week_time = hs_user->time_per_week[i-1];
if ((i==1) && hs_user->join_time) week_time += now - hs_user->join_time;
! helpserv_interval((char *)tbl.contents[++line][2], week_time);
!
! /* Requests */
! sprintf((char *)tbl.contents[line][1], "%u", hs_user->picked_up[i-1]+hs_user->reassigned_to[i-1]);
}
mktime(&week_tm); /* To fix up stuff after messing with tm_mday */
***************
*** 1976,1979 ****
--- 1994,1998 ----
for (line=1; line <= dict_size(hs->users); line++) {
free((char *)tbl.contents[line][1]);
+ free((char *)tbl.contents[line][2]);
}
***************
*** 2879,2883 ****
struct saxdb_context *ctx = extra;
struct string_list strlist;
! char str[4][16], *strs[4];
unsigned int i;
--- 2898,2902 ----
struct saxdb_context *ctx = extra;
struct string_list strlist;
! char str[5][16], *strs[5];
unsigned int i;
***************
*** 2890,2916 ****
for (i=0; i < ArrayLength(strs); ++i) strs[i] = str[i];
strlist.list = strs;
/* Time in help channel */
- strlist.used = 4;
for (i=0; i < strlist.used; i++) {
unsigned int week_time = hs_user->time_per_week[i];
! if ((i==0) && hs_user->join_time) week_time += now - hs_user->join_time;
sprintf(str[i], "%u", week_time);
}
saxdb_write_string_list(ctx, KEY_HELPER_STATS_TIME, &strlist);
/* Requests picked up */
- strlist.used = 2;
for (i=0; i < strlist.used; i++) sprintf(str[i], "%u", hs_user->picked_up[i]);
saxdb_write_string_list(ctx, KEY_HELPER_STATS_PICKUP, &strlist);
/* Requests closed */
- strlist.used = 2;
for (i=0; i < strlist.used; i++) sprintf(str[i], "%u", hs_user->closed[i]);
saxdb_write_string_list(ctx, KEY_HELPER_STATS_CLOSE, &strlist);
/* Requests reassigned from user */
- strlist.used = 2;
for (i=0; i < strlist.used; i++) sprintf(str[i], "%u", hs_user->reassigned_from[i]);
saxdb_write_string_list(ctx, KEY_HELPER_STATS_REASSIGNFROM, &strlist);
/* Requests reassigned to user */
! strlist.used = 2;
! for (i=0; i < 2; i++) sprintf(str[i], "%u", hs_user->reassigned_to[i]);
saxdb_write_string_list(ctx, KEY_HELPER_STATS_REASSIGNTO, &strlist);
/* End of stats and whole record. */
--- 2909,2931 ----
for (i=0; i < ArrayLength(strs); ++i) strs[i] = str[i];
strlist.list = strs;
+ strlist.used = 5;
/* Time in help channel */
for (i=0; i < strlist.used; i++) {
unsigned int week_time = hs_user->time_per_week[i];
! if ((i==0 || i==4) && hs_user->join_time) week_time += now - hs_user->join_time;
sprintf(str[i], "%u", week_time);
}
saxdb_write_string_list(ctx, KEY_HELPER_STATS_TIME, &strlist);
/* Requests picked up */
for (i=0; i < strlist.used; i++) sprintf(str[i], "%u", hs_user->picked_up[i]);
saxdb_write_string_list(ctx, KEY_HELPER_STATS_PICKUP, &strlist);
/* Requests closed */
for (i=0; i < strlist.used; i++) sprintf(str[i], "%u", hs_user->closed[i]);
saxdb_write_string_list(ctx, KEY_HELPER_STATS_CLOSE, &strlist);
/* Requests reassigned from user */
for (i=0; i < strlist.used; i++) sprintf(str[i], "%u", hs_user->reassigned_from[i]);
saxdb_write_string_list(ctx, KEY_HELPER_STATS_REASSIGNFROM, &strlist);
/* Requests reassigned to user */
! for (i=0; i < strlist.used; i++) sprintf(str[i], "%u", hs_user->reassigned_to[i]);
saxdb_write_string_list(ctx, KEY_HELPER_STATS_REASSIGNTO, &strlist);
/* End of stats and whole record. */
***************
*** 2961,2974 ****
if (stats) {
strlist = database_get_data(stats, KEY_HELPER_STATS_TIME, RECDB_STRING_LIST);
! if (strlist) for (i=0; i < 4 && i < strlist->used; i++) hs_user->time_per_week[i] = strtoul(strlist->list[i], NULL, 0);
strlist = database_get_data(stats, KEY_HELPER_STATS_PICKUP, RECDB_STRING_LIST);
! if (strlist) for (i=0; i < 2 && i < strlist->used; i++) hs_user->picked_up[i] = strtoul(strlist->list[i], NULL, 0);
strlist = database_get_data(stats, KEY_HELPER_STATS_CLOSE, RECDB_STRING_LIST);
! if (strlist) for (i=0; i < 2 && i < strlist->used; i++) hs_user->closed[i] = strtoul(strlist->list[i], NULL, 0);
strlist = database_get_data(stats, KEY_HELPER_STATS_REASSIGNFROM, RECDB_STRING_LIST);
! if (strlist) for (i=0; i < 2 && i < strlist->used; i++) hs_user->reassigned_from[i] = strtoul(strlist->list[i], NULL, 0);
strlist = database_get_data(stats, KEY_HELPER_STATS_REASSIGNTO, RECDB_STRING_LIST);
! if (strlist) for (i=0; i < 2 && i < strlist->used; i++) hs_user->reassigned_to[i] = strtoul(strlist->list[i], NULL, 0);
}
--- 2976,2995 ----
if (stats) {
+ /* The tests for strlist->used are for converting the old format to the new one */
strlist = database_get_data(stats, KEY_HELPER_STATS_TIME, RECDB_STRING_LIST);
! if (strlist) for (i=0; i < 5 && i < strlist->used; i++) hs_user->time_per_week[i] = strtoul(strlist->list[i], NULL, 0);
! if (strlist->used == 4) hs_user->time_per_week[4] = hs_user->time_per_week[0]+hs_user->time_per_week[1]+hs_user->time_per_week[2]+hs_user->time_per_week[3];
strlist = database_get_data(stats, KEY_HELPER_STATS_PICKUP, RECDB_STRING_LIST);
! if (strlist) for (i=0; i < 5 && i < strlist->used; i++) hs_user->picked_up[i] = strtoul(strlist->list[i], NULL, 0);
! if (strlist->used == 2) hs_user->picked_up[4] = hs_user->picked_up[0]+hs_user->picked_up[1];
strlist = database_get_data(stats, KEY_HELPER_STATS_CLOSE, RECDB_STRING_LIST);
! if (strlist) for (i=0; i < 5 && i < strlist->used; i++) hs_user->closed[i] = strtoul(strlist->list[i], NULL, 0);
! if (strlist->used == 2) hs_user->closed[4] = hs_user->closed[0]+hs_user->closed[1];
strlist = database_get_data(stats, KEY_HELPER_STATS_REASSIGNFROM, RECDB_STRING_LIST);
! if (strlist) for (i=0; i < 5 && i < strlist->used; i++) hs_user->reassigned_from[i] = strtoul(strlist->list[i], NULL, 0);
! if (strlist->used == 2) hs_user->reassigned_from[4] = hs_user->reassigned_from[0]+hs_user->reassigned_from[1];
strlist = database_get_data(stats, KEY_HELPER_STATS_REASSIGNTO, RECDB_STRING_LIST);
! if (strlist) for (i=0; i < 5 && i < strlist->used; i++) hs_user->reassigned_to[i] = strtoul(strlist->list[i], NULL, 0);
! if (strlist->used == 2) hs_user->reassigned_to[4] = hs_user->reassigned_to[0]+hs_user->reassigned_to[1];
}
***************
*** 3372,3375 ****
--- 3393,3397 ----
if (hs_user->join_time && (hs_user->join_time < now)) {
hs_user->time_per_week[0] += (unsigned int)(now - hs_user->join_time);
+ hs_user->time_per_week[4] += (unsigned int)(now - hs_user->join_time);
}
hs_user->join_time = 0;
***************
*** 4032,4040 ****
if (hs_user->join_time) {
hs_user->time_per_week[0] += now - hs_user->join_time;
hs_user->join_time = now;
}
! /* Shift time */
! for (i=3; i > 0; i--) hs_user->time_per_week[i] = hs_user->time_per_week[i-1];
/* Reset it for this week */
--- 4054,4069 ----
if (hs_user->join_time) {
hs_user->time_per_week[0] += now - hs_user->join_time;
+ hs_user->time_per_week[4] += now - hs_user->join_time;
hs_user->join_time = now;
}
! /* Shift everything */
! for (i=3; i > 0; i--) {
! hs_user->time_per_week[i] = hs_user->time_per_week[i-1];
! hs_user->picked_up[i] = hs_user->picked_up[i-1];
! hs_user->closed[i] = hs_user->closed[i-1];
! hs_user->reassigned_from[i] = hs_user->reassigned_from[i-1];
! hs_user->reassigned_to[i] = hs_user->reassigned_to[i-1];
! }
/* Reset it for this week */
|