Exemple #1
0
def plot_stack_generic(X,
                       Y,
                       c,
                       semantic,
                       *reports,
                       color_theme=C_cold_colors,
                       color_offset=0):
    """ generic function for plotting stacks """
    # bring the data together
    dates, data = join_data(X, Y)

    # format the dates to a readable format
    str_dates = [
        Bank_Date.fromtimestamp(d).strftime(C_format_date) for d in dates
    ]

    add_labels(semantic,
               *reports,
               color_theme=color_theme,
               color_offset=color_offset)

    if len(data) > 0:
        stackplot(dates, data, colors=c)
    else:
        # if data is empty, plot at least zeros to make this plot more complete
        plot(dates, np.zeros(len(dates)))

    xticks(dates, str_dates, rotation=45)
Exemple #2
0
    def add_unique(self, from_acc, to_acc, payment,
                   date, name = '', fixed = True, meta={}):
        """ adds a one-time payment to the list, optional give it
        a name """
        if not isinstance(date, datetime):
            raise TypeError("Date must be at least from type datetime")

        self.check_errors_payment(payment)

        # converts any input to a function that returns the right value
        conv_payment = conv_payment_func(payment)

        self._uniques.append(
                             Payment(
                                     from_acc = from_acc,
                                     to_acc = to_acc,
                                     date = Bank_Date.fromtimestamp(date.timestamp()),
                                     name = name,
                                     kind = 'unique',
                                     payment = conv_payment,
                                     fixed = fixed,
                                     meta = meta
                                     )
                             )

        # sort the whole list with date as key
        self._uniques = sorted(self._uniques, key = lambda p: p['date'] )
Exemple #3
0
def valid_date(date):
    """ routine for making a date out of anything that the user might
    have given to the function """
    if date is None:
        return Bank_Date.today()
    if isinstance(date, Bank_Date):
        return date
    if isinstance(date, datetime):
        return Bank_Date.fromtimestamp(date.timestamp())
    if isinstance(date, str):
        return parse_datestring(date)
    raise TypeError("Date must be at least from type datetime or callable")
Exemple #4
0
    def append(self, status = None, date = None, **kwargs):
        """ adds either an instance of status to the list or
        data given to the append method as keyword arguments """
        assert((status and not date) or (date and not status))

        if date:
            status = Status( Bank_Date.fromtimestamp(date.timestamp()), **kwargs )

        if not isinstance(status, Status):
            raise TypeError("status must be of type Status")

        self._statuses.append(status)
        # add potential new keys to the list
        self._keys = list(set(self._keys) | set(status.keys()))
Exemple #5
0
    def add_regular(self, from_acc, to_acc, payment, interval,
                    date_start, day=1, name='', date_stop = None,
                    fixed = False, meta={}):
        """ Adds a regular payment to the list, with a given
        payment: amount to pay
        interval: 'monthly': every month
                  'quarter': every quarter with date_start as start month
                  'quarter_year': every quarter of a year (mar, jun, sep, dec)
                  'yearly': every year
        day: day to start with
        date_start: start date of this payment
        name : optional name
        fixed: only everything or nothing must be transfered (true)
               or depending on the receiving account a smaller amount
               can be transfered (false)
        """
        if not interval in C_interval.keys():
            raise ValueError("interval must be one of '" + '\',\''.join(C_interval))
        if day >= 29:
            warnings.warn(("note that in months which have less days than {} the " +
                           "payment will be transferred earlier").format(day)
                          )
        self.check_errors_payment(payment)

        if not date_stop:
            date_stop = Bank_Date.max
        else:
            date_stop = validate.valid_stop_date(date_stop)

        # converts any payment to a function
        conv_payment = conv_payment_func(payment)

        self._regular.append({'from_acc': from_acc,
                              'to_acc': to_acc,
                              'interval': interval,
                              'day' : day,
                              'date_start': Bank_Date.fromtimestamp(date_start.timestamp()),
                              'date_stop': date_stop,
                              'payment': conv_payment,
                              'name' : name,
                              'fixed': fixed,
                              'meta': meta
                              }
                             )