def analyze_entity(entity_id):

    if entity_is_earmark(entity_id):
        print "Entity is matched to earmark already, your data might be stale. Ignoring entity %d" % (entity_id)
        return
    if entity_is_negative_example(entity_id):
        print "Entity %d is flagged as negative example, ignoring" % (entity_id)
        return
    entity = Entity(entity_id)
    question = "Does this entity look like an earmark?\n%s\nId: %d\nPath: %s\n" % (
        entity.entity_inferred_name,
        entity_id,
        path_tools.doc_id_to_path(entity.document_id),
    )
    is_earmark = prompt.query_yes_no(question, default="yes")
    if is_earmark:
        question = "Does it match an earmark on OMB website?\n"
        is_match = prompt.query_yes_no(question, default="yes")
        if is_match:
            question = "What is the earmark id?\n"
            earmark_id = prompt.query_number(question)
            amend_earmark.match_earmark_with_entity(earmark_id, entity.id)
        else:
            question = "Are you sure you want to create new earmark?\n"
            if prompt.query_yes_no(question, default="yes"):
                # question = "Please enter a year for the earmark?\n"
                year = path_tools.get_report_year(entity.document_id)  # prompt.query_number(question)
                amend_earmark.crete_new_earmark(entity.id, year)
    else:
        # it is not an earmark, now flag it as negative
        question = "Do you want to flag it as negative match?\n"
        if prompt.query_yes_no(question, default="yes"):
            amend_earmark.insert_entity_to_negative_table(entity_id)
            print "Entity %d has been labeled as negative example" % (entity_id)
    print chr(27) + "[2J"  # this clears the terminal
    def handle(self, *args, **options):
        """
        This handler operation does the actual work!
        """
        if len(args) != 1 and len(args) != 2:
            raise CommandError("delete_course requires one or more arguments: <course_id> |commit|")

        try:
            course_key = CourseKey.from_string(args[0])
        except InvalidKeyError:
            course_key = SlashSeparatedCourseKey.from_deprecated_string(args[0])

        commit = False
        if len(args) == 2:
            commit = args[1] == 'commit'

        if commit:
            print('Actually going to delete the course references from LMS database....')
            print('Note: There is a corresponding CMS command you must run BEFORE this command.')

            if hasattr(settings, 'TEST_ROOT'):
                course_deleted.send(sender=None, course_key=course_key)
            else:

                if query_yes_no("Deleting ALL records with references to course {0}. Confirm?".format(course_key), default="no"):
                    if query_yes_no("Are you sure. This action cannot be undone!", default="no"):

                        # Broadcast the deletion event to CMS listeners
                        print 'Notifying LMS system components...'
                        course_deleted.send(sender=None, course_key=course_key)

                        print 'LMS Course Cleanup Complete!'
Exemplo n.º 3
0
    def handle(self, *args, **options):
        try:
            course_key = CourseKey.from_string(options['course_key'])
        except InvalidKeyError:
            raise CommandError("Invalid course_key: '%s'." % options['course_key'])

        if not modulestore().get_course(course_key):
            raise CommandError("Course with '%s' key not found." % options['course_key'])

        print 'Going to delete the %s course from DB....' % options['course_key']
        if query_yes_no("Deleting course {0}. Confirm?".format(course_key), default="no"):
            if query_yes_no("Are you sure. This action cannot be undone!", default="no"):
                delete_course(course_key, ModuleStoreEnum.UserID.mgmt_command, options['keep_instructors'])
                print "Deleted course {}".format(course_key)
def label_earmark(earmark, matches, conn, cmd, cur):
    
    os.system('clear')

    short_desc = normalize(earmark['short_description'])
    full_desc = normalize(earmark['full_description'])
    recipient = normalize(earmark['recipient'])

    print "Lets Label Earmark: %d" % earmark['earmark_id']
    #print "Recipient: %s" % bcolors.OKGREEN + recipient + bcolors.ENDC
    print "Short Desription: %s" % bcolors.OKGREEN + short_desc + bcolors.ENDC
    print "Full Description: %s" % bcolors.OKGREEN + full_desc + bcolors.ENDC

    consecutive_nos = 0
    labeled = False

    for i in range(len(matches)):
        score = matches[i][0]
        entity = matches[i][1]
        earmark_document_id = matches[i][2]
        entity_id = entity['id']

        query_str = bcolors.WARNING + entity['entity_inferred_name'] + bcolors.ENDC

        #Auto label the rest false
        if consecutive_nos > 10:
            cur.execute(cmd, (earmark['earmark_id'], earmark_document_id, entity_id, score, False))


        elif score >= AUTO_LABEL_POSITIVE:
            print "Auto Lableing: %s" % query_str
            cur.execute(cmd, (earmark['earmark_id'], earmark_document_id, entity_id, score, True))
            labeled = True

        elif score <= AUTO_LABEL_NEGATIVE:
            pass
            #cur.execute(cmd, (earmark['earmark_id'], earmark_document_id, entity_id, score, False))

        else:
            print path_tools.doc_id_to_path(earmark_document_id)
            if query_yes_no(query_str):
                cur.execute(cmd, (earmark['earmark_id'], earmark_document_id, entity_id, score,  True))
                consecutive_nos = 0
            else:
                cur.execute(cmd, (earmark['earmark_id'], earmark_document_id, entity_id, score, False))
                consecutive_nos += 1
            labeled = True

    if not labeled:
        print "no matches above minimum theshold!"
        cur.execute(cmd, (earmark['earmark_id'], -1, -1, 0, False))



    conn.commit()
Exemplo n.º 5
0
    def handle(self, *args, **options):
        if len(args) != 1 and len(args) != 2:
            raise CommandError("delete_course requires one or more arguments: <course_id> |commit|")

        try:
            course_key = CourseKey.from_string(args[0])
        except InvalidKeyError:
            course_key = SlashSeparatedCourseKey.from_deprecated_string(args[0])

        commit = False
        if len(args) == 2:
            commit = args[1] == 'commit'

        if commit:
            print('Actually going to delete the course from DB....')
            print('Note: There is a corresponding LMS cleanup command you should run afterwards')

            if query_yes_no("Deleting course {0}. Confirm?".format(course_key), default="no"):
                if query_yes_no("Are you sure. This action cannot be undone!", default="no"):
                    delete_course_and_groups(course_key, ModuleStoreEnum.UserID.mgmt_command)
    def handle(self, *args, **options):
        course_id = options.get('course_id')
        compute_for_all_open_courses = options.get('compute_for_all_open_courses')
        compute_for_inactive_courses = options.get('compute_for_inactive_courses')
        months_back_limit = options.get('months_back_limit')
        interactive = options.get('interactive')

        if course_id:
            task_compute_social_scores_in_course.delay(course_id)
        elif compute_for_all_open_courses or compute_for_inactive_courses:
            # prompt for user confirmation in interactive mode
            execute = query_yes_no(
                "Are you sure to compute social engagement scores for all selected courses?"
                , default="no"
            ) if interactive else True

            if execute:
                courses = CourseOverview.objects.none()
                today = datetime.datetime.today().replace(tzinfo=UTC)

                # Add active courses to queryset if compute_for_all_open_courses is True
                if compute_for_all_open_courses:
                    courses |= CourseOverview.objects.filter(
                        Q(end__gte=today) |
                        Q(end__isnull=True)
                    )
                # Add inactive courses to queryset if compute_for_inactive_courses is True
                if compute_for_inactive_courses:
                    filter_set = Q(end__lt=today)
                    # If user set months back limit, add filter to queryset
                    if months_back_limit:
                        backwards_query_limit_date = (
                            datetime.datetime.today() - relativedelta(months=months_back_limit)
                        ).replace(tzinfo=UTC)
                        filter_set &= Q(end__gte=backwards_query_limit_date)
                    # Filter courses and add them to courses list
                    courses |= CourseOverview.objects.filter(filter_set)

                for course in courses:
                    course_id = unicode(course.id)
                    task_compute_social_scores_in_course.delay(course_id)
                    log.info("Task queued to compute social engagment score for course %s", course_id)