def json_for_group_line_chart(data):
    """Takes input data and returns formatted values for to a JSON file"""
    # TODO: Maybe use the known global key groups to init groupname dicts once
    out = {}

    # Group line charts (vol/num) have the group name in the last column
    for month, date, v_adj, v_unadj, groupname in data:
        sec = util.epochtime(date)

        # JSON fix for age groups - strip off the "Age "
        if groupname.lower().find("age ") == 0:
            groupname = groupname[4:]

        # Initialize if first time groupname is encountered
        if groupname not in out:
            out[groupname] = {"adjusted": [], "unadjusted": []}

        try:
            out[groupname]["adjusted"].append(
                [util.milliseconds(sec), float(v_adj)])
            out[groupname]["unadjusted"].append(
                [util.milliseconds(sec),
                 float(v_unadj)])
        except ValueError:
            logger.debug(
                "Ignore ValueError: Discard 'NA' and other non-float values")
            continue
        except TypeError as e:
            logger.warning("Missing value as '{}' in row\n'{}'".format(
                row[2 + colnum], repr(row)))
            # TODO: Raise error with data so filename can be determined
            continue

    return out
def json_for_group_bar_chart(data, val_cols, out_names):
    """Takes input data and returns formatted values for a JSON file """

    tmp = {}
    for col in val_cols:
        tmp[col] = []

    # Group bar charts (yoy) have a variable numbers of columns by groups
    for row in data:
        sec = util.epochtime(row[1])
        for colnum in range(len(val_cols)):
            try:
                tmp_col = val_cols[colnum]
                tmp[tmp_col].append(
                    [util.milliseconds(sec),
                     float(row[2 + colnum])])
            except ValueError:
                logger.debug("Ignore ValueError: Discard 'NA' and other " +
                             "non-float values")
                continue

    out = {}

    # Translate into JSON output columns
    for col_key in tmp:
        idx = val_cols.index(col_key)
        if idx < 0:
            msg = "Key '{}' does not exist in {}".format(col_key, val_cols)
            logger.error(msg)
            raise IndexError(msg)
        out[out_names[idx]] = tmp[col_key][:]

    return out
def json_for_line_chart(data):
    """Takes input data and returns formatted values for a JSON file """

    out = {"adjusted": [], "unadjusted": []}

    for monthnum, date, v_adj, v_unadj in data:
        sec = util.epochtime(date)
        try:
            out["adjusted"].append([util.milliseconds(sec), float(v_adj)])
            out["unadjusted"].append([util.milliseconds(sec), float(v_unadj)])
        except ValueError:
            logger.debug(
                "Ignore ValueError: Discard 'NA' and other non-float values")
            continue

    return out
def json_for_bar_chart(data):
    """Takes input data and returns formatted values for a JSON file"""

    outnum = []
    outvol = []

    for month, date, yoy_num, yoy_vol in data:
        sec = util.epochtime(date, schema=cfg.DATA_FILE_DATE_SCHEMA)
        try:
            outnum.append([util.milliseconds(sec), float(yoy_num)])
            outvol.append([util.milliseconds(sec), float(yoy_vol)])
        except ValueError:
            logger.debug(
                "Ignore ValueError: Discard 'NA' and other non-float values")
            continue

    return {"Number of Loans": outnum, "Dollar Volume": outvol}
def json_for_line_chart(data):
    """Takes input data and returns formatted values for a JSON file """

    out = {"adjusted": [], "unadjusted": []}

    for monthnum, date, v_adj, v_unadj in data:
        sec = util.epochtime(date)
        try:
            out["adjusted"].append([util.milliseconds(sec), float(v_adj)])
            out["unadjusted"].append([util.milliseconds(sec), float(v_unadj)])
        except ValueError:
            logger.debug(
                "Ignore ValueError: Discard 'NA' and other non-float values")
            continue
        except TypeError as e:
            logger.warning("Missing value as '{}' in row\n'{}'".format(
                row[2 + colnum], repr(row)))
            # TODO: Raise error with data so filename can be determined
            continue

    return out
def json_for_bar_chart(data):
    """Takes input data and returns formatted values for a JSON file"""

    outnum = []
    outvol = []

    for month, date, yoy_num, yoy_vol in data:
        sec = util.epochtime(date, schema=cfg.DATA_FILE_DATE_SCHEMA)
        try:
            outnum.append([util.milliseconds(sec), float(yoy_num)])
            outvol.append([util.milliseconds(sec), float(yoy_vol)])
        except ValueError:
            logger.debug(
                "Ignore ValueError: Discard 'NA' and other non-float values")
            continue
        except TypeError as e:
            logger.warning("Missing value as '{}' in row\n'{}'".format(
                row[2 + colnum], repr(row)))
            # TODO: Raise error with data so filename can be determined
            continue

    return {"Number of Loans": outnum, "Dollar Volume": outvol}