def callSuitable(mlalgo, v2):
    #evaluate the selected Machine Learning algorithm
    global X, Y, XT, YT

    if mlalgo == 'Decision Tree':
        model = models.DTModel(X, Y, XT, YT, v2)
        model.start()
    elif mlalgo == 'Naive Bayes':
        model = models.NBModel(X, Y, XT, YT, v2)
        model.start()
    elif mlalgo == 'SVM':
        model = models.SVMModel(X, Y, XT, YT, v2)
        model.start()
    elif mlalgo == 'K Nearest Neighbours':
        model = models.KNNModel(X, Y, XT, YT, v2)
        model.start()
    elif mlalgo == 'Logistic Regression':
        model = models.LogModel(X, Y, XT, YT, v2)
        model.start()
    else:
        model = models.ANNModel(X, Y, XT, YT, v2)
        model.start()
コード例 #2
0
def loadModel(modelName, fileName=None):
    """load the modelName ML model and test the accuracy"""
    global X, Y, XT, YT
    mlalgo = modelName
    if mlalgo == 'Decision Tree':
        model = models.DTModel(X, Y, XT, YT)
        model.start()
    elif mlalgo == 'Naive Bayes':
        model = models.NBModel(X, Y, XT, YT)
        model.start()
    elif mlalgo == 'SVM':
        model = models.SVMModel(X, Y, XT, YT)
        model.start()
    elif mlalgo == 'K Nearest Neighbours':
        model = models.KNNModel(X, Y, XT, YT)
        model.start()
    elif mlalgo == 'Logistic Regression':
        model = models.LogModel(X, Y, XT, YT)
        model.start()
    else:
        model = models.ANNModel(X, Y, XT, YT)
        model.start()
コード例 #3
0
ファイル: app.py プロジェクト: ZeroICQ/timetable
def record_get(table, pk):
    data = {}

    last_updated = request.args.get('last_update', None, type=float)
    values = None

    if table not in tables or last_updated is None:
        abort(404)

    model = tables[table]()
    fields = model.fields_no_pk

    now_update = datetime.now()
    data['last_update'] = now_update.timestamp()

    last_updated = datetime.fromtimestamp(last_updated)

    log = models.LogModel()
    status = log.get_status(pk, model.table_name, last_updated, now_update)

    if status is None and model.fields_fks:
        fks_values = model.fetch_by_pk(pk, model.fields_fks)
        for fk in model.fields_fks:
            f_table_status = log.get_status(fks_values[fk.qualified_col_name],
                                            fk.pk.table_name, last_updated,
                                            now_update)
            if f_table_status == 'MODIFIED' or f_table_status == 'DELETED':
                status = 'MODIFIED'
                break

    if status == 'MODIFIED':
        values = model.fetch_by_pk(pk, model.fields_short_resolved_no_pk)

    data['status'] = status
    data['values'] = values

    return jsonify(data)
コード例 #4
0
ファイル: app.py プロジェクト: ZeroICQ/timetable
def get_log(table):
    data = {}

    last_updated = request.args.get('last_update', None, type=float)

    if table not in tables or last_updated is None:
        data = 'error'
        return jsonify(data)

    model = tables[table]()

    pks = request.args.getlist('pk', type=int)

    logs = models.LogModel()

    statuses = dict(
        logs.get_statuses(pks, model.table_name,
                          datetime.fromtimestamp(last_updated),
                          datetime.now()))

    updating_pks = [pk for pk in pks if pk in statuses]

    # TODO: check for foreign tables
    # for pk in pks:
    #     if pk in updating_pks:
    #         continue
    #
    #     if :

    values = model.fetch_by_pks(updating_pks, model.fields_short_resolved)

    data['values'] = dict(zip(updating_pks, values))
    data['last_update'] = datetime.now().timestamp()
    data['statuses'] = statuses

    return jsonify(data)
コード例 #5
0
ファイル: app.py プロジェクト: ZeroICQ/timetable
def edit(table, pk):
    data = {}

    if table not in tables:
        return data

    model = tables[table]()
    data['table'] = table
    data['pk'] = pk
    fields = model.fields_no_pk
    data['fields'] = fields

    values = None
    deleted = False

    if request.method == 'POST':
        action = request.form.get('action', None)
        last_updated = request.form.get('last_update', type=float)

        if not last_updated:
            abort(404)

        # TODO: refactor
        log = models.LogModel()
        status = log.get_status(pk, model.table_name,
                                datetime.fromtimestamp(last_updated),
                                datetime.now())

        if status == 'MODIFIED':
            old_values = {
                field.qualified_col_name:
                request.form.get(field.qualified_col_name, None)
                for field in fields
            }
            modified_values = model.fetch_by_pk(pk,
                                                model.fields_short_resolved)
            data['already_modified'] = True
            data['modified_values'] = modified_values
            data['values'] = old_values
            data['last_update'] = datetime.now().timestamp()
            return data

        if action == 'delete':
            values = model.delete_by_pk(pk_val=pk, return_fields=model.fields)
            deleted = values is not None
            data['record_name'] = values[model.main_field.qualified_col_name]
        elif action == 'close' or action == 'edit':
            new_fields = {
                field.qualified_col_name:
                request.form.get(field.qualified_col_name, None)
                for field in fields
            }
            # test updating deleted record
            values = model.update(return_fields=model.fields,
                                  new_fields=new_fields,
                                  pk_val=pk)
            data['close_window'] = action == 'close'
    else:
        values = model.fetch_by_pk(pk, model.fields)

    if not values or all(v is None for v in values.values()):
        abort(404)

    data['last_update'] = datetime.now().timestamp()
    data['deleted'] = deleted
    data['values'] = values
    return data