Skip to content

Commit

Permalink
Adding methods in preparation to expose new function in chrome plugin
Browse files Browse the repository at this point in the history
* Ability to trigger a model update (forget old and retrain clf)
* Ability to record selected links from the plugin page in the model
  • Loading branch information
Profir-Petru Partachi committed Apr 5, 2018
1 parent 59dd2c6 commit 29766dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Prediction/Linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ def predict(self, prediction_object):
)
return prediction_object.id_, predictions

def most_recent_sha(self):
return sorted(self.repository_obj.commits, key=lambda c: c.timestamp)[-1].c_hash

def update_and_predict(self, event):
if isinstance(event[1], Commit):
if event[0] not in self.repository_obj.commits:
Expand Down Expand Up @@ -304,9 +307,10 @@ def update_from_github(self, since):
links = list()
# TODO: Record links as we add new entities
for pr_ref in repo.get_pulls(state='all'):
if pr_ref.number in pr_numbers:
break
pr = parse_pr_ref(pr_ref, self.repository_obj.name)
if pr_ref.number in pr_numbers:
old_pr = [pr for pr in self.repository_obj.prs if pr.number == pr_ref.number][0]
self.repository_obj.prs.remove(old_pr)
self.repository_obj.prs.append(pr)
for issue_ref in repo.get_issues(state='all', since=since):
issue = parse_issue_ref(issue_ref)
Expand Down
13 changes: 11 additions & 2 deletions backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ class RequestHandler(SimpleXMLRPCRequestHandler):
locations[os.path.basename(location)] = location
git_locations[os.path.basename(location)] = config['git_locations'][config['locations'].index(location)]
last_update[os.path.basename(location)] = datetime.now
# TODO: Extract most recent sha from git
most_recent_sha[os.path.basename(location)] = None
max_age_to_keep = config['max_age_to_keep']

for model in models:
linkers[model] = Linker.load_from_disk(locations[model])
most_recent_sha[model] = linkers[model].most_recent_sha()

server.register_introspection_functions()

Expand Down Expand Up @@ -76,6 +75,16 @@ def predict_pr(self, project, pr_id):
except KeyError:
return None

def trigger_model_updates(self):
for model in models:
linkers[model].update_from_github(last_update[model])
last_update[model] = datetime.now
linkers[model].update_from_local_git(git_locations[model], most_recent_sha[model])
linkers[model].forget_older_than(max_age_to_keep)

def record_link(self, project, issue_id, pr_id):
linkers[project].update_truth((issue_id, pr_id))


server.register_instance(PredictionFunctions())
print('Loading done, entering serve loop')
Expand Down

0 comments on commit 29766dd

Please sign in to comment.