コード例 #1
0
ファイル: handlers.py プロジェクト: kenhester/fsi-samples
    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))
コード例 #2
0
import ipywidgets as widgets
from bqplot.colorschemes import CATEGORY20
from bqplot import Axis, Figure, LinearScale, Lines
import os
from greenflow.dataframe_flow.task import load_modules
load_modules(os.getenv('MODULEPATH')+'/rapids_modules/')
from rapids_modules.cuindicator import kst_oscillator as indicator_fun  # noqa #F401


def get_para_widgets():
    para_selector = widgets.IntSlider(
        min=2, max=60, description="KST Oscillator")
    para_selector_widgets = [para_selector]
    return para_selector_widgets


def get_parameters(stock_df, para_selector_widgets):
    param = [w.value for w in para_selector_widgets]
    param_grp = [param[0] + i for i in range(8)]
    return (stock_df["close"], param_grp[0], param_grp[1],
            param_grp[2], param_grp[3],
            param_grp[4], param_grp[5], param_grp[6], param_grp[7])


def process_outputs(output, stock_df):
    output.index = stock_df.index

    stock_df['out'] = output
    stock_df['out'] = output.fillna(0)
    return stock_df
コード例 #3
0
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(all_modules)
    all_nodes = {}
    # not implemented yet for greenflow
    for item in inspect.getmembers(plugin_nodes):
        if inspect.ismodule(item[1]):
            print(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': []
                }
                t = Task(task)
                n = nodecls(t)
                nodeObj = get_node_obj(n, 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
            }
            t = Task(task)
            n = nodecls(t)
            nodeObj = get_node_obj(n, 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
        node_lists = []
        all_nodes[modulename] = node_lists
        for class_name in dynamic_modules[module].keys():
            classObj = dynamic_modules[module][class_name]
            if issubclass(classObj, Node):
                task = {
                    'id': 'node_' + str(uuid.uuid4()),
                    'type': classObj.__name__,
                    'conf': {},
                    'inputs': [],
                    'module': module
                }
                t = Task(task)
                n = classObj(t)
                nodeObj = get_node_obj(n, False)
                node_lists.append(nodeObj)

    # 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
            }
            t = Task(task)
            n = nodecls(t)
            nodeObj = get_node_obj(n, False)
            all_nodes.setdefault(modulename, []).append(nodeObj)
            loaded_node_classes.append(nodecls)

    return all_nodes