| 6556 | |
| 6557 | @classmethod |
| 6558 | def stats(cls, start_year=1): |
| 6559 | count = gap_count = fold_count = zeros_count = 0 |
| 6560 | min_gap = min_fold = timedelta.max |
| 6561 | max_gap = max_fold = ZERO |
| 6562 | min_gap_datetime = max_gap_datetime = datetime.min |
| 6563 | min_gap_zone = max_gap_zone = None |
| 6564 | min_fold_datetime = max_fold_datetime = datetime.min |
| 6565 | min_fold_zone = max_fold_zone = None |
| 6566 | stats_since = datetime(start_year, 1, 1) # Starting from 1970 eliminates a lot of noise |
| 6567 | for zonename in cls.zonenames(): |
| 6568 | count += 1 |
| 6569 | tz = cls.fromname(zonename) |
| 6570 | for dt, shift in tz.transitions(): |
| 6571 | if dt < stats_since: |
| 6572 | continue |
| 6573 | if shift > ZERO: |
| 6574 | gap_count += 1 |
| 6575 | if (shift, dt) > (max_gap, max_gap_datetime): |
| 6576 | max_gap = shift |
| 6577 | max_gap_zone = zonename |
| 6578 | max_gap_datetime = dt |
| 6579 | if (shift, datetime.max - dt) < (min_gap, datetime.max - min_gap_datetime): |
| 6580 | min_gap = shift |
| 6581 | min_gap_zone = zonename |
| 6582 | min_gap_datetime = dt |
| 6583 | elif shift < ZERO: |
| 6584 | fold_count += 1 |
| 6585 | shift = -shift |
| 6586 | if (shift, dt) > (max_fold, max_fold_datetime): |
| 6587 | max_fold = shift |
| 6588 | max_fold_zone = zonename |
| 6589 | max_fold_datetime = dt |
| 6590 | if (shift, datetime.max - dt) < (min_fold, datetime.max - min_fold_datetime): |
| 6591 | min_fold = shift |
| 6592 | min_fold_zone = zonename |
| 6593 | min_fold_datetime = dt |
| 6594 | else: |
| 6595 | zeros_count += 1 |
| 6596 | trans_counts = (gap_count, fold_count, zeros_count) |
| 6597 | print("Number of zones: %5d" % count) |
| 6598 | print("Number of transitions: %5d = %d (gaps) + %d (folds) + %d (zeros)" % |
| 6599 | ((sum(trans_counts),) + trans_counts)) |
| 6600 | print("Min gap: %16s at %s in %s" % (min_gap, min_gap_datetime, min_gap_zone)) |
| 6601 | print("Max gap: %16s at %s in %s" % (max_gap, max_gap_datetime, max_gap_zone)) |
| 6602 | print("Min fold: %16s at %s in %s" % (min_fold, min_fold_datetime, min_fold_zone)) |
| 6603 | print("Max fold: %16s at %s in %s" % (max_fold, max_fold_datetime, max_fold_zone)) |
| 6604 | |
| 6605 | |
| 6606 | def transitions(self): |