Consumption History

Rinn

Developer
This might be information worth adding to the proxy field for items, if a good way to keep the data up to date without hitting "showconsumption.php?recent=1" after every consume is added.

Code:
record consumption_data {
	int count;
	string date;
};


consumption_data [ item ] consumption_history;


void load_history()
{
	buffer page = visit_url( "showconsumption.php?recent=1" );


	// <a class=nounder href='javascript:descitem\(\d+?\);'>(.+?)</a>   </td><td>(.+?)</td><td nowrap><small>(.+?)</small>
	matcher m = create_matcher( "<a class=nounder href='javascript:descitem\\(\\d+?\\);'>(.+?)</a>   </td><td>(.+?)</td><td nowrap><small>(.+?)</small>", page );


	while ( m.find() )
	{
		item i = m.group( 1 ).to_item();


		consumption_history[ i ].count = m.group( 2 ).to_int();
		consumption_history[ i ].date = m.group( 3 );
	}
}


load_history();


void main()
{
	foreach i in consumption_history
	{
		print( i + ": " + consumption_history[ i ].count + " - " + consumption_history[ i ].date );
	}
}
 

Attachments

  • consumption_history.ash
    867 bytes · Views: 81
Is there a way to get this script to split the food/booze into different sections?
And is it possible to get it to sort by date (maybe even remove the ones that were consumed in the last 30 days)?
 
Apparently I type the same way I talk. I get answers like this all the time. I will rephrase.

How would I go about implementing those changes? Will someone help me?

Here's what I tried:
I tried using the sort function, but couldn't figure out what to put in for the value to sort by.
I also tried to just print the results that weren't in the last 30 days, but because the date is a string, it wouldn't let me do any math on that field. I couldn't figure out how to change it to another data type that would allow me to do some math on it.
 

heeheehee

Developer
Staff member
Of course, you'd probably also want to combine that with some parsing, since dateform is constructed by something of the form YYYYMMDD (string or int, doesn't matter). Also, the code confuses me (i.e. I have no idea why I wrote anything the way I did, or what I was doing with formatting back then).
 

hesuchia

Member
Here's a script I stitched together for it. I'm a noob to ash but it seems to work for me. Anyway, it should print everything you haven't drank in the last 30 days or since the current pvp season started (so basically prints what should increase your score). You can change the current pvp season's date at the top of the file. I figured I'd make it easily moddable just in case the same mini gets re-used later.

Anyway, it requires both consumption_history.ash (this thread) and datelib.ash (linked above). Thanks to Rinn and heeheehee for their hard work and allowing me to be more lazy :).

After some tweaking, it now takes an integer as an argument. If you just click okay or type 0, it'll check all boozes in your consumption list. If you put in a number, it'll only list the boozes that give that amount of drunkenness. It's convenient for me since there's too many boozes for me to remember the consumption details for :p. Quick lazy crosschecking ftw. The number also helps you not get bombarded with as huge a list.

Code:
# Booze Consumption Info Script v 0.02
# by DarkAxz (hesuchia on mafia forums)
# Thanks to Rinn for consumption_history.ash
# and Heeheehee for datelib.ash

import <consumption_history.ash>;
import <datelib.ash>;

int pvpstart = 20120701;

string parse_date( string pre_date )
{
	string parsed_date;
	matcher m = create_matcher("(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)", pre_date);
	
	if ( m.find() )
	{
		parsed_date = m.group(1) + m.group(2) + m.group(3);
		return parsed_date;
	}
	return parsed_date;
}


boolean scorecheck(item booze)
{
	string predate = consumption_history [ booze ].date;
	string pdate = parse_date(predate);
	boolean scoreplus = true;

	if ((datediff(pdate) <= 30) && (datediff(pvpstart, pdate) >= 0))
	{
		scoreplus = false;
	}
	return scoreplus;
}

void main( int drunk )
{
	foreach i in consumption_history
	{
		if ((drunk > 0 && i.inebriety == drunk) || (drunk == 0 && i.inebriety > drunk))
		{		
			if (scorecheck(i))
			{
				print(i + " should increase your score.");
			}		
		}
	}
}

Any tips on efficiency are welcome too >.>. I mostly know python so all these java/ash strict declarations and annoying syntax quirks just give me a headache :p.
 
Last edited:
Top