Esempio n. 1
0
def update_defense_point(game, teamname, servicename):
    team = utils.get_team_byname(game['teams'], teamname)
    if game['flags'][teamname][servicename]['stole'] is False:
        try:
            if service_is_up(
                    team['host']['ipaddress_{}bit'.format(
                        services[servicename]['arch'])],
                    servicename) is True:  # Check if service is up
                db_flag = game['flags'][teamname][servicename]['flag']
                catted_flag = utils.get_flag(team['host'],
                                             services[servicename])
                if safe_str_cmp(catted_flag,
                                db_flag) is True:  # Check if flag is integry
                    # Save to database
                    mongodb.ctfgame.update_one(
                        {
                            "_id": current_game['_id'],
                            "teams": {
                                "$elemMatch": {
                                    "name": teamname
                                }
                            }
                        }, {"$inc": {
                            "teams.$.points.defense": 1
                        }})
                    utils.append_to_history(
                        mongodb, current_game['_id'],
                        "{} , {} DEFENSE +1!".format(teamname.title(),
                                                     servicename))
                else:
                    utils.append_to_history(
                        mongodb, current_game['_id'],
                        "{} , {} FLAG NOT INTEGRITY".format(
                            teamname.title(), servicename))
            else:
                utils.append_to_history(
                    mongodb, current_game['_id'],
                    "{} , {} SERVICE DOWN!".format(teamname.title(),
                                                   servicename))
        except Exception as e:
            logger.error("Exception raised on: {}".format(e))
            # Plot estimation and prediction
            plt.plot(est_Tt, est_path[:, iD], color='r', lw=3)
            plt.plot(pred_Tt, opt_pred_path[:, iD], color='r', lw=3)

            # Plot true states if this uses fake data
            if true_states is not None:
                plt.plot(scF.Tt, true_states[:, iD], color='k')

            iL_idx += 1
        else:
            plt.plot(est_Tt, est_path[:, iD], color='r', lw=3)
            plt.plot(pred_Tt, opt_pred_path[:, iD], color='r', lw=3)
            if true_states is not None:
                plt.plot(scF.Tt, true_states[:, iD], color='k')
    save_opt_pred_plots(data_flag)
    plt.show()

    # Save all the optimal predictions, measurement and stimuli to txt files
    stim_to_save = sp.vstack((full_Tt.T, scF.stim[full_range].T)).T
    meas_to_save = sp.vstack((full_Tt.T, scF.meas_data[full_range].T)).T
    est_to_save = sp.vstack((est_Tt.T, est_path.T)).T
    pred_to_save = sp.vstack((pred_Tt.T, opt_pred_path.T)).T
    params_to_save = sp.vstack((scF.model.param_names, est_params)).T
    save_opt_pred_data(data_flag, stim_to_save, meas_to_save, est_to_save,
                       pred_to_save, params_to_save)


if __name__ == '__main__':
    data_flag = get_flag()
    pred_plot(data_flag)
Esempio n. 3
0
def hasDoneFit():
    ready_flag = utils.get_flag()
    return flask.jsonify(ready_flag)