-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalmu.py
131 lines (90 loc) · 3 KB
/
palmu.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import numpy as np
import pandas as pandas
import faiss
import pickle
import argparse
import os
import json
from flask import Flask
from flask import request
from flask import jsonify
import requests
from dataManager import DataManager
FAST_TEXT_MODEL = "./data/wordEmbedding/qtmodel_100.bin"
LGB_PATH = "./data/lgb_results"
JSONS_PATH = "./data"
class Palmu():
def __init__( self , refresh = False ):
self.dm = DataManager( jsons_path = JSONS_PATH , model_fasttext = FAST_TEXT_MODEL , lgb_path = LGB_PATH , lgb_name = "Concat" , refresh = refresh )
self.counter_new_reqs = 0
def create_app(self):
app = Flask( __name__ )
@app.route("/getRelated", methods=['GET'])
def main():
if not self.dm.ready:
return json.dumps( { "dependencies" : ["no data"] })
query_id = request.args.get('id')
k = request.args.get("k")
# Multiplies used to enhance the orphan score
multiplier = 1
try:
multiplier = int( request.args.get("m") )
except:
multiplier = 1
if k == None:
k = 5
else:
k = int( k )
if query_id is None:
return json.dumps( { "dependencies" : [""] } )
#Query issues from given id
similar_issues = self.dm.find_by_id( query_id , k = k , multiplier = multiplier )
results = dict()
results["dependencies"] = similar_issues
return json.dumps( results )
@app.route("/newIssue" , methods = ["POST"])
def new_issue():
# read request, the requirement
req = request.get_json()
k = None
try:
k = int( req["k"] )
except:
k = 5
similar_issues = self.dm.find_by_new( req , k )
if similar_issues == []:
return jsonify( { "dependencies" : [""]})
else:
return jsonify( {"dependencies": similar_issues })
@app.route("/postProject", methods=['POST'])
def post_project():
#get data from request
data = request.get_json()
if data is None:
return jsonify( {"status" : "ok"} )
project_name = data["projects"][0]["id"]
#
filename = project_name + '.json'
self.dm.delete_files()
path = os.path.join( JSONS_PATH , filename)
with open(path, 'w' , encoding = "utf-8") as json_file:
json.dump(data, json_file)
json_file.close()
# This will re launch the server and reload all available projects
data = { "status" : "ok"}
return jsonify( data )
@app.route("/updateRequirements", methods=['POST'])
def update_reqs():
data = request.get_json()
reqs = data["requirements"]
data = request.get_json()
with open( JSONS_PATH + "/new_reqs_{}.json".format(self.counter_new_reqs) , "a" , encoding = "utf-8" ) as f:
f.write( json.dumps(data) )
reqs = data["requirements"]
# Requirements will be added, updated as needed but one important thing is that it will not return
# any response until the whole thing is done. so it will only make sense if the number of requeriments to be updated is small
self.dm.add_or_update_reqs( reqs )
self.counter_new_reqs = self.counter_new_reqs + 1
resp = { "status" : "ok" }
return jsonify( resp )
return app