1 /* Citadel/UX call log stats program
11 #define disply(x,y) printf("%20s %4.1f %4.1f %4d\n",x,((float)y)/calls,((float)y)/days,y)
13 #define GRANULARITY 100
34 printf ("Press return to continue...");
35 fgets (buf, 16, stdin);
44 halfhour (time) /* Returns half-hour time period of time */
49 tm = (struct tm *) localtime (&time);
50 a = (tm->tm_hour) * 3;
51 if ((tm->tm_min) > 19)
53 if ((tm->tm_min) > 39)
70 printf ("--------------------------------------");
71 printf ("--------------------------------------\r");
76 pos = (curr * 72) / max;
101 struct calllog calllog;
102 struct usersupp usersupp;
103 int file, pos, a, b, lowest;
109 long cftime, cttime, aa;
110 int calls, logins, newusers;
111 int badpws, terms, drops, sleeps;
112 long from, to, tottime;
113 int days, hours, minutes;
116 struct caller *callers = NULL;
117 struct caller *callptr = NULL;
119 char thegraph[GRANULARITY][73];
122 for (a = 0; a < argc; ++a)
124 if (!strcmp (argv[a], "-b"))
126 if (!strcmp (argv[a], "-p"))
131 for (a = 0; a < GRANULARITY; ++a)
133 "........................................................................");
141 printf ("Scanning call log, please wait...\n\n\n\n");
143 file = open ("calllog.pos", O_RDONLY);
144 read (file, &pos, 2);
148 for (a = 0; a < 72; ++a)
163 file = open ("calllog", O_RDONLY);
164 lseek (file, (long) (pos * sizeof (struct calllog)), 0);
166 printf ("Scanning call log, please wait...\n");
167 for (a = 0; a < CALLLOG; ++a)
170 progress ((long) a, (long) (CALLLOG - 1));
171 if ((a + pos) == CALLLOG)
173 read (file, &calllog, sizeof (struct calllog));
174 if (calllog.CLflags != 0)
176 if ((calllog.CLtime < from) || (from == 0L))
177 from = calllog.CLtime;
178 if ((calllog.CLtime > to) || (to == 0L))
181 if (calllog.CLflags & CL_CONNECT)
186 cftime = calllog.CLtime;
187 strcpy (dname, calllog.CLfullname);
189 if (calllog.CLflags & CL_LOGIN)
193 for (callptr = callers; callptr != NULL; callptr = callptr->next)
195 if (!strcmp (callptr->Cname, calllog.CLfullname))
198 ++callptr->Ctimescalled;
203 callptr = (struct caller *) malloc (sizeof (struct caller));
204 callptr->next = callers;
206 strcpy (callers->Cname, calllog.CLfullname);
207 callers->Ctimescalled = 1;
210 if (calllog.CLflags & CL_NEWUSER)
212 if (calllog.CLflags & CL_BADPW)
214 if (calllog.CLflags & CL_TERMINATE)
220 cttime = calllog.CLtime;
221 for (aa = cftime; aa <= cttime; aa = aa + 300L)
222 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
227 if (calllog.CLflags & CL_DROPCARR)
233 cttime = calllog.CLtime;
234 for (aa = cftime; aa <= cttime; aa = aa + 300L)
235 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
240 if (calllog.CLflags & CL_SLEEPING)
246 cttime = calllog.CLtime;
247 for (aa = cftime; aa <= cttime; aa = aa + 300L)
248 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
261 days = (int) (tottime / 86400L);
262 hours = (int) ((tottime % 86400L) / 3600L);
263 minutes = (int) ((tottime % 3600L) / 60L);
265 printf (" Avg/Call Avg/Day Total\n");
266 disply ("Calls:", calls);
267 disply ("Logins:", logins);
268 disply ("New users:", newusers);
269 disply ("Bad pw attempts:", badpws);
270 disply ("Proper logoffs:", terms);
271 disply ("Carrier drops:", drops);
272 disply ("Sleeping drops:", sleeps);
275 tm = (struct tm *) localtime (&from);
276 printf ("From: %s", (char *) asctime (localtime (&from)));
277 printf ("To: %s", (char *) asctime (localtime (&to)));
278 printf ("Total report time: ");
279 printf ("%d days, %d hours, %d minutes\n",
280 days, hours, minutes);
282 for (aa = from; aa <= to; aa = aa + 1200L)
283 timeup[halfhour (aa)] = timeup[halfhour (aa)] + 20L;
286 lowest = GRANULARITY - 1;
287 for (b = 0; b < 72; ++b)
289 for (a = 0; a <= GRANULARITY; ++a)
291 p = ((float) timeon[b]) / ((float) timeup[b]) * GRANULARITY;
295 thegraph[(GRANULARITY - 1) - a][b] = '#';
296 if (lowest > (GRANULARITY - 1) - a)
297 lowest = (GRANULARITY - 1) - a;
302 printf ("\n\n\n\n\n\n");
304 b = ((GRANULARITY - lowest) / 18);
307 for (a = lowest; a < GRANULARITY; a = a + b)
308 printf ("%2d%% |%s\n",
311 printf (" +------------------------------------------------------------------------\n");
312 printf (" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23\n");
319 printf ("Top 20 Callers (sorted by total number of logins)\n");
320 printf ("Calls Avg/Day Username\n");
321 printf ("----- ------- ------------------------------\n");
323 sortpipe = (FILE *) popen ("sort |tail -20 |sort -r", "w");
324 for (callptr = callers; callptr != NULL; callptr = callptr->next)
326 fprintf (sortpipe, "%5d %7.2f %-30s\n",
327 callptr->Ctimescalled,
328 (((float) callptr->Ctimescalled) / ((float) days)),
332 while (callers != NULL)
334 callptr = callers->next;
341 printf ("Top 20 Contributing Users (post to call ratio)\n");
342 printf ("P/C Ratio Username\n");
343 printf ("--------- ------------------------------\n");
345 sortpipe = (FILE *) popen ("sort |tail -20 |sort -r", "w");
346 fp = fopen ("usersupp", "r");
348 && (fread ((char *) &usersupp, sizeof (struct usersupp), 1, fp) > 0))
350 fprintf (sortpipe, "%9.2f %-30s\n",
351 ((float) usersupp.posted / (float) usersupp.timescalled),