def generateRecords(csv_filename, start_date, interval, end_date):
    '''
    Generator function reads csv data file and returns records
    with an updated timestamp on demand.

    Records are read from a file and stored in a local array, once
    all the records have been read the function does not loop
    round to the beginning again instead it flips and outputs
    the records in reverse order and so on.

    The csv file must contain a field with the name 'time'
    '''

    csv_data = []
    csv_file = open(csv_filename, 'rb')
    reader = csv.reader(csv_file)
    header = reader.next()

    time_field_idx = -1
    for i in range(len(header)):
        if header[i] == 'time':
            time_field_idx = i
            break

    if time_field_idx == -1:
        logging.error("Cannot find 'time' field in csv header")
        return

    reverse = False
    while start_date < end_date:
        try:
            yield header

            if len(csv_data) == 0:
                # populate csv_data record
                for row in reader:
                    row[time_field_idx] = start_date.isoformat()
                    start_date += interval

                    csv_data.append(row)
                    yield row

                    if start_date > end_date:
                        break

                csv_file.close()

            else:
                if reverse:
                    for row in reversed(csv_data):
                        row[time_field_idx] = start_date.isoformat()
                        start_date += interval
                        yield row

                        if start_date > end_date:
                            break
                else:
                    for row in csv_data:
                        row[time_field_idx] = start_date.isoformat()
                        start_date += interval
                        yield row

                        if end_date > start_date:
                            break

            reverse = not reverse

        except KeyboardInterrupt:
            raise StopIteration
dataset/ETHPy150Open prelert/engine-python/streamingApm.py/generateRecords/swapped operands of `>`