11 int hstat_is_prime_time(void)
13 time_t timer
= time(NULL
);
14 struct tm
*tstruct
= localtime(&timer
);
16 if (tstruct
->tm_hour
> 12 && tstruct
->tm_hour
< 23)
21 void hstat_scheduler(void)
23 time_t timer
= time(NULL
);
24 struct tm
*tstruct
= localtime(&timer
);
25 int is_sunday
= (tstruct
->tm_wday
== 0); /* is it sunday ? */
30 haccount
*ptr
= haccounts
;
32 for (;ptr
;ptr
= ptr
->next
)
33 if (ptr
->level
> H_PEON
)
35 hstat_account
*ptr2
= ptr
->stats
;
36 for (;ptr2
;ptr2
= ptr2
->next
)
38 HSTAT_ACCOUNT_ZERO(ptr2
->longterm
[(hstat_week() - 1) % 10]);
41 HSTAT_ACCOUNT_SUM(ptr2
->longterm
[(hstat_week() - 1) % 10], ptr2
->longterm
[(hstat_week() - 1) % 10], ptr2
->week
[i
]);
43 /*ptr2->longterm[(hstat_week() - 1) % 10] = ptr2->longterm[hstat_week()];*/
46 HSTAT_ACCOUNT_ZERO(ptr2->week[i]);
52 hchannel
*ptr
= hchannels
;
53 for (;ptr
;ptr
= ptr
->next
)
55 if ((ptr
->flags
& H_REPORT
) && hchannel_is_valid(ptr
))
57 hstat_channel_entry
*entry
= &ptr
->stats
->week
[hstat_day()];
58 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
);
62 hstat_channel
*ptr2
= ptr
->stats
;
63 HSTAT_CHANNEL_ZERO(ptr2
->longterm
[(hstat_week() - 1) % 10]);
66 HSTAT_CHANNEL_SUM(ptr2
->longterm
[(hstat_week() - 1) % 10], ptr2
->longterm
[(hstat_week() - 1) % 10], ptr2
->week
[i
]);
68 /*ptr2->longterm[(hstat_week() - 1) % 10] = ptr2->longterm[hstat_week()];*/
71 HSTAT_CHANNEL_ZERO(ptr2->week[i]);
78 int hstat_get_schedule_time(void)
80 time_t timer
= time(NULL
);
81 struct tm
*tstruct
= localtime(&timer
);
83 return timer
+ (HDEF_d
- (HDEF_h
* tstruct
->tm_hour
+ HDEF_m
* tstruct
->tm_min
+ tstruct
->tm_sec
));
86 hstat_channel
*get_hstat_channel(void)
90 tmp
= malloc(sizeof(hstat_channel
));
92 memset(tmp
, 0x00, sizeof(hstat_channel
));
97 void hstat_del_channel(void* ptr
)
99 hchannel
*hchan
= (hchannel
*)ptr
;
100 haccount
*hacc
= haccounts
;
101 hstat_account
**hs_acc
;
102 for (;hacc
;hacc
= hacc
->next
)
103 for (hs_acc
= &hacc
->stats
;*hs_acc
;hs_acc
= &(*hs_acc
)->next
)
104 if ((*hs_acc
)->hchan
== hchan
)
106 hstat_account
*tmp
= (*hs_acc
)->next
;
113 hstat_account
*get_hstat_account(void)
117 tmp
= malloc(sizeof(hstat_account
));
119 memset(tmp
, 0x00, sizeof(hstat_account
));
121 tmp
->next
= NULL
; /* just for style */
126 void hstat_calculate_general(void* param1
, void* param2
, const char *message
)
128 hchannel
*hchan
= (hchannel
*)param1
;
129 huser
*husr
= (huser
*)param2
;
130 hstat_account
**acc_stat
;
131 hstat_account_entry
*acc_entry
;
132 hstat_channel_entry
*chan_entry
;
133 huser_channel
*huserchan
= huser_on_channel(husr
, hchan
);
135 int wordc
= 0, time_spent
;
137 if (huserchan
== NULL
|| husr
->account
== NULL
)
140 for (acc_stat
= &husr
->account
->stats
;*acc_stat
;acc_stat
= &(*acc_stat
)->next
)
141 if ((*acc_stat
)->hchan
== hchan
)
144 if (*acc_stat
== NULL
)
145 /* this user has no stats for the channel -> create them */
147 *acc_stat
= get_hstat_account();
148 (*acc_stat
)->hchan
= hchan
;
151 acc_entry
= &(*acc_stat
)->week
[hstat_day()];
152 chan_entry
= &hchan
->stats
->week
[hstat_day()];
154 time_spent
= time(NULL
) - huserchan
->last_activity
;
156 if (time_spent
< HSTAT_ACTIVITY_TRESHOLD
)
158 acc_entry
->time_spent
+=time_spent
;
159 chan_entry
->time_spent
+=time_spent
;
161 if (hstat_is_prime_time())
163 acc_entry
->prime_time_spent
+=time_spent
;
164 chan_entry
->prime_time_spent
+=time_spent
;
171 wordc
= hword_count(message
);
173 acc_entry
->words
+=wordc
;
174 chan_entry
->words
+=wordc
;
177 void hstat_add_join(void *param
)
179 hchannel
*hchan
= (hchannel
*)param
;
180 hchan
->stats
->week
[hstat_day()].joins
++;
183 void hstat_add_queue(void *param
, int amount
)
185 hchannel
*hchan
= (hchannel
*)param
;
186 hchan
->stats
->week
[hstat_day()].queue_use
+=amount
;
190 const char *hstat_channel_print(hstat_channel_entry
*entry
, int type
)
192 static char buffer
[256];
196 case HSTAT_CHANNEL_LONG
:
197 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
);
199 case HSTAT_CHANNEL_SHORT
:
200 sprintf(buffer
, "%-15s %-15s", helpmod_strtime(entry
->time_spent
), helpmod_strtime(entry
->prime_time_spent
));
206 const char *hstat_account_print(hstat_account_entry
*entry
, int type
)
208 static char buffer
[256];
212 case HSTAT_ACCOUNT_LONG
:
213 sprintf(buffer
, "%-15s %-15s %-10d %-10d", helpmod_strtime(entry
->time_spent
), helpmod_strtime(entry
->prime_time_spent
), entry
->lines
, entry
->words
);
215 case HSTAT_ACCOUNT_SHORT
:
216 sprintf(buffer
, "%-15s %-15s", helpmod_strtime(entry
->time_spent
), helpmod_strtime(entry
->prime_time_spent
));
222 const char *hstat_header(hstat_type type
)
226 case HSTAT_ACCOUNT_SHORT
:
227 return "TimeSpent PrimeTimeSpent";
228 case HSTAT_ACCOUNT_LONG
:
229 return "TimeSpent PrimeTimeSpent Lines Words";
230 case HSTAT_CHANNEL_SHORT
:
231 return "TimeSpent PrimeTimeSpent";
232 case HSTAT_CHANNEL_LONG
:
233 return "TimeSpent PrimeTimeSpent Joins QueueUse Lines Words";
235 return "error: please contact strutsi";
241 return (hstat_cycle
/ 7) % 10;
246 time_t timer
= time(NULL
);
247 struct tm
*tstruct
= localtime(&timer
);
249 return tstruct
->tm_wday
;
252 int hstat_account_count(hstat_account
*hs_acc
)
255 for (;hs_acc
;hs_acc
= hs_acc
->next
)
260 hstat_account_entry_sum
hstat_account_last_week(hstat_account
*hs_acc
)
262 hstat_account_entry_sum tmp
= {0,0,0,0};
266 HSTAT_ACCOUNT_SUM(tmp
, tmp
, hs_acc
->week
[i
]);
271 hstat_account_entry_sum
hstat_account_last_month(hstat_account
*hs_acc
)
273 hstat_account_entry_sum tmp
= {0,0,0,0};
276 //HSTAT_ACCOUNT_SUM(tmp, tmp, hstat_account_last_week(hs_acc));
279 HSTAT_ACCOUNT_SUM(tmp
, tmp
, hs_acc
->longterm
[(hstat_week() + i
) % 10]);
284 hstat_channel_entry
hstat_channel_last_week(hstat_channel
*hs_chan
)
286 hstat_channel_entry tmp
= {0,0,0,0,0,0};
290 HSTAT_CHANNEL_SUM(tmp
, tmp
, hs_chan
->week
[i
]);
295 hstat_channel_entry
hstat_channel_last_month(hstat_channel
*hs_chan
)
297 hstat_channel_entry tmp
= {0,0,0,0,0,0};
300 //HSTAT_CHANNEL_SUM(tmp, tmp, hstat_channel_last_week(hs_chan));
303 HSTAT_CHANNEL_SUM(tmp
, tmp
, hs_chan
->longterm
[(hstat_week() + i
) % 10]);
308 static int hstat_account_compare(hstat_account_entry_sum
*e1
, hstat_account_entry_sum
*e2
)
310 return e2
->prime_time_spent
- e1
->prime_time_spent
;
313 hstat_accounts_array
create_hstat_account_array(void* tptr
, hlevel lvl
)
315 hchannel
*hchan
= (hchannel
*)tptr
;
316 hstat_accounts_array arr
= {NULL
, 0};
318 hstat_account_entry_sum tmp1
, tmp2
;
319 haccount
*hacc
= haccounts
;
320 int initial_arrlen
= 0;
323 initial_arrlen
= haccount_count(H_OPER
) + haccount_count(H_ADMIN
);
324 else if (lvl
== H_STAFF
)
325 initial_arrlen
= haccount_count(H_STAFF
) + haccount_count(H_TRIAL
);
327 initial_arrlen
= haccount_count(lvl
);
332 arr
.array
= malloc(sizeof(hstat_account_entry_sum
) * initial_arrlen
);
333 for (;hacc
;hacc
= hacc
->next
)
334 if ((lvl
== H_OPER
&& (hacc
->level
== H_OPER
|| hacc
->level
== H_ADMIN
)) ||
335 (lvl
== H_STAFF
&& (hacc
->level
== H_TRIAL
|| hacc
->level
== H_STAFF
)))
336 //if ((lvl == H_OPER)?(hacc->level >= H_OPER && hacc->level < H_SERVICE):(hacc->level > H_PEON || hacc->level < H_OPER))
337 for (ptr
= hacc
->stats
;ptr
;ptr
= ptr
->next
)
338 if (ptr
->hchan
== hchan
)
340 assert(arr
.arrlen
< initial_arrlen
);
341 tmp1
= hstat_account_last_month(ptr
);
342 tmp2
= hstat_account_last_week(ptr
);
343 HSTAT_ACCOUNT_SUM(arr
.array
[arr
.arrlen
], tmp1
, tmp2
);
344 arr
.array
[arr
.arrlen
].owner
= (void*)hacc
;
348 qsort(arr
.array
, arr
.arrlen
, sizeof(hstat_account_entry_sum
), (int(*)(const void*, const void*))hstat_account_compare
);