| 146 | for key,value in sample['header'].items(): |
---|
| 147 | try: |
---|
| 148 | if value == INVALID: |
---|
| 149 | raise ValueError |
---|
| 150 | sample['header'][key] = int(value) |
---|
| 151 | except (ValueError, TypeError, KeyError): |
---|
| 152 | sample['header'][key] = n.NaN |
---|
| 153 | |
---|
| 154 | def _stamp(self): |
---|
| 155 | """Add a datetime stamp to each sample.""" |
---|
| 156 | for sample in self.samples: |
---|
| 157 | try: |
---|
| 158 | header = sample['header'] |
---|
| 159 | sample['stamp'] = datetime.datetime(header['YEAR'], |
---|
| 160 | header['MONTH'], |
---|
| 161 | header['DAY'], |
---|
| 162 | header['HOUR'], |
---|
| 163 | header['MIN']) |
---|
| 164 | except (KeyError, TypeError): |
---|
| 165 | sample['stamp'] = datatime.datetime.min |
---|
| 166 | |
---|
| 167 | def _timeInterval(self): |
---|
| 168 | """Add a time interval attribute""" |
---|
| 169 | intervals = zip([sample['stamp'] for sample in self.samples[:-1]], |
---|
| 170 | [sample['stamp'] for sample in self.samples[1:]]) |
---|
| 171 | intervals = [interval[1] - interval[0] for interval in intervals] |
---|
| 172 | accumulator = {} |
---|
| 173 | for interval in intervals: |
---|
| 174 | if interval in accumulator: |
---|
| 175 | accumulator[interval] += 1 |
---|
| 176 | else: |
---|
| 177 | accumulator[interval] = 1 |
---|
| 178 | maxVotes = max(accumulator.values()) |
---|
| 179 | for key,value in accumulator.items(): |
---|
| 180 | if value == maxVotes: |
---|
| 181 | self.timeInterval = key |
---|
| 182 | break |
---|
| 183 | self.timeInterval = getattr(self, |
---|
| 184 | 'timeInterval', |
---|
| 185 | datetime.timedelta.resolution) |
---|