Access to session logs

holatuwol

Developer
If you had the ability to access session logs, for implementing something like what's mentioned here, what would you want the function call to look like?

(string [int] refers to a map where the keys are the approximate line numbers in the file corresponding to non-blank lines)

- string [int] session_log( string date )
- string [int] session_log( int days_before_today )
- ????
 
My personal preference would be just

string session_log( string date )

and have access to a function which would return the EOL char(s) for the system in use. This would allow using contains_text on the log as a whole, and we can always use split_string to make a map of strings using the systems eol char(S) as the splitting point.

A function could be written easy enough to return days before today.
 

holatuwol

Developer
I decided to implement

string [int] session_logs( string player, int day_count )
Also, since it's relevant, split_string can now be called with just one parameter. If the last parameter is left off, KoLmafia will assume you want to use the system default line separators for it.
 
string [int] split_string( string source ) added to the scripting wiki.

Because the parameter name "day_count" changed since the first post I would like to be sure theat it means days before today rather than assuming so I have not added it. Also Should this function be added to string handling routines or your character or miscellaneous or another page?
 

holatuwol

Developer
The parameter passed to the function is now the number of days you want including today.  The indices into the map are now the days from today.  So, suppose you wanted the last 30 days worth of session logs (which is really where this was made).  Instead of having to write a for loop, it's a single function call.  If you wanted to read things line by line, you would then take a single day and split it, using the new split_string method.

PHP:
int [item] food_list;
int [item] booze_list;

string [int] my_logs = session_logs( my_name(), 30 );

foreach day in my_logs
{
    print( "Parsing day " + day + "..." );

    if ( my_logs[day] == "" )
        continue;

    string [int] lines = my_logs[day].split_string();
    foreach line in lines
    {
        // It will always be "eat # itemname"
        if ( lines[line].index_of( "eat" ) == 0 )
            food_list[ string_to_item( lines[line].substring(6) ) ] = day;

        // It will always be "drink # itemname"
        if ( lines[line].index_of( "drink" ) == 0 )
            booze_list[ string_to_item( lines[line].substring(8) ) ] = day;
    }
}

print( "Food history:" );
foreach food in food_list
    print( food + " (" + food_list[food] + " days ago)" );

print( "\n\n" );
print( "Booze history:" );
foreach booze in booze_list
    print( booze + " (" + booze_list[booze] + " days ago)" );
 
OK and 1 more question, if you only have 15 days worth of logs, and ask for 30 will kolmafia just return what it has, or will this result in an error?

I will put more details on the wiki later. Time is not my friend at the moment.
 
Top