Ejemplo n.º 1
0
    def customize_citations(self):

        # Obtain the parameters.
        show_journal_str = request.params['toggle_journal']
        show_authors_str = request.params['toggle_authors']
        show_keywords_str = request.params['toggle_keywords']

        # Obtain the User object (as opposed to the auth.User object).
        cur_user = controller_globals._get_user_from_email(
            request.environ.get('repoze.who.identity')['user'].email)

        # Make changes to the booleans of the user object.
        cur_user.show_journal = {"Show": True, "Hide": False}[show_journal_str]
        cur_user.show_authors = {"Show": True, "Hide": False}[show_authors_str]
        cur_user.show_keywords = {
            "Show": True,
            "Hide": False
        }[show_keywords_str]

        # Add the changes to the database.
        Session.commit()

        # These messages appear in their designated separate locations,
        #   i.e. on the top left corner of the div that corresponds to this function.
        # This is more appropriate than having a general message on some part of the screen.
        c.account_msg = ""
        c.account_msg_citation_settings = "Citation Settings changes have been applied."

        return render("/accounts/account.mako")
Ejemplo n.º 2
0
 def _clear_this_user_locks(self, all_assignments):
     priorities_locked_by_this_user = self._get_all_priorities_locked_by_this_user(all_assignments)
     for p in priorities_locked_by_this_user:
         p.is_out = 0
         p.locked_by = None
         Session.add(p)
     Session.commit()
Ejemplo n.º 3
0
 def _clear_this_user_locks(self, all_assignments):
     priorities_locked_by_this_user = self._get_all_priorities_locked_by_this_user(all_assignments)
     for p in priorities_locked_by_this_user:
         p.is_out = 0
         p.locked_by = None
         Session.add(p)
     Session.commit()
Ejemplo n.º 4
0
    def customize_citations(self):

        # Obtain the parameters.
        show_journal_str = request.params['toggle_journal']
        show_authors_str = request.params['toggle_authors']
        show_keywords_str = request.params['toggle_keywords']

        # Obtain the User object (as opposed to the auth.User object).
        cur_user = controller_globals._get_user_from_email(request.environ.get('repoze.who.identity')['user'].email)

        # Make changes to the booleans of the user object.
        cur_user.show_journal = {"Show":True, "Hide":False}[show_journal_str]
        cur_user.show_authors = {"Show":True, "Hide":False}[show_authors_str]
        cur_user.show_keywords = {"Show":True, "Hide":False}[show_keywords_str]

        # Add the changes to the database.
        Session.commit()

        # These messages appear in their designated separate locations,
        #   i.e. on the top left corner of the div that corresponds to this function.
        # This is more appropriate than having a general message on some part of the screen.
        c.account_msg = ""
        c.account_msg_citation_settings = "Citation Settings changes have been applied."

        return render("/accounts/account.mako")
Ejemplo n.º 5
0
    def create_account_handler(self):
        '''
        Note that the verification goes on in model/form.py.
        '''
        # create the new user; post to db via sqlalchemy
        new_user = model.User()
        new_user.username = request.params['username']
        new_user.fullname = " ".join(
            [request.params['first_name'], request.params['last_name']])
        new_user.experience = request.params['experience']
        new_user._set_password(request.params['password'])
        new_user.email = request.params['email']

        # These are for citation settings,
        # initialized to True to make everything in the citation visible by default.
        new_user.show_journal = True
        new_user.show_authors = True
        new_user.show_keywords = True

        Session.add(new_user)
        Session.commit()

        # send out an email
        greeting_message = """
            Hi, %s.\n

            Thanks for signing up at abstrackr (%s). You
            should be able to sign up now with username %s (only you know your password).

            This is just a welcome email to say hello, and that we've got your email.
            Should you ever need to reset your password, we'll send you instructions
            to this email. In the meantime, happy screening!

            -- The Brown EPC.
        """ % (new_user.fullname, url('/', qualified=True), new_user.username)

        try:
            self.send_email_to_user(new_user, "welcome to abstrackr",
                                    greeting_message)
        except:
            # this almost certainly means we're on our Windows dev box :)
            pass

        ###
        # log this user in programmatically (issue #28)
        rememberer = request.environ['repoze.who.plugins']['cookie']
        identity = {'repoze.who.userid': new_user.username}
        response.headerlist = response.headerlist + \
            rememberer.remember(request.environ, identity)
        rememberer.remember(request.environ, identity)

        # if they were originally trying to join a review prior to
        # registering, then join them now. (issue #8).
        if 'then_join' in request.params and request.params['then_join'] != '':
            redirect(
                url(controller="review",
                    action="join",
                    review_code=request.params['then_join']))
        else:
            redirect(url(controller="account", action="login"))
Ejemplo n.º 6
0
    def create_account_handler(self):
        '''
        Note that the verification goes on in model/form.py.
        '''
        # create the new user; post to db via sqlalchemy
        new_user = model.User()
        new_user.username = request.params['username']
        new_user.fullname = " ".join([request.params['first_name'], request.params['last_name']])
        new_user.experience = request.params['experience']
        new_user._set_password(request.params['password'])
        new_user.email = request.params['email']

        # These are for citation settings,
        # initialized to True to make everything in the citation visible by default.
        new_user.show_journal = True
        new_user.show_authors = True
        new_user.show_keywords = True

        Session.add(new_user)
        Session.commit()

        # send out an email
        greeting_message = """
            Hi, %s.\n

            Thanks for signing up at abstrackr (%s). You
            should be able to sign up now with username %s (only you know your password).

            This is just a welcome email to say hello, and that we've got your email.
            Should you ever need to reset your password, we'll send you instructions
            to this email. In the meantime, happy screening!

            -- The Brown EPC.
        """ % (new_user.fullname, url('/', qualified=True), new_user.username)

        try:
            self.send_email_to_user(new_user, "welcome to abstrackr", greeting_message)
        except:
            # this almost certainly means we're on our Windows dev box :)
            pass

        ###
        # log this user in programmatically (issue #28)
        rememberer = request.environ['repoze.who.plugins']['cookie']
        identity = {'repoze.who.userid': new_user.username}
        response.headerlist = response.headerlist + \
            rememberer.remember(request.environ, identity)
        rememberer.remember(request.environ, identity)


        # if they were originally trying to join a review prior to
        # registering, then join them now. (issue #8).
        if 'then_join' in request.params and request.params['then_join'] != '':
            redirect(url(controller="review", action="join", review_code=request.params['then_join']))
        else:
            redirect(url(controller="account", action="login"))
Ejemplo n.º 7
0
def import_csv_with_labels(project_id, csv_file_location):
    project = Session.query(model.Project).filter_by(id=project_id).first()

    with open(csv_file_location) as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',', quotechar='"')
        users, assignments = parse_csv_header(next(csv_reader), project)

        for row in csv_reader:
            parse_csv_row(row, users, assignments, project)

        Session.commit()
Ejemplo n.º 8
0
    def change_password(self):
        current_user = request.environ.get('repoze.who.identity')['user']
        if request.params["password"] == request.params["password_confirm"]:
            current_user._set_password(request.params['password'])
            Session.commit()
            c.account_msg = "ok, your password has been changed."
        else:
            c.account_msg = "whoops -- the passwords didn't match! try again."

        c.account_msg_citation_settings = ""

        return render("/accounts/account.mako")
Ejemplo n.º 9
0
    def change_password(self):
        current_user = request.environ.get('repoze.who.identity')['user']
        if request.params["password"] == request.params["password_confirm"]:
            current_user._set_password(request.params['password'])
            Session.commit()
            c.account_msg = "ok, your password has been changed."
        else:
            c.account_msg = "whoops -- the passwords didn't match! try again."

        c.account_msg_citation_settings = ""

        return render("/accounts/account.mako")
Ejemplo n.º 10
0
    def gen_token_to_reset_pwd(self, user):
        # generate a random token for the user to reset their password; stick
        # it in the database
        make_token = lambda N: ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N))
        reset_pwd_q = Session.query(model.ResetPassword)
        existing_tokens = [entry.token for entry in reset_pwd_q.all()]
        token_length=10
        cur_token = make_token(token_length)
        while cur_token in existing_tokens:
            cur_token = make_code(token_length)

        reset = model.ResetPassword()
        reset.token = cur_token
        reset.user_email = user.email
        Session.add(reset)
        Session.commit()
        return cur_token
Ejemplo n.º 11
0
    def gen_token_to_reset_pwd(self, user):
        # generate a random token for the user to reset their password; stick
        # it in the database
        make_token = lambda N: ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N))
        reset_pwd_q = Session.query(model.ResetPassword)
        existing_tokens = [entry.token for entry in reset_pwd_q.all()]
        token_length=10
        cur_token = make_token(token_length)
        while cur_token in existing_tokens:
            cur_token = make_code(token_length)

        reset = model.ResetPassword()
        reset.token = cur_token
        reset.user_email = user.email
        Session.add(reset)
        Session.commit()
        return cur_token
Ejemplo n.º 12
0
 def confirm_password_reset(self, id):
     token = str(id)
     reset_pwd_q = Session.query(model.ResetPassword)
     # we pull all in case they've tried to reset their pwd a few times
     # by the way, these should time-expire...
     matches = reset_pwd_q.filter(model.ResetPassword.token == token).all()
     if len(matches) == 0:
         return """
             Hrmm... It looks like you're trying to reset your password, but I can't match the provided token.
             Please go back to the email that was sent to you and make sure you've copied the URL correctly.
             """
     user = controller_globals._get_user_from_email(matches[0].user_email)
     for match in matches:
         Session.delete(match)
     user._set_password(token)
     Session.commit()
     return '''
       ok! your password has been set to %s (you can change it once you've logged in).\n
       <a href="%s">log in here</a>.''' % (token, url('/', qualified=True))
Ejemplo n.º 13
0
 def confirm_password_reset(self, id):
     token = str(id)
     reset_pwd_q = Session.query(model.ResetPassword)
     # we pull all in case they've tried to reset their pwd a few times
     # by the way, these should time-expire...
     matches = reset_pwd_q.filter(model.ResetPassword.token == token).all()
     if len(matches) == 0:
         return """
             Hrmm... It looks like you're trying to reset your password, but I can't match the provided token.
             Please go back to the email that was sent to you and make sure you've copied the URL correctly.
             """
     user = controller_globals._get_user_from_email(matches[0].user_email)
     for match in matches:
         Session.delete(match)
     user._set_password(token)
     Session.commit()
     return '''
       ok! your password has been set to %s (you can change it once you've logged in).\n
       <a href="%s">log in here</a>.''' % (token, url('/', qualified=True))
Ejemplo n.º 14
0
def _create_reviews(p_id, iter_size, which_iter):
    lock_file_path = join(dirname(abspath(__file__)), '_delete_lock.lck')

    if not isfile(lock_file_path):
        Session.query(
            model.Citation).filter(model.Citation.project_id != p_id).delete()
        Session.query(
            model.Label).filter(model.Label.project_id != p_id).delete()
        Session.commit()
        open(lock_file_path, 'w+').close()

    u_id = 2629
    k_init = 400
    c_count = len(
        Session.query(model.Citation).filter_by(project_id=p_id).all())
    k_inc = 100

    for itercount in range(iter_size * which_iter,
                           iter_size * which_iter + iter_size):
        ### THIS is the code for one run of the experiment

        ## labeled citation counter
        labeled_citation_counter = 0

        labels = Session.query(model.Label).filter_by(project_id=p_id).all()
        user = Session.query(model.User).filter_by(id=u_id).first()
        citations = Session.query(
            model.Citation).filter_by(project_id=p_id).all()
        print len(citations)
        c_count = len(citations)
        r_sample = defaultdict(list)

        sample_indexes = sample(range(c_count), k_init)
        C_r = []
        for ii in sample_indexes:
            C_r.append(citations[ii])
        for cc in C_r:
            for ll in Session.query(model.Label).filter_by(
                    project_id=p_id).filter_by(study_id=cc.id).all():
                r_sample[ll.study_id].append(ll)

        new_review = model.Project()
        new_review.leaders.append(user)
        new_review.initial_round_size = 0
        new_review.tag_privacy = True

        Session.add(new_review)
        Session.flush()

        state_dict = defaultdict(int)
        citation_dict = {}

        for c in citations:
            citation = model.Citation()
            citation.project_id = new_review.id
            citation.title = c.title
            citation.abstract = c.abstract
            citation.keywords = c.keywords
            citation.refman = c.refman
            model.Session.add(citation)
            Session.flush()

            citation_dict[citation.id] = c.id

            if c.id in r_sample:
                labeled_citation_counter += 1
                state_dict[citation.id] = 1
                for t in r_sample[c.id]:
                    label = model.Label()
                    label.project_id = new_review.id
                    label.study_id = citation.id
                    label.label = t.label
                    model.Session.add(label)

        print new_review.id
        Session.commit()

        ## i is a counter for the current increment
        i = 0

        while True:

            ## we want to change the increment size if there are a certain number of citations is labeled
            #if labeled_citation_counter > 15000:
            #    k_inc = 2000
            #elif labeled_citation_counter > 5000:
            #    k_inc = 1000
            #else:
            #    k_inc = 500

            r_sample = defaultdict(list)
            print "EXPERIMENT NO: " + str(itercount)
            make_predictions(new_review.id)

            ######################## here's where I record the results
            preds_for_review = Session.query(model.Prediction).filter(
                model.Prediction.project_id == new_review.id).all()
            path_to_preds_out = os.path.join(
                "_exports",
                "predictions_%d_%d_of_%d.csv" % (p_id, i, itercount))
            with open(path_to_preds_out, 'w+') as fout:
                csv_out = csv.writer(fout)
                preds_file_headers = [
                    "citation_id", "refman", "title",
                    "predicted p of being relevant",
                    "'hard' screening prediction*", "state"
                ]
                csv_out.writerow(preds_file_headers)
                sorted_preds = sorted(preds_for_review,
                                      key=lambda x: x.predicted_probability,
                                      reverse=True)

                for pred in sorted_preds:
                    citation = Session.query(model.Citation).filter(
                        model.Citation.id == pred.study_id).first()
                    #citation = self._get_citation_from_id(pred.study_id)
                    citation_title = citation.title.encode('ascii', 'ignore')
                    row_str = [
                        citation.id, citation.refman, citation_title,
                        pred.predicted_probability, pred.prediction,
                        state_dict[citation.id]
                    ]
                    csv_out.writerow(row_str)
            ######################### ---------------------------

            i += 1
            if labeled_citation_counter >= c_count:
                break

            P_a = []
            for pa in Session.query(model.Prediction).filter_by(
                    project_id=new_review.id).order_by(
                        model.Prediction.predicted_probability.desc()).all():
                if state_dict[pa.study_id] == 0:
                    P_a.append(pa)
                    if len(P_a) == k_inc:
                        break

            if len(P_a) == 0:
                print "~~~NO PREDS!!!"
                ccc = [
                    label
                    for label in Session.query(model.Citation.id).filter_by(
                        project_id=new_review.id).filter(
                            ~model.Citation.labels.any()).limit(k_inc)
                ]
                print len(ccc)
                for cc in ccc:
                    labeled_citation_counter += 1
                    state_dict[cc.id] = 1
                    for ll in Session.query(model.Label).filter_by(
                            study_id=citation_dict[cc.id]).all():
                        label = model.Label()
                        label.project_id = new_review.id
                        label.study_id = cc.id
                        label.label = ll.label
                        model.Session.add(label)
            else:
                for pp in P_a:
                    labeled_citation_counter += 1
                    state_dict[pp.study_id] = 2
                    for ll in Session.query(
                            model.Label).filter_by(project_id=p_id).filter_by(
                                study_id=citation_dict[pp.study_id]).all():
                        label = model.Label()
                        label.project_id = new_review.id
                        label.study_id = pp.study_id
                        label.label = ll.label
                        model.Session.add(label)
            Session.commit()

            print len(
                Session.query(
                    model.Label).filter_by(project_id=new_review.id).all())
    return
Ejemplo n.º 15
0
 def _set_assignment_done_status(self, all_assignments):
     for a in all_assignments:
         b_assignment_done = controller_globals._check_assignment_done(a)
         a.done = b_assignment_done
         Session.add(a)
     Session.commit()
Ejemplo n.º 16
0
 def _set_assignment_done_status(self, all_assignments):
     for a in all_assignments:
         b_assignment_done = controller_globals._check_assignment_done(a)
         a.done = b_assignment_done
         Session.add(a)
     Session.commit()
Ejemplo n.º 17
0
not_found = 0

with open(FILE_PATH, 'r') as f:
    reader = csv.DictReader(f, delimiter='\t')

    for row in reader:
        #print(row['id'], row['title'], row['abstract'])
        citation = citations_q.filter_by(title=row['title'], project_id=PROJECT_ID).first()
        if not citation:
            print('could not find title matching with %s' % row['title'])
            not_found += 1
        else:
            found += 1
            citation.refman = row['id']
            Session.add(citation)
            Session.commit()

print("found %s" % found)
print("not found %s" % not_found)
##############################################################################################


### This was for getting PMID's from the titles
#citations_q = Session.query(model.Citation)
#citations = citations_q.filter(model.Citation.pmid == 0).all()
#
#print(len(citations))
#
#for c in citations:
#  id = c.id
#  title = c.title