Historical price data

zarqon

Well-known member
Okay, so map_to_file(url) is out.

It seems from your comments that file_to_map(someurl,"mallprices.txt") would preserve the map format with version number on top? Or are you suggesting separate ASH functions for storing/retrieving this file from the server?

If you tell me how the data would be sent/requested (post data is fine, and I could just make a server-side mallprices.txt which you could grab by direct url), I could write a server-side script to parse the data and maintain a most-updated map for easy access. If it were just a regular map, I'd probably already have it finished. I'm just really unsure what to do with that version number on top.
 

jasonharper

Developer
There is no need to use file_to_map() on mallprices.txt - it would be read with the CLI update prices command. What you'd do with the version number on top is simply leave it on top.

Let me take a closer look at what's involved in posting a file from Java, and I'll get back to you. Actually, it looks like a HTTP PUT would be fairly simple from my end, but that would probably require server reconfiguration at your end.
 

zarqon

Well-known member
If it helps in your research, my server disallows FTP, instead using SCP, so some kind of direct upload would not work so well. It would have to be a PHP script. I can easily access GET and POST data, and attached files as submitted by an HTML form. POST would be easiest for me to deal with.
 

jasonharper

Developer
Ok, let's go with a POST, as if from a file upload field named "upload", with the filename being specified as "mallprices.txt".
 

zarqon

Well-known member
Great! I'll put together a script and post the URL here once I get something I think will work.
 

Bale

Minion
I love this! I make a wish and then sit back to watch the magic happen as Jason and zarqon collaborate.

I can't wait for the upload_data command~!
 

jasonharper

Developer
More details: Please return a text/plain response, the first line of which will be shown as the success message.

To minimize your bandwidth use, only one submission to a given URL will be allowed per session.

No submission will be allowed at all if the user doesn't have any updated prices - but it's possible that all of their updated prices actually came from the server they're submitting to, that wouldn't be easy to detect.
 

zarqon

Well-known member
Dudes! This is going to be awesome! A far, far, far cry from the Wiki workaround I was doing way back; a far, far cry from value.ash; and a far cry even from the price crawlbot on items.ofloathing.org, which I find often underprices items. It may even be crying at some distance from mall_price() itself.

Design question. Would you rather two separate URLs for uploading/downloading, or a single URL (action=getmap vs. upload=file; no query string would provide an HTML upload form)? If a single URL, the data-upload call could return the updated map on success or a text/plain error message on failure. This would avoid the need for two exchanges to accomplish a two-way update. Your call, Jason.
 

jasonharper

Developer
I would expect the normal usage pattern to be: update on login, submit on logout. Therefore, there would be no real benefit in a two-way exchange. Also, having the updated file be the result of the submit would leave no place for you to return a status message. Also also, having the download be a static file would mean less CPU time used by your script.
 

zarqon

Well-known member
Okay!

I think I have it working.

http://zachbardon.com/mafiatools/updateprices.php

For uploading: as Jason outlined, accepts only text files with a filename of 'mallprices.txt', submitted via POST in a file upload field named 'upload'. Returns text/plain, where the first line says "Prices successfully updated.", or whatever error was encountered. Beneath that is an event log in case further debugging is needed.

For downloading: specify "action=getmap" in the query string (both POST and GET work for this). I opted to do it this way, since the data file has 777 file permissions; it's better for only the script to know where it is.

For fun/testing: visit the URL in a web browser to access the simulation-only updating, which does not save the updated map.
 
Last edited:

jasonharper

Developer
And it works - "spade prices <URL>" added in r7544.

zarqon, it might be more interesting if the status message included the number of updated prices.

Summary:
To update your prices, perhaps in your loginScript, use:
update prices http://zachbardon.com/mafiatools/updateprices.php?action=getmap

To submit your prices, perhaps in your logoutScript, use:
spade prices http://zachbardon.com/mafiatools/updateprices.php
 

Bale

Minion
Quick question:
If a price isn't in mallprices.txt, what will be returned by historical_age()? I'm hoping it will return maxint or something else huge, because a return value of 0 would be misleading.​

This would reduce if(historical_age(key) > 3 || historical_price(key) == 0) to
if(historical_age(key) > 3)
 

zarqon

Well-known member
The number of updated prices is included in the event log, but I could also include it in the status message. I thought perhaps you wanted to do some kind of success recognition, so I made the message constant. But, as that doesn't seem to be important, I'll change it right now.
 

Bale

Minion
Code:
[COLOR="Olive"]> spade prices http://zachbardon.com/mafiatools/updateprices.php[/COLOR]

Success: Update successful -- 28 prices updated.

Gosh darn, this is so awesome!
 

Catch-22

Active member
I opted to do it this way, since the data file has 777 file permissions; it's better for only the script to know where it is.

Security through obscurity is never a good idea :) You should chmod 664 it, so that the file can't be executed and can't be written to by everyone. At least chmod 666 ;)

Infinity? Is that bigger than max int? Wait! How do you do that?

Java supports positive and negative infinity, ie. 1.0/0.0 = Infinity, -1.0/0.0 = -Inifnity.
 

zarqon

Well-known member
Maybe I just told you it has 777 permissions when actually it doesn't. Security through misdirection AND obscurity FTW. :D
 

dj_d

Member
So Z - how about rolling auto-price-uploads in to zlib, so we can all distribute it to the mafia masses in our new scripts?
 
Top