Food stats scraping [Prime script]

Forum for alternative clients, mods & discussions on the same.

Food stats scraping [Prime script]

Postby tirioll » Wed Feb 15, 2017 7:19 pm

With introduction of new mechanics in cooking that allows variable ingredients, we got hundreds if not thousands of new foods. There are probably a few enthusiasts that would like to collect these new data and put them in wiki. But the process is very tedious in two respects: typing up all info from food tooltip images, and converting all stats to q10 base. The task could be much more manageable if there were a tool to help with data collection.

For example, I collect inventory of foods, click a button, and stats of all food items are converted to q10 and appended to a CSV file. Can any of the Wizards' Tower experts make such an extension for their client?

I could also try to do it myself, but I need some advice to get started, since I never worked with client's code. Is it possible to write and compile a separate .class file that does the job, and make it somehow available from the client interface without recompiling the whole client? I've never worked on a big Java project, and the task of compiling the whole Hafen behemoth seems overwhelming.

Update 21-may-2017
I made a script for Prime client that prints stats of every food item in inventory, converted to q10. Text then can be copy-pasted into CSV file and opened in a spreadsheet software for further editing. Copy code hidden below into a file, for example "food_stats.js", put it into your Prime_client_folder/Scripts/ and launch from "Xtensions -> Prime Script Manager". It seems that Prime is not maintained anymore, but you can still use it if you character does not have Numen quests unlocked.
Code: Select all
var haven = Packages.haven,
    FoodInfo = haven.resutil.FoodInfo,
    Ingredient = Packages.Ingredient,
    gui = haven.GameUI.Game.gameui();

function main() {
   
    print('basename|q|energy|hunger|ingredients|fep');
    var item, food;
    for (item = gui.maininv.lchild; item !== null; item = item.prev) {
        if (item instanceof haven.GItem) {
            food = foodItem(item);
            if (food !== false) {
                print(food.q10());
            }
        }
    }

    haven.PrimeManager.StopScript(Prime.__ScriptIndex);
}

function foodItem(gItem) {
    var name, q, end, glut, evs, evsQ10, ingrs;
    var i, j;

    var info = gItem.info().toArray();
    ingrs = [];
    for (i = 0; i < info.length; i++) {
        if (info[i] instanceof FoodInfo) {
            end = info[i].end;
            glut = info[i].glut;
            evs = [];
            for (j = 0; j < info[i].evs.length; j++) {
                evs.push({
                    nm: info[i].evs[j].ev.nm,
                    a: info[i].evs[j].a
                });
            }
        } else if (info[i] instanceof Ingredient) {
            ingrs.push(info[i].descr());
        }
    }
   
    if (typeof end === 'undefined') {
        return false;
    }

    name = gItem.getres().basename();
    q = gItem.quality().q;
    evsQ10 = evs.map(function (ev) {
        return {nm: ev.nm, a: ev.a / Math.sqrt(q / 10)};
    });
   
    function toStringFactory(q10) {
        var _q, _evs;
        if (q10) {
            _q = 10;
            _evs = evsQ10;
        } else {
            _q = q;
            _evs = evs;
        }
       
        return function() {
            var s = name + '|';
            s += round(_q) + '|';
            s += round(end * 100) + '|';
            s += round(glut * 100) + '|';
           
            s += '[';
            ingrs.forEach(function (ingr, i) {
                s += ingr;
                if (i !== ingrs.length - 1) {
                    s += ',';
                }
            });
            s += ']|';

            s += '[';
            _evs.forEach(function (ev, i) {
                s += shortFEP(ev);
                if (i !== _evs.length - 1) {
                    s += ',';
                }
            });
            s += ']';
            return s;
        }
    }
   
   
    var fi = {
        q: q,
        name: name,
        end: end,
        glut: glut,
        evs: evs,
        ingrs: ingrs,
        toString: toStringFactory(false),
        q10: toStringFactory(true)
    };
   
   
    return fi;
}

function round(x, decimals) {
    decimals = decimals || 0;
    var mul = Math.pow(10, decimals);
    return Math.round(x * mul) / mul;
}

function shortFEP(ev) {
    var s = '';
    s += ev.nm.substr(0, 3).toLowerCase(); // "Agility +2" -> "agi"
    s += ev.nm.substr(-2, 2); // "Agility +2" -> "+2"
    s += ' ' + round(ev.a, 2);
    return s;
}

Image
Last edited by tirioll on Sun May 21, 2017 10:37 pm, edited 3 times in total.
User avatar
tirioll
 
Posts: 144
Joined: Thu Nov 21, 2013 4:05 pm

Re: Please help with food stats scraping

Postby Aethyr » Wed Feb 15, 2017 7:33 pm

+1 for this idea!

(and if the client could add those info in-game it would be even better)
User avatar
Aethyr
 
Posts: 323
Joined: Sun Jun 22, 2014 6:55 pm

Re: Food stats scraping [Prime script]

Postby tirioll » Sun May 21, 2017 10:28 pm

Made a Prime script that prints food stats.
User avatar
tirioll
 
Posts: 144
Joined: Thu Nov 21, 2013 4:05 pm


Return to The Wizards' Tower

Who is online

Users browsing this forum: No registered users and 10 guests