def earnings_statement(self, color): value = ("%.2f" % self.value) if not color else str_color(("%.2f" % self.value), self.gain) cost = "%.2f" % (self.value - self.gain) gain = ("%+.2f" % self.gain) if not color else str_color(("%+.2f" % self.gain), self.gain) return ( "Total value: " + value + " (" + self.currency + ")\n" "Total cost: " + cost + " (" + self.currency + ")\n" + "Total Profit: " + gain + " (" + self.currency + ")" )
def row(self,form): def is_float(form): match = re.search('f$',form) return match # create alignment def align_fl(form,color): sign = (1 if (re.search('^\%\+',form)) else 0) match = re.search('([0-9]+)\.([0-9]+)f$',form) ansii = (len('\x1b[1m\x1b[32m') + len('\x1b(B\x1b[m\x1b(B\x1b[m')) if color else 0 if match: return ("%" + str(int(match.group(1)) + int(match.group(2)) + ansii + sign + 1) + "s") else : return form # process format nform = map((lambda x: align_fl(x,False)),form[:2]) + map((lambda x: align_fl(x,True)),form[2:]) finalform = " ".join(nform); # process arguments args = [("("+self.currency+")"),self.day_gain] if self.lots is not None: args.append(self.gain) args = [(str_color((x % y),y) if is_float(x) else y) for x,y in zip(form[2:],args)] return finalform % tuple([self.name,self.last_price] + args)