int is_sunday = (tstruct->tm_wday == 0); /* is it sunday ? */
int i;
- /* Fix the hstat_cycle in case it's broken */
- if (is_sunday)
- hstat_cycle = hstat_cycle - (hstat_cycle % 7) + 6;
-
{ /* accounts */
haccount *ptr = haccounts;
for (;ptr;ptr = ptr->next)
}
}
HSTAT_ACCOUNT_ZERO(ptr2->week[(hstat_day() + 1) % 7]);
- /* ptr2->longterm[(hstat_week() - 1) % 10] = ptr2->longterm[hstat_week()];
- for (i=0;i<7;i++)
- {
- HSTAT_ACCOUNT_ZERO(ptr2->day[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->day[i]);
- }*/
}
HSTAT_CHANNEL_ZERO(ptr2->week[(hstat_day() + 1) % 7]);
}
}
- hstat_cycle++;
+ if (is_sunday)
+ hstat_cycle++;
}
int hstat_get_schedule_time(void)
return tmp;
}
-void hstat_calculate_general(hchannel *hchan, huser* husr, const char *message)
+void hstat_calculate_account(hchannel *hchan, huser* husr, const char *message)
{
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;
}
acc_entry = &(*acc_stat)->week[hstat_day()];
- chan_entry = &hchan->stats->week[hstat_day()];
time_spent = time(NULL) - huserchan->last_activity;
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;
}
switch (type)
{
case HSTAT_CHANNEL_LONG:
- 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);
- 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, "%-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_CHANNEL_SHORT:
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";
}
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(hchannel *hchan, hlevel lvl)
+hstat_accounts_array create_hstat_account_array(hchannel *hchan, hlevel lvl, hstat_account_array_type type)
{
hstat_accounts_array arr = {NULL, 0};
hstat_account *ptr;
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)
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_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);
- tmp1 = hstat_account_last_month(ptr);
+
+ 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;