コード例 #1
0
ファイル: app.py プロジェクト: szatkus/k15-05
def submit():
    for key in flask.request.form:
        question_id = int(key[key.find('-') + 1:])
        answer_id = int(flask.request.form[key])
        respondent_id = str(uuid4())
        result = Result()
        result.respondent_id = respondent_id
        result.question_id = question_id
        result.answer_id = answer_id
        session.add(result)
    session.commit()
    return flask.render_template('strona.html')
コード例 #2
0
def run_test(test, graphql=False, log_data=True):
    """
    Runs a test stored in the database.
    Return: Tuple. First element is a boolean that is True if passed with an "OK" error code,
     False otherwise. Second is the Result object to be stored in the database.
     If log_data is False, it will only return the boolean (no tuple)
    """
    # Here "valid" means its a 200 code
    is_valid_error_code = lambda code: code - 200 < 100 and code - 200 >= 0
    # Get info for test
    endpoint = test.url
    method = test.method
    try:
        if graphql:  # Make graphql request
            parameters = test.parameters
            no_whitespace = parameters.replace(' ', '').replace('\n',
                                                                '').replace(
                                                                    '\t', '')
            endpoint = endpoint + '?query=' + no_whitespace
            parameters = ''
        else:  # normal request
            parameters = dict(test.parameters)
    except:  # Error, likely from graphql/normal request mismatch
        # Treat as failure
        if log_data:
            unix_time = int(time.time())
            result = Result(test_id=test.id,
                            success=False,
                            createdAt=unix_time,
                            updatedAt=unix_time)
            return False, result
        else:
            return False

    # Make request
    request_type = method.get_requests_method()
    response = request_type(endpoint, data=parameters)

    # Get result and store in database
    result_bool = is_valid_error_code(response.status_code)

    if log_data:
        unix_time = int(time.time())
        result = Result(test_id=test.id,
                        success=result_bool,
                        createdAt=unix_time,
                        updatedAt=unix_time)
        return result_bool, result
    else:
        return result_bool
コード例 #3
0
ファイル: run.py プロジェクト: intrepidlemon/deep-ultrasound
def run(model, description):
    run_id = str(uuid4())

    model.run(run_id)
    K.clear_session()

    model_instance = evaluate.load(os.path.join(
        config.MODEL_DIR,
        "{}-{}.h5".format(run_id, model.MODEL_NAME),
        ))

    train, validation, test_data = data()
    train_data_stats = characterize_data(train)
    validation_data_stats = characterize_data(validation)
    test_data_stats = characterize_data(test_data)
    results = test(model_instance, train, validation, test_data)

    result = Result(
        model.MODEL_NAME,
        run_id,
        train_data_stats,
        validation_data_stats,
        test_data_stats,
        description,
        **results
        )
    db.session.add(result)
    db.session.commit()
コード例 #4
0
ファイル: run.py プロジェクト: intrepidlemon/uterus-mri
def run(model,
        description,
        input_form,
        label_form="shrunk",
        split_id=None,
        loaded_data=None,
        hyperparameters=dict()):
    run_id = uuid4()
    if split_id is None:
        split_id = run_id

    history = model.run(run_id,
                        input_form=input_form,
                        loaded_data=loaded_data,
                        label_form=label_form,
                        hyperparameters=hyperparameters)
    K.clear_session()

    model_instance = evaluate.load(
        os.path.join(
            config.MODEL_DIR,
            "{}-{}.h5".format(str(run_id), model.MODEL_NAME),
        ))

    if loaded_data is None:
        train, validation, test = data(split_id,
                                       input_form=input_form,
                                       label_form=label_form,
                                       balanced_train=True)
    else:
        train, validation, test = loaded_data
        train.reset()
        validation.reset()
        test.reset()

    train_data_stats = characterize_data(train)
    validation_data_stats = characterize_data(validation)
    test_data_stats = characterize_data(test)
    results = test_model(model_instance, train, validation, test)
    training.reset()
    validation.reset()
    test.reset()

    result = Result(model.MODEL_NAME,
                    str(run_id),
                    str(split_id),
                    train_data_stats,
                    validation_data_stats,
                    test_data_stats,
                    description,
                    input_form,
                    label=label_form,
                    hyperparameters=hyperparameters,
                    history=history,
                    **results)
    db.session.add(result)
    db.session.commit()
コード例 #5
0
ファイル: sqlite.py プロジェクト: Longi94/chaos_db
    def evaluate_result(self, result: Result):
        super().evaluate_result(result)

        if self.query == TPCH_UPDATES:
            db_file = os.path.join(self.directory,
                                   f'db.{self.iteration}.sqlite')
            db_hash = subprocess.check_output(['sha1sum', db_file
                                               ]).decode('utf-8').split(' ')[0]

            if db_hash == SHA_UPDATED:
                result.result = RESULT_OK
                return
            elif db_hash != SHA_ORIGINAL and (result.result is None
                                              or result.result < 0):
                result.result = RESULT_INCORRECT_OUTPUT

            # check for corruption
            p = subprocess.Popen([
                os.path.join(self.database_dir, 'bin/sqlite3'), db_file,
                'pragma integrity_check'
            ],
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)

            integrity_check, integrity_stderr = p.communicate()

            if len(integrity_stderr) > 0:
                if result.stderr is None or len(result.stderr) == 0:
                    result.stderr = b'[INTEGRITY]:' + integrity_stderr
                else:
                    result.stderr += b'\n[INTEGRITY]:' + integrity_stderr

            if p.returncode != 0:
                result.db_corrupted = True
                return

            integrity_check = integrity_check.decode('utf-8').strip()

            if integrity_check != 'ok':
                result.db_corrupted = True
                return
コード例 #6
0
ファイル: monitor.py プロジェクト: Longi94/chaos_db
    def evaluate_result(self, result: Result):
        if result.timeout:
            result.result = RESULT_TIMEOUT
        elif result.exited:
            if result.return_code == 0:
                if self.query in (TPCH1, TPCH3, SSB11, SSB41):
                    answer_file = f'databases/{self.db}/answers'
                    if self.query == TPCH1:
                        answer_file += '/q1.out'
                    elif self.query == TPCH3:
                        answer_file += '/q3.out'
                    elif self.query == SSB11:
                        answer_file += '/ssb11.out'
                    elif self.query == SSB41:
                        answer_file += '/ssb41.out'

                    if self.compare_output(answer_file, result.stdout):
                        result.result = RESULT_OK
                        result.stdout = None
                    else:
                        result.result = RESULT_INCORRECT_OUTPUT
            else:
                result.result = RESULT_ABNORMAL_BEHAVIOR
        elif result.signaled:
            result.result = RESULT_CRASH
コード例 #7
0
def scan(task, dbconn):
    data = dict(task)
    data['root'] = data['root'].split(';')
    data['urls'] = data['urls'].split('\n')

    goal = worker(data['url'], data['query'], data['root'])
    goal = sorted(goal.items(), key=(lambda x: x[0]))
    data['result'] = goal

    if data.get('engine'):
        se = SearchEngineParser(data['query'], data['engine']).scan()
        data['sites'] = se.sites['sites']
    else:
        data['sites'] = data['urls']

    done = dict()
    with ChromeBrowser(headless=True) as br:
        for n, s in enumerate(data['sites'], 1):
            try:
                _page, _res = dict(), None
                t1 = time()
                _page['html'] = br.get(s)
                _page['load'] = time() - t1
                _page['url'] = s
                _page['key'] = data['query']
                _page['root'] = data['root']
                _data = get_elements(_page['html'], REGULARS)
                _res = analyze(_page, _data)
                done[str(n)] = _res
            except Exception as e:
                print(type(e), e)

    data['done'] = done
    data['keys'] = sorted(done.keys(), key=lambda x: int(x))
    data['fromto'], data['avarage'] = find_avarage(goal, done)
    data['timestamp'] = data['timestamp'].isoformat()

    dbconn.execute(Result.insert().values(taskid=data['id'],
                                          data=json.dumps(data,
                                                          ensure_ascii=False)))

    data['result_url'] = f"http://topomer.site/done/{data['uuid']}"
    smail(data, data['email'])
    print('Done: ', data['result_url'])
コード例 #8
0
    def evaluate_result(self, result: Result):
        if result.timeout:
            result.result = RESULT_TIMEOUT
        elif result.signaled:
            if result.term_sig == 9:
                answer_file = None
                if self.query == TPCH1:
                    answer_file = 'databases/monetdb/answers/q1.out'
                elif self.query == TPCH3:
                    answer_file = 'databases/monetdb/answers/q3.out'

                if self.compare_output(answer_file, result.stdout):
                    result.result = RESULT_OK
                    result.stdout = None
                else:
                    result.result = RESULT_INCORRECT_OUTPUT
            else:
                result.result = RESULT_CRASH
        elif self.query_return_code != 0:
            result.result = RESULT_ABNORMAL_BEHAVIOR
        else:
            result.result = RESULT_UNKNOWN
コード例 #9
0
ファイル: app.py プロジェクト: Waweru007/Flask_DB
def querying_resuls():
    results = Result.select().where(Result.student > 20)
    return render_template("Exam_Results.html", results=results)
コード例 #10
0
from db import session, Result, Entry_Requirement, Entry

# add possible results
session.add_all(
    [Result(result='win'),
     Result(result='lose'),
     Result(result='deferred')])

# add possible entry conditions
session.add_all([
    Entry_Requirement(
        giveaway_type='Watch a short video',
        query_selector="('.continue_button_inner', '.boxClickTarget')"),
    Entry_Requirement(giveaway_type='No entry requirement',
                      query_selector="('.boxClickTarget', '.a-button-input')"),
    Entry_Requirement(
        giveaway_type='Follow * on *',
        query_selector=
        "('.a-button-input','.a-button-input', '.boxClickTarget')"),
    Entry_Requirement(giveaway_type='Subscribe to a newsletter',
                      query_selector="('.a-button-input')"),
])

session.commit()

#result: a-size-base-plus a-color-secondary qa-giveaway-result-text a-text-bold
#deferred result: a-size-base-plus a-color-secondary qa-giveaway-result-text a-text-bold
#time: a-size-small a-color-secondary qa-giveaway-winner-declare-time-text
#Aug 17, 2018 11:59 PM PDT

# prize_image in #prize-image