Example #1
0
def _by_custom(ts) -> None:
    """Prints transactions in a series of months and years based on user input
    """
    def cond(y0, y1, m0, m1, t):
        return m0 <= t.get_month() <= m1 and y0 <= t.get_year() <= y1

    print()
    y0 = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if 0 == y0:
        return
    s = (bc.months_abv(m) for m in sorted(set(t.get_month() for t in ts)))
    print()
    m0 = bc.trans_timeframe(list(s) + [-1])
    if 0 == m0:
        return

    print()
    y1 = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if 0 == y1:
        return
    s = (bc.months_abv(m) for m in sorted(set(t.get_month() for t in ts)))
    print()
    m1 = bc.trans_timeframe(list(s) + [-1])
    if 0 == m1:
        return

    print("\n" + header())
    for t in (i for i in ts
              if cond(y0, y1, bc.months_to_int[m0], bc.months_to_int[m1], i)):
        print(view(t))
Example #2
0
def _by_custom(ts) -> None:
    """Prints transactions in a series of months and years based on user input
    """
    def cond(y0,y1,m0,m1,t): return m0 <= t.get_month() <= m1 and y0 <= t.get_year() <= y1
    print()
    y0 = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if 0 == y0: 
        return
    s = (bc.months_abv(m) for m in sorted(set(t.get_month() for t in ts)))
    print()
    m0 = bc.trans_timeframe(list(s) + [-1])
    if 0 == m0: 
        return
    
    print()
    y1 = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if 0 == y1: 
        return
    s = (bc.months_abv(m) for m in sorted(set(t.get_month() for t in ts)))
    print()
    m1 = bc.trans_timeframe(list(s) + [-1])
    if 0 == m1: 
        return 
    
    print("\n"+header())
    for t in (i for i in ts if cond(
        y0,y1,bc.months_to_int[m0],bc.months_to_int[m1],i)): 
        print(view(t))    
 def __init__(self, a: Account, tf: [(int, int)], master=None):
     Graph.__init__(self, a, tf, master)
         
     min_year, min_month = self._tf[0][0]+1,  months_abv(self._tf[0][1])
     max_year, max_month = self._tf[-1][0]+1, months_abv(self._tf[-1][1])
     self._t.title(
         "Cash Flow of Account "+ a.get_name()+" ({}) from {} {} to {} {}".format(
             kind_to_str[a.get_kind()],min_month, min_year, max_month, max_year))
         
     self._canvas = tk.Canvas(master=self._t, height=1200, width=800)
     self._canvas.grid(row=0,column=0,sticky = tk.N + tk.S + tk.W + tk.E)
     self._canvas.bind('<Configure>', self._resize)
         
     self._t.rowconfigure(0, weight = 1)
     self._t.columnconfigure(0, weight = 1)
Example #4
0
def _select_trans(ts) -> Transaction or None:
    """Returns transaction selected based on iteration
    """
    def _cond(y,m,t): return t.get_year() == y and t.get_month() == bc.months_to_int[m]
    
    print("Unique Years\n"+("=" * 40))
    y = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if y == -1: 
        return 
    
    print("\nUnique Months\n"+("=" * 40))
    s = (bc.months_abv(m) for m in sorted(set(t.get_month() for t in ts if t.get_year() == y)))
    m = bc.trans_timeframe(list(s) + [-1])
    if m == -1: 
        return 

    ts_tf = sorted((t for t in ts if _cond(y,m,t)), key = lambda x: x.get_day())
    
    while True:     
        try: 
            print("\n"+header(True))
            for n0,t in enumerate(ts_tf, 1):
                print(view(t,n0))        
            n = int(input("Select transaction number: ").rstrip())
            for n1, v in enumerate(ts_tf, 1):
                if n == n1:
                    return v 
        except Exception as e: 
            print("    An error has occurred: " + str(e))
Example #5
0
    def _draw_points(self, h, w_dist):
        """Draws points indicating net cash flows on the canvas 
        """
        largest = max(abs(self._a.get_remain(y, m)) for (y, m) in self._tf)
        for y, m in self._tf:
            perc_r = (1 - ((self._a.get_remain(y, m) /
                            largest) if largest != 0 else 1)) / 2
            y_point_r = (h - 40) * (perc_r) if perc_r != 0 else (h / 2) - 20

            radius = 2

            self._canvas.create_text(
                w_dist * self._tf.index((y, m)) + 25,
                h - 15,
                text=months_abv(m) + "\n" + str(y),
                font=standard_font)  # Labels on the x-axis

            self._canvas.create_oval(
                w_dist * self._tf.index((y, m)) + 25 - radius,
                y_point_r - radius,
                w_dist * self._tf.index((y, m)) + 25 + radius,
                y_point_r + radius,
                fill="#4B8A08" if self._a.get_remain(y, m) >= 0 else "#f00",
                outline="#4B8A08" if self._a.get_remain(y, m) >= 0 else
                "#f00")  # Points of reached

            self._canvas.create_text(
                w_dist * self._tf.index((y, m)) + 25 - radius,
                y_point_r + 10,
                text="{:.2f}".format(self._a.get_remain(y, m) / 100, 2),
                font=standard_font,
                fill="#4B8A08" if self._a.get_remain(y, m) >= 0 else
                "#f00")  # Values of reached
Example #6
0
    def __init__(self, a: Account, tf: [(int, int)], master=None):
        Graph.__init__(self, a, tf, master)

        min_year, min_month = self._tf[0][0] + 1, months_abv(self._tf[0][1])
        max_year, max_month = self._tf[-1][0] + 1, months_abv(self._tf[-1][1])
        self._t.title(
            "Cash Flow of Account " + a.get_name() +
            " ({}) from {} {} to {} {}".format(kind_to_str[
                a.get_kind()], min_month, min_year, max_month, max_year))

        self._canvas = tk.Canvas(master=self._t, height=1200, width=800)
        self._canvas.grid(row=0, column=0, sticky=tk.N + tk.S + tk.W + tk.E)
        self._canvas.bind('<Configure>', self._resize)

        self._t.rowconfigure(0, weight=1)
        self._t.columnconfigure(0, weight=1)
    def _draw_points(self, h, w_dist):
        """Draws points indicating net cash flows on the canvas 
        """
        largest = max(abs(self._a.get_remain(y,m)) for (y,m) in self._tf)
        for y,m in self._tf: 
            perc_r = (1 - ((self._a.get_remain(y,m)/largest) if largest != 0 else 1)) / 2
            y_point_r = (h-40)*(perc_r) if perc_r != 0 else (h/2)-20
                                    
            radius = 2
            
            self._canvas.create_text(
                w_dist * self._tf.index((y,m)) + 25, h - 15, 
                text=months_abv(m)+"\n"+str(y), font=standard_font)             # Labels on the x-axis

            self._canvas.create_oval(
                w_dist * self._tf.index((y,m)) + 25 - radius, y_point_r-radius, 
                w_dist * self._tf.index((y,m)) + 25 + radius, y_point_r+radius,
                fill="#4B8A08" if self._a.get_remain(y,m) >= 0 else "#f00",
                outline="#4B8A08" if self._a.get_remain(y,m) >= 0 else "#f00")    # Points of reached
            
            self._canvas.create_text(
                w_dist * self._tf.index((y,m)) + 25 - radius, y_point_r+10,
                text="{:.2f}".format(self._a.get_remain(y,m)/100, 2),
                font=standard_font, 
                fill="#4B8A08" if self._a.get_remain(y,m) >= 0 else "#f00")   # Values of reached
Example #8
0
def _select_trans(ts) -> Transaction or None:
    """Returns transaction selected based on iteration
    """
    def _cond(y, m, t):
        return t.get_year() == y and t.get_month() == bc.months_to_int[m]

    print("Unique Years\n" + ("=" * 40))
    y = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if y == -1:
        return

    print("\nUnique Months\n" + ("=" * 40))
    s = (bc.months_abv(m)
         for m in sorted(set(t.get_month() for t in ts if t.get_year() == y)))
    m = bc.trans_timeframe(list(s) + [-1])
    if m == -1:
        return

    ts_tf = sorted((t for t in ts if _cond(y, m, t)),
                   key=lambda x: x.get_day())

    while True:
        try:
            print("\n" + header(True))
            for n0, t in enumerate(ts_tf, 1):
                print(view(t, n0))
            n = int(input("Select transaction number: ").rstrip())
            for n1, v in enumerate(ts_tf, 1):
                if n == n1:
                    return v
        except Exception as e:
            print("    An error has occurred: " + str(e))
Example #9
0
    def _draw_points(self, h, w_dist):
        """Draws to canvas points and their labels
        """
        largest = max(self._a.get_reached(y, m) for (y, m) in self._tf)
        for y, m in self._tf:
            perc = 1 - (self._a.get_reached(y, m) / largest)
            y_point = 10 + (perc * (h - 10 - 20))
            radius = 2

            self._canvas.create_text(
                w_dist * self._tf.index((y, m)) + 25,
                h - 15,
                text=months_abv(m) + "\n" + str(y),
                font=standard_font)  # Labels on the x-axis

            self._canvas.create_oval(w_dist * self._tf.index(
                (y, m)) + 25 - radius,
                                     y_point - radius,
                                     w_dist * self._tf.index(
                                         (y, m)) + 25 + radius,
                                     y_point + radius,
                                     fill="#00f",
                                     outline="#00f")  # Points

            self._canvas.create_text(w_dist * self._tf.index(
                (y, m)) + 25 - radius,
                                     y_point + 10,
                                     text="{:.2f}".format(
                                         self._a.get_reached(y, m) / 100, 2),
                                     font=standard_font)  # Values
Example #10
0
def _um_ats(ats: "generator", y: int) -> [int]:
    """Returns integers represnting unique months of an Account collection
    and breakout integer
    """
    return sorted(
        set(bc.months_abv(m) for a in ats for m in a.get_budgets(y)), 
        key=lambda x: bc.months_to_int[x]) + [-1]
Example #11
0
def _view_range_budget(a: Account, timeframe: [(int, int)], width: int) -> str:
    """Returns string of Account's budget tuple over a certain time period
    """
    bud_lim = ((width-10)//11)                                                  # How many budgets can be on one line
    it = len(timeframe)                                                         # How many budgets that will be displayed 
    set_lim = it//bud_lim + 1                                                   # How many sets to iterate through  
    set_apprch = 0; bud_apprch = 0; lines = list() 
        
    while set_apprch != set_lim: 
        set_apprch += 1
        title_sub_str = "Account {} for set {}".format(a.get_name(), set_apprch)
        hd          = "="*width + "\n"
        space_amt   = width//2-len(title_sub_str)
        title_str   = "{}{}{}".format(" "*space_amt, title_sub_str, " "*space_amt)
        attrib_str  = "Attribute|"
        goal_str    = "Goal.....|"
        reach_str   = 'Reached..|'
        remain_str  = "Remaining|"
                
        for y,m in timeframe[(set_apprch-1)*min(bud_lim, it):set_apprch*min(bud_lim, it)]:
            bud_apprch += 1

            attrib_str += "  {} {}|".format(bc.months_abv(m), y+1)
            
            g_str = "{:.2f}".format(a.get_goal(y,m)/100) 
            goal_str += "."*(10-len(g_str)) + g_str+"|"
            
            r_str = "{:.2f}".format(a.get_reached(y,m)/100)
            reach_str += "."*(10-len(r_str)) + r_str+"|"
            
            e_str = "{:.2f}".format(a.get_remain(y,m)/100)
            remain_str += "."*(10-len(e_str)) + e_str + "|"
        lines.append(title_str + "\n" + hd + attrib_str + "\n" + goal_str + "\n" + reach_str + "\n" + remain_str + "\n")
    return "\n".join(lines)
Example #12
0
def _um(a: Account, y: int) -> [int]:
    """Returns integers representing unique months of an Account and breakout integer
    """
    if y in a.get_budgets(): 
        return sorted(
        set(bc.months_abv(m) for m in a.get_budgets(y)), 
        key=lambda x: bc.months_to_int[x]) + [-1]
    return [-1]
Example #13
0
def _by_month(ts) -> None:
    """Prints transactions in a month based on user input 
    """
    s = (bc.months_abv(m) for m in sorted(set(t.get_month() for t in ts)))
    print()
    m = bc.trans_timeframe(list(s) + [-1])
    if m == -1: 
        return 
    print("\n"+header())
    for t in (i for i in ts if i.get_month() == bc.months_to_int[m]): 
        print(view(t)) 
Example #14
0
def _by_month(ts) -> None:
    """Prints transactions in a month based on user input 
    """
    s = (bc.months_abv(m) for m in sorted(set(t.get_month() for t in ts)))
    print()
    m = bc.trans_timeframe(list(s) + [-1])
    if m == -1:
        return
    print("\n" + header())
    for t in (i for i in ts if i.get_month() == bc.months_to_int[m]):
        print(view(t))
    def _draw_points(self, h, w_dist):
        """Draws on a graph the goal and reached attributes of an Account's 
        budgets 
        """
        largest = max(max(self._a.get_reached(y, m) for (y, m) in self._tf),
                      max(self._a.get_goal(y, m) for (y, m) in self._tf))
        for y, m in self._tf:
            perc_r = 1 - (self._a.get_reached(y, m) / largest)
            y_point_r = 10 + (perc_r * (h - 10 - 20))

            perc_g = 1 - (self._a.get_goal(y, m) / largest)
            y_point_g = 10 + (perc_g * (h - 10 - 20))
            radius = 2

            self._canvas.create_text(
                w_dist * self._tf.index((y, m)) + 25,
                h - 15,
                text=months_abv(m) + "\n" + str(y),
                font=standard_font)  # Labels on the x-axis

            self._canvas.create_oval(w_dist * self._tf.index(
                (y, m)) + 25 - radius,
                                     y_point_r - radius,
                                     w_dist * self._tf.index(
                                         (y, m)) + 25 + radius,
                                     y_point_r + radius,
                                     fill="#f00",
                                     outline="#f00")  # Points of reached

            self._canvas.create_text(w_dist * self._tf.index(
                (y, m)) + 25 - radius,
                                     y_point_r + 10,
                                     text="{:.2f}".format(
                                         self._a.get_reached(y, m) / 100, 2),
                                     font=standard_font,
                                     fill="#f00")  # Values of reached

            self._canvas.create_oval(w_dist * self._tf.index(
                (y, m)) + 25 - radius,
                                     y_point_g - radius,
                                     w_dist * self._tf.index(
                                         (y, m)) + 25 + radius,
                                     y_point_g + radius,
                                     fill="#00f",
                                     outline="#00f")  # Points of goal

            self._canvas.create_text(w_dist * self._tf.index(
                (y, m)) + 25 - radius,
                                     y_point_g + 10,
                                     text="{:.2f}".format(
                                         self._a.get_goal(y, m) / 100, 2),
                                     font=standard_font,
                                     fill="#00f")  # Values of goal
Example #16
0
def _view_range_budgets(ats: [Account], timeframe: [(int, int)], width: int) -> str:
    """Returns string of multiple Accounts' budgets over a certain time period 
    """
    bud_lim = ((width-30)//11)                                                  # How many budgets can be on one line
    it = len(timeframe)                                                         # How many budgets that will be displayed 
    set_lim = it//bud_lim + 1                                                   # How many sets to iterate through  
    set_apprch = 0; bud_apprch = 0; lines = list() 

    while set_apprch != set_lim:
        set_apprch += 1
        title_sub_str = "Set {}".format(set_apprch)
        hd          = "="*width + "\n"
        space_amt   = width//2-len(title_sub_str)
        title_str   = "{}{}{}".format(" "*space_amt, title_sub_str, " "*space_amt)
        a_index     = 0
        lines.append(title_str + "\n" + hd)
        
        for a in sorted(ats, key=lambda x: x.get_name()):
            a_index     += 1
            a_str       = "{:>3}. {}".format(a_index, a.get_name())
            attrib_str  = a_str + (20-len(a_str)) * "." + "|Attribute|"
            goal_str    = " "*20+"|Goal.....|"
            reach_str   = " "*20+"|Reached..|"
            remain_str  = " "*20+"|Remaining|"
            
            for y,m in timeframe[(set_apprch-1)*min(bud_lim, it):set_apprch*min(bud_lim, it)]:
                bud_apprch += 1
                attrib_str += "  {} {}|".format(bc.months_abv(m), y+1)
                try: 
                    g_str = "{:.2f}".format(a.get_goal(y,m)/100) 
                    goal_str += "."*(10-len(g_str)) + g_str+"|"
                
                    r_str = "{:.2f}".format(a.get_reached(y,m)/100)
                    reach_str += "."*(10-len(r_str)) + r_str+"|"
                
                    e_str = "{:.2f}".format(a.get_remain(y,m)/100)
                    remain_str += "."*(10-len(e_str)) + e_str + "|"
                except:                 
                    goal_str    += "."*10 + "|"
                    reach_str   += "."*10 + "|"
                    remain_str  += "."*10 + "|"
            lines.append(attrib_str + "\n" + goal_str + "\n" + reach_str + "\n" + remain_str + "\n")
    return "\n".join(lines)
    def _draw_points(self, h, w_dist):
        """Draws to canvas points and their labels
        """
        largest = max(self._a.get_reached(y,m) for (y,m) in self._tf)
        for y,m in self._tf: 
            perc = 1 - (self._a.get_reached(y,m)/largest)
            y_point = 10+(perc*(h-10-20))
            radius = 2
            
            self._canvas.create_text(
                w_dist * self._tf.index((y,m)) + 25, h - 15, 
                text=months_abv(m)+"\n"+str(y), font=standard_font)             # Labels on the x-axis

            self._canvas.create_oval(
                w_dist * self._tf.index((y,m)) + 25 - radius, y_point-radius, 
                w_dist * self._tf.index((y,m)) + 25 + radius, y_point+radius,
                fill="#00f", outline="#00f")                                    # Points
            
            self._canvas.create_text(
                w_dist * self._tf.index((y,m)) + 25 - radius, y_point+10,
                text="{:.2f}".format(self._a.get_reached(y,m)/100, 2),
                font=standard_font)                                             # Values
    def _draw_points(self, h, w_dist):
        """Draws on a graph the goal and reached attributes of an Account's 
        budgets 
        """
        largest = max(
            max(self._a.get_reached(y,m) for (y,m) in self._tf),
            max(self._a.get_goal(y,m) for (y,m) in self._tf))
        for y,m in self._tf: 
            perc_r = 1 - (self._a.get_reached(y,m)/largest)
            y_point_r = 10+(perc_r*(h-10-20))
            
            perc_g = 1 - (self._a.get_goal(y,m)/largest)
            y_point_g = 10+(perc_g*(h-10-20))
            radius = 2
            
            self._canvas.create_text(
                w_dist * self._tf.index((y,m)) + 25, h - 15, 
                text=months_abv(m)+"\n"+str(y), font=standard_font)             # Labels on the x-axis

            self._canvas.create_oval(
                w_dist * self._tf.index((y,m)) + 25 - radius, y_point_r-radius, 
                w_dist * self._tf.index((y,m)) + 25 + radius, y_point_r+radius,
                fill="#f00", outline="#f00")                                    # Points of reached
            
            self._canvas.create_text(
                w_dist * self._tf.index((y,m)) + 25 - radius, y_point_r+10,
                text="{:.2f}".format(self._a.get_reached(y,m)/100, 2),
                font=standard_font, fill="#f00")                                # Values of reached

            self._canvas.create_oval(
                w_dist * self._tf.index((y,m)) + 25 - radius, y_point_g-radius, 
                w_dist * self._tf.index((y,m)) + 25 + radius, y_point_g+radius,
                fill="#00f", outline="#00f")                                    # Points of goal
            
            self._canvas.create_text(
                w_dist * self._tf.index((y,m)) + 25 - radius, y_point_g+10,
                text="{:.2f}".format(self._a.get_goal(y,m)/100, 2),
                font=standard_font, fill="#00f")                                # Values of goal