123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- class History(object):
- """docstring for History."""
- def __init__(self):
- self.dates = []
- self.datescount = []
- def __str__(self, sep='; '):
- return sep.join("{0}={1}".format(self.dates[i], self.datescount[i]) for i in range(len(self.dates)))
- # get the index of a specified date
- def getdateindex(self, moddate):
- for i, dat in enumerate(reversed(self.dates) if self.shouldbereversed(moddate) else self.dates):
- if dat == moddate:
- return i
- return -1
- # compares proximity of date to start and end of data structure
- def shouldbereversed(self, moddate):
- if self.dates == []:
- return False
- if abs(self.dates[0] - moddate) < abs(self.dates[-1] - moddate):
- return True
- return False
- def add(self, moddate):
- self.dates.append(moddate)
- self.datescount.append(1)
- def record(self, moddate):
- i = self.getdateindex(moddate)
- if i < 0:
- self.add(moddate)
- else:
- self.datescount[i] += 1
- # def qsort(self):
- def highestdate(self):
- current = 0
- for dat in self.dates:
- if dat > current:
- current = dat
- print("highest date: {0}".format(current))
- return current
- def highestcount(self):
- current = 0
- for count in self.datescount:
- if count > current:
- current = count
- print("highest count: {0}".format(current))
- return current
- def lowestdate(self):
- if len(self.dates) > 0:
- current = self.dates[0]
- else:
- return -1
- for dat in self.dates:
- if dat < current:
- current = dat
- print("lowest date: {0}".format(current))
- return current
- def lowestcount(self):
- if len(self.datescount) > 0:
- current = self.datescount[0]
- else:
- return -1
- for count in self.datescount:
- if count < current:
- current = count
- print("lowest count: {0}".format(current))
- return current
|