Created
March 1, 2018 20:38
-
-
Save fuzzy/2f5596ae0976fd5d64bdb65680bab305 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python2 | |
import sys | |
class Line(object): | |
average = 0 | |
minimum = 0 | |
maximum = 0 | |
host = None | |
total = 0 | |
count = 0 | |
def __init__(self, data): | |
if type(data) not in (str, unicode): | |
raise ValueError, 'Invalid data based to Line.__init__()' | |
self.host = data.split(',')[0] | |
for bit in data.split('|')[1].split(','): | |
if not bit.isalpha(): | |
if float(bit) < self.minimum: | |
self.minimum = float(bit) | |
elif float(bit) > self.maximum: | |
self.maximum = float(bit) | |
self.total += float(bit) | |
self.count += 1 | |
self.average = (self.total / self.count) | |
def __str__(self): | |
return '%s: Average: %f Max: %f Min %f' % (self.host, | |
self.average, | |
self.maximum, | |
self.minimum) | |
def __repr__(self): | |
return self.__str__() | |
if __name__ == '__main__': | |
lines = [] | |
buff = sys.stdin.readline() | |
while buff: | |
lines.append(Lines(buff.strip())) | |
buff = sys.stdin.readline() | |
lines.sort(key = lambda x: x.average) | |
lines.reverse() | |
for i in lines: | |
print lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment