This repository has been archived by the owner on Dec 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathsql_models.py
50 lines (44 loc) · 2.04 KB
/
sql_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Issues(db.Model):
__tablename__ = "issues"
issue_id = db.Column(db.Integer, primary_key=True)
repo = db.Column(db.String, nullable=False)
username = db.Column(db.String, nullable=False)
issue_num = db.Column(db.Integer, nullable=False)
title = db.Column(db.String, nullable=False)
body = db.Column(db.String, nullable=True)
# the below statement allows you to call `Predictions.issue` to refer back to the issue
predictions = db.relationship('Predictions', backref='issue', lazy=True)
def add_prediction(self, comment_id, prediction, probability, logs, threshold, labeled, prediction_type='issue label'):
p = Predictions(issue_id = self.issue_id,
comment_id=comment_id,
prediction=prediction,
probability=probability,
likes=None,
dislikes=None,
prediction_type=prediction_type,
logs=logs,
threshold=threshold,
labeled=labeled)
db.session.add(p)
db.session.commit()
class Predictions(db.Model):
__tablename__ = "predictions"
prediction_id = db.Column(db.Integer, primary_key=True)
issue_id = db.Column(db.Integer, db.ForeignKey("issues.issue_id"), nullable=False)
comment_id = db.Column(db.BigInteger, nullable=False)
prediction = db.Column(db.String, nullable=False)
probability = db.Column(db.Float, nullable=False)
likes = db.Column(db.Integer, nullable=True)
dislikes = db.Column(db.Integer, nullable=True)
prediction_type = db.Column(db.String, nullable=False)
logs = db.Column(db.String, nullable=True)
threshold = db.Column(db.Float, nullable=False)
labeled = db.Column(db.Boolean, nullable=False)
def update_feedback(self, likes, dislikes):
p = Predictions.get(self.prediction_id)
p.likes = likes
p.dislikes = dislikes