예제 #1
0
 def test_4_timeinterval(self):
     self.assertEqual(
         time_interval('1/17/2016 03:30:15 AM', '1/17/2016 03:31:45 AM',
                       '%m/%d/%Y %I:%M:%S %p'), 1.5)
     self.assertEqual(
         time_interval('1/17/2016 03:30:15 AM', '1/17/2016 03:31:45 PM',
                       '%m/%d/%Y %I:%M:%S %p'), 721.5)
     self.assertEqual(
         time_interval('1/aa/2016 03:30:15 AM', '', '%m/%d/%Y %I:%M:%S %p'),
         0.0)
예제 #2
0
 def test_4_timeinterval(self):
     self.assertEqual(time_interval('1/17/2016 03:30:15 AM',
                                    '1/17/2016 03:31:45 AM',
                                    '%m/%d/%Y %I:%M:%S %p'), 1.5)
     self.assertEqual(time_interval('1/17/2016 03:30:15 AM',
                                    '1/17/2016 03:31:45 PM',
                                    '%m/%d/%Y %I:%M:%S %p'), 721.5)
     self.assertEqual(time_interval('1/aa/2016 03:30:15 AM',
                                    '',
                                    '%m/%d/%Y %I:%M:%S %p'), 0.0)
예제 #3
0
파일: data2es.py 프로젝트: rotblade/data2es
    def all_docs():
        with open(filename, newline='') as doc_file:
            fields = get_fieldnames(doc_file)
            dict_reader = csv.DictReader(doc_file, fieldnames=fields)
            if 'ticket' in doc_type:
                fields.append("ticket_time")

            echo('Using the following ' + str(len(fields)) + ' fields:',
                 quiet)
            for field in fields:
                echo(field, quiet)

            i = 0
            for row in dict_reader:
                # Prepare meta info for each indexed document.
                meta = {
                    'index': idx_name,
                    'type': doc_type,
                }
                if id_field_idx is not None:
                    meta['id'] = row[fields[int(id_field_idx)]]
                # Convert tim inteval to an integer in minutes.
                for k, v in row.items():
                    if isinstance(v, str) and isperiod(v):
                        row[k] = t2i(v)
                if 'ticket' in doc_type:
                    row['ticket_time'] = time_interval(row['create_time'],
                                                       row['close_time'],
                                                       '%m/%d/%Y %I:%M:%S %p')
                i += 1
                echo('Sending item %s to ES ...' % i, quiet)
                yield index_op(row, meta)
예제 #4
0
파일: video.py 프로젝트: tacaswell/mr
def which_video(directory,
                t0,
                target_start,
                target_duration=None,
                target_end=None):
    """Take a directory of videos and a desired range of time (relative to t0).
    Return a video that spans that time and when to start relative to the
    timeline of the video."""
    if target_duration:
        target_end = target_start + target_duration
    table = {}
    for filename in sorted(os.listdir(directory)):
        filepath = os.path.join(directory, filename)
        info = video_info(filepath)
        if not (info['creation'] and info['duration']):
            continue
        video_duration = time_interval(
            info['duration'])  # TO DO: Do this in video_info()
        start = info['creation'] - t0
        table[filepath] = (start, start + video_duration)
    for filepath, age_range in table.iteritems():
        start, end = age_range
        if start < target_start and end > target_start:
            # This video covers the beginning of our target range.
            if end > target_end:
                # This video also covers the end.
                vstart = target_start - start
                logging.info("Matched video file: %s", filepath)
                return filepath, vstart
    return None
예제 #5
0
파일: csv2es.py 프로젝트: rotblade/csv2es
    def all_docs():
        with open(filename, newline='') as doc_file:
            fields = get_fieldnames(doc_file)
            dict_reader = csv.DictReader(doc_file, fieldnames=fields)
            if 'ticket' in doc_type:
                fields.append("ticket_time")

            echo('Using the following ' + str(len(fields)) + ' fields:',
                 quiet)
            for field in fields:
                echo(field, quiet)

            i = 0
            for row in dict_reader:
                # Prepare meta info for each indexed document.
                meta = {
                    'index': idx_name,
                    'type': doc_type,
                }
                if id_field_idx is not None:
                    meta['id'] = row[fields[int(id_field_idx)]]
                # Convert tim inteval to an integer in minutes.
                for k, v in row.items():
                    if isinstance(v, str) and isperiod(v):
                        row[k] = t2i(v)
                if 'ticket' in doc_type:
                    row['ticket_time'] = time_interval(row['create_time'],
                                                       row['close_time'],
                                                       '%m/%d/%Y %I:%M:%S %p')
                i += 1
                echo('Sending item %s to ES ...' % i, quiet)
                yield index_op(row, meta)
예제 #6
0
파일: video.py 프로젝트: tacaswell/mr
def _maybe_cast_time(time_or_string):
    if type(time_or_string) is str:
        return time_interval(time_or_string)
    else:
        return time_or_string