Beispiel #1
0
    def next(self):
        while True:
            if (self.e1 == None) and (self.e2 == None):
                raise StopIteration()

            # No more db1 events
            if self.e1 == None:
                diff = EventDiff(both=[], db1=None, db2=[self.e2])
                self.e2 = __builtin__.next(self.events2, None)
                return diff

            # No more db2 events
            if self.e2 == None:
                diff = EventDiff(both=[], db1=[self.e1], db2=None)
                self.e1 = __builtin__.next(self.events1, None)
                return diff

            # Collect all events for the lowest of two timestamps
            if self.e2.timestamp >= self.e1.timestamp:
                timestamp = self.e1.timestamp
            else:
                timestamp = self.e2.timestamp

            el1 = []
            el2 = []
            while (self.e1 <> None) and (self.e1.timestamp == timestamp):
                el1.append(self.e1)
                self.e1 = __builtin__.next(self.events1, None)
            while (self.e2 <> None) and (self.e2.timestamp == timestamp):
                el2.append(self.e2)
                self.e2 = __builtin__.next(self.events2, None)

            diff = compare_event_lists(self.db1, self.db2, el1, el2)
            diff.timestamp = timestamp
            return diff
Beispiel #2
0
 def __init__(self, db1, db2, events1, events2):
     self.db1 = db1
     self.db2 = db2
     self.events1 = iter(events1)
     self.events2 = iter(events2)
     self.e1 = __builtin__.next(self.events1, None)
     self.e2 = __builtin__.next(self.events2, None)
 def parse_csv_file(self):
     
     with open(self.file_path, "rb", 1) as csv_file:
         dialect = csv.Sniffer().sniff(csv_file.read(1024))
         has_header = csv.Sniffer().has_header(csv_file.read(1024))
         csv_file.seek(0)
         
         if not has_header:
             raise Exception('Not a correct CSV file')
         
         csv_data = csv.reader(csv_file, dialect)
         
         company_names = next(csv_data)[2:] # Extract the Companies name
         
         for name in company_names:
             self.output[name] = {'price': 0, 'year': 'year', 'month': 'month'}
         for row in csv_data:
             year, month = row[:2]
             for name, price in zip(company_names, map(int, row[2:])):
                 if self.output[name]['price'] < price:
                     self.output[name] = {'price':price, 'year': year, 'month': month}
         
         self.result = '\nCompany name\tYear\tMonth\tMax Price\n\n'
         for company_name , analysis_dict in self.output.items():
             self.result += '%s\t%s\t%s\t%d\n' % (company_name, analysis_dict['year'], analysis_dict['month'], analysis_dict['price'])
Beispiel #4
0
    def parse_csv_file(self):

        with open(self.file_path, "rb", 1) as csv_file:
            dialect = csv.Sniffer().sniff(csv_file.read(1024))
            has_header = csv.Sniffer().has_header(csv_file.read(1024))
            csv_file.seek(0)

            if not has_header:
                raise Exception('Not a correct CSV file')

            csv_data = csv.reader(csv_file, dialect)

            company_names = next(csv_data)[2:]  # Extract the Companies name

            for name in company_names:
                self.output[name] = {
                    'price': 0,
                    'year': 'year',
                    'month': 'month'
                }
            for row in csv_data:
                year, month = row[:2]
                for name, price in zip(company_names, map(int, row[2:])):
                    if self.output[name]['price'] < price:
                        self.output[name] = {
                            'price': price,
                            'year': year,
                            'month': month
                        }

            self.result = '\nCompany name\tYear\tMonth\tMax Price\n\n'
            for company_name, analysis_dict in self.output.items():
                self.result += '%s\t%s\t%s\t%d\n' % (
                    company_name, analysis_dict['year'],
                    analysis_dict['month'], analysis_dict['price'])
Beispiel #5
0
def first(iterable):
    try:
        return builtins.next(iter(iterable))
    except StopIteration:
        return None
Beispiel #6
0
 def next(self):
     return __builtin__.next(self.iter)