# Path: core/model/date.py
# ONE_DAY = timedelta(1)


from datetime import date
from .geometry import Point
from ..model.date import ONE_DAY
from .graph import Graph, PenID as PenIDBase


class PenID(PenIDBase):
    Graph = 3
    TodayLine = 4

class BrushID:
    GraphNormal = 1
    GraphFuture = 2

class BalanceGraph(Graph):
    # BalanceGraph's data point is (float x, float y)
    # --- Virtual
    def _balance_for_date(self, date):
        return 0

    # --- Override
    def compute_data(self):
        date_range = self.document.date_range
        TODAY = date.today()
        date2value = {}
        last_balance = self._balance_for_date(date_range.start - ONE_DAY)
        if last_balance:
            date2value[date_range.start] = last_balance
        for date_point in date_range:
            balance = self._balance_for_date(date_point)
            if (balance != last_balance) or (date_point == TODAY) or (date_point == date_range.end):
                if date2value and last_balance != balance:
                    # create a "step"
                    date2value[date_point] = last_balance

# Path: core/model/date.py
# ONE_DAY = timedelta(1)


# Path: core/gui/balance_graph.py
from datetime import date
from .geometry import Point
from ..model.date import ONE_DAY
from .graph import Graph, PenID as PenIDBase



class PenID(PenIDBase):
    Graph = 3
    TodayLine = 4

class BrushID:
    GraphNormal = 1
    GraphFuture = 2

class BalanceGraph(Graph):
    # BalanceGraph's data point is (float x, float y)
    # --- Virtual
    def _balance_for_date(self, date):
        return 0

    # --- Override
    def compute_data(self):
        date_range = self.document.date_range
        TODAY = date.today()
        date2value = {}
        last_balance = self._balance_for_date(date_range.start - ONE_DAY)
        if last_balance:
            date2value[date_range.start] = last_balance
        for date_point in date_range:
            balance = self._balance_for_date(date_point)
            if (balance != last_balance) or (date_point == TODAY) or (date_point == date_range.end):
                if date2value and last_balance != balance:
                    # create a "step"
                    date2value[date_point] = last_balance

                date2value[date_point + ONE_DAY] = balance