This commit is contained in:
mysticbbs 2012-08-21 17:55:30 -04:00
parent d03d6419dc
commit df00c62ae8
1 changed files with 140 additions and 55 deletions

View File

@ -20,7 +20,7 @@ Const
fmRWDN = 66;
Type
RecHistory = Record // from records.pas 1.10
RecHistory = Record // From records.pas 1.10
Date : LongInt;
Emails : Word;
Posts : Word;
@ -36,35 +36,84 @@ Type
SMTP : Word;
NNTP : Word;
HTTP : Word;
Reserved : Array[1..26] of Byte;
Hourly : Array[0..23] of Byte;
Reserved : Array[1..2] of Byte;
End;
Function DisplayMonthly : Boolean;
Var
HistFile : File;
Days : Cardinal;
OneDay : RecHistory;
Months : Array[1..12] of Cardinal;
CurMonth : Byte;
TotalCalls : Cardinal;
Loop1 : Byte;
Loop2 : Byte;
Days : LongInt;
Calls : LongInt;
Month : Array[1..12] of Cardinal;
Week : Array[0..6] of Cardinal;
Hour : Array[0..23] of Cardinal;
Procedure DrawBar (XPos, Value: Byte);
Var
Temp : Byte;
Begin
Write ('|01');
Procedure DrawBar (XPos, Value: Byte);
Var
Temp : Byte;
Begin
For Temp := 1 to Value Do
WriteXY (XPos, 18 - Temp, 1, #219 + #219 + #219);
End;
For Temp := 1 to Value Do Begin
GotoXY (XPos, 18 - Temp);
Write (#219 + #219 + #219);
Procedure DisplayMonthly;
Var
Count : Byte;
Count2 : Byte;
Begin
WriteLn ('|CL|09|17 ' + #176 + ' |15Monthly Usage Graph ' + PadLT(strComma(Days) + '|07 days, |15' + strComma(Calls) + ' |07calls ', 63, ' ') + '|09' + #176 + ' |16');
GotoXY (6, 18);
For Count := 1 to 12 Do
Write ('|08' + #196 + #196 + #196 + ' ');
WriteXY (6, 19, 14, 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec');
WriteXY (2, 21, 08, strRep(#196, 78));
For Count := 1 to 12 Do
For Count2 := 15 DownTo 1 Do Begin
GotoXY (Count * 6, 2 + Count2);
Write (#250 + #250 + #250);
End;
For Count := 1 to 12 Do
DrawBar (6 * Count, Month[Count]);
End;
Procedure DisplayWeekly;
Var
Count : Byte;
Count2 : Byte;
Begin
WriteLn ('|CL|09|17 ' + #176 + ' |15Weekly Usage Graph ' + PadLT(strComma(Days) + '|07 days, |15' + strComma(Calls) + ' |07calls ', 64, ' ') + '|09' + #176 + ' |16');
For Count := 0 to 6 Do Begin
GotoXY (10 * (Count + 1), 18);
Write ('|08' + #196 + #196 + #196);
End;
Begin
DisplayMonthly := False;
WriteXY (10, 19, 14, 'Sun Mon Tue Wed Thu Fri Sat');
WriteXY ( 2, 21, 08, strRep(#196, 78));
For Count := 0 to 6 Do
For Count2 := 15 DownTo 1 Do Begin
GotoXY (10 * (Count + 1), 2 + Count2);
Write (#250 + #250 + #250);
End;
For Count := 0 to 6 Do
DrawBar (10 * (Count + 1), Week[Count]);
End;
Procedure CalculateHistory;
Var
HistFile : File;
OneDay : RecHistory;
TempLong : Cardinal;
TempReal : Real;
Count : LongInt;
Highest : Cardinal;
Begin
fAssign (HistFile, CfgDataPath + 'history.dat', fmRWDN);
fReset (HistFile);
@ -77,58 +126,94 @@ Begin
Days := fSize(HistFile) / SizeOf(OneDay);
WriteLn ('|16|CL|15Calculating Monthly usage (' + strComma(Days) + ' days)...');
WriteLn ('|16|CL|15Calculating usage for last ' + strComma(Days) + ' days...');
While Not fEof(HistFile) Do Begin
fReadRec(HistFile, OneDay);
CurMonth := Str2Int(Copy(DateStr(OneDay.Date, 1), 1, 2));
Months[CurMonth] := Months[CurMonth] + OneDay.Calls;
TotalCalls := TotalCalls + OneDay.Calls;
Calls := Calls + OneDay.Calls;
TempLong := Str2Int(Copy(DateStr(OneDay.Date, 1), 1, 2));
Month[TempLong] := Month[TempLong] + OneDay.Calls;
TempLong := DayOfWeek(OneDay.Date);
Week[TempLong] := Week[TempLong] + OneDay.Calls;
For Count := 0 to 23 Do
Hour[Count] := Hour[Count] + OneDay.Hourly[Count];
End;
fClose (HistFile);
Highest := 0;
For Loop1 := 1 to 12 Do Begin
If Months[Loop1] > 0 Then
Months[Loop1] := Months[Loop1] / TotalCalls * 15
Else
Months[Loop1] := 1;
End;
For Count := 1 to 12 Do
If Month[Count] > Highest Then
Highest := Month[Count];
WriteLn ('|CL|09|17 ' + #176 + ' |15Monthly Usage Graph ' + PadLT(strComma(Days) + '|07 days, |15' + strComma(TotalCalls) + ' |07calls ', 63, ' ') + '|09' + #176 + ' |16');
GotoXY (6, 18);
For Loop1 := 1 to 12 Do
Write ('|08' + #196 + #196 + #196 + ' ');
GotoXY (6, 19);
Write ('|14Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec');
GotoXY (2, 21);
Write ('|08|$D78' + #196);
For Loop1 := 1 to 12 Do
For Loop2 := 15 DownTo 1 Do Begin
GotoXY (Loop1 * 6, 2 + Loop2);
Write (#250 + #250 + #250);
For Count := 1 to 12 Do
If Month[Count] > 0 Then Begin
TempReal := (Month[Count] / Highest * 100);
Month[Count] := TempReal / 7 + 1;
End;
For Loop1 := 1 to 12 Do
DrawBar (6 * Loop1, Months[Loop1]);
Highest := 0;
DisplayMonthly := True;
For Count := 0 to 6 Do
If Week[Count] > Highest Then
Highest := Week[Count];
For Count := 0 to 6 Do
If Week[Count] > 0 Then Begin
TempReal := (Week[Count] / Highest * 100);
Week[Count] := TempReal / 7 + 1;
End;
Highest := 0;
For Count := 0 to 23 Do
If Hour[Count] > Highest Then
Highest := Hour[Count];
For Count := 0 to 23 Do
If Hour[Count] > 0 Then Begin
TempReal := (Hour[Count] / Highest * 100);
Hour[Count] := TempReal / 7 + 1;
End;
fClose (HistFile);
End;
Var
ShowMode : Byte;
Begin
If Graphics = 0 Then Begin
WriteLn ('|CRSorry, usage graphs require ANSI graphics|CR|CR|PA');
Exit;
End;
If DisplayMonthly Then Begin
GotoXY (28, 22);
Write ('|07Press |08[|15ENTER|08] |07to continue|PN');
CalculateHistory;
If ParamCount > 0 Then Begin
Case Upper(ParamStr(1)) of
'MONTHLY' : DisplayMonthly;
'WEEKLY' : DisplayWeekly;
// 'HOURLY' : DisplayHourly;
Else
WriteLn ('USAGE.MPS: Invalid command line option.|PN');
End;
End Else Begin
ShowMode := 1;
Repeat
Case ShowMode of
1 : DisplayMonthly;
2 : DisplayWeekly;
// 3 : DisplayHourly;
End;
WriteXYPipe (22, 23, 7, 0, 'Press |08[|15TAB|08] |07for more or |08[|15ENTER|08] |07to Quit');
Case OneKey(#09 + #13, False) of
#09 : If ShowMode < 2 Then ShowMode := ShowMode + 1 Else ShowMode := 1;
#13 : Break;
End;
Until False;
End;
End