struct tm *tstruct = localtime(&timer);
int is_sunday = (tstruct->tm_wday == 0); /* is it sunday ? */
int i;
- hstat_cycle++;
{ /* accounts */
haccount *ptr = haccounts;
- if (is_sunday)
- for (;ptr;ptr = ptr->next)
- if (ptr->level > H_PEON)
- {
- hstat_account *ptr2 = ptr->stats;
- for (;ptr2;ptr2 = ptr2->next)
- {
- HSTAT_ACCOUNT_ZERO(ptr2->longterm[(hstat_week() - 1) % 10]);
- for (i=0;i<7;i++)
- {
- HSTAT_ACCOUNT_SUM(ptr2->longterm[(hstat_week() - 1) % 10], ptr2->longterm[(hstat_week() - 1) % 10], ptr2->week[i]);
- }
- /*ptr2->longterm[(hstat_week() - 1) % 10] = ptr2->longterm[hstat_week()];*/
- /*for (i=0;i<7;i++)
- {
- HSTAT_ACCOUNT_ZERO(ptr2->week[i]);
- }*/
- }
- }
+ for (;ptr;ptr = ptr->next)
+ if (ptr->level > H_PEON)
+ {
+ hstat_account *ptr2 = ptr->stats;
+ for (;ptr2;ptr2 = ptr2->next)
+ {
+ if (is_sunday)
+ {
+ HSTAT_ACCOUNT_ZERO(ptr2->longterm[(hstat_week() + 1) % 10]);
+ for (i=0;i<7;i++)
+ {
+ HSTAT_ACCOUNT_SUM(ptr2->longterm[(hstat_week() + 1) % 10], ptr2->longterm[(hstat_week() + 1) % 10], ptr2->week[i]);
+ }
+ }
+ HSTAT_ACCOUNT_ZERO(ptr2->week[(hstat_day() + 1) % 7]);
+ }
+ }
}
{ /* hchannels */
hchannel *ptr = hchannels;
for (;ptr;ptr = ptr->next)
{
- if ((ptr->flags & H_REPORT) && hchannel_is_valid(ptr))
+ hstat_channel *ptr2;
+ if (ptr->flags & H_REPORT && hchannel_is_valid(ptr->report_to))
{
hstat_channel_entry *entry = &ptr->stats->week[hstat_day()];
helpmod_message_channel(ptr->report_to, "Daily summary for channel %s: Time spent %s, joins %d and queue usage %d", hchannel_get_name(ptr),helpmod_strtime(entry->time_spent), entry->joins, entry->queue_use);
}
- if (is_sunday)
- {
- hstat_channel *ptr2 = ptr->stats;
- HSTAT_CHANNEL_ZERO(ptr2->longterm[(hstat_week() - 1) % 10]);
+
+ ptr2 = ptr->stats;
+ if (is_sunday)
+ {
+ HSTAT_CHANNEL_ZERO(ptr2->longterm[(hstat_week() + 1) % 10]);
for (i=0;i<7;i++)
{
- HSTAT_CHANNEL_SUM(ptr2->longterm[(hstat_week() - 1) % 10], ptr2->longterm[(hstat_week() - 1) % 10], ptr2->week[i]);
+ HSTAT_CHANNEL_SUM(ptr2->longterm[(hstat_week() + 1) % 10], ptr2->longterm[(hstat_week() + 1) % 10], ptr2->week[i]);
}
- /*ptr2->longterm[(hstat_week() - 1) % 10] = ptr2->longterm[hstat_week()];*/
- /*for (i=0;i<7;i++)
- {
- HSTAT_CHANNEL_ZERO(ptr2->week[i]);
- }*/
- }
+ }
+ HSTAT_CHANNEL_ZERO(ptr2->week[(hstat_day() + 1) % 7]);
}
}
+
+ if (is_sunday)
+ hstat_cycle++;
}
int hstat_get_schedule_time(void)
return tmp;
}
-void hstat_del_channel(void* ptr)
+void hstat_del_channel(hchannel *hchan)
{
- hchannel *hchan = (hchannel*)ptr;
haccount *hacc = haccounts;
hstat_account **hs_acc;
for (;hacc;hacc = hacc->next)
return tmp;
}
-void hstat_calculate_general(void* param1, void* param2, const char *message)
+void hstat_calculate_account(hchannel *hchan, huser* husr, const char *message)
{
- hchannel *hchan = (hchannel*)param1;
- huser *husr = (huser*)param2;
hstat_account **acc_stat;
hstat_account_entry *acc_entry;
- hstat_channel_entry *chan_entry;
huser_channel *huserchan = huser_on_channel(husr, hchan);
int wordc = 0, time_spent;
break;
if (*acc_stat == NULL)
- /* this user has no stats for the channel -> create them */
- {
+ { /* this user has no stats for the channel -> create them */
*acc_stat = get_hstat_account();
(*acc_stat)->hchan = hchan;
}
acc_entry = &(*acc_stat)->week[hstat_day()];
- chan_entry = &hchan->stats->week[hstat_day()];
time_spent = time(NULL) - huserchan->last_activity;
- if (time_spent < HSTAT_ACTIVITY_TRESHOLD)
+ if (time_spent > 0 && time_spent < HSTAT_ACTIVITY_TRESHOLD)
{
acc_entry->time_spent+=time_spent;
- chan_entry->time_spent+=time_spent;
if (hstat_is_prime_time())
- {
acc_entry->prime_time_spent+=time_spent;
- chan_entry->prime_time_spent+=time_spent;
- }
}
acc_entry->lines++;
- chan_entry->lines++;
wordc = hword_count(message);
-
acc_entry->words+=wordc;
+}
+
+void hstat_calculate_channel(hchannel *hchan, huser* husr, const char *message)
+{
+ hstat_channel_entry *chan_entry;
+ huser_channel *huserchan = huser_on_channel(husr, hchan);
+
+ int wordc = 0, time_spent, activity_channel, activity_staff_channel;
+
+ if (huserchan == NULL)
+ return;
+
+ chan_entry = &hchan->stats->week[hstat_day()];
+
+ activity_channel = time(NULL) - hchan->last_activity;
+ activity_staff_channel = time(NULL) - hchan->last_staff_activity;
+
+ time_spent = time(NULL) - huserchan->last_activity;
+
+ if (time_spent > 0 && time_spent < HSTAT_ACTIVITY_TRESHOLD)
+ {
+ chan_entry->time_spent+=time_spent;
+
+ if (hstat_is_prime_time())
+ chan_entry->prime_time_spent+=time_spent;
+ }
+
+
+ { /* everyone */
+ if (activity_channel > 0 && activity_channel < HSTAT_ACTIVITY_TRESHOLD)
+ chan_entry->active_time+=activity_channel;
+ hchan->last_activity = time(NULL);
+ }
+
+ if (huser_get_level(husr) > H_PEON)
+ { /* staff */
+ if (activity_staff_channel > 0 && activity_staff_channel < HSTAT_ACTIVITY_TRESHOLD)
+ chan_entry->staff_active_time+=activity_staff_channel;
+ hchan->last_staff_activity = time(NULL);
+ }
+
+ chan_entry->lines++;
+
+ wordc = hword_count(message);
chan_entry->words+=wordc;
}
-void hstat_add_join(void *param)
+void hstat_add_join(hchannel *hchan)
{
- hchannel *hchan = (hchannel*)param;
hchan->stats->week[hstat_day()].joins++;
}
-void hstat_add_queue(void *param, int amount)
+void hstat_add_queue(hchannel *hchan, int amount)
{
- hchannel *hchan = (hchannel*)param;
hchan->stats->week[hstat_day()].queue_use+=amount;
}
-
const char *hstat_channel_print(hstat_channel_entry *entry, int type)
{
static char buffer[256];
switch (type)
{
case HSTAT_CHANNEL_LONG:
- sprintf(buffer, "%-15s %-15s %-10d %-10d %-10d %-10d", helpmod_strtime(entry->time_spent), helpmod_strtime(entry->prime_time_spent), entry->joins, entry->queue_use, entry->lines, entry->words);
- break;
+ /* sprintf(buffer, "%-18s %-18s %-10d %-10d %-10d %-10d", helpmod_strtime(entry->time_spent), helpmod_strtime(entry->prime_time_spent), entry->joins, entry->queue_use, entry->lines, entry->words); */
+ sprintf(buffer, "%-16s %-5.1f%% %-16s %-5.1f%% %-8d %-8d %-8d %-10d", helpmod_strtime(entry->time_spent), helpmod_percentage(entry->time_spent, entry->prime_time_spent), helpmod_strtime(entry->active_time), helpmod_percentage(entry->active_time, entry->staff_active_time), entry->joins, entry->queue_use, entry->lines, entry->words);
+ break;
case HSTAT_CHANNEL_SHORT:
- sprintf(buffer, "%-15s %-15s", helpmod_strtime(entry->time_spent), helpmod_strtime(entry->prime_time_spent));
+ sprintf(buffer, "%-18s %-18s", helpmod_strtime(entry->time_spent), helpmod_strtime(entry->prime_time_spent));
break;
}
return buffer;
switch (type)
{
case HSTAT_ACCOUNT_LONG:
- sprintf(buffer, "%-15s %-15s %-10d %-10d", helpmod_strtime(entry->time_spent), helpmod_strtime(entry->prime_time_spent), entry->lines, entry->words);
+ sprintf(buffer, "%-18s %-18s %-10d %-10d", helpmod_strtime(entry->time_spent), helpmod_strtime(entry->prime_time_spent), entry->lines, entry->words);
break;
case HSTAT_ACCOUNT_SHORT:
- sprintf(buffer, "%-15s %-15s", helpmod_strtime(entry->time_spent), helpmod_strtime(entry->prime_time_spent));
+ sprintf(buffer, "%-18s %-18s", helpmod_strtime(entry->time_spent), helpmod_strtime(entry->prime_time_spent));
break;
}
return buffer;
}
+
const char *hstat_header(hstat_type type)
{
switch (type)
{
case HSTAT_ACCOUNT_SHORT:
- return "TimeSpent PrimeTimeSpent";
+ return "TimeSpent PrimeTimeSpent";
case HSTAT_ACCOUNT_LONG:
- return "TimeSpent PrimeTimeSpent Lines Words";
+ return "TimeSpent PrimeTimeSpent Lines Words";
case HSTAT_CHANNEL_SHORT:
- return "TimeSpent PrimeTimeSpent";
+ return "TimeSpent PrimeTimeSpent";
case HSTAT_CHANNEL_LONG:
- return "TimeSpent PrimeTimeSpent Joins QueueUse Lines Words";
+ /*return "TimeSpent PrimeTimeSpent Joins QueueUse Lines Words";*/
+ return "TimeSpent Prime-% Activity Staff-% Joins QueueUse Lines Words";
default:
- return "error: please contact strutsi";
+ return "Error: please contact strutsi";
}
}
int hstat_week(void)
{
- return (hstat_cycle / 7) % 10;
+ return hstat_cycle % 10;
}
int hstat_day(void)
hstat_account_entry_sum tmp = {0,0,0,0};
int i;
- //HSTAT_ACCOUNT_SUM(tmp, tmp, hstat_account_last_week(hs_acc));
for (i=0;i<4;i++)
{
- HSTAT_ACCOUNT_SUM(tmp, tmp, hs_acc->longterm[(hstat_week() + i) % 10]);
+ HSTAT_ACCOUNT_SUM(tmp, tmp, hs_acc->longterm[(hstat_week() - i + 10) % 10]);
}
return tmp;
}
hstat_channel_entry hstat_channel_last_week(hstat_channel *hs_chan)
{
- hstat_channel_entry tmp = {0,0,0,0,0,0};
+ hstat_channel_entry tmp = {0,0,0,0,0,0,0,0};
int i;
for (i=0;i<7;i++)
{
hstat_channel_entry hstat_channel_last_month(hstat_channel *hs_chan)
{
- hstat_channel_entry tmp = {0,0,0,0,0,0};
+ hstat_channel_entry tmp = {0,0,0,0,0,0,0,0};
int i;
- //HSTAT_CHANNEL_SUM(tmp, tmp, hstat_channel_last_week(hs_chan));
for (i=0;i<4;i++)
{
- HSTAT_CHANNEL_SUM(tmp, tmp, hs_chan->longterm[(hstat_week() + i) % 10]);
+ HSTAT_CHANNEL_SUM(tmp, tmp, hs_chan->longterm[(hstat_week() - i + 10) % 10]);
}
return tmp;
}
static int hstat_account_compare(hstat_account_entry_sum *e1, hstat_account_entry_sum *e2)
{
- return e2->prime_time_spent - e1->prime_time_spent;
+ return e2->time_spent - e1->time_spent;
}
-hstat_accounts_array create_hstat_account_array(void* tptr, hlevel lvl)
+hstat_accounts_array create_hstat_account_array(hchannel *hchan, hlevel lvl, hstat_account_array_type type)
{
- hchannel *hchan = (hchannel*)tptr;
hstat_accounts_array arr = {NULL, 0};
hstat_account *ptr;
hstat_account_entry_sum tmp1, tmp2;
initial_arrlen = haccount_count(H_OPER) + haccount_count(H_ADMIN);
else if (lvl == H_STAFF)
initial_arrlen = haccount_count(H_STAFF) + haccount_count(H_TRIAL);
- else
+ else /* works fine for H_ANY */
initial_arrlen = haccount_count(lvl);
if (!initial_arrlen)
return arr;
- arr.array = malloc(sizeof(hstat_account_entry_sum) * initial_arrlen);
+ arr.array = (hstat_account_entry_sum*)malloc(sizeof(hstat_account_entry_sum) * initial_arrlen);
for (;hacc;hacc = hacc->next)
- if ((lvl == H_OPER && (hacc->level == H_OPER || hacc->level == H_ADMIN)) ||
- (lvl == H_STAFF && (hacc->level == H_TRIAL || hacc->level == H_STAFF)))
- //if ((lvl == H_OPER)?(hacc->level >= H_OPER && hacc->level < H_SERVICE):(hacc->level > H_PEON || hacc->level < H_OPER))
- for (ptr = hacc->stats;ptr;ptr = ptr->next)
- if (ptr->hchan == hchan)
- {
- assert(arr.arrlen < initial_arrlen);
- tmp1 = hstat_account_last_month(ptr);
- tmp2 = hstat_account_last_week(ptr);
- HSTAT_ACCOUNT_SUM(arr.array[arr.arrlen], tmp1, tmp2);
- arr.array[arr.arrlen].owner = (void*)hacc;
- arr.arrlen++;
- }
+ if ((lvl == H_ANY) ||
+ (lvl == H_OPER && (hacc->level == H_OPER || hacc->level == H_ADMIN)) ||
+ (lvl == H_STAFF && (hacc->level == H_TRIAL || hacc->level == H_STAFF)))
+ for (ptr = hacc->stats;ptr;ptr = ptr->next)
+ if (ptr->hchan == hchan)
+ {
+ assert(arr.arrlen < initial_arrlen);
+
+ if (type == HSTAT_ACCOUNT_ARRAY_TOP10)
+ tmp1 = hstat_account_last_month(ptr);
+ else
+ {
+ HSTAT_ACCOUNT_ZERO(tmp1);
+ }
+
+ tmp2 = hstat_account_last_week(ptr);
+ HSTAT_ACCOUNT_SUM(arr.array[arr.arrlen], tmp1, tmp2);
+ arr.array[arr.arrlen].owner = hacc;
+ arr.arrlen++;
+ }
qsort(arr.array, arr.arrlen, sizeof(hstat_account_entry_sum), (int(*)(const void*, const void*))hstat_account_compare);
return arr;