Exemplo n.º 1
0
    def parse(self):
        bugsfn = os.path.join(self.folder, self.BUGS_FILE)
        commentsfn = os.path.join(self.folder, self.COMMENTS_FILE)

        if self.label == Label.ASSIGNEE:
            label_field = "assigned_to"
        elif self.label == Label.COMPONENT:
            label_field = "component"

        with open(bugsfn, "r") as bugsf:
            bugs_raw = bugsf.read()
        with open(commentsfn, "r") as commentsf:
            comments_raw = commentsf.read()

        bugs = json.loads(bugs_raw)["bugs"]
        comments = json.loads(comments_raw)

        documents = []
        for bug in bugs:
            title = bug["summary"]
            description = comments[str(bug["id"])]["comments"]["text"]
            label = bug[label_field]
            document = Document(title, description, label)
            document._created = comments[str(bug["id"])]["comments"]["time"]
            documents.append(document)

        return documents
Exemplo n.º 2
0
    def parse(self):
        bugsfn = os.path.join(self.folder, self.BUGS_FILE)
        commentsfn = os.path.join(self.folder, self.COMMENTS_FILE)

        if self.label == Label.ASSIGNEE:
            label_field = "assigned_to"
        elif self.label == Label.COMPONENT:
            label_field = "component"

        with open(bugsfn, "r") as bugsf:
            bugs_raw = bugsf.read()
        with open(commentsfn, "r") as commentsf:
            comments_raw = commentsf.read()

        bugs = json.loads(bugs_raw)["bugs"]
        comments = json.loads(comments_raw)

        documents = []
        for bug in bugs:
            title = bug["summary"]
            description = comments[str(bug["id"])]["comments"]["text"]
            label = bug[label_field]
            document = Document(title, description, label)
            document._created = comments[str(bug["id"])]["comments"]["time"]
            documents.append(document)

        return documents
Exemplo n.º 3
0
def post_feedback(id):
    project = Project.query.get_or_404(id)

    form = FeedbackForm()
    if form.validate():
        issue = Document(form.summary.data, form.description.data)
        feedback = Feedback()
        feedback.project = project
        feedback.id = Feedback.get_id_from_doc(issue, project=project)
        existing_feedback = Feedback.query.get(feedback.id)
        if existing_feedback:
            feedback = existing_feedback

        if form.selected_recommendation.data:
            feedback.selected_recommendation = \
                form.selected_recommendation.data
        if form.confirmed_recommendation.data:
            feedback.confirmed_recommendation = \
                form.confirmed_recommendation.data
        db.session.add(feedback)
        db.session.commit()

        return jsonify(result="success")

    return jsonify(result="error", errors=form.errors), 400
Exemplo n.º 4
0
    def parse(self):
        issues = []
        for fn in os.listdir(self.folder):
            filepath = os.path.join(self.folder, fn)
            if os.path.isfile(filepath) and self.project_key in fn:
                with open(filepath) as f:
                    issues += simplejson.load(f)['issues']

        documents = []
        for issue in issues:
            doc = Document(issue['fields']['summary'],
                           issue['fields']['description'],
                           issue['fields']['assignee']['name'])
            doc._created = issue['fields']['created']
            if doc.content or len(doc.title.split()) > 1:
                documents.append(doc)

        return documents
Exemplo n.º 5
0
    def parse(self):
        issues = []
        for fn in os.listdir(self.folder):
            filepath = os.path.join(self.folder, fn)
            if os.path.isfile(filepath) and self.project_key in fn:
                with open(filepath) as f:
                    issues += simplejson.load(f)['issues']

        documents = []
        for issue in issues:
            doc = Document(issue['fields']['summary'],
                           issue['fields']['description'],
                           issue['fields']['assignee']['name'])
            doc._created = issue['fields']['created']
            if doc.content or len(doc.title.split()) > 1:
                documents.append(doc)

        return documents
Exemplo n.º 6
0
    def parse(self):
        """Parses data from given folder into list of documents.

        :returns: List of Document objects
        """

        files = os.listdir(self.folder)
        documents = []

        for f in files:
            if f not in ['.DS_Store']:  # excluded files
                full_f = os.path.join(self.folder, f)
                ticket_info = self._parse_file(full_f)
                if ticket_info and re.match(
                        self.project_match, ticket_info[3]):
                    if ticket_info[2] == "Unassigned":
                        ticket_info[2] = None
                    document = Document(
                        ticket_info[0], ticket_info[1], ticket_info[2])
                    document._created = ticket_info[4]
                    documents.append(document)

        return documents
Exemplo n.º 7
0
    def parse(self):
        """Parses data from given folder into list of documents.

        :returns: List of Document objects
        """

        files = os.listdir(self.folder)
        documents = []

        for f in files:
            if f not in ['.DS_Store']:  # excluded files
                full_f = os.path.join(self.folder, f)
                ticket_info = self._parse_file(full_f)
                if ticket_info and re.match(self.project_match,
                                            ticket_info[3]):
                    if ticket_info[2] == "Unassigned":
                        ticket_info[2] = None
                    document = Document(ticket_info[0], ticket_info[1],
                                        ticket_info[2])
                    document._created = ticket_info[4]
                    documents.append(document)

        return documents
Exemplo n.º 8
0
    def parse(self):
        csv_filepath = os.path.join(self.folder, self.BUGS_FILE)
        bugs = []
        with open(csv_filepath, 'rb') as csvf:
            reader = csv.reader(csvf, delimiter=',')
            for line in reader:
                bugs.append(line)
        bugs = np.array(bugs)
        documents = []

        for bug in bugs:
            document = Document(bug[7], str(bug[9]), bug[4])
            documents.append(document)

        return documents
Exemplo n.º 9
0
def view_project(id):
    project = Project.query.get_or_404(id)

    form = IssueForm()
    feedback_form = FeedbackForm()
    predictions = []
    model_path = os.path.join(app.config['MODEL_FOLDER'], '%s/svm.pkl' % id)
    trained = project.train_status != TS.NOT_TRAINED \
        and os.path.isfile(model_path)
    summary_or_description = form.summary.data or form.description.data

    if trained and form.validate_on_submit() and summary_or_description:
        issue = Document(form.summary.data, form.description.data)
        model = joblib.load(model_path)
        try:
            predictions = model.predict(issue, n=10)
        except ValueError:
            flash(
                "There is too little information provided. "
                "You need to add more text to the description or summary.",
                "error")

        feedback_form.summary.data = form.summary.data
        feedback_form.description.data = form.description.data
        existing_feedback = Feedback.query.get(
            Feedback.get_id_from_doc(issue, project=project))
        if existing_feedback:
            feedback_form.confirmed_recommendation.data = \
                existing_feedback.confirmed_recommendation

    if request.method == "POST" and not summary_or_description:
        err_msg = "Summary or description must not be empty."
        form.summary.errors.append(err_msg)
        form.description.errors.append(err_msg)

    fscore = tests.fscore(project.precision, project.recall)
    return render_template("project/view.html",
                           project=project,
                           fscore=fscore,
                           form=form,
                           predictions=predictions,
                           trained=trained,
                           feedback_form=feedback_form)
Exemplo n.º 10
0
    def get_data(self):
        jira = Jira(self.jira_api_url)
        jql = "project=%s and status in (%s) " + \
              "and assignee!=null"
        jql = jql % (self.jira_project_key, self.jira_statuses)
        if self.jira_resolutions:
            jql += " resolutions in (%s)" % self.jira_resolutions
        fields = 'summary,description,assignee,created'
        raw_issues = jira.find_all(jql,
                                   fields,
                                   limit=int(config.general__ticket_limit))

        data = []
        for issue in raw_issues:
            fields = issue['fields']
            document = Document(fields['summary'], fields['description'],
                                fields['assignee']['name'])
            data.append(document)

        return data