with Ada.Text_Io;
use Ada.Text_Io;
with Ada.Calendar.Formatting;
package body Sky.Logs is
procedure Open (Session : in out Session_Record) is
begin
Session.Top := Clock;
end Open;
procedure Close (Session : in out Session_Record) is
begin
Session.Bot := Clock;
end Close;
Total : Long_Long_Float := 0.0;
procedure Statistic (Sessions : in out Session_Array; Logs : in out Log_Array) is
Sum : Long_Long_Float := 0.0;
begin
for Session in Sessions'Range loop
if Sessions(Session).Bot > Sessions(Session).Top then
declare
Elapsed : constant Duration := Sessions(Session).Bot - Sessions(Session).Top;
begin
if Elapsed > 0.0 then
Logs(Session).Total := Logs(Session).Total + Long_Long_Float(Elapsed);
Total := Total + Logs(Session).Total;
Sessions(Session).Top := Time_Of(2399, 12, 31, 86399.99);
end if;
end;
end if;
end loop;
if Total > 0.0 then
for Log in Logs'Range loop
if Logs(Log).Total >= 1.0 then
Sum := Logs(Log).Total / Total;
Logs(Log).Rate := Rate_Type(Sum * 100.0);
else
Logs(Log).Rate := 0.0;
end if;
end loop;
end if;
end Statistic;
procedure Save (Logs : in Log_Array; Filename : in String) is
File : File_Type;
begin
begin
Open(File, Out_File, Filename);
exception
when others =>
Create(File, Out_File, Filename);
end;
for log in Logs'Range loop
Put_Line(File, Long_Long_Float'Image(Logs(Log).Total));
Put_Line(File, Rate_Type'Image(Logs(Log).Rate));
end loop;
Close(File);
end Save;
procedure Restore (Logs : out Log_Array; Filename : in String) is
File : File_Type;
begin
Open(File, In_File, Filename);
for Log in Logs'Range loop
if not End_Of_File(File) then
Logs(Log).Total := Long_Long_Float'Value(Get_Line(File));
Logs(Log).Rate := Rate_Type'Value(Get_Line(File));
Total := Total + Logs(Log).Total;
end if;
end loop;
Close(File);
end Restore;
end Sky.Logs ;