views.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:MultiExplorer 作者: priestc 项目源码 文件源码
def plot_supply(request):
    from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
    from matplotlib.figure import Figure
    from matplotlib.dates import DateFormatter
    currency = request.GET['currency']
    genesis = crypto_data[currency.lower()]['genesis_date']
    currency_name = crypto_data[currency.lower()]['name']
    s = SupplyEstimator(currency)

    try:
        max_block = crypto_data[currency.lower()]['supply_data']['reward_ends_at_block']
        end = s.estimate_date_from_height(max_block)
    except KeyError:
        end = genesis + datetime.timedelta(days=365 * 50)

    x = list(date_generator(genesis, end))
    y = [s.calculate_supply(at_time=z)/1e6 for z in x]

    fig = Figure()
    ax = fig.add_subplot(111)
    ax.plot_date(x, y, '-')

    ax.set_title("%s Supply" % currency_name)
    ax.grid(True)
    ax.xaxis.set_label_text("Date")
    ax.yaxis.set_label_text("%s Units (In millions)" % currency.upper())

    ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
    fig.autofmt_xdate()

    canvas = FigureCanvas(fig)
    response = http.HttpResponse(content_type='image/png')
    canvas.print_png(response)
    return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号