Monday, January 13, 2014

Of Code and ISK Part II: I Just Wanna Tend the Coffers

After my last post, Of Code and ISK, I received some feedback indicating that although I accomplished what I had in mind, I could have done so much more.  For those of you who don't feel like reading my other post, I assembled a sequence of programs that would allow me to scan the entire market of a station, export all orders to a CSV file, read those orders, perform some analytics, and spit out a list of items that would be profitable to trade.  The downside to this method was that it would take a matter of hours to scan the entire market of a station.

Some of the comments I received led me to the EMDR, or EVE Market Data Relay.  I had been adverse to using this tool previously fearing many a spoofed order or inaccurate data, not to mention difficulty implementing it into my code.

I was so wrong.

I spent a few hours today tweaking my code and have managed to truncate my entire line of software to an HTML file and two Python files (one of which does nothing more than host a local HTTP server to make accessing the HTML file easier).  All I have to do is run both Python files, navigate to my server in the IGB, and refresh the view once in a while to see the latest data on my screen.

For the webpage, I took advantage of the fact that the IGB supports HTML5 by using a button that runs a XMLHttpRequest function to pull my file into a table I have in the page.  This table uses the jQuery Tablesorter to keep everything organized, allowing me to easily read and interpret the data.

I have to say, I am very impressed with how easy to use EMDR was and how much nicer this is compared to my previous method.  I will include some samples of my code to make life a little easier for those of you who wish to make something similar.  This is the Javascript code to parse a file (outputhtml.txt) which is stored in the same directory as index.html and set the contents of the div with id='main' to the contents of the file.
 function doStuff () {
            var oReq = new XMLHttpRequest();
            oReq.onload = reqListener;
            oReq.open("get", "outputhtml.txt", true);
            oReq.send(); 
        };
        
function reqListener () {
            document.getElementById('main').innerHTML = this.responseText;
        };

If you wish to use EMDR in your Python program, check out the data format guide so you know what you're dealing with.  In case their example didn't make it clear, you're going to be dealing with a series of dictionaries.  In the case of orders, each dictionary will have a key ('rowsets') which contains an array of dictionaries, each of a different item or region.  Simply configure your calculations and have the program output your results to a text file.  Be sure to format them properly in HTML for easy importation into your webpage.  I will also include a method for outputting your data in HTML while linking the name of each item to its market details:
<a href='javascript:void(0)' onclick='CCPEVE.showMarketDetails("+str(itemid)+")'>"+ rec.name+ "</a>"
Finally, a screenshot of my site.  It's nice, clean, and simple, and can be sorted by any column.



And with that, feel free to ask any questions you may have and I will do my best to answer them.  Thanks for reading and fly safe o7 

1 comment:

  1. I have coded my own script quite similar in style to yours but slightly different, wondering where you get the movement figures from? I assume they tell you how many of that Item shifts per day? But I am not sure where to gather that data?

    ReplyDelete