# Path: lib/fpos/core.py
# def money(value):
#     return "{:.2f}".format(value)


import argparse
import pystrgrp
import csv
import numpy as np
import matplotlib.pyplot as plt
from collections import namedtuple
from datetime import datetime, timedelta
from itertools import chain, cycle, islice
from .core import money
    table = {}
    for gd in keep:
        prev = last(gd.group)
        delta = (date - prev).days
        period = icmf(gd.deltas)
        f = expense_offset(delta, period, gd.deltas)
        if not f:
            continue
        mean = sum(float(e[1]) for e in gd.group) / (sum(gd.deltas) + 1)
        for d in range(f - delta, 31, period):
            row = fet(distance=d,
                    previous=prev.strftime("%d/%m/%y"),
                    next=(date + timedelta(d)).strftime("%d/%m/%y"),
                    description=gd.group[0][2],
                    n=len(gd.group),
                    period=period,
                    mean=mean)
            if d not in table:
                table[d] = []
            table[d].append(row)
    print("Distance,Previous,Next,Description,N,Period,Mean Value,Sum Expense")
    e, i = 0, 0
    for k in sorted(x for x in table.keys() if x >= 0 and x <= 31):
        for row in table[k]:
            if row.mean < 0:
                e += row.mean
            else:
                i += row.mean
            strrow = [str(e) for e in row[:-1]]
            strrow.append(money(row.mean))

# Path: lib/fpos/core.py
# def money(value):
#     return "{:.2f}".format(value)


# Path: lib/fpos/predict.py
import argparse
import pystrgrp
import csv
import numpy as np
import matplotlib.pyplot as plt
from collections import namedtuple
from datetime import datetime, timedelta
from itertools import chain, cycle, islice
from .core import money

    table = {}
    for gd in keep:
        prev = last(gd.group)
        delta = (date - prev).days
        period = icmf(gd.deltas)
        f = expense_offset(delta, period, gd.deltas)
        if not f:
            continue
        mean = sum(float(e[1]) for e in gd.group) / (sum(gd.deltas) + 1)
        for d in range(f - delta, 31, period):
            row = fet(distance=d,
                    previous=prev.strftime("%d/%m/%y"),
                    next=(date + timedelta(d)).strftime("%d/%m/%y"),
                    description=gd.group[0][2],
                    n=len(gd.group),
                    period=period,
                    mean=mean)
            if d not in table:
                table[d] = []
            table[d].append(row)
    print("Distance,Previous,Next,Description,N,Period,Mean Value,Sum Expense")
    e, i = 0, 0
    for k in sorted(x for x in table.keys() if x >= 0 and x <= 31):
        for row in table[k]:
            if row.mean < 0:
                e += row.mean
            else:
                i += row.mean
            strrow = [str(e) for e in row[:-1]]
            strrow.append(money(row.mean))

            strrow.append(money(e))