# Path: lib/fpos/core.py
# def money(value):
# def lcs(a, b):


import argparse
import csv
from datetime import datetime as dt
from collections import defaultdict, deque
from .core import date_fmt, month_fmt
def name():
    return __name__.split(".")[-1]

def parse_args(subparser=None):
    parser_init = subparser.add_parser if subparser else argparse.ArgumentParser
    parser = parser_init(name(), description=cmd_description, help=cmd_help)
    parser.add_argument("infile", metavar="INPUT", type=argparse.FileType('r'),
            help="The document to window")
    parser.add_argument("outfile", metavar="OUTPUT", type=argparse.FileType('w'),
            help="The file to write the windowed transactions")
    parser.add_argument("--start", metavar="DATE", type=str,
            help="The start month and year, in the form 'mm/yyyy'")
    parser.add_argument("--end", metavar="DATE", type=str,
            help="The end month and year (exclusive), in the form 'mm/yyyy'")
    parser.add_argument("--span", metavar="NUMBER", type=int,
            help="The number of months to cover from the most recent transaction")
    return [ parser ] if subparser else parser.parse_args()

def gen_span_oracle(start, end):
    o_true = lambda x: True
    oracle = defaultdict(lambda : o_true)
    if None is start and None is end:
        return o_true
    if None is not start:
        oracle["start"] = lambda x: x >= dt.strptime(start, month_fmt)
    if None is not end:
        oracle["end"] = lambda x: x < dt.strptime(end, month_fmt)
    return lambda x: oracle["start"](x) and oracle["end"](x)

def day2month(datestr):

# Path: lib/fpos/core.py
# def money(value):
# def lcs(a, b):


# Path: lib/fpos/window.py
import argparse
import csv
from datetime import datetime as dt
from collections import defaultdict, deque
from .core import date_fmt, month_fmt

def name():
    return __name__.split(".")[-1]

def parse_args(subparser=None):
    parser_init = subparser.add_parser if subparser else argparse.ArgumentParser
    parser = parser_init(name(), description=cmd_description, help=cmd_help)
    parser.add_argument("infile", metavar="INPUT", type=argparse.FileType('r'),
            help="The document to window")
    parser.add_argument("outfile", metavar="OUTPUT", type=argparse.FileType('w'),
            help="The file to write the windowed transactions")
    parser.add_argument("--start", metavar="DATE", type=str,
            help="The start month and year, in the form 'mm/yyyy'")
    parser.add_argument("--end", metavar="DATE", type=str,
            help="The end month and year (exclusive), in the form 'mm/yyyy'")
    parser.add_argument("--span", metavar="NUMBER", type=int,
            help="The number of months to cover from the most recent transaction")
    return [ parser ] if subparser else parser.parse_args()

def gen_span_oracle(start, end):
    o_true = lambda x: True
    oracle = defaultdict(lambda : o_true)
    if None is start and None is end:
        return o_true
    if None is not start:
        oracle["start"] = lambda x: x >= dt.strptime(start, month_fmt)
    if None is not end:
        oracle["end"] = lambda x: x < dt.strptime(end, month_fmt)
    return lambda x: oracle["start"](x) and oracle["end"](x)

def day2month(datestr):

    return dt.strftime(dt.strptime(datestr, date_fmt), month_fmt)