]> jfr.im git - irc/quakenet/newserv.git/blob - helpmod2/hstat.h
Initial Import
[irc/quakenet/newserv.git] / helpmod2 / hstat.h
1 #ifndef HSTAT_H
2 #define HSTAT_H
3
4 #include "hdef.h"
5
6 extern int hstat_cycle;
7 extern time_t hstat_last_cycle;
8
9 #define HSTAT_ACTIVITY_TRESHOLD (3 * 60)
10
11 #define HSTAT_ACCOUNT_SUM(sum, op1, op2)\
12 {\
13 (sum).time_spent = (op1).time_spent + (op2).time_spent;\
14 (sum).prime_time_spent = (op1).prime_time_spent + (op2).prime_time_spent;\
15 (sum).lines = (op1).lines + (op2).lines;\
16 (sum).words = (op1).words + (op2).words;\
17 }
18
19 #define HSTAT_ACCOUNT_ZERO(target)\
20 {\
21 (target).time_spent = 0;\
22 (target).prime_time_spent = 0;\
23 (target).lines = 0;\
24 (target).words = 0;\
25 }
26
27 #define HSTAT_CHANNEL_SUM(sum, op1, op2)\
28 {\
29 (sum).time_spent = (op1).time_spent + (op2).time_spent;\
30 (sum).prime_time_spent = (op1).prime_time_spent + (op2).prime_time_spent;\
31 (sum).lines = (op1).lines + (op2).lines;\
32 (sum).words = (op1).words + (op2).words;\
33 (sum).joins = (op1).joins + (op2).joins;\
34 (sum).queue_use = (op1).queue_use + (op2).queue_use;\
35 }
36
37 #define HSTAT_CHANNEL_ZERO(target)\
38 {\
39 (target).time_spent = 0;\
40 (target).prime_time_spent = 0;\
41 (target).lines = 0;\
42 (target).words = 0;\
43 (target).joins = 0;\
44 (target).queue_use = 0;\
45 }
46
47 typedef enum
48 {
49 HSTAT_ACCOUNT_SHORT,
50 HSTAT_ACCOUNT_LONG,
51 HSTAT_CHANNEL_SHORT,
52 HSTAT_CHANNEL_LONG
53 } hstat_type;
54
55 typedef struct hstat_account_entry_struct
56 {
57 int time_spent;
58 int prime_time_spent;
59 int lines;
60 int words;
61 } hstat_account_entry;
62
63 typedef struct hstat_account_entry_sum_struct
64 {
65 int time_spent;
66 int prime_time_spent;
67 int lines;
68 int words;
69 void *owner; /* haccount* */
70 } hstat_account_entry_sum;
71
72 typedef struct hstat_channel_entry_struct
73 {
74 int time_spent;
75 int prime_time_spent;
76
77 int joins;
78 int queue_use;
79
80 int lines;
81 int words;
82 } hstat_channel_entry;
83
84 typedef struct hstat_channel_struct
85 {
86 hstat_channel_entry week[7]; /* 7 days */
87 hstat_channel_entry longterm[10]; /* 10 weeks */
88
89 } hstat_channel;
90
91 typedef struct hstats_account_struct
92 {
93 struct hchannel_struct *hchan;
94
95 hstat_account_entry week[7]; /* 7 days */
96 hstat_account_entry longterm[10]; /* 10 weeks */
97
98 struct hstats_account_struct *next;
99 } hstat_account;
100
101 typedef struct hstat_accounts_array_struct
102 {
103 hstat_account_entry_sum *array;
104 int arrlen;
105 } hstat_accounts_array;
106
107 /* free() this.entries, arguments: channel, level to list */
108 hstat_accounts_array create_hstat_account_array(void*, hlevel);
109
110 hstat_channel *get_hstat_channel(void);
111 hstat_account *get_hstat_account(void);
112
113 const char *hstat_header(hstat_type);
114
115 const char *hstat_channel_print(hstat_channel_entry*, int);
116
117 const char *hstat_account_print(hstat_account_entry*, int);
118
119 /* void* = hchannel*, huser* */
120 void hstat_calculate_general(void*, void*, const char *);
121
122 /* void* = hchannel* */
123 void hstat_add_join(void*);
124 void hstat_del_channel(void*);
125
126 /* void* = hchannel* */
127 void hstat_add_queue(void*, int);
128
129 int is_prime_time(void); /* tells if now is the "main" time in #feds */
130
131 int hstat_week(void);
132 int hstat_day(void);
133
134 hstat_account_entry_sum hstat_account_last_week(hstat_account*);
135 hstat_account_entry_sum hstat_account_last_month(hstat_account*);
136 hstat_channel_entry hstat_channel_last_week(hstat_channel*);
137 hstat_channel_entry hstat_channel_last_month(hstat_channel*);
138
139 int hstat_account_count(hstat_account*);
140
141 /* handles the cycle and today -> week -> longterm changes */
142 void hstat_scheduler(void);
143 int hstat_get_schedule_time(void);
144
145 #endif