# Path: header.py
# def headerheader(self, dir1, dir2, **kwargs):  # XYZZY
#     def group(self, keyfunc=None):  # XYZZY
#         """get a dictionary containing lists of singleton bags with the same
#            value (by default; other functions available)"""
#         groups = {}
#         if keyfunc is None:
#             keyfunc = lambda x: x.value
#         protogroups = groupby(sorted(self, key=keyfunc), key=keyfunc)
#         for k, v in protogroups:
#             newbag = xypath.Bag.from_list(v)
#             newbag.table = self.table
#             groups[k] = newbag
#         return groups
#     """Given a header (e.g. "COUNTRY") get all things in one direction
#        from it (e.g. down: "FRANCE", "GERMANY"), then use those to get
#        a suitable xyzzy dict"""
#     header = group(self.fill(dir1), **kwargs)
#     return {k: header[k].fill(dir2) for k in header}


import dl
import messytables
import xypath
import orm
from header import headerheader
           "last_updated": None,
           "last_scraped": orm.now(),
           "name": "ECHO Europa"}


orm.DataSet(**dataset).save()

indicators = [{"indID": "gna-vi",
              "name": "GNA Vulnerability Index",
              "units": "index"},
             {"indID": "gna-ci",
              "name": "GNA Crisis Index",
              "units": "index"}]

for indicator in indicators:
    orm.Indicator(**indicator).save()

value_template = {"dsID": "echo",
                  "period": 2012,
                  "source": baseurl,
                  "is_number": True}

xls_raw = dl.grab(baseurl)
mt = messytables.excel.XLSTableSet(xls_raw).tables[0]
assert mt.name == "GNA Final Index (rank)"
xy = xypath.Table.from_messy(mt)
countries = xy.filter("ISO3").assert_one().fill(xypath.DOWN)
vuln_h = xy.filter("GNA Vulnerability Index (VI)").assert_one()
crisis_h = xy.filter("GNA Crisis Index (CI)").assert_one()


# Path: header.py
# def headerheader(self, dir1, dir2, **kwargs):  # XYZZY
#     def group(self, keyfunc=None):  # XYZZY
#         """get a dictionary containing lists of singleton bags with the same
#            value (by default; other functions available)"""
#         groups = {}
#         if keyfunc is None:
#             keyfunc = lambda x: x.value
#         protogroups = groupby(sorted(self, key=keyfunc), key=keyfunc)
#         for k, v in protogroups:
#             newbag = xypath.Bag.from_list(v)
#             newbag.table = self.table
#             groups[k] = newbag
#         return groups
#     """Given a header (e.g. "COUNTRY") get all things in one direction
#        from it (e.g. down: "FRANCE", "GERMANY"), then use those to get
#        a suitable xyzzy dict"""
#     header = group(self.fill(dir1), **kwargs)
#     return {k: header[k].fill(dir2) for k in header}


# Path: echo.py
import dl
import messytables
import xypath
import orm
from header import headerheader

           "last_updated": None,
           "last_scraped": orm.now(),
           "name": "ECHO Europa"}


orm.DataSet(**dataset).save()

indicators = [{"indID": "gna-vi",
              "name": "GNA Vulnerability Index",
              "units": "index"},
             {"indID": "gna-ci",
              "name": "GNA Crisis Index",
              "units": "index"}]

for indicator in indicators:
    orm.Indicator(**indicator).save()

value_template = {"dsID": "echo",
                  "period": 2012,
                  "source": baseurl,
                  "is_number": True}

xls_raw = dl.grab(baseurl)
mt = messytables.excel.XLSTableSet(xls_raw).tables[0]
assert mt.name == "GNA Final Index (rank)"
xy = xypath.Table.from_messy(mt)
countries = xy.filter("ISO3").assert_one().fill(xypath.DOWN)
vuln_h = xy.filter("GNA Vulnerability Index (VI)").assert_one()
crisis_h = xy.filter("GNA Crisis Index (CI)").assert_one()


headerheader(xy.filter("ISO3").assert_one(), xypath.DOWN, xypath.RIGHT)