Some general questions - file_to_map() and other.

fronobulax

Developer
Staff member
I am occasionally a professional software archeologist. Thus looking for information in my spare time is sometimes tedious and I will gravitate towards asking questions rather than perform in-depth research for what is supposed to be a pleasurable, spare time project. Nevertheless, since I have looked for answers to all of these questions, if the response is RTFM then please provide a link to TFM so that I can look there first the next time. Thank you.

1) I used networth.ash and note that it generates a lot of output. I ran it from the Scripts menu in mafia and note that all output appeared in the gCLI window. Is there a way to run an arbitrary ash script that uses print, and tee or pipe the output so that I end up with a file that only contains the script generated output? If yes then examples or syntax, please.

2) I am having trouble finding examples of file_to_map usage. In particular I would like an example that includes the input file itself since I anticipate I would create files external to mafia and ash and read them. Specifically, can the mafia data file mallprices.txt be read as a map? I'd guess not for several reasons including the version number as the first line, but if that is incorrect, what would the resulting map look like?

3) Related to 2) is there a way to search ash scripts attached to forum posts? I can only figure out how to search Posts. The obvious usage would be to find examples of function use.

4) I micro-mange my display case. I would like a file that contains items and associated prices, for items that can be bought, can be displayed and are NOT currently in my display case. I come pretty close with Cygwin, tcsh, awk and some web scraping but it seems like ash will be a more elegant (and portable) solution. If I can iterate over the items in mallprices.txt then it seem pretty trivial to emit a line of output (or add something to a map, that is saved to a file at the end of the iteration) if display_amount of that item is less than 1. But, I see no easy way to get access to mallprices.txt if file_to_map doesn't apply. I could iterate across all items and do various tests, in which case where do I get my list of all items from? I suspect is_tradeable, is_displayable, display_amount and mall_price would give me what I need once I had a list of items.

5) Is there a way to sort a map? If I generated a map of item name and price in 4) above, it would be nice if the resulting file, after map_to_file, were sorted on price, from low to high.

Thanks in advance.
 
Last edited:

StDoodle

Minion
[Questions]

I think a lot of your questions could be answered by looking through the KoLmafia wiki (which I'm guessing you didn't know about).

Also, there's a mafia cli command called "ashref" that excepts a text parameter. By itself, it returns all ash commands. With a parameter, it returns the results of a sub-string search.

Once you've dove into map_to_file & file_to_map, you may want to look here:
http://kolmafia.svn.sourceforge.net/...afia/src/data/

All of those files can be imported with file_to_map even if local copies don't exist (and they'll be updated each time mafia is upgraded, of course).

After perusing the above info, please feel free to ask for more specifics on things not covered (a lot of info IS pretty bare on the wiki), and I'd be happy to help as I can.
 
You don't need to load mallprices.txt yourself. If I recall correctly, that is exactly where the historical_price() function gets its prices. Of course, I may recall incorrectly, in which case someone will correct me soon!

historical_price() doesn't actually seem to be on the wiki. It takes an item, and returns the price from mallprices.txt. (If I get some time later today I may add it; in the meantime I would suggest searching the forums.)
 

fronobulax

Developer
Staff member
I think a lot of your questions could be answered by looking through the KoLmafia wiki (which I'm guessing you didn't know about).
I know about the wiki and am especially thankful that zarqon links to it in his profile. However I didn't find this page especially helpful and missed this in my first pass. Anyone interested in improving the wiki might link the the two pages together and preempt more questions like mine :)
Also, there's a mafia cli command called "ashref" that excepts a text parameter. By itself, it returns all ash commands. With a parameter, it returns the results of a sub-string search.
Knew about that too but again, listing the function signature is helpful if you are trying to remember something but less useful if you are trying to learn and determine fitness for purpose.
Once you've dove into map_to_file & file_to_map, you may want to look here:
http://kolmafia.svn.sourceforge.net/...afia/src/data/

All of those files can be imported with file_to_map even if local copies don't exist (and they'll be updated each time mafia is upgraded, of course).
It is good to know that they can all be imported via file_to_map. I wondered because the first line in some of them is different from the rest of the lines, i.e. a version string in mallprices.txt before the map data actually starts.

After perusing the above info, please feel free to ask for more specifics on things not covered (a lot of info IS pretty bare on the wiki), and I'd be happy to help as I can.
Thank you.

My sort question can be answered yes according to this.

I am guessing that the following snippet would work:

int [int][int] prices
file_to_map("mallprices.txt", prices")

knowing that I really should do something with the return value and presuming the context will provide a fully qualified path to the mafia data file.

Thank you.
 

fronobulax

Developer
Staff member
You don't need to load mallprices.txt yourself. If I recall correctly, that is exactly where the historical_price() function gets its prices. Of course, I may recall incorrectly, in which case someone will correct me soon!

historical_price() doesn't actually seem to be on the wiki. It takes an item, and returns the price from mallprices.txt. (If I get some time later today I may add it; in the meantime I would suggest searching the forums.)
Thank you.
In the context of item 4 in the OP, I need something to iterate over. A list of all items would work although a list of all items that could be found in a display case or all that could be bought in the mall would be more efficient. I can get the latter by loading a copy of mallitems.txt as my own map. Is there an alternative using something that is already present?
 

jasonharper

Developer
All of the internal data files have a version number on the first line; file_to_map() ignores any line that contains no tabs, or that starts with a "#".

There is no point in reading mallprices.txt this way, since all of the data it contains is already accessible from ASH - historical_price() and historical_age(), to be specific.
 

mredge73

Member
Thank you.
In the context of item 4 in the OP, I need something to iterate over. A list of all items would work although a list of all items that could be found in a display case or all that could be bought in the mall would be more efficient. I can get the latter by loading a copy of mallitems.txt as my own map. Is there an alternative using something that is already present?

To iterate over all items you need something like this (example will build a map file of all items currently in your DC):

Code:
//DC Map
int [item] DC;

foreach it in $items[]
{
    //to find items currently in your DC
    if (display_amount(it)>0)
    {
        print("You have "+display_amount(it)+" "+it+" in your display case.","olive");
        //to build a map of the items you currently have in your display case
        DC[it]=display_amount(it);
    }

    //use this function to find tradeable items
    if (is_tradeable(it))
    {    
        //print(it+" is tradeable","green");
    }
    else
    {
        //print(it+" is not tradeable","red");
    }
}
Map_To_File(DC, my_name()+today_to_string()+"DC.txt");
print("Check your data folder for: "+my_name()+today_to_string()+"DC.txt","blue");
Map Tip:
Using Records make maps much easier.

Example for concoctions (and use of historical_price):
Code:
record
{
string type;
item basic;
item garnish;
}[item] Ingrediants;
file_to_map("concoctions.txt", Ingrediants);

item BreakDown=$item[ pink pony ];

item Base1=Ingrediants[BreakDown].basic;
item Garnish1=Ingrediants[BreakDown].garnish;
int cost1= historical_price(Base1)+historical_price(Garnish1)+(historical_price($item[bartender-in-the-box])/90);

print("Breakdown of "+BreakDown+" which is a "+Ingrediants[BreakDown].type);
print(Base1,"blue");
print(Garnish1,"blue");
print(cost1,"blue");
 
Last edited:

fronobulax

Developer
Staff member
Thanks jason for the confirmation.

mredge73 et. al.

I feel like I am being incredibly dense and missing something.

In my non-mafia approach to the problem, I start with the Jicken Wings Historical Collections database. I query it for the set of All Displayable Items that are NOT in my display case. I then web scrape and go from there. The point is that these are items that exist in KoL but are not in my display case (and presumably not in my inventory, store or storage either, but the scripts don't have to deal with that).

So the only reason I would want to read mallprices.txt again is because what I want is the list of items and NOT the values returned by historical_price() and historical_age().

Is the thing that I am missing the fact that
Code:
foreach it in $items[]
will iterate over all items defined in KoL that mafia currently knows about?

If so, then :eek: and if anyone can tell me where I should have found that on the wiki, I'd appreciate it.

Regardless, thanks for your help and patience.
 

mredge73

Member
Is the thing that I am missing the fact that
Code:
foreach it in $items[]
will iterate over all items defined in KoL that mafia currently knows about?

If so, then :eek: and if anyone can tell me where I should have found that on the wiki, I'd appreciate it.

Regardless, thanks for your help and patience.

That was the reason for the first mini script that I posted. The $items[] datatype is fairly new so it may not appear in the wiki but you can read about it here. Your best resource for building scripts are from scripts that already exist. Check out the many item management scripts that are available, most of them that are up to date and iterate over all items use this method.
 
Last edited:
Huh. I thought I added plural typed constants somewhere on the wiki a while ago... yeah, I did. But if you didn't know you were looking for them, I guess you wouldn't really know to do so, and they are sorta hidden down at the bottom of the Datatype Constants page.
 

fronobulax

Developer
Staff member
Thanks all.

It's quick and dirty but it does what I wanted. Pasted here just because.
Code:
int [item] NeedDC;
foreach it in $items[]
{
	if (is_tradeable(it))
	{
		if (display_amount(it) < 1)
		{
			NeedDC[it] = historical_price(it);
		}
	}
}
map_to_file(NeedDC, my_name()+today_to_string()+"BuyDC.txt");
 

fronobulax

Developer
Staff member
heh, what does the total on that end up being?
42,641,326,107 and that doesn't count a few things that are not available at any price at the moment. I didn't total things because I'm aiming for % complete and so I get the most bang for the buck by buying the cheaper items :) That, incidentally, is about 10x my current net worth so I'll be buying Mr. A's or farming for quite some time.
 

StDoodle

Minion
Didn't mean to be snarky, and apologies if I came off that way. It's just I knew your answers were on the wiki. I had forgot, however, about the fact that those particular functions show up in several places, without links to their other locations.

Yeah, one of these days I'm going to go through there and clean things up. Maybe. ;)

For now, when looking there, I highly recommend using "search," and if the first link isn't descriptive, try the others. It's a pain, yeah... but some of the stuff is rather involved, and difficult to help with short of copypasta.
 
Top