Commit ec6fb55e by Ethan Mertz

fixed top variables?

parent 6bfedaf8
Showing with 8 additions and 5 deletions
......@@ -6,6 +6,8 @@ import math
CAPACITY = 500
VARIABLE_REGEX = ("[\s]*([\w, ]+)[\s]*=")
class TopVariables(MRJob):
def mapper(self, _, line):
......@@ -43,15 +45,15 @@ class TopVariables(MRJob):
yield variable, (1, simscore)
yield comp, (1, simscore)
#Track the total by yielding with None.
yield None, (len(f1vars) + len(f2vars))
yield None, len(f1vars) + len(f2vars)
else:
#When the subset is odd, only yield once.
yield None, len(f1vars)
def combiner(self, name, scores):
if not name:
total = sum(scores)
if type(name) != str:
total = sum(list(scores))
yield None, total
else:
count = 0
......@@ -69,7 +71,7 @@ class TopVariables(MRJob):
heapq.heapify(self.h)
def reducer(self, name, scores):
if not name:
if type(name) != str:
self.total = sum(scores)
else:
count = 0
......@@ -89,7 +91,7 @@ class TopVariables(MRJob):
for i in range(len(self.h)):
item = heapq.heappop(self.h)
#Yield the mean scores.
yield item[1], -item[0] / (self.total - 1)
yield item[1], -item[0] / self.total
if __name__ == '__main__':
TopVariables.run()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment