コード例 #1
0
ファイル: views.py プロジェクト: Lscheinman/FioriFlask4
def stream_data():

    i=0
    while stream:
        time.sleep(3)
        stream['events'].append({'time': get_datetime(), 'message': 'Test %d' % i})
        click.echo("[%s_View_ThreadStream] Running %d" % (get_datetime(), i))
        i+=1
コード例 #2
0
ファイル: views.py プロジェクト: Lscheinman/FioriFlask4
def load_views():
    views = {}
    for view in simserver.Actions_All:
        views[view] = odbserver.get_event_driven_calc_view(view)
        click.echo("[%s_load_views] %s" % (get_datetime(), view))

    return views
コード例 #3
0
ファイル: views.py プロジェクト: Lscheinman/FioriFlask4
def new_db():

    # Get the form values into a dictionary
    r = request.form.to_dict(flat=True)
    # Check if a name was received
    if len(str(r['db_name'])) > 0:
        # Check if the name is already taken
        if str(r['db_name']) in odbserver.databases:
            message = '%s already taken' % r['db_name']
        else:
            # All good so create the DB
            message = odbserver.create_db(r['db_name'], r['db_type'])
    else:
        message = 'No database name received'

    # Form the response
    odata = {
        'status': 200,
        'message': '%s %s' % (get_datetime(), message),
        'd': {
            'results': odbserver.get_db_stats(),
        }
    }

    return jsonify(odata)
コード例 #4
0
ファイル: views.py プロジェクト: Lscheinman/FioriFlask4
def sim_thread():
    family_count = 1  # 3 seconds to make 2 families
    sim_run_count = 2

    click.echo(
        "[%s_View_ThreadSim] Starting simulation with creating %d families" %
        (get_datetime(), family_count))
    i = 0
    while i < family_count:
        simserver.create_family()
        i += 1
    click.echo("[%s_View_ThreadSim] Starting %d simulation rounds" %
               (get_datetime(), sim_run_count))
    simserver.run_simulation(sim_run_count)
    click.echo("[%s_View_ThreadSim] Exporting snapshot JSON for starter set" %
               (get_datetime()))
    simserver.export_json()
    click.echo("[%s_View_ThreadSim] Complete with set up" % (get_datetime()))
コード例 #5
0
ファイル: views.py プロジェクト: Lscheinman/FioriFlask4
def home():

    sim = Thread(target=sim_thread, )
    stm = Thread(target=stream_data, )
    sim.start()
    click.echo("[%s_View_Home] Getting calc views" % (get_datetime()))
    views = load_views()
    click.echo("[%s_View_Home] Complete with calc views" % (get_datetime()))

    # App tile will always have an index applied to their model when 'GET"
    odata = {
        'status': 200,
        'message': '%s logged in' % get_datetime(),
        'd': {
            'index': odbserver.get_db_stats(),
            'demo_data': odbserver.fill_demo_data(),
            'clipboard': {
                'keys': [],
                'nodes': []
            },
            'dialogs': {
                'nodes': [],
                'lines': [],
                'groups': []
            },
            'files': [],
            'charts': {
                'ChartContainerData1.json':
                odbserver.get_model('ChartContainerData1.json'),
                'ChartContainerData2.json':
                odbserver.get_model('ChartContainerData2.json'),
                'ChartContainerData3.json':
                odbserver.get_model('ChartContainerData3.json')
            },
            'views': views,
            'network': odbserver.fill_demo_data_small()
        }
    }
    # Get a small net from each db
    current_selection = odata['d']['index'][0]
    current_selection['network'] = odata['d']['network'][
        current_selection['name']]
    odata['d']['current_selection'] = odata['d']['index'][0]
    click.echo("[%s_View_Home] Packaging model for client" % (get_datetime()))
    try:
        odata = jsonify(odata)
    except Exception as e:
        if "TypeError: '<' not supported between instances" in str(e):
            click.echo("[%s_View_Home] ERROR \n%s Showing oData" %
                       (get_datetime(), odata))
        else:
            click.echo("[%s_View_Home] UNKNOWN ERROR" % (get_datetime()))
    click.echo("[%s_View_Home] Sending model to client" % (get_datetime()))
    return odata
コード例 #6
0
ファイル: views.py プロジェクト: Lscheinman/FioriFlask4
def get_sample():

    r = request.form.to_dict(flat=False)
    if 'db_classes[]' in r.keys():
        message = '%s %s' % (get_datetime(), 'Sample for %s ' % r['db_name'])
    else:
        message = '%s %s' % (get_datetime(),
                             'No classes found for %s ' % r['db_name'])
        r['db_classes[]'] = []

    # Form the response
    odata = {
        'status': 200,
        'message': message,
        'd': {
            'results': odbserver.get_sample(r['db_name'][0],
                                            r['db_classes[]']),
        }
    }
    odata['message'] = odata['message'] + 'with %d results' % len(
        odata['d']['results'])
    return jsonify(odata)
コード例 #7
0
def create_app():
    """
    Create a Flask application using the app factory pattern.

    :param settings_override: Override settings
    :return: Flask app
    """

    app = Flask(__name__)
    app.config.from_object('config.settings')
    app.config.from_pyfile('settings.py', silent=True)
    app.register_blueprint(home)
    app.register_blueprint(orientdb)
    click.echo('[%s_app] All blueprints registered' % (get_datetime()))

    return app
コード例 #8
0
ファイル: views.py プロジェクト: Lscheinman/FioriFlask4
def get_stream():
    r = request.form.to_dict(flat=True)
    cur_len = int(len(stream['events']))
    cur_index = int(r['cur_index'])
    payload = stream['events'][cur_index:cur_len - 1]
    click.echo("[%s_View_getStream] Running %d" % (get_datetime(), len(stream['events'])))

    #TODO update graph with new version
    #TODO Determine routing with multiple views and setting up the ODB as a stream and PUSHing data to graph

    return jsonify(
        {'new_index': cur_len,
         'old_index': cur_index,
         'payload': payload,
         'message': 'Found %d new events' % len(payload)
         }
    )
コード例 #9
0
ファイル: views.py プロジェクト: Lscheinman/FioriFlask4
def get_atts_from_request(r, node_label):
    """

    :param r: Request dictionary from client POST
    :param node_label: Variable for situations such as multiple nodes within a dictionary.
            Expects 'node_propvals',
    :return:
    """
    icon = "sap-icon://calendar"
    title = 'Title'
    FirstName = LastName = ''
    i = 0
    propvals = []
    prop_val = {}
    for n in r:
        try:
            if '%s[%d][prop]' % (node_label, i) in n:
                prop_val = {'property': r['%s[%d][prop]' % (node_label, i)]}
            elif '%s[%d][value]' % (node_label, i) in n:
                prop_val['value'] = r['%s[%d][value]' % (node_label, i)]
                propvals.append(prop_val)
                i += 1
                if prop_val['label'] == 'icon':
                    icon = prop_val['value']
                if prop_val['label'] == 'title':
                    title = prop_val['value']
                if prop_val['label'] == 'FirstName':
                    FirstName = prop_val['value']
                if prop_val['label'] == 'LastName':
                    LastName = prop_val['value']
            if '%s[attributes][%d][property]' % (node_label, i) in n:
                prop_val = {
                    'label':
                    r['%s[attributes][%d][property]' % (node_label, i)]
                }
            elif '%s[attributes][%d][label]' % (node_label, i) in n:
                prop_val = {
                    'label': r['%s[attributes][%d][label]' % (node_label, i)]
                }
            elif '%s[attributes][%d][value]' % (node_label, i) in n:
                prop_val['value'] = r['%s[attributes][%d][value]' %
                                      (node_label, i)]
                propvals.append(prop_val)
                i += 1
                if prop_val['label'] == 'icon':
                    icon = prop_val['value']
                if prop_val['label'] == 'title':
                    title = prop_val['value']
                if prop_val['label'] == 'FirstName':
                    FirstName = prop_val['value']
                if prop_val['label'] == 'LastName':
                    LastName = prop_val['value']
        except Exception as e:
            click.echo("[%s_View_get_atts_from_request] UNKNOWN ERROR %s" %
                       (get_datetime(), str(e)))
    if FirstName != '':
        title = FirstName
    if LastName != '':
        title = title + ' ' + LastName

    return propvals, icon, title