-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/python | ||
import sys | ||
import operator | ||
|
||
# The histogram file path should be given in argument | ||
# The file should have two columns, key and value | ||
# Each line in the histogram file should contain the key | ||
# then a space and then the value | ||
# The following code would sum the values against the same | ||
# key and print the result in descending order | ||
|
||
f = open(sys.argv[1]) # Open the histogram file | ||
|
||
# Create histogram map | ||
hist = {} | ||
for line in f: | ||
line = line.strip() | ||
if line == "": | ||
continue | ||
fields = line.split() | ||
mtype = fields[0].strip() | ||
mval = fields[1].strip() | ||
|
||
if mtype in hist: | ||
hist[mtype] = hist[mtype] + int(mval) | ||
else: | ||
# print ">>>" + mval | ||
hist[mtype] = int(mval) | ||
|
||
# Sort in descending order | ||
sorted_hist = reversed(sorted(hist.items(), key=operator.itemgetter(1))) | ||
|
||
for i in sorted_hist: | ||
print i[1], "\t", i[0] | ||
|