#!/usr/bin/env python

import evelib.newdb as db
import emcom.gmi as gmi
from emcom import humane

GROUP_TAG = {'Arkonor': "zero",
             'Bistot': "zero",
             'Crokite': "zero",
             'Dark Ochre': "zero",
             'Gneiss': "zero",
             'Spodumain': "zero",
             'Mercoxit': "zero",

             'Veldspar': "high",
             'Scordite': "high",
             'Plagioclase': "high M/G/C",
             'Pyroxeres': "high C/A",
             'Omber': "high M/G",
             'Kernite': "low M/C, high A",
             'Hedbergite': "low M/C",
             'Hemorphite': "low G/A",
             'Jaspet': "low G/A",
             }


def main():
    index = gmi.current()
    conn = db.connect()
    c = conn.cursor()
    c.execute("SELECT t.typename, t.volume, t.portionsize, "
              "       mt.typename, tm.quantity "
              "FROM ccp.invtypematerials tm "
              "     INNER JOIN ccp.invtypes t ON tm.typeid = t.typeid "
              "     INNER JOIN ccp.invgroups g ON t.groupid = g.groupid "
              "     INNER JOIN ccp.invcategories c "
              "       ON c.categoryid = g.categoryid "
              "     INNER JOIN ccp.invtypes mt "
              "       ON tm.materialtypeid = mt.typeid "
              "WHERE t.published = 1 "
              "  AND c.categoryname = 'Asteroid' "
              "  AND g.groupname = t.typename "
              "  AND g.groupname != 'Ice' "
              "  AND t.typename NOT LIKE 'Compressed %%'")
    compositions = {}
    for roid, volume, portionsize, mineral, qty in c.fetchall():
        compositions.setdefault(roid, 0)
        compositions[roid] += (index[mineral] * qty) / float(portionsize) / float(volume)

    profits = [(price, roid) for (roid, price) in compositions.items()]
    profits.sort(reverse=True)
    for profit, name in profits:
        print "%8s %s (%s)" % (humane(profit), name, GROUP_TAG[name])

if __name__ == '__main__':
    main()

453f8effeb31cb74b43411d88b5a2a2d7b34a8ef
#!/usr/bin/env python

import evelib.newdb as db
import emcom.gmi as gmi
from emcom import humane

GROUP_TAG = {'Arkonor': "zero",
             'Bistot': "zero",
             'Crokite': "zero",
             'Dark Ochre': "zero",
             'Gneiss': "zero",
             'Spodumain': "zero",
             'Mercoxit': "zero",

             'Veldspar': "high",
             'Scordite': "high",
             'Plagioclase': "high M/G/C",
             'Pyroxeres': "high C/A",
             'Omber': "high M/G",
             'Kernite': "low M/C, high A",
             'Hedbergite': "low M/C",
             'Hemorphite': "low G/A",
             'Jaspet': "low G/A",
             }


def main():
    index = gmi.current()
    conn = db.connect()
    c = conn.cursor()
    c.execute("SELECT t.typename, t.volume, t.portionsize, "
              "       mt.typename, tm.quantity "
              "FROM ccp.invtypematerials tm "
              "     INNER JOIN ccp.invtypes t ON tm.typeid = t.typeid "
              "     INNER JOIN ccp.invgroups g ON t.groupid = g.groupid "
              "     INNER JOIN ccp.invcategories c "
              "       ON c.categoryid = g.categoryid "
              "     INNER JOIN ccp.invtypes mt "
              "       ON tm.materialtypeid = mt.typeid "
              "WHERE t.published = 1 "
              "  AND c.categoryname = 'Asteroid' "
              "  AND g.groupname = t.typename "
              "  AND g.groupname != 'Ice' "
              "  AND t.typename NOT LIKE 'Compressed %%'")
    compositions = {}
    for roid, volume, portionsize, mineral, qty in c.fetchall():
        compositions.setdefault(roid, 0)
        compositions[roid] += (index[mineral] * qty) / float(portionsize) / float(volume)

    profits = [(price, roid) for (roid, price) in compositions.items()]
    profits.sort(reverse=True)
    for profit, name in profits:
        print "%8s %s (%s)" % (humane(profit), name, GROUP_TAG[name])

if __name__ == '__main__':
    main()
