Exemple #1
0
def pv_multiple_stream(database, var):

    # Get the list of IDs for the var name
    IDs = postgres_api.pv_internal(database, ret_id=var, front_end_abort=True)

    # get the configs for each ID
    configs, starts, ends, toggles, downloads = [], [], [], [], []
    for ID in IDs:
        configs.append(
            postgres_api.pv_meta_internal(database, ID, front_end_abort=True))
        starts.append("start-" + str(ID))
        ends.append("end-" + str(ID))
        toggles.append("toggle-" + str(ID))
        downloads.append("download-" + str(ID))

    # print config
    render_args = {
        "var": var,
        "IDs": IDs,
        "configs": configs,
        "starts": starts,
        "ends": ends,
        "toggles": toggles,
        "downloads": downloads,
        "database": database
    }
    return render_template('common/pv_multiple_stream.html', **render_args)
Exemple #2
0
def view_streams():
    postgres_stream_info = {}
    redis_stream_info = {}
    # parse GET parameters
    try:
        for arg, val in request.args.items(multi=True):
            # postgres streams
            if arg.startswith("postgres_"):
                database_name = arg[9:]
                database_ids = [int(x) for x in val.split(",") if x]
                if database_name not in postgres_stream_info:
                    postgres_stream_info[database_name] = database_ids
                else:
                    postgres_stream_info[database_name] += database_ids
            # redis streams
            elif arg.startswith("redis_"):
                database_name = arg[6:]
                database_keys = val.split(",")
                if database_name not in redis_stream_info:
                    redis_stream_info[database_name] = database_keys
                else:
                    redis_stream_info[database_name] += database_keys
            else:
                raise ValueError
    except:
        return abort(404)

    postgres_streams = []
    redis_streams = []
    # collect configuration for postgres streams
    for database, IDs in postgres_stream_info.items():
        for ID in IDs:
            config = postgres_api.pv_meta_internal(database,
                                                   ID,
                                                   front_end_abort=True)
            postgres_streams.append((ID, database, config))
    # TODO: collect redis stream configuration
    for database, keys in redis_stream_info.items():
        for key in keys:
            try:
                metric_name = key.split(":")[-2]
            except:
                metric_name = key
            config = {"title": key, "yTitle": metric_name}
            redis_streams.append((key, database, config))

    checked = []
    # get the currently checked items
    for database, IDs in postgres_stream_info.items():
        configs = postgres_api.get_configs(database, IDs, front_end_abort=True)
        checked += configs
    for database, keys in redis_stream_info.items():
        checked += online_metrics.get_configs(database,
                                              keys,
                                              front_end_abort=True)

    # build the data tree
    tree = build_data_browser_tree()

    # functions to build the "Stream" object from the config
    def make_redis_stream(info):
        key, database, _ = info
        return RedisDataStream(database, key)

    def make_postgres_stream(info):
        ID, database, _ = info
        return PostgresDataStream(database, ID)

    render_args = {
        "tree": tree,
        "redis_streams": redis_streams,
        "postgres_streams": postgres_streams,
        "make_redis_stream": make_redis_stream,
        "make_postgres_stream": make_postgres_stream,
        "checked": checked
    }
    return render_template("common/view_streams.html", **render_args)
Exemple #3
0
def pv_single_stream(database, ID):
    # get the config
    config = postgres_api.pv_meta_internal(database, ID, front_end_abort=True)
    # get the list of other data
    # tree = postgres_api.test_pv_internal(database)

    # check the currently visited item
    checked = postgres_api.get_configs(database, [ID], front_end_abort=True)

    tree = build_data_browser_tree()

    #low and high thresholds given by url parameters
    low = request.args.get('low')
    high = request.args.get('high')
    #TODO: add try and catch cases for getting timestamps
    #Use 24 hour clock for defining time in url
    #date format from URL: Month-Day-Year_Hour:Minute | mm-dd-yr hr-min
    #date format to turn back to string: Month/Day/Year Hour:Minute
    start = request.args.get('start')
    if start is not None:
        start_obj = datetime.strptime(start, '%m-%d-%Y_%H:%M')
        #start time string to be placed in date picker
        start_time = datetime.strftime(start_obj, '%m/%d/%Y %H:%M')
        #%m%d%y%H:%M format to convert string into integer|mmddyyyyHHMM

        # start timestamp to update plot
        start_timestamp_int = parseiso(start_time)

    else:
        start_obj = None
        start_time = start
        start_timestamp_int = None

    end = request.args.get('end')
    if end is not None:
        end_obj = datetime.strptime(end, '%m-%d-%Y_%H:%M')
        #end time string to be placed in date picker
        end_time = datetime.strftime(end_obj, '%m/%d/%Y %H:%M')
        #%m%d%y%H:%M format to convert string into integer|mmddyyyyHHMM

        #end timestamp to update plot
        end_timestamp_int = parseiso(end_time)

    else:
        end_obj = None
        end_time = end
        end_timestamp_int = None

    dbrows = postgres_api.get_epics_last_value_pv(database,
                                                  ID,
                                                  front_end_abort=True)

    render_args = {
        "ID": ID,
        "config": config,
        "database": database,
        "tree": tree,
        "low": low,
        "high": high,
        "start_time": start_time,
        "end_time": end_time,
        "start_timestamp": start_timestamp_int,
        "end_timestamp": end_timestamp_int,
        "checked": checked,
        "rows": dbrows
    }

    return render_template('common/pv_single_stream.html', **render_args)