Exemplo n.º 1
0
def discover_channel_psd_difference():
    highscore_epoch, lowscore_epoch = None, None
    highscorenum, lowscorenum = 0, 0
    for i in range(1, 60):
        try:
            data_score = get_score(i)[0]
            data_state = get_state(i, 3)
            data_eeg = get_epoch_eeg(i).drop(["condition"], axis=1)
            data_raw_eeg = get_raw_eeg(i)
            if not (len(data_score) == len(data_eeg["epoch"].value_counts())
                    and len(data_score) == len(
                        data_state[data_state["markerText"] == "ShotOps"])):
                continue
            print("yes")
            events, event_id = mne.events_from_annotations(data_raw_eeg)
            epochs = mne.Epochs(data_raw_eeg,
                                events,
                                event_id,
                                tmin=-3,
                                tmax=0,
                                event_repeated='drop',
                                preload=True)
            first, second = get_score(i + 1)
            rest_eeg = epochs["s1001"][0]
            total_shot_num = len(first) + len(second)
            first_shoot_eeg = epochs["s1002"][-total_shot_num:-len(second)]
            for j in range(len(data_score)):
                if data_score[j] > 9:
                    if highscore_epoch == None:
                        highscore_epoch = first_shoot_eeg["s1002"][j]
                    else:
                        highscore_epoch = mne.concatenate_epochs(
                            [highscore_epoch, first_shoot_eeg["s1002"][j]])
                    highscorenum += 1

                if data_score[j] < 8:
                    if lowscore_epoch == None:
                        lowscore_epoch = first_shoot_eeg["s1002"][j]
                    else:
                        lowscore_epoch = mne.concatenate_epochs(
                            [lowscore_epoch, first_shoot_eeg["s1002"][j]])
                    lowscorenum += 1
            print(highscorenum)
            print(lowscorenum)
        except Exception as e:
            traceback.print_exc()
    channelnames = ["Fz", "F3", "F4", "P3", "Pz", "P4", "O1", "O2", "POz"]
    print("test")
    for channelname in channelnames:
        plot_channel_psd(highscore_epoch, channelname)

    for channelname in channelnames:
        plot_channel_psd(lowscore_epoch, channelname)
Exemplo n.º 2
0
def home():
    db.drop_all()
    db.create_all()
    if request.method == 'POST':
        # Get the resume and save it into to database.
        if 'resume' not in request.form:
            flash('No input yet')
            return redirect(request.url)
        else:
            resume = request.form['resume']
            resume = User(resume=resume)
            db.session.add(resume)
            db.session.commit()

        # Get the job post and save it into database.
        if 'job_description' not in request.form:
            flash('No input yet')
            return redirect(request.url)
        else:
            # Save the submited plain text data into database
            job_post = request.form['job_description']
            job_post = Job(job_post=job_post)
            db.session.add(job_post)
            db.session.commit()
        # Query the database and get the matching score.
        user = User.query.first()
        job = Job.query.first()
        resume = user.resume
        job_post = job.job_post
        matching_score = score.get_score(skills=skills,
                                         job_post=job_post,
                                         resume=resume)
        return render_template('home.html', matching_score=matching_score)
    else:
        return render_template('home.html')
    def calculate_score(pose):
        position, orientation = split_pose_array(pose)
        image_pose = ImagePose(position=position, orientation=orientation)

        debug = False
        dist = np.linalg.norm(np.array([150.0, -6.0]) - position[0:2])
        #if dist < 2:
            #debug = True

        predicted_detections = prediction.predicted_detections(image_pose, landmark_list, camera, debug=debug)

        _, _, yaw = tf.euler.quat2euler(orientation, axes='sxyz')

        if debug:
            print(np.rad2deg(yaw))
            debug_image = np.zeros((camera.height, camera.width, 3))
            debug_image = detection.generate_debug_image(debug_image, predicted_detections)
            plt.imshow(util.bgr_to_rgb(debug_image)/255)
            plt.show()

        # If there are no detections predicted use the cached score for that case
        if len(predicted_detections) == 0:
            score_val = empty_predicted_score
        else:
            score_val = score.get_score(predicted_detections, query_detections, sign_types, debug=debug)

        global score_calc_count
        score_calc_count += 1
        progress = 100 * score_calc_count / total_poses
        print('{:.2f}%    '.format(progress), end='\r')
        return score_val
Exemplo n.º 4
0
def add_to_result(senten, fix_word, result, detraction, string):
    senten = data_dict[fix_word][:(5 - len(senten))]
    result += [
        AutoCompleteData(sentences[index.id].sentence,
                         sentences[index.id].path, index.offset,
                         get_score(string, detraction)) for index in senten
    ]
Exemplo n.º 5
0
def calculate_gaussian_score(pose, landmark_list, query_detections, camera,
                             sign_types):
    position, orientation = split_pose_array(pose)
    image_pose = ImagePose(position=position, orientation=orientation)

    debug = False
    dist = np.linalg.norm(np.array([150.0, -6.0]) - position[0:2])
    #if dist < 2:
    #debug = True

    predicted_detections = prediction.predicted_detections(image_pose,
                                                           landmark_list,
                                                           camera,
                                                           debug=debug)

    _, _, yaw = tf.euler.quat2euler(orientation, axes='sxyz')

    # If there are no detections predicted use the cached score for that case
    if len(predicted_detections) == 0:
        score_val = empty_predicted_score
    else:
        score_val = get_score(predicted_detections,
                              query_detections,
                              sign_types,
                              debug=debug)

    return score_val
Exemplo n.º 6
0
def get_data():
    datax = []
    datay = []
    for i in tqdm(range(1, 60)):
        try:
            data_score = get_score(i)[0]
            data_state = get_state(i, 5)
            data_eeg = get_epoch_eeg(i).drop(["condition"], axis=1)
            if not (len(data_score) == len(data_eeg["epoch"].value_counts())
                    and len(data_score) == len(
                        data_state[data_state["markerText"] == "ShotOps"])):
                continue

            print("yes")
            for shoot in range(len(data_score)):
                datax.append(
                    get_aeraeeg_psd(data_eeg[data_eeg["epoch"] == i][-1000:]))
            datay.extend(data_score)
            """
            data=get_raw_eeg(i)
            events,event_id=mne.events_from_annotations(data)
            epochs=mne.Epochs(data,events,event_id,tmin=-5,tmax=0,event_repeated='drop',preload=True)
            first,second=get_score(i+1)
            rest_eeg=epochs["s1001"][0]
            total_shot_num=len(first)+len(second)
            first_shoot_eeg=epochs["s1002"][-total_shot_num:-len(second)]
            first_shoot_eeg["s1002"][0].plot_psd(fmin=2., fmax=40., average=True, spatial_colors=False,picks=["Fz"])
            plt.show()
            """
        except Exception as e:
            traceback.print_exc()
            pass
    return datax, datay
Exemplo n.º 7
0
def main(filepath):
    try:
        os.remove("result.html")
    except FileNotFoundError:
        pass
    java, submitter, url, snarf, web_browser = getInfo()
    targets = getTargets(java, submitter, url).split('\n')
    for i, target in enumerate(targets):
        print(f"{i}\t{target}")
    submission_target = targets[int(input("Which number? "))]
    html = submit(
        java,
        submitter,
        url,
        submission_target,
        getUsername(),
        getPassword(),
        filepath
    )
    # with open("result.html", "w+") as fout:
    #     fout.write(html)
    # viewInBrowser("result.html")
    html = html[html.find("url="):]
    url = html[4:html.find('"')]
    print(repr(url))
    try:
        call(f"echo {url} "
              "| /mnt/c/Windows/System32/WindowsPowerShell/v1.0//powershell.exe "
              "-c clip", shell=True)
        # powershell.exe -c "& \"C:\\Program Files\\Mozilla Firefox\\firefox.exe\" $url"
        call([
            "/mnt/c/Windows/System32/WindowsPowerShell/v1.0//powershell.exe",
            '-c',
            "& \"C:\\Program Files\\Mozilla Firefox\\firefox.exe\"",
            url
        ])
    except:
        pass
    try:
        try:
            correctness, final = get_score(url)
        except:
            correctness, final = get_score(url)
        print("Correctness/Testing:", correctness)
        print("Final score:", final)
    except:
        pass
def get_pose_scores(landmark_list, query_detections, possible_camera_poses, camera, sign_types):
    """
    Attach scores to each possible pose from `get_possible_poses`

    :param landmark_list: List of landmarks detected in the map
    :param query_detections: List of instances of TrafficSignDetection
    :param possible_camera_poses: Possible poses and orientation of the camera
    :param camera: Camera parameters
    :param sign_types: List of landmark types
    :returns: Array where scores are attached to possible poses
    """

    # Filter only landmarks of given sign types
    landmark_list = list(filter(lambda l: l.sign_type in sign_types, landmark_list))

    empty_predicted_score = score.get_score([], query_detections, sign_types, debug=False)

    total_poses = possible_camera_poses.size / 7
    global score_calc_count
    score_calc_count = 0

    def calculate_score(pose):
        position, orientation = split_pose_array(pose)
        image_pose = ImagePose(position=position, orientation=orientation)

        debug = False
        dist = np.linalg.norm(np.array([150.0, -6.0]) - position[0:2])
        #if dist < 2:
            #debug = True

        predicted_detections = prediction.predicted_detections(image_pose, landmark_list, camera, debug=debug)

        _, _, yaw = tf.euler.quat2euler(orientation, axes='sxyz')

        if debug:
            print(np.rad2deg(yaw))
            debug_image = np.zeros((camera.height, camera.width, 3))
            debug_image = detection.generate_debug_image(debug_image, predicted_detections)
            plt.imshow(util.bgr_to_rgb(debug_image)/255)
            plt.show()

        # If there are no detections predicted use the cached score for that case
        if len(predicted_detections) == 0:
            score_val = empty_predicted_score
        else:
            score_val = score.get_score(predicted_detections, query_detections, sign_types, debug=debug)

        global score_calc_count
        score_calc_count += 1
        progress = 100 * score_calc_count / total_poses
        print('{:.2f}%    '.format(progress), end='\r')
        return score_val

    scores = np.apply_along_axis(calculate_score, 3, possible_camera_poses)

    print('Done     ')

    return scores
Exemplo n.º 9
0
def get_data():
    datax = []
    datay = []
    high, low = 0, 0
    for i in tqdm(range(1, 60)):
        if i == 32: continue
        try:
            data_score = get_score(i)[0]
            data_state = get_state(i, 3)
            data_eeg = get_epoch_eeg(i).drop(["condition"], axis=1)
            if not (len(data_score) == len(data_eeg["epoch"].value_counts())
                    and len(data_score) == len(
                        data_state[data_state["markerText"] == "ShotOps"])):
                continue
            print("yes")
            for j in range(len(data_score)):
                if data_score[j] > 9.5:
                    datay.append(0)
                    c6 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-3000:-2500])
                    c5 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-2500:-2000])
                    c4 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-2000:-1500])
                    c3 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-1500:-1000])
                    c2 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-1000:-500])
                    c1 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-500:])
                    datax.append([c6, c5, c4, c3, c2, c1])
                    high += 1

                if data_score[j] < 7.5:
                    datay.append(1)
                    c6 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-3000:-2500])
                    c5 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-2500:-2000])
                    c4 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-2000:-1500])
                    c3 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-1500:-1000])
                    c2 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-1000:-500])
                    c1 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-500:])
                    datax.append([c6, c5, c4, c3, c2, c1])
                    low += 1
            print(len(datay), len(datax))
            #if len(datay)!=len(datax):
            #    raise Exception("length not matched")
        except Exception as e:
            traceback.print_exc()
            pass
    print(low, high)
    return datax, datay
def get_data():
    datax = []
    datay = []
    high, low = 0, 0
    for i in tqdm(range(1, 60)):
        if i == 32: continue
        try:
            data_score = get_score(i)[0]
            data_state = get_state(i, 3)
            data_eeg = get_epoch_eeg(i).drop(["condition"], axis=1)
            data_aimtrack = get_aimtrack(i)
            data_aimtrack.drop(
                data_aimtrack[data_aimtrack["exp_num"] == 2].index,
                inplace=True)
            data_aimtrack.drop(["exp_num"], axis=1, inplace=True)
            """
            extract aimtrack data
            """
            if not (len(data_score) == len(data_eeg["epoch"].value_counts())
                    and len(data_score) == len(
                        data_state[data_state["markerText"] == "ShotOps"])
                    and len(data_score) == len(
                        data_aimtrack["shoot_num"].value_counts())):
                continue
            print("yes")
            for j in range(len(data_score)):
                if data_score[j] > 9.5:
                    curaimtrackx = data_aimtrack[data_aimtrack["shoot_num"] ==
                                                 j + 1]["x"][-40:].tolist()
                    curaimtracky = data_aimtrack[data_aimtrack["shoot_num"] ==
                                                 j + 1]["y"][-40:].tolist()
                    if len(curaimtrackx) != 40 or len(curaimtracky) != 40:
                        continue
                    datax.append([curaimtrackx, curaimtracky])
                    datay.append(0)
                    print(data_score[j])
                    high += 1

                if data_score[j] < 7.5:
                    curaimtrackx = data_aimtrack[data_aimtrack["shoot_num"] ==
                                                 j + 1]["x"][-40:].tolist()
                    curaimtracky = data_aimtrack[data_aimtrack["shoot_num"] ==
                                                 j + 1]["y"][-40:].tolist()
                    if len(curaimtrackx) != 40 or len(curaimtracky) != 40:
                        continue
                    datax.append([curaimtrackx, curaimtracky])
                    datay.append(1)
                    low += 1

            print(len(datay), len(datax))
            #if len(datay)!=len(datax):
            #    raise Exception("length not matched")
        except Exception as e:
            traceback.print_exc()
            pass
    print(low, high)
    return datax, datay
Exemplo n.º 11
0
    def test_get_score_start_with_0_0(self):
        # Given
        expected_score: Score = Scores.score_0_0

        # When
        score: Score = get_score(score=Scores.score_0_0)

        # Then
        self.assertEqual(expected_score, score)
Exemplo n.º 12
0
    def test_get_score_when_player_1_score_once(self):
        # Given
        expected_score: Score = Scores.score_15_0
        scoring_player: int = Players.player_1

        # When
        score: Score = get_score(Scores.score_0_0, scoring_player)

        # Then
        self.assertEqual(expected_score, score)
Exemplo n.º 13
0
def preprocess():
    global files, path_eeg_save_h5
    if not os.path.exists(path_eeg_save_h5):
        os.makedirs(path_eeg_save_h5)

    count = 0
    for i, f in enumerate(files):
        try:
            print(i)
            print("Reading eeg from {}".format(f))
            data = mne.io.read_raw_fif(f)
            data = data.set_montage("standard_1020")
            events, event_id = mne.events_from_annotations(data)
            epochs = mne.Epochs(data,
                                events,
                                event_id,
                                tmin=-10,
                                tmax=0,
                                event_repeated='drop',
                                preload=True)
            first, second = get_score(i + 1)
            rest_eeg = epochs["s1001"][0]
            total_shot_num = len(first) + len(second)
            first_shoot_eeg = epochs["s1002"][-total_shot_num:-len(second)]
            second_shoot_eeg = epochs["s1002"][-len(second):]
            fc = 0
            sc = 0

            for j in range(len(epochs) - 1, 1, -1):
                if epochs.events[j][2] == 4:
                    sc += 1
                else:
                    if sc > 0: break
            for k in range(j, 1, -1):
                if epochs.events[k][2] == 6: continue
                else: break
            for j in range(k, 1, -1):
                if epochs.events[j][2] == 4:
                    fc += 1
                else:
                    if fc > 0: break
            print(len(first_shoot_eeg))
            print(fc)
            first_pd = first_shoot_eeg.to_data_frame()
            second_pd = second_shoot_eeg.to_data_frame()
            cur_path = os.path.join(path_eeg_save_h5,
                                    re.findall(r".*\\(.*?)\.[a-z]", f)[0])
            epoch_min = min(first_pd["epoch"])
            first_pd["epoch"] = first_pd["epoch"].apply(
                lambda x: x - epoch_min)

            first_pd.to_hdf(cur_path + ".h5", key="shoot_eeg")
        except Exception as e:
            traceback.print_exc()
            pass
Exemplo n.º 14
0
    def test_get_score_when_player_2_lead_by_0_15_player_1_scores(self):
        # Given
        expected_score: Score = Scores.score_15_15
        scoring_player: int = Players.player_1
        current_score: Score = Scores.score_0_15

        # When
        score: Score = get_score(current_score, scoring_player)

        # Then
        self.assertEqual(expected_score, score)
Exemplo n.º 15
0
    def test_get_score_when_player_2_score_then_score_is_0_15(self):
        # Given
        expected_score: Score = Scores.score_0_30
        scoring_player: int = Players.player_2
        current_score: Score = Scores.score_0_15

        # When
        score: Score = get_score(current_score, scoring_player)

        # Then
        self.assertEqual(expected_score, score)
Exemplo n.º 16
0
def get_data():
    datax=[]
    datay=[]
    high,low=0,0
    for i in tqdm(range(1,60)):
        if i==32: continue
        try:
            data_score=get_score(i)[0]
            data_state=get_state(i,3)
            data_eeg=get_epoch_eeg(i).drop(["condition"],axis=1)
            if not (len(data_score)==len(data_eeg["epoch"].value_counts()) and len(data_score)==len(data_state[data_state["markerText"]=="ShotOps"])): continue
            print("yes")
            for j in range(len(data_score)):
                if data_score[j]>9.5:
                    datay.append(0)
                    high+=1
                    d6=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-3000:-2500])
                    d5=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-2500:-2000])
                    d4=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-2000:-1500])
                    d3=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-1500:-1000])
                    d2=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-1000:-500])
                    d1=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-500:])
                    datax.append([d6,d5,d4,d3,d2,d1])
                
                if data_score[j]<7.5:
                    datay.append(1)
                    low+=1
                    d6=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-3000:-2500])
                    d5=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-2500:-2000])
                    d4=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-2000:-1500])
                    d3=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-1500:-1000])
                    d2=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-1000:-500])
                    d1=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-500:])
                    datax.append([d6,d5,d4,d3,d2,d1])
            
            print(len(datay),len(datax))
            #if len(datay)!=len(datax):
            #    raise Exception("length not matched")
            """
            data=get_raw_eeg(i)
            events,event_id=mne.events_from_annotations(data)
            epochs=mne.Epochs(data,events,event_id,tmin=-5,tmax=0,event_repeated='drop',preload=True)
            first,second=get_score(i+1)
            rest_eeg=epochs["s1001"][0]
            total_shot_num=len(first)+len(second)
            first_shoot_eeg=epochs["s1002"][-total_shot_num:-len(second)]
            first_shoot_eeg["s1002"][0].plot_psd(fmin=2., fmax=40., average=True, spatial_colors=False,picks=["Fz"])
            plt.show()
            """
        except Exception as e:
            traceback.print_exc()
            pass
    print(low,high)
    return datax,datay
Exemplo n.º 17
0
    def test_get_score_when_player_1_score_then_score_is_updated(self):
        # Given
        expected_score: Score = Scores.score_30_0
        scoring_player: int = Players.player_1
        current_score: Score = Scores.score_15_0

        # When
        score: Score = get_score(current_score, scoring_player)

        # Then
        self.assertEqual(expected_score, score)
Exemplo n.º 18
0
    def test_get_score_when_player_2_score_once(self):
        # Given
        expected_score: Score = Scores.score_0_15
        scoring_player: int = Players.player_2
        current_score: Score = Scores.score_0_0

        # When
        score: Score = get_score(score=current_score,
                                 scoring_player=scoring_player)

        # Then
        self.assertEqual(expected_score, score)
Exemplo n.º 19
0
def upload():
    if request.method == 'POST':
        file = request.files['file']
        if file:
            filename = str(uuid.uuid4()) + secure_filename(file.filename)
            output_file = os.path.join(app.config['UPLOAD_FOLDER'], filename)
            file.save(output_file)
            res = score.get_score(output_file)
            with open('current_score.yaml', 'w') as f:
              f.write( yaml.dump(res, default_flow_style=True) )
            return str(res)
    return '''
Exemplo n.º 20
0
def upload():
    if request.method == 'POST':
        file = request.files['file']
        if file:
            filename = str(uuid.uuid4()) + secure_filename(file.filename)
            output_file = os.path.join(app.config['UPLOAD_FOLDER'], filename)
            file.save(output_file)
            res = score.get_score(output_file)
            with open('current_score.yaml', 'w') as f:
                f.write(yaml.dump(res, default_flow_style=True))
            return str(res)
    return '''
Exemplo n.º 21
0
def main(args):


    prediction = args.prediction
    train = args.train
    if prediction:
        test_path = args.data_dir
        test_file = args.test_file
        context =  args.Context
        res_dir = args.res_dir
        test_SNPs = pd.read_csv(test_path + '/' + test_file, sep='\t')


        test_SNPs = test_SNPs[['Chromosome','Start','End']]
        data = score.get_score(test_SNPs)

        '''
        kde get transformed score
        '''

        trans_score = transform.transform(data, context)

        '''
        load WEVar model, and predict WEVar score
        '''
        res = model.WEVar(trans_score, context)

        test_SNPs['WEVar_{}'.format(context)] = res
        test_SNPs.to_csv('{}/{}'.format(res_dir,test_file), index=False, sep='\t')

    elif train:

        data_path = args.data_dir
        train_file = args.train_file
        train_SNPs = pd.read_csv(data_path + '/'  + train_file, sep='\t')
        X = train_SNPs[['Chromosome', 'Start', 'End']]
        X = score.get_score(X)
        Y = train_SNPs['Labels'].to_numpy()
        train_model.train(X,Y, train_file)
        train_model.test(X,Y, train_file)
Exemplo n.º 22
0
def draw_score_distribution():
    score = []
    for i in range(1, 60):
        try:
            score.extend(get_score(i)[0])
        except Exception as e:
            pass
    print(score)
    plt.hist(score, width=0.8, color="orange")
    plt.title("shot score distribution")
    plt.xlabel("shot score")
    plt.ylabel("num")
    plt.show()
Exemplo n.º 23
0
    def two_player_min_max(self, player, depth):
        self.update_event()
        score = get_score(self.game_board, player, self.players, self.goal)
        if score == 10000 or score == -10000 or score == 0 or depth == 0:
            return score

        best_score = -100000
        for move in self.get_possible_moves():
            self.game_board[move[1]][move[0]].value = player.color
            score = -self.two_player_min_max(self.change_turn(player), depth - 1)
            self.game_board[move[1]][move[0]].value = None
            best_score = max(score, best_score)

        return best_score
Exemplo n.º 24
0
def get_score(bot, context):
    global ID
    global URL
    global want
    global last_ball
    msg=None
    print("-----")
    print(last_ball, msg)
    print("----")
    last_ball, msg=score.get_score(URL, ID, last_ball)
    print("called")
    if msg:
        global user_id
        for u in user_id:
          bot.send_message(u, msg)
Exemplo n.º 25
0
def send_job():
    if request.method == 'POST':
        if 'job_post' not in request.form:
            flash('No input yet')
            return redirect(request.url)
        job_post = request.form['job_post']
        job_post = Job(job_post=job_post)
        db.session.add(job_post)
        db.session.commit()

        user = User.query.first()
        resume = user.resume
        matching_score = score.get_score(skills=skills,
                                         job_post=job_post,
                                         resume=resume)
        return render_template('score.html', matching_score=matching_score)
    else:
        return render_template('send_job.html')
Exemplo n.º 26
0
 def get_score(self,
               pred,
               y,
               from_paths=False,
               tgt_size=None,
               post_processing=False,
               method=None):
     '''Reimplement this function and return the score'''
     # for i in range(len(pred)):
     #     pred[i] = pred[i] / pred[i].max()
     if from_paths:
         y = utils.load_masks(y, tgt_size=tgt_size, method=method)
     if not post_processing:
         pred = utils.trsf_proba_to_binary(pred)
     s = score.get_score(y,
                         pred,
                         label_pred=(self.multi_head and post_processing))
     return s
Exemplo n.º 27
0
def evaluate(model, data, logdir, epoch, out_f, gpu):
    get_embedding(model, data, logdir, gpu, test=False)
    img_embeddings, img_fns, gel_embeddings, gel_fns = get_embedding(model,
                                                                     data,
                                                                     logdir,
                                                                     gpu,
                                                                     test=True)
    precision = get_score(img_embeddings, img_fns, gel_embeddings, gel_fns)
    return precision

    nb_img = len(img_embeddings)
    nb_gel = len(gel_embeddings)
    distance_matrix = np.zeros((nb_gel, nb_img))
    img_embeddings = np.array(img_embeddings)
    gel_embeddings = np.array(gel_embeddings)
    dim_embedding = img_embeddings.shape[-1]
    img_embeddings = img_embeddings.reshape((nb_img, dim_embedding))
    gel_embeddings = gel_embeddings.reshape((nb_gel, dim_embedding))

    scores = []
    for i in range(nb_gel):
        distance_matrix[i, :] = np.mean(np.square(img_embeddings -
                                                  gel_embeddings[i, :]),
                                        axis=1).T

        r = []
        for j in range(nb_img):
            if (get_gel_id(img_fns[j]) == get_gel_id(gel_fns[i])):
                r.append(1)
            else:
                r.append(0)
        d = distance_matrix[i, :].tolist()
        a = zip(d, r)
        a = sorted(a, key=lambda d: d[0])
        r = [x[1] for x in a]
        ndcg = [rank_metrics.ndcg_at_k(r, k) for k in [10, 20, 30]]
        precision = [rank_metrics.precision_at_k(r, k) for k in [10, 20, 30]]
        scores.append(ndcg + precision)

    scores = np.array(scores)
    scores = np.mean(scores, axis=0)
    print "ndcg & precision", scores
    print >> out_f, "ndcg & precision", scores
Exemplo n.º 28
0
def home():
	if request.method == 'POST':
		# Get the resume from user's input form
		if 'resume' not in request.form:
			return redirect(request.url)
		else:
			resume = request.form['resume']
			
		# Get the job post from user's input form
		if 'job_description' not in request.form:
			return redirect(request.url)
		else:
			job_post = request.form['job_description']

		matching_score = score.get_score(job_post=job_post, resume=resume)
		matching_score = matching_score*100
		matching_score= "{:.0f}".format(matching_score)
		classified_title = classify(job_post, preprocessor= tfidfVectorizer, model=classifier)
		return render_template('home.html',matching_score=matching_score, classified_title=classified_title)
	else:
		return render_template('home.html')
Exemplo n.º 29
0
def run_eval():
    '''
    0.647781443332231 0.751431565552603 0.6957674364205794 1.453401803970337
    0.7561888945873121 0.8691474231820053 0.8087429315200878 105.16041398048401
    0.756098554597748 0.8682866125229237 0.8083184530290493 121.29132223129272
    0.7572781508769642 0.8693719824843744 0.8094628264770966 226.5253984928131
    0.760764030300562 0.8739005950821512 0.8134171725177012 3.427755832672119
    0.742910027361983 0.8637486432875482 0.7987851308320643 0.9492778778076172
    '''
    testfile = './data/test.txt'
    P, R, F, cost = get_score(testfile, 'hmm')
    P, R, F, cost = get_score(testfile, 'forward')
    P, R, F, cost = get_score(testfile, 'backward')
    P, R, F, cost = get_score(testfile, 'biward')
    P, R, F, cost = get_score(testfile, 'maxngram')
    P, R, F, cost = get_score(testfile, 'biwardngram')
Exemplo n.º 30
0
def find_sequence(string):
    detraction = 0
    senten = data_dict[string][:5]
    result = [
        AutoCompleteData(sentences[index.id].sentence,
                         sentences[index.id].path, index.offset,
                         get_score(string, detraction)) for index in senten
    ]

    if len(result) < 5:
        if len(string) > 1:
            fix_word, detraction = replace_char(string, 1, len(string))
            add_to_result(senten, fix_word, result, detraction, string)

    if len(result) < 5:
        if len(string) > 3:
            fix_word, detraction = delete_unnecessary_char(string, 3, 4)
            add_to_result(senten, fix_word, result, detraction, string)

    if len(result) < 5:
        if len(string) > 3:
            fix_word, detraction = add_missed_char(string, 3, 4)
            add_to_result(senten, fix_word, result, detraction, string)

    if len(result) < 5:
        if len(string) > 0:
            fix_word, detraction = replace_char(string, 0, 1)
            add_to_result(senten, fix_word, result, detraction, string)

    if len(result) < 5:

        fix_word, detraction = delete_unnecessary_char(string, 0, len(string))
        add_to_result(senten, fix_word, result, detraction, string)

    if len(result) < 5:
        fix_word, detraction = add_missed_char(string, 0, len(string))
        add_to_result(senten, fix_word, result, detraction, string)

    return result[:5]
Exemplo n.º 31
0
def send_job():
    if request.method == 'POST':
        # check if the post request has the file part
        if 'job_post' not in request.form:
            flash('No input yet')
            return redirect(request.url)
        job_post = request.form['job_post']
        #job_post = Job(name=file.filename, resume=file.read())
        #db.session.add(resume)
        #db.session.commit()
        user = User.query.first()
        resume = user.resume
        #return resume
        matching_score = score.get_score(skills=skills,
                                         job_post=job_post,
                                         resume=resume)
        #flash("score was calculated")
        return render_template('score.html', matching_score=matching_score)

        #return 'Saved ' + file.filename + ' to the database!'
        ### return top 10 jobs you need to consider today.
    return render_template('send_job.html')
Exemplo n.º 32
0
output =[]
finalscore = 0
counter = 0
flad = [0.8]*700 + [0.2]*2800
for train, test in skf:
	counter = counter + 1	
	clf = AdaBoostClassifier(n_estimators = 1500, learning_rate = 0.1)
	clf = clf.fit([ newdata[i][:] for i in train ], [ data[i][-1] for i in train ],np.array([flad[i] for i in train ]) )
	prediction = clf.predict([ newdata[i][:] for i in test ])
	# pred = []
	# for i in prediction:
	# 	if(i > 1.5):
	# 		pred.append(2)
	# 	else:
	# 		pred.append(1)
	xscore = score.get_score( prediction , [ data[i][-1] for i in test ])
	finalscore = finalscore + xscore
	print xscore
	print "done"
finalscore = finalscore * (1.0) / counter
print counter
print finalscore
# score = cross_val_score(clf, newdata[:,:], data[:,-1], cv = 5, scoring = 'get_score')
# print "in scores"
# for i in score:
# 	print i

# print "out of score"
# for i in output:
# 	print i
Exemplo n.º 33
0
			testL.append(i)
			testL.append(i)
			testL.append(i)
			labels3.append(1)
			labels3.append(1)
			labels3.append(1)

	prj = PCA(n_components = 10)
	newdata = prj.fit_transform([normdata[i][:] for i in trainL ], labels2)#[ labels[i] for i in trainL ])
	newtestdata = prj.transform([normdata[i][:] for i in testL ])
	print np.shape(newdata)
	clf = RandomForestClassifier(n_estimators = 500)
	clf = clf.fit(newdata, labels2)
	prediction = clf.predict(newtestdata)
	# pred = []
	# for i in prediction:
	# 	if(i > 1.5):
	# 		pred.append(2)
	# 	else:
	# 		pred.append(1)
	print score.get_score(prediction, labels3) #[ labels[i] for i in test ])
print "done"
# score = cross_val_score(clf, newdata[:,:], data[:,-1], cv = 5, scoring = 'get_score')
# print "in scores"
# for i in score:
# 	print i

# print "out of score"
# for i in output:
# 	print i
Exemplo n.º 34
0
def build_summary(starting_summary, parent_keywords=[]):

    partial_summary = (
        list(starting_summary),  # summary until this point
        0,                       # score until this point
        list(starting_summary)   # starting summary
    )

    partial_summaries = []
    heappush(partial_summaries, (-partial_summary[1], partial_summary))
    completed_summaries = []

    while partial_summaries:

        # generate potential summaries
        # expand them and keep the best ones
        _, (summary, summary_score, keywords) = heappop(partial_summaries)

        # add words to summary
        add_forward = g.ng.get((summary[-2], summary[-1]), {}).keys()
        add_reverse = g.ing.get((summary[0], summary[1]), {}).keys()

        # compute score for possible next moves 
        # also updates ng
        previous_bigram = tuple(summary[-2:])
        next_options = [
            (
                summary + list(bigr)[1:], 
                get_score(
                    summary, 
                    bigr, 
                    get_and_update(3, None, previous_bigram + (bigr[1],), g.ts), 
                    previous_bigram,
                    1,
                    list(keywords) + list(parent_keywords)
                ),
                bigr[1]
            )
            for bigr in add_forward
        ]

        # repeat for reverse links (not elegant, refactor?)
        previous_bigram = tuple(summary[:2])
        next_options += [
            (
                list(bigr)[:1] + summary, 
                get_score(
                    summary, 
                    bigr, 
                    get_and_update(3, None, (bigr[0],) + previous_bigram, g.ts), 
                    previous_bigram,
                    2,
                    list(keywords) + list(parent_keywords)
                ),
                bigr[0]
            )
            for bigr in add_reverse
        ]

        next_options = nlargest(5, next_options, key=lambda x: x[1])

        for next in next_options:
            summary, score = (
                    next[0], 
                    summary_score + next[1]
            )

            
            if summary[-1] == '_E' and summary[0] == '_S' and len(summary) > 8:
                # this summary looks good, we keep it
                # update penalties
                for w in summary:
                    g.penalty[w] += 1
                print score
                return summary

            elif (summary[-1] == '_E' and summary[0] == '_S'):
                # this summary is too short, discard it
                for w in summary:
                    g.penalty[w] += 1
            else:
                partial_summaries.append((-score, (summary, score, keywords)))

    # no summary could be built
    return None
Exemplo n.º 35
0
def get_score(username, passwd):
    import score
    
    return score.get_score(username, passwd)
Exemplo n.º 36
0
def game(score_state):
	# No sound. :(
        #pygame.mixer.pre_init(44100,8,4,1024)
        pygame.init()
        pygame.font.init()
        #pygame.mixer.music.set_volume(2.0)
#        if pygame.mixer.music.get_busy():
#                pass
#        else:
#                musicfile = data.filepath('midi','bumblbee.mid')
#                pygame.mixer.music.load(musicfile)
#                pygame.mixer.music.play(-1)
	
	screen = pygame.display.set_mode(SCREENRECT.size)
	clock = pygame.time.Clock()
	background = pygame.image.load(data.filepath('images/new_background.png')).convert()
	level = Level()

	tornadoes = pygame.sprite.Group()
	houses = pygame.sprite.Group()
	player = pygame.sprite.Group()
	rays = pygame.sprite.Group()
	lightnings = pygame.sprite.Group()
	all = pygame.sprite.OrderedUpdates()
	titles = pygame.sprite.Group()
	statuses = pygame.sprite.Group()
	scores = pygame.sprite.Group()
	sparks = pygame.sprite.Group()
	
	start_new_game = False

	Score.containers = all
	Status.containers = all
	Title.containers = all
	Tornado.containers = tornadoes,all
	House.containers = houses,all
	Ray.containers = rays,all
	Lightning.containers = lightnings,all
	Score.containers = all
	Spark.containers = all
	Status.containers = all
	Player.containers = all

	screen.blit(background,(0,0))
        pygame.display.flip()

	# Title Screen
	score = Score(score_state)
	status_pause = 0
	first_time = True

        while start_new_game == False:
                status_pause = status_pause + 1
                if (first_time):
                        title_text = "Twisted Twister!"
                        Title(title_text,(0,0,0))
                        Title(title_text,(255,0,0))
                        Title(title_text,(0,255,255))
                        Title(title_text,(0,255,0))
                        Title(title_text,(0,0,255))
                        first_time = False
                for event in pygame.event.get():
                        if event.type == QUIT:
                                sys.exit()
                        if event.type == MOUSEBUTTONDOWN:
                                start_new_game = True
                        if event.type == KEYDOWN:
                                if event.key == K_ESCAPE:
                                        sys.exit()
                                else:
                                        start_new_game = True

                if status_pause > 100:
			Status ("Press any key to start...")
                        status_pause = 0
                all.clear(screen,background)
                all.update()
                dirty = all.draw(screen)
                pygame.display.update(dirty)
                clock.tick(30)
	kill_objects(all)

	house_container = []
	# Stuff to do to start the game
	#for i in range(100,800,150):
	for i in range(0,5):
		house_container.append(House(((i*150)+100,500)))

	# Reset the level
	level.start()

	# Start the scoreboard
	score = Score(score_state)

	# Populate the screen with the actors
	fujita = start_game(level)
	player = Player((400,550))

	# Lights! Camera! Silence on the set!
	playing = True
	bonus_house = 0
	last_bonus = 0
	bonus_at = 10000

	# Cameras rolling...
	# 3...2...1... Action!
	while playing:
		active = True
		lightning_counter = 0
		Status("Level %d, %s spotted!" % (level.get_level(), 'F' + str(fujita) + 's'))
		if (bonus_house > 0):
			for t in range(0,5):
				if (house_container[t].is_alive() == False):
					if (bonus_house >= 1):
						house_container[t].set_alive()
						bonus_house = bonus_house - 1
		while active:
			lightning_counter = lightning_counter + 1
			if lightning_counter > min(300,10000 - (level.get_level() * 200)):
				Lightning(player.get_position()) 
				lightning_counter = 0
			for event in pygame.event.get():
				if event.type == QUIT:
					sys.exit()
				if event.type == KEYDOWN:
					# Put in an escape key / Q key handler
					if event.key == K_ESCAPE:
						active = False
						playing = False
					if event.key == K_LEFT:
						player.left()
					if event.key == K_RIGHT:
						player.right()
					if event.key == K_LCTRL or event.key == K_RCTRL:
						player.fire()
				if event.type == KEYUP:
					if event.key == K_LEFT:
						player.stop()
					if event.key == K_RIGHT:
						player.stop()
					pass

			tornado_house_collide = pygame.sprite.groupcollide(houses,tornadoes,False,False)
			if (tornado_house_collide):
				for house in (tornado_house_collide):
					for tornado in (tornado_house_collide[house]):
						if (house.is_alive()):
							tornado.rise()
							house.rise(tornado.get_fujita())
			tornado_ray_collide = pygame.sprite.groupcollide(tornadoes,rays,False,False)
			if (tornado_ray_collide):
				for tornado in (tornado_ray_collide):
					tornado.hit(score)
			if (not tornadoes.sprites()):
				active = False
			lightning_player_collide = pygame.sprite.spritecollide(player,lightnings,False)
			if (lightning_player_collide):
				player.hit()
				Spark(player.get_midtop_position())

			if (score.get_score() >= (last_bonus + bonus_at)):
				bonus_house = bonus_house + 1
				# Should return the last score at 10,000 increments
				last_bonus = (score.get_score() / 1000) * 1000
				Status("Bonus!")
			all.clear(screen,background)
			all.update() 
			dirty = all.draw(screen) 
			pygame.display.update(dirty)
			clock.tick(30)

		# Reset for the next level
		if playing:
			level.next_level()	
			player.kill()
			fujita = start_game(level)
			player = Player((400,550))
			lightning_counter = 0
			houses_alive = False
			for i in range(0,5):
				house_container[i].restoration()
				houses_alive = houses_alive or house_container[i].is_alive()
			if (houses_alive or bonus_house > 0):
				playing = True
				active = True
			else:
				active = False
				playing = False
	score_state = score.get_score_state()
	kill_objects(all)
	return (score_state)
Exemplo n.º 37
0
skf = StratifiedKFold(data[:,-1], n_folds=10, shuffle=True)
finalscore = 0
counter = 0
output =[]
for train, test in skf:
	counter = counter + 1
	clf = GaussianNB()
	clf = clf.fit([ newdata[i][:] for i in train ], [ data[i][-1] for i in train ])
	prediction = clf.predict([ newdata[i][:] for i in test ])
	# pred = []
	# for i in prediction:
	# 	if(i > 1.5):
	# 		pred.append(2)
	# 	else:
	# 		pred.append(1)
	finalscore = finalscore + score.get_score( prediction , [ data[i][-1] for i in test ])
	print "done"
finalscore = finalscore*(1.0)/counter
print finalscore
# score = cross_val_score(clf, newdata[:,:], data[:,-1], cv = 5, scoring = 'get_score')
# print "in scores"
# for i in score:
# 	print i

# print "out of score"
# for i in output:
# 	print i



# import numpy as np
Exemplo n.º 38
0
# 	print newdata[i]
print len(newdata)
print len(newdata[0])
print np.shape(newdata)
print "data done"
print "logistic initialized"
# clf.fit(data[:,:-1], data[:,-1])
print "fitted data"
skf = StratifiedKFold(data[:,-1], n_folds=10, shuffle=True)
output =[]
for train, test in skf:
	clf = RandomForestClassifier(n_estimators = 500)
	clf = clf.fit([ newdata[i][:] for i in train ], [ data[i][-1] for i in train ])
	prediction = clf.predict([ newdata[i][:] for i in test ])
	# pred = []
	# for i in prediction:
	# 	if(i > 1.5):
	# 		pred.append(2)
	# 	else:
	# 		pred.append(1)
	output.append(score.get_score([ data[i][-1] for i in test ], prediction))
	print "done"
# score = cross_val_score(clf, newdata[:,:], data[:,-1], cv = 5, scoring = 'get_score')
# print "in scores"
# for i in score:
# 	print i

print "out of score"
for i in output:
	print i