def get_segment_data(): '''view returning the response for the segment data (and/or metadata)''' data = request.get_json() seg_index = data['seg_index'] # this must be present seg_id = core.get_segment_id(get_session(current_app), seg_index) plot_indices = data.get('plot_indices', []) preprocessed = data.get('pre_processed', False) zooms = data.get('zooms', None) all_components = data.get('all_components', False) metadata = data.get('metadata', False) classes = data.get('classes', False) config = data.get('config', {}) return jsonify( core.get_segment_data(get_session(current_app), seg_id, core.get_plot_manager(), plot_indices, all_components, preprocessed, zooms, metadata, classes, config))
def init(): data = request.get_json() segment_select_conditions = data.get('segment_select', None) # Note: data.get('segment_orderby', None) is not anymore implemented in the config # it will default to None (order by event time desending and by event_distance ascending) dic = core.init(get_session(current_app), segment_select_conditions, data.get('segment_orderby', None), data.get('metadata', False), data.get('classes', False)) return jsonify(dic)
def set_selection(): try: data = request.get_json() segment_select_conditions = data.get('segment_select', None) # Note: data.get('segment_orderby', None) is not anymore implemented in the config # it will default to None (order by event time desending and by event_distance ascending) num_segments = core.get_segments_count(get_session(current_app), segment_select_conditions) # set the plot manager new condition at the end: in case of errors # (e.g. overflow integer in 'id') we do not change the previous selection condition # with a erroneous one core.get_plot_manager( ).config['segment_select'] = segment_select_conditions or {} return jsonify({'num_segments': num_segments, 'error_msg': ''}) except Exception as exc: return jsonify({'num_segments': 0, 'error_msg': str(exc)})
def main(): plotmanager = core.create_plot_manager(current_app.config['pyfile'], current_app.config['configfile']) config = plotmanager.config or {} configure_classes(get_session(current_app), config.get('class_labels', [])) ud_plots = plotmanager.userdefined_plots settings = { 'segment_select': config.get('segment_select', {}), 'hasPreprocessFunc': plotmanager.has_preprocessfunc } # pop keys not to be shown in the gui config form (either already processed, or not # regarding plot settings: config.pop('class_labels', None) # create a flatten dict by joining nested dict keys with the dot: settings['config'] = core.flatten_dict(config) # filterfunc_doc = current_app.config['PLOTMANAGER'].get_filterfunc_doc.replace("\n", "<p>") return render_template( 'mainapp.html', title=secure_dburl(current_app.config["DATABASE"]), settings=settings, rightPlots=[_ for _ in ud_plots if _['position'] == 'r'], bottomPlots=[_ for _ in ud_plots if _['position'] == 'b'], preprocessfunc_doc=plotmanager.get_doc(-1))
def set_class_id(): json_req = request.get_json() core.set_class_id(get_session(current_app), json_req['segment_id'], json_req['class_id'], json_req['value']) # the above raises, otherwise return empty json to signal success: return jsonify({})
def session(self): '''returns the db session by using the same function used from the Flask app i.e., DO NOT CALL `db.session` in the tests methods but `self.session`''' return get_session(self.app)