Created
September 3, 2014 06:56
-
-
Save signalpillar/b7b062354f947e11f09a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import print_function | |
| # std | |
| from collections import defaultdict | |
| import random | |
| import time | |
| # 3rd-party | |
| from blessed import Terminal | |
| TERM = Terminal() | |
| def main(): | |
| models = ['source', 'migration', 'step', 'target', 'image'] | |
| is_discarded = [True, False] | |
| statistics = dict( | |
| total=0, | |
| saved=0, | |
| discarded=0, | |
| per_model=defaultdict(lambda: dict(saved=0, discarded=0)) | |
| ) | |
| for _ in range(100): | |
| model = random.choice(models) | |
| is_saved = random.choice(is_discarded) | |
| op_state = 'saved' if is_saved else 'discarded' | |
| # update statistics | |
| statistics[op_state] += 1 | |
| statistics['per_model'][model][op_state] += 1 | |
| statistics['total'] += 1 | |
| render(statistics) | |
| time.sleep(.2) | |
| def render(statistics): | |
| with TERM.fullscreen(), TERM.hidden_cursor(), TERM.location(0, 0): | |
| for model, stat in statistics['per_model'].iteritems(): | |
| print('{model}: {saved}, {discarded}'.format( | |
| model=model, | |
| saved=stat['saved'], | |
| discarded=stat['discarded'] | |
| )) | |
| print('-' * 30) | |
| print('total saved: {}'.format(statistics['saved'])) | |
| print('total discarded: {}'.format(statistics['discarded'])) | |
| print('-' * 30) | |
| print('total: {}'.format(statistics['total'])) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment