Пример #1
0
 async def value(self, ctx, user=None):
     """Check the value of your portfolio, or of another user on the server."""
     if not user:
         user = ctx.message.author
     else:
         user = util.GetUserFromNameStr(ctx.message.server.members, user)
     p = portfolio.GetPortfolio(user.id)
     await self.bot.say('%s\'s portfolio is now worth $%.2f.' %
                        (user, p.Value()))
Пример #2
0
 async def list(self, ctx, user=None, date=None):
     """Display your portfolio, or optionally another user's portfolio."""
     if not user:
         user = ctx.message.author
     else:
         user = util.GetUserFromNameStr(ctx.message.server.members, user)
     timestamp = util.GetTimestamp(date)
     p = portfolio.GetPortfolio(user.id)
     await self.bot.say('```%s\'s portfolio:\n'
                        'Total Value: $%s (%s) \n'
                        '%s```' %
                        (user, p.Value(timestamp), p.GetChange(timestamp),
                         p.AsTable(timestamp)))
Пример #3
0
 async def breakdown(self, ctx, user=None, date=None):
     """Display your portfolio, or optionally another user's portfolio."""
     if not user:
         user = ctx.message.author
     else:
         user = util.GetUserFromNameStr(ctx.message.server.members, user)
     change = GetPortfolioChange(user.id)
     portfolio = GetPortfolio(user.id, util.GetTimestamp(date))
     await self.bot.say(
         '```%s\'s portfolio diversity breakdown:\n'
         'Total Value: $%s (%.2f%s) \n'
         '%s```' %
         (user, portfolio.Value(), change, "%", portfolio.BreakTable()))
Пример #4
0
 async def graph(self, ctx, time_delta="", *users: str):
     """Graph portfolios."""
     if not users:
         users = [
             user for user in ctx.message.server.members
             if len(portfolio.GetPortfolio(user.id))
         ]
     else:
         users = [
             util.GetUserFromNameStr(ctx.message.server.members, user)
             for user in users
         ]
     if time_delta is "":
         start_t = min(
             portfolio.GetPortfolio(user.id).CreationDate()
             for user in users)
     else:
         start_t = int((datetime.datetime.now() -
                        util.GetTimeDelta(time_delta)).timestamp())
     end_t = int(datetime.datetime.now().timestamp())
     graph_file = graph.GraphPortfolioTimeSeries('Gainz', users, start_t,
                                                 end_t)
     await self.bot.upload(graph_file)
Пример #5
0
    async def graph(self, ctx, start_t="", user=None, end_t=""):
        """Graph portfolios."""
        if not user:
            user = ctx.message.author
        else:
            user = util.GetUserFromNameStr(ctx.message.server.members, user)
        if start_t is "":
            start_t = GetPortfolioCreationDate(user.id)
        else:
            start_t = int((datetime.datetime.now() -
                           util.GetTimeDelta(start_t)).timestamp())
        if end_t is "":
            end_t = int(datetime.datetime.now().timestamp())
        else:
            end_t = int(util.GetTimestamp(end_t))
        t_list = list(range(start_t, end_t,
                            (end_t - start_t) // 100)) + [end_t]
        y_values = GetPortfolioValueList(user.id, t_list)
        x_values = [
            mdates.date2num(datetime.datetime.fromtimestamp(t)) for t in t_list
        ]
        # build the figure
        fig, ax = plt.subplots()
        df = pd.DataFrame({'USD': y_values, 'time': x_values})
        df['subject'] = 0
        graph = sns.tsplot(data=df, value='USD', time='time', unit='subject')
        graph.set_title('%s\'s gainz' % user)

        # assign locator and formatter for the xaxis ticks.
        ax.xaxis.set_major_locator(mdates.AutoDateLocator())
        ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y.%m.%d'))

        # put the labels at 45deg since they tend to be too long
        fig.autofmt_xdate()
        plt.savefig(GRAPHLOC)

        await self.bot.upload(GRAPHLOC)