PDA

View Full Version : [11 January] SRL Stats Changes



Wizzup?
01-11-2011, 06:46 PM
Hi,

Effective immediately, I have changed the SRL Stats server to only allow commits with time worked greater than 5 minutes. The change to "save" commits until later has yet to be added into stats.simba in the srl-opendev repos. In other words, scripts won't have to do anything, but some commits will be lost. (All with time less than 5 minutes)

I have also added some fail-safes to the stats system to see if I can find out why it crashed previously; haven't been able to find it so far.

Wizzup?
01-11-2011, 09:20 PM
Also, it is no longer OK to send empty variables ( eg, iron ores : 0 ) although the server won't deny those requests at the moment.

Coh3n
01-11-2011, 10:46 PM
Committed the 'Worked' change to opendev.

Heavenzeyez1
01-11-2011, 10:50 PM
MSI keeps telling me: SRL Stats: Invalid time.
Let's say I'm chopping willows and I get my inventory done with 3 minutes. It won't upload the data. But will the counter still run or start from the beginning? If so, then none of my stats will be sent?

~Eerik.

Wizzup?
01-11-2011, 10:51 PM
(Triple post)
Latest SRL-Opendev now has a fixed stats.simba that will not commit if the time < 5 minutes; but it should store your variables for the next commit.

But you must NOT use stats_SetVariable; always use stats_IncVariable instead!

Wizzup?
01-11-2011, 10:52 PM
MSI keeps telling me: SRL Stats: Invalid time.
Let's say I'm chopping willows and I get my inventory done with 3 minutes. It won't upload the data. But will the counter still run or start from the beginning? If so, then none of my stats will be sent?

~Eerik.

Wait for srl-opendev update. (Within an hour. It will fix it)
Or manually change the < 1 to < 5 in stats.simba. :)

Coh3n
01-11-2011, 10:53 PM
MSI keeps telling me: SRL Stats: Invalid time.
Let's say I'm chopping willows and I get my inventory done with 3 minutes. It won't upload the data. But will the counter still run or start from the beginning? If so, then none of my stats will be sent?

~Eerik.
Update SRL and you'll be fine. It'll commit after 5 minutes, but the var will still be added (i.e. if you did 2 loads in < 5 minutes, they'll both be added).

Heavenzeyez1
01-11-2011, 10:56 PM
Wait for srl-opendev update. (Within an hour. It will fix it)
Or manually change the < 1 to < 5 in stats.simba. :)

Thanks, Wizzup?, You are the best! <3
You've done such a great job with the new stats!!!
Coh3n, thank you also!! <3
~Eerik.

Narcle
01-11-2011, 10:59 PM
Should of let me do 5 mins like I said before Wizzup :P

Wizzup?
01-11-2011, 11:19 PM
There's still as bug left in the server side application, but the debug messages aren't very verbose. I'll try my best to find the bug soon. :)

If anyone sees another error page, please PM it to me. (html source of the page or something)

Nava2
01-11-2011, 11:54 PM
Since I cannot, for the life of me, find the dev SVN URL..

(*

Stats
=====

The Stats include contains wrapper functions provided by the SRL Stats API.
The functions contained are meant for ease of use for implementation into
scripts.

*)

// behaves as entries in a dict.
type
TStats_Vars = record
Name: string;
Value: integer;
end;


var
stats_Vars: Array of TStats_Vars;
stats_UserName, stats_UserPass, stats_ScriptID: String;
stats_Timer: integer;
stats_RandNames: Array of String;
stats_RandSolved: Array of Integer;


(*
SetupSRLStats
~~~~~~~~~~~~~

.. code-block:: pascal
procedure SetupSRLStats(ScriptID: integer; UserName, UserPass: string);

Initializes all variables necessary for SRL stats to function. Username and
password are *not* case sensitive.

Example:
.. code-block:: pascal
SetupSRLStats(64, 'SRL-Developers', 'SRLSRLSRL');
*)
procedure SetupSRLStats(ScriptID: integer; UserName, UserPass: string);
begin
stats_Timer := GetSystemTime;
stats_ScriptID := IntToStr(ScriptID);
stats_Username := LowerCase(UserName);
stats_UserPass := LowerCase(UserPass);
stats_RandNames := ['leo the gravedigger', 'freaky forester', 'maze',
'prison pete', 'evil bob''s island', 'drill demon',
'quiz', 'surprise exam', 'mollys evil twin', 'pinball',
'sandwich lady', 'bee keeper', 'pillory', 'capn arnav',
'abyssal teleport', 'certer', 'mime', 'frog', 'trade',
'mod', 'fight', 'lamp', 'bird nest', 'death'];
SetArrayLength(stats_RandSolved, Length(stats_RandNames));
end;

(*
stats_InitVariable
~~~~~~~~~~~~~~~~~~

.. code-block:: pascal
stats_InitVariable(VarName: String; InitValue: Integer);

Helper method to clean up code in the include. Removes some repeating code
internally.

.. WARNING::
Use of this method outside of this include *may* lead to multiple variables
of the same name. It does **not** check to see if the variable is already
present.

.. code-block:: pascal
stats_InitVariable('coal', 0);

*)
procedure stats_InitVariable(VarName: String; InitValue: Integer);
var
len: Integer;
begin
len := Length(stats_Vars);
SetArrayLength(stats_Vars, len + 1);
stats_Vars[len].Name := LowerCase(VarName);
stats_Vars[len].Value := InitValue;
end;


(*
stats_SetVariable
~~~~~~~~~~~~~~~~~

.. code-block:: pascal
stats_SetVariable(VarName: string; NewValue: Integer);

Sets the passed variable to the new value regardless of old value. This method
behaves much like stats_InitVariable but checks for the variable present first.

Example:
.. code-block:: pascal
stats_SetVariable('runite', 10)
*)
procedure stats_SetVariable(VarName: string; NewValue: Integer);
var
i, h: Integer;
begin
h := High(stats_Vars);
VarName := LowerCase(VarName); // set it to lowercase since not case sensitive

if (h >= 0) then
for i := h downto 0 do
if (VarName = stats_Vars[i].Name) then
begin
stats_Vars[i].Value := NewValue;
Exit;
end;

// the variable is not present already, thus make a new entry into the dict.
stats_InitVariable(VarName, NewValue);
end;

(*
stats_IncVariable
~~~~~~~~~~~~~~~~~

.. code-block:: pascal
procedure stats_IncVariable(VarName: string; Value: integer);

Increments a variable by the value passed.

Example:
.. code-block:: pascal
stats_IncVariable('cod', 69);

*)
procedure stats_IncVariable(VarName: string; Value: integer);
var
i, h: Integer;
begin
h := High(stats_Vars);
VarName := LowerCase(VarName); // set it to lowercase since not case sensitive

if (h >= 0) then
for i := h downto 0 do
if (VarName = stats_Vars[i].Name) then
begin
stats_Vars[i].Value := stats_Vars[i].Value + Value;
Exit;
end;

// the variable is not present already, thus make a new entry into the dict.
stats_InitVariable(VarName, Value);
end;


(*
stats_Commit
~~~~~~~~~~~~

.. code-block:: pascal
function stats_Commit: Boolean;

Sends all the information currently stored in the system to the server. Returns
true if commit was successful, displays error messages. One should note that the
stats variables are set to 0 on commit.

Example:
.. code-block:: pascal
if (stats_Commit) then
WriteLn('We are success.');

*)
function stats_Commit: Boolean;
var
SRLClient, Worked, i, ExtraTime: integer;
S: String;
begin
ExtraTime := GetSystemTime - stats_Timer;
Worked := ExtraTime div 60000;
if Worked < 5 then
Exit;
ExtraTime := ExtraTime - (Worked*60000);

stats_Timer := GetSystemTime - ExtraTime;
{$IFDEF Simba}
SRLClient := InitializeHTTPClientWrap(False);
{$ELSE}
SRLClient := InitializeHTTPClient(False, False);
{$ENDIF}
ClearPostData(SRLClient);

AddPostVariable(SRLClient, 'user', stats_UserName);
AddPostVariable(SRLClient, 'password', stats_UserPass);
AddPostVariable(SRLClient, 'script', stats_ScriptID);
AddPostVariable(SRLClient, 'time', IntToStr(Worked));

for i := 0 to 23 do
if (RandSolved[i] > stats_RandSolved[i]) then
begin
AddPostVariable(
SRLClient,
stats_RandNames[i],
IntToStr(RandSolved[i]-stats_RandSolved[i])
);
stats_RandSolved[i]:= RandSolved[i];
end;

if (Length(stats_Vars) > 0) then
for i := High(stats_Vars) downto 0 do
with stats_Vars[i] do
begin
if (Value <= 0) then
Continue;

AddPostVariable(SRLClient, Name, IntToStr(Value));
Value := 0;//Clear for next commit
end;

S := PostHTTPPageEx(SRLClient, 'http://stats.villavu.com/api/commit');
FreeHTTPClient(SRLClient);
Result := False;
{$IFDEF Simba}
case StrToIntDef(ExtractFromStr(S, Numbers), -1) of
{$ELSE}
case StrToIntDef(GetNumbers(S), -1) of
{$ENDIF}
100: Result := True; // successful commit.
110: Writeln('SRL_Stats: Incorrect user and/or password');
120: Writeln('SRL_Stats: Incorrect script ID');
130: Writeln('SRL_Stats: Invalid time');
140: Writeln('SRL_Stats: Variable does not exist');
150: Writeln('SRL_Stats: Wrong info for variable');
160: Writeln('SRL_Stats: Internal server error');
else
Writeln('SRL_Stats: No POST return');
end;
end;

Updated to stop 0 vars from being sent, as well as it will not send commits if they are less than 5 minutes.

E: I guess I took too long..? o.O

Wizzup?
01-12-2011, 10:29 AM
Since I cannot, for the life of me, find the dev SVN URL..

(*

Stats
=====

The Stats include contains wrapper functions provided by the SRL Stats API.
The functions contained are meant for ease of use for implementation into
scripts.

*)

// behaves as entries in a dict.
type
TStats_Vars = record
Name: string;
Value: integer;
end;


var
stats_Vars: Array of TStats_Vars;
stats_UserName, stats_UserPass, stats_ScriptID: String;
stats_Timer: integer;
stats_RandNames: Array of String;
stats_RandSolved: Array of Integer;


(*
SetupSRLStats
~~~~~~~~~~~~~

.. code-block:: pascal
procedure SetupSRLStats(ScriptID: integer; UserName, UserPass: string);

Initializes all variables necessary for SRL stats to function. Username and
password are *not* case sensitive.

Example:
.. code-block:: pascal
SetupSRLStats(64, 'SRL-Developers', 'SRLSRLSRL');
*)
procedure SetupSRLStats(ScriptID: integer; UserName, UserPass: string);
begin
stats_Timer := GetSystemTime;
stats_ScriptID := IntToStr(ScriptID);
stats_Username := LowerCase(UserName);
stats_UserPass := LowerCase(UserPass);
stats_RandNames := ['leo the gravedigger', 'freaky forester', 'maze',
'prison pete', 'evil bob''s island', 'drill demon',
'quiz', 'surprise exam', 'mollys evil twin', 'pinball',
'sandwich lady', 'bee keeper', 'pillory', 'capn arnav',
'abyssal teleport', 'certer', 'mime', 'frog', 'trade',
'mod', 'fight', 'lamp', 'bird nest', 'death'];
SetArrayLength(stats_RandSolved, Length(stats_RandNames));
end;

(*
stats_InitVariable
~~~~~~~~~~~~~~~~~~

.. code-block:: pascal
stats_InitVariable(VarName: String; InitValue: Integer);

Helper method to clean up code in the include. Removes some repeating code
internally.

.. WARNING::
Use of this method outside of this include *may* lead to multiple variables
of the same name. It does **not** check to see if the variable is already
present.

.. code-block:: pascal
stats_InitVariable('coal', 0);

*)
procedure stats_InitVariable(VarName: String; InitValue: Integer);
var
len: Integer;
begin
len := Length(stats_Vars);
SetArrayLength(stats_Vars, len + 1);
stats_Vars[len].Name := LowerCase(VarName);
stats_Vars[len].Value := InitValue;
end;


(*
stats_SetVariable
~~~~~~~~~~~~~~~~~

.. code-block:: pascal
stats_SetVariable(VarName: string; NewValue: Integer);

Sets the passed variable to the new value regardless of old value. This method
behaves much like stats_InitVariable but checks for the variable present first.

Example:
.. code-block:: pascal
stats_SetVariable('runite', 10)
*)
procedure stats_SetVariable(VarName: string; NewValue: Integer);
var
i, h: Integer;
begin
h := High(stats_Vars);
VarName := LowerCase(VarName); // set it to lowercase since not case sensitive

if (h >= 0) then
for i := h downto 0 do
if (VarName = stats_Vars[i].Name) then
begin
stats_Vars[i].Value := NewValue;
Exit;
end;

// the variable is not present already, thus make a new entry into the dict.
stats_InitVariable(VarName, NewValue);
end;

(*
stats_IncVariable
~~~~~~~~~~~~~~~~~

.. code-block:: pascal
procedure stats_IncVariable(VarName: string; Value: integer);

Increments a variable by the value passed.

Example:
.. code-block:: pascal
stats_IncVariable('cod', 69);

*)
procedure stats_IncVariable(VarName: string; Value: integer);
var
i, h: Integer;
begin
h := High(stats_Vars);
VarName := LowerCase(VarName); // set it to lowercase since not case sensitive

if (h >= 0) then
for i := h downto 0 do
if (VarName = stats_Vars[i].Name) then
begin
stats_Vars[i].Value := stats_Vars[i].Value + Value;
Exit;
end;

// the variable is not present already, thus make a new entry into the dict.
stats_InitVariable(VarName, Value);
end;


(*
stats_Commit
~~~~~~~~~~~~

.. code-block:: pascal
function stats_Commit: Boolean;

Sends all the information currently stored in the system to the server. Returns
true if commit was successful, displays error messages. One should note that the
stats variables are set to 0 on commit.

Example:
.. code-block:: pascal
if (stats_Commit) then
WriteLn('We are success.');

*)
function stats_Commit: Boolean;
var
SRLClient, Worked, i, ExtraTime: integer;
S: String;
begin
ExtraTime := GetSystemTime - stats_Timer;
Worked := ExtraTime div 60000;
if Worked < 5 then
Exit;
ExtraTime := ExtraTime - (Worked*60000);

stats_Timer := GetSystemTime - ExtraTime;
{$IFDEF Simba}
SRLClient := InitializeHTTPClientWrap(False);
{$ELSE}
SRLClient := InitializeHTTPClient(False, False);
{$ENDIF}
ClearPostData(SRLClient);

AddPostVariable(SRLClient, 'user', stats_UserName);
AddPostVariable(SRLClient, 'password', stats_UserPass);
AddPostVariable(SRLClient, 'script', stats_ScriptID);
AddPostVariable(SRLClient, 'time', IntToStr(Worked));

for i := 0 to 23 do
if (RandSolved[i] > stats_RandSolved[i]) then
begin
AddPostVariable(
SRLClient,
stats_RandNames[i],
IntToStr(RandSolved[i]-stats_RandSolved[i])
);
stats_RandSolved[i]:= RandSolved[i];
end;

if (Length(stats_Vars) > 0) then
for i := High(stats_Vars) downto 0 do
with stats_Vars[i] do
begin
if (Value <= 0) then
Continue;

AddPostVariable(SRLClient, Name, IntToStr(Value));
Value := 0;//Clear for next commit
end;

S := PostHTTPPageEx(SRLClient, 'http://stats.villavu.com/api/commit');
FreeHTTPClient(SRLClient);
Result := False;
{$IFDEF Simba}
case StrToIntDef(ExtractFromStr(S, Numbers), -1) of
{$ELSE}
case StrToIntDef(GetNumbers(S), -1) of
{$ENDIF}
100: Result := True; // successful commit.
110: Writeln('SRL_Stats: Incorrect user and/or password');
120: Writeln('SRL_Stats: Incorrect script ID');
130: Writeln('SRL_Stats: Invalid time');
140: Writeln('SRL_Stats: Variable does not exist');
150: Writeln('SRL_Stats: Wrong info for variable');
160: Writeln('SRL_Stats: Internal server error');
else
Writeln('SRL_Stats: No POST return');
end;
end;

Updated to stop 0 vars from being sent, as well as it will not send commits if they are less than 5 minutes.

E: I guess I took too long..? o.O

The < 0 vars change is still appreciated. The time change has been committed. (Dev repo = http://villavu.com/repositories/srl-opendev ... )

Bad Boy JH
03-07-2011, 01:19 AM
Just wondering if there was a way we can "force" the acceptance of a commit, so if our script is about to terminate, we can force the commit, and termiante the script.
Edit: sorry for gravedig, it was related to this thread, and I didn't think twice

Edit 2: Something like this perhaps?
function stats_Commit(Force: Boolean): Boolean;
var
SRLClient, Worked, i, ExtraTime: integer;
S: String;
begin
ExtraTime := GetSystemTime - stats_Timer;
Worked := ExtraTime div 60000;
// Exit if 5 minutes of time has not passed since last commit.
if (Worked < 5) and (not Force) then Exit;
ExtraTime := ExtraTime - (Worked*60000);

stats_Timer := GetSystemTime - ExtraTime;
{$IFDEF Simba}
SRLClient := InitializeHTTPClientWrap(False);
{$ELSE}
SRLClient := InitializeHTTPClient(False, False);
{$ENDIF}
ClearPostData(SRLClient);

AddPostVariable(SRLClient, 'user', stats_UserName);
AddPostVariable(SRLClient, 'password', stats_UserPass);
AddPostVariable(SRLClient, 'script', stats_ScriptID);
AddPostVariable(SRLClient, 'time', IntToStr(Worked));

for i := 0 to 23 do
if (RandSolved[i] > stats_RandSolved[i]) then
begin
AddPostVariable(
SRLClient,
stats_RandNames[i],
IntToStr(RandSolved[i]-stats_RandSolved[i])
);
stats_RandSolved[i]:= RandSolved[i];
end;

if (Length(stats_Vars) > 0) then
for i := High(stats_Vars) downto 0 do
with stats_Vars[i] do
begin
if (Value <= 0) then
Continue;

AddPostVariable(SRLClient, Name, IntToStr(Value));
Value := 0;//Clear for next commit
end;

S := PostHTTPPageEx(SRLClient, 'http://stats.villavu.com/api/commit');
FreeHTTPClient(SRLClient);
Result := False;
{$IFDEF Simba}
case StrToIntDef(ExtractFromStr(S, Numbers), -1) of
{$ELSE}
case StrToIntDef(GetNumbers(S), -1) of
{$ENDIF}
100: Result := True; // successful commit.
110: Writeln('SRL_Stats: Incorrect user and/or password');
120: Writeln('SRL_Stats: Incorrect script ID');
130: Writeln('SRL_Stats: Invalid time');
140: Writeln('SRL_Stats: Variable does not exist');
150: Writeln('SRL_Stats: Wrong info for variable');
160: Writeln('SRL_Stats: Internal server error');
else
Writeln('SRL_Stats: No POST return');
end;
end;

Also, why on script management, is burning actic pine logs not a variable, but every other burnable log is?

Wizzup?
03-08-2011, 04:02 PM
Well, you could just send the post data. But I don't really like the idea. You'll have to live with that fact that you lose a bit of stats. :)
Plus, Stats throws away commits with time < 5 minutes anyway.