Exemple #1
0
def save_result(asset, algorithm, value, passed, point_list):
    # find existing results that are active, or were active and are still unacknowledged
    result = Result.query.filter(
        Result.asset_id == asset.id, Result.algorithm_id == algorithm.id,
        (Result.active == True) | (Result.acknowledged == False)).first()
    # note: do not change the acknowledged state, if the result already exists

    # or create a new one if none
    if result is None:
        result = Result(first_timestamp=datetime.datetime.now(),
                        asset_id=asset.id,
                        algorithm_id=algorithm.id,
                        occurances=0,
                        priority=asset.priority)
        result.acknowledged = passed
        db.session.add(result)

    # update with details of the algorithm check
    result.recent_timestamp = datetime.datetime.now()
    result.value = value
    result.passed = passed
    result.active = not passed
    result.occurances += 1
    result.points = point_list
    result.recent = True
    db.session.commit()

    return result