def set_data_setting(): setting = io.load('MLM::training::setting') setting_input = flask.request.args setting = process_form_input('setting', setting, setting_input) print(setting) io.save('MLM::training::setting', setting) return flask.jsonify(result=True)
def save(self, frame): if not isinstance(frame, ClassifierList): raise ValueError("ClassifierPool only accept ClassifierList") io.raw_save(self.get_redis_key(len(self.pool)), frame.to_pickle()) _id = len(self.pool) self.pool.append(self.get_redis_key(len(self.pool))) io.save(self.name_prefix, self.pool) return _id
def get_features(): selected_feature_table_id = int( flask.request.args.get('selected_feature_table_id', None)) selected_feature_table = feature_table_frame.publish_dict( )[selected_feature_table_id]['feature_table'] io.save('selected_feature_table', selected_feature_table) global feature_id_frame feature_id_frame = connector.get_feature_ids(selected_feature_table) return flask.jsonify(result=feature_id_frame.publish_dicts())
def save(self, frame): if not isinstance(frame, FeatureFrame): raise ValueError("FramePool only accept FeatureFrame") io.raw_save(self.get_redis_key(len(self.pool)), frame.to_msgpack(compress='zlib')) _id = len(self.pool) self.pool.append(self.get_redis_key(len(self.pool))) io.save(self.name_prefix, self.pool) return _id
def save(self, frame): if not isinstance(frame, DataFrame): raise ValueError("FramePool only accept FeatureFrame") io.raw_save(self.get_redis_key(len(self.pool)), frame.to_msgpack(compress='zlib')) _id = len(self.pool) self.pool.append( dict(key=self.get_redis_key(_id), is_splitted=False, training_rows=[], frac=None, splitted_timestamp=None)) io.save(self.name_prefix, self.pool) return _id
def split(self, _id, frac): if _id < 0 or _id >= len(self.pool): raise ValueError("Invalid FeatureFrame id") frame = pandas.read_msgpack(io.raw_load(self.get_redis_key(_id))) self.pool[_id]['is_splitted'] = True self.pool[_id]['frac'] = frac self.pool[_id]['splitted_timestamp'] = datetime.now() training_rows = [] nweek = max(frame['feature_week'].unique()) for week in range(1, nweek + 1): idx = frame[frame['feature_week'] == week].index.tolist() training_rows.extend(random.sample(idx, int(frac * len(idx)))) self.pool[_id]['training_rows'] = training_rows io.save(self.name_prefix, self.pool) return DataFrame(frame=frame)
def set_selected_features(): selected_feature_id_ids = str( flask.request.args.get('selected_feature_id_ids', None)).split(',') selected_feature_id_ids = [ int(selected_id) for selected_id in selected_feature_id_ids ] selected_feature_ids = [ feature_id_frame.publish_dict()[selected_id]['feature_id'] for selected_id in selected_feature_id_ids ] selected_feature_names = [ feature_id_frame.publish_dict()[selected_id]['feature_name'] for selected_id in selected_feature_id_ids ] io.save('selected_feature_ids', selected_feature_ids) io.save('selected_feature_names', selected_feature_names) selected_feature_table = str(io.load('selected_feature_table')) return flask.jsonify(result=connector.save_features( selected_feature_table, selected_feature_ids, selected_feature_names))
def training(): global data_pool global classifier_pool data_pool = DataPool() classifier_pool = ClassifierPool() setting = initialize_form_dicts(FORM_DICT['setting']) config = initialize_form_dicts(FORM_DICT['config']) io.save('MLM::training::setting', setting) io.save('MLM::training::config', config) setting = io.load('MLM::training::setting') config = io.load('MLM::training::config') if setting is None or config is None: raise ValueError("Cannot load forms from redis, cache missing") html = flask.render_template( 'training/training.html', setting=setting, config=config, ) return html
def initialize_forms(plot_type): if not check_plot_type(plot_type): raise ValueError("Invalid Plot Type") data_setting = initialize_form_dicts(FORM_DICTS[plot_type]['data_setting']) config = initialize_form_dicts(FORM_DICTS[plot_type]['config']) io.save(plot_type+'_data_setting', data_setting) io.save(plot_type+'_config', config) if 'interaction_config' in FORM_DICTS[plot_type]: interaction_config = initialize_form_dicts(FORM_DICTS[plot_type]['interaction_config']) io.save(plot_type+'_interaction_config', interaction_config)
def set_config(): config = io.load('MLM::training::config') config_input = flask.request.args config = process_form_input('config', config, config_input) io.save('MLM::training::config', config) return flask.jsonify(result=True)
app.register_blueprint(training_api, url_prefix='/training') app.register_blueprint(frames_api, url_prefix='/frames') app.register_blueprint(classifier_api, url_prefix='/classifiers') # open redis connection rds = redis.StrictRedis(host='localhost', port=6379, db=1) @app.route('/') def index(): html = flask.render_template('index.html', ) return html if __name__ == "__main__": rds.flushall() io.connect(rds) if len(sys.argv) < 2: cfg = config.ConfigParser() else: cfg = config.ConfigParser(sys.argv[1]) if not cfg.is_valid(): sys.exit("Config file is invalid.") cfg_mysql = cfg.get_or_query_mysql() io.save('MLM::config::cfg_mysql', cfg_mysql) data_pool = DataPool() app.run(host='0.0.0.0')
def save_interaction_config(plot_type, interaction_config): if not check_plot_type(plot_type): raise ValueError("Invalid Plot Type") io.save(plot_type + '_interaction_config', interaction_config)
def save_config(plot_type, config): if not check_plot_type(plot_type): raise ValueError("Invalid Plot Type") io.save(plot_type + '_config', config)
def save_data_setting(plot_type, data_setting): if not check_plot_type(plot_type): raise ValueError("Invalid Plot Type") io.save(plot_type + '_data_setting', data_setting)
def save_selected_frame_id(plot_type, selected_frame_id): if not check_plot_type(plot_type): raise ValueError("Invalid Plot Type") io.save(plot_type + '_selected_frame_id', selected_frame_id)
def get_features(): io.save('selected_feature_table', 'user_long_feature') global feature_id_frame feature_id_frame = connector.get_feature_ids('user_long_feature') return flask.jsonify(result=feature_id_frame.publish_dicts())