def get(self): # load all the plugin information from the backend modules = get_greenflow_config_modules() client_info = {} client_info['validation'] = {} client_info['display'] = {} for key in modules.keys(): if os.path.isdir(modules[key]): mod = load_modules(modules[key]) # if hasattr(mod.mod, 'client'): client_mod = mod.mod if hasattr(client_mod, 'validation'): val_dict = getattr(client_mod, 'validation') client_info['validation'].update(val_dict) else: pass # print(client_mod, 'no validation') if hasattr(client_mod, 'display'): val_dict = getattr(client_mod, 'display') client_info['display'].update(val_dict) else: pass # print(client_mod, 'no display') # else: # print(key, mod.mod, 'no client') # load all the plugins from entry points for entry_point in importlib_metadata.entry_points().get( 'greenflow.plugin', ()): client_mod = entry_point.load() if hasattr(client_mod, 'validation'): val_dict = getattr(client_mod, 'validation') client_info['validation'].update(val_dict) else: pass # print(client_mod, 'no validation') if hasattr(client_mod, 'display'): val_dict = getattr(client_mod, 'display') client_info['display'].update(val_dict) else: pass # print(client_mod, 'no display') self.finish(json.dumps(client_info))
def add_nodes(): """ It will load all the nodes for the UI client so user can add new node to the graph. The nodes are from two sources: default greenflow nodes and customized node modules. The output is a dictionary whose keys are module names and values are a list of the nodes inside that module. Arguments ------- Returns ------- dict dictionary of all the nodes that can be added in the client """ loaded_node_classes = [] all_modules = get_greenflow_config_modules() # print('Greenflow config modules: {}\n'.format(all_modules)) all_nodes = {} # not implemented yet for greenflow for item in inspect.getmembers(plugin_nodes): if inspect.ismodule(item[1]): # print('Greenflow builtin plugin: {}'.format(item)) labmod_pkg = 'greenflow.{}'.format(item[0]) all_nodes[labmod_pkg] = [] for node in inspect.getmembers(item[1]): nodecls = node[1] if not inspect.isclass(nodecls): continue if not issubclass(nodecls, Node): continue if nodecls in loaded_node_classes: continue task = { 'id': 'node_' + str(uuid.uuid4()), 'type': node[0], 'conf': {}, 'inputs': [] } task_inst = Task(task) node_inst = get_node_tgraphmixin_instance(nodecls, task_inst) nodeObj = init_get_labnode_obj(node_inst, False) all_nodes[labmod_pkg].append(nodeObj) loaded_node_classes.append(nodecls) for module in all_modules: module_file_or_path = Path(all_modules[module]) loaded = load_modules(all_modules[module], module) mod = loaded.mod modulename = module # all_nodes[modulename] = [] for node in inspect.getmembers(mod): nodecls = node[1] if not inspect.isclass(nodecls): continue if nodecls == Node: continue if not issubclass(nodecls, Node): continue if nodecls in loaded_node_classes: continue task = { 'id': 'node_' + str(uuid.uuid4()), 'type': node[0], 'conf': {}, 'inputs': [], 'module': module } task_inst = Task(task) node_inst = get_node_tgraphmixin_instance(nodecls, task_inst) nodeObj = init_get_labnode_obj(node_inst, False) if module_file_or_path.is_dir(): # submod = nodecls.__module__.split('.')[1:] # flatten out the namespace hierarchy submod = nodecls.__module__.split('.')[1:2] modulename_ = '.'.join([modulename, '.'.join(submod)]) \ if submod else modulename all_nodes.setdefault(modulename_, []).append(nodeObj) else: all_nodes.setdefault(modulename, []).append(nodeObj) loaded_node_classes.append(nodecls) for module in DYNAMIC_MODULES.keys(): modulename = module all_nodes[modulename] = [] for class_name in DYNAMIC_MODULES[module].keys(): nodecls = DYNAMIC_MODULES[module][class_name] if not issubclass(nodecls, Node): continue if nodecls in loaded_node_classes: continue task = { 'id': 'node_' + str(uuid.uuid4()), 'type': nodecls.__name__, 'conf': {}, 'inputs': [], 'module': module } task_inst = Task(task) node_inst = get_node_tgraphmixin_instance(nodecls, task_inst) nodeObj = init_get_labnode_obj(node_inst, False) all_nodes.setdefault(modulename, []).append(nodeObj) loaded_node_classes.append(nodecls) # load all the plugins from entry points for entry_point in importlib_metadata.entry_points().get( 'greenflow.plugin', ()): mod = entry_point.load() modulename = entry_point.name for node in inspect.getmembers(mod): nodecls = node[1] if not inspect.isclass(nodecls): continue if nodecls == Node: continue if not issubclass(nodecls, Node): continue if nodecls in loaded_node_classes: continue task = { 'id': 'node_' + str(uuid.uuid4()), 'type': node[0], 'conf': {}, 'inputs': [], 'module': modulename } task_inst = Task(task) node_inst = get_node_tgraphmixin_instance(nodecls, task_inst) nodeObj = init_get_labnode_obj(node_inst, False) all_nodes.setdefault(modulename, []).append(nodeObj) loaded_node_classes.append(nodecls) return all_nodes
import ipywidgets as widgets from bqplot.colorschemes import CATEGORY20 from bqplot import Axis, Figure, LinearScale, Lines import os from greenflow.dataframe_flow.config_nodes_modules import load_modules load_modules(os.getenv('MODULEPATH') + '/rapids_modules/') from rapids_modules.cuindicator import force_index as indicator_fun # noqa #F401 def get_para_widgets(): para_selector = widgets.IntSlider(min=2, max=60, description="Force Index") para_selector_widgets = [para_selector] return para_selector_widgets def get_parameters(stock_df, para_selector_widgets): return (stock_df["close"], stock_df["volume"]) + tuple( [w.value for w in para_selector_widgets]) def process_outputs(output, stock_df): output.index = stock_df.index stock_df['out'] = output stock_df['out'] = output.fillna(0) return stock_df def create_figure(stock, dt_scale, sc, color_id, f, indicator_figure_height, figure_width, add_new_indicator): sc_co = LinearScale()