Skip to content

Commit

Permalink
Script to remove a certain number of links.
Browse files Browse the repository at this point in the history
  • Loading branch information
Profir-Petru Partachi committed Jun 11, 2019
1 parent dcd69f5 commit 242d7c9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Util/remove_links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import random
import sys
import jsonpickle

if __name__ == '__main__':
location = sys.argv[1]
keep_rate = float(sys.argv[2])

with open(location[:-5] + '_truth.json') as f:
truth = jsonpickle.decode(f.read())
with open(location) as f:
repo = jsonpickle.decode(f.read())

pr_nr = [pr.number for pr in repo.prs]
issue_ids = [i.id_ for i in repo.issues]

noisy_truth = dict()
for issue_id, pr_nrs in truth.items():
for pr_nr in pr_nrs:
roll = random.uniform(0.0, 1.0)
target = keep_rate
if roll > target:
try:
noisy_truth[issue_id].append(pr_nr)
except KeyError:
noisy_truth[issue_id] = [pr_nr]

with open(location[:-5] + '_r_%2.2f_truth.json' % keep_rate, 'w') as f:
f.write(jsonpickle.encode(noisy_truth))

0 comments on commit 242d7c9

Please sign in to comment.