python类Stream()的实例源码

__init__.py 文件源码 项目:evologger 作者: freeranger 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def create_plots():
    # We make a plot for every room
    plotly_logger.info('max points per graph: %s', ploty_max_points_per_graph)
    for zone in zones:
        plotly_logger.info('Creating graph for: %s' % zone)
        stream_id = zones[zone]
        stream = Stream(
            token=stream_id,
            maxpoints=ploty_max_points_per_graph
        )
        trace1 = Scatter(
            x=[],
            y=[],
            mode='lines+markers',
            line=Line(
                shape='spline'
            ),
            stream=stream
        )

        data = Data([trace1])
        layout = Layout(title=zone)
        fig = Figure(data=data, layout=layout)
        py.plot(fig, filename=zone, fileopt='extend')


# if called directly then this is what will execute
# It will create the initial plot.ly reports if need be.
__init__.py 文件源码 项目:evologger 作者: freeranger 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def write(timestamp, temperatures):

    if invalidConfig:
        if plotly_debugEnabled:
            plotly_logger.debug('Invalid config, aborting write')
            return []

    debug_message = 'Writing to ' + plugin_name
    if not plotly_writeEnabled:
        debug_message += ' [SIMULATED]'
    plotly_logger.debug(debug_message)

    debug_text = '%s: ' % timestamp

    if plotly_writeEnabled:
        # Stream tokens from plotly
        tls.set_credentials_file(stream_ids=stream_ids_array)

    try:
        if plotly_writeEnabled:
            py.sign_in(plotly_username, plotly_api_key)

        for temperature in temperatures:
            debug_text += "%s (%s A" % (temperature.zone, temperature.actual)
            if temperature.target is not None:
                debug_text += ", %s T" % temperature.target
            debug_text += ') '

            if plotly_writeEnabled:
                if temperature.zone in zones:
                    stream_id = zones[temperature.zone]
                    s = py.Stream(stream_id)
                    s.open()
                    ts = timestamp.strftime('%Y-%m-%d %H:%M:%S')
                    s.write(dict(x=ts, y=temperature.actual))
                    s.close()
                else:
                    plotly_logger.debug("Zone %s does not have a stream id, ignoring")

    except Exception, e:
        plotly_logger.error("Plot.ly API error - aborting write\n%s", e)

    if plotly_debugEnabled:
        plotly_logger.debug(debug_text)


问题


面经


文章

微信
公众号

扫码关注公众号