From 626307f135fe3f399a96c2918a39a1d0b6d5816c Mon Sep 17 00:00:00 2001 From: siulkilulki Date: Fri, 25 May 2018 15:09:23 +0200 Subject: [PATCH] Fix get next utterance (by score). Switch to argparse in annotation_stats.py --- annotation_stats.py | 41 +++++++++++++++++++++++++++++++++-------- webapp/app.py | 6 +++--- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/annotation_stats.py b/annotation_stats.py index 859f60f..f678f22 100755 --- a/annotation_stats.py +++ b/annotation_stats.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import sys +import argparse import redis from extractor.find_hours import color_hour import pickle @@ -77,18 +78,42 @@ def print_stats(): print('Annotated utterances: {}'.format(len(annotated))) +def get_args(): + parser = argparse.ArgumentParser() + subparser = parser.add_subparsers(dest='cmd') + parser_stats = subparser.add_parser('stats', help='Show annotation stats.') + parser_investigate = subparser.add_parser( + 'investigate', help='investigate cookie.') + parser_investigate.add_argument('cookie', help='User cookie string') + parser_index = subparser.add_parser('index', help='Print utterance.') + parser_index.add_argument('index', type=int, help='Utterance index') + subparser.add_parser('ipdb', help='Get into ipdb.') + parser_exec = subparser.add_parser('exec', help='Execute redis command.') + parser_exec.add_argument( + 'redis_command', + help= + 'Redis command (lowercased). e.g. to get r.zrangebyscore("key", "-inf", "inf", start=0, num=1) pass \'zrangebyscore("key", "-inf", "inf", start=0, num=1)\'' + ) + + return parser.parse_args() + + def main(): - if sys.argv[1] == 'stats': + args = get_args() + if args.cmd == 'stats': print_stats() - elif sys.argv[1] == 'investigate': - investigate_by_cookie(sys.argv[2]) - elif sys.argv[1] == 'index': - pprint_utterance(int(sys.argv[2])) - elif sys.argv[1] == 'console': + elif args.cmd == 'investigate': + investigate_by_cookie(args.cookie) + elif args.cmd == 'index': + pprint_utterance(args.index) + elif args.cmd == 'ipdb': import ipdb ipdb.set_trace() - elif sys.argv[1] == 'exec': - exec('print(r.{})'.format(sys.argv[2]), {'print': print, 'r': r}) + elif args.cmd == 'exec': + exec('print(r.{})'.format(args.redis_command), { + 'print': print, + 'r': r + }) if __name__ == '__main__': diff --git a/webapp/app.py b/webapp/app.py index 78ed9d6..252b40f 100644 --- a/webapp/app.py +++ b/webapp/app.py @@ -65,13 +65,13 @@ def get_next(cookie_hash): """returns utterance with minmum annotations if that utterance wasn't annotated by cookie_hash user or not yet annotated utterance by cookie_hash user""" - index = int(r.zrangebyscore(UTT_SCORES, '-inf', 'inf')[1]) + index = int(r.zrangebyscore(UTT_SCORES, '-inf', 'inf', start=0, num=1)[0]) if r.exists(f'{cookie_hash}:{index}'): index = find_not_annotated(cookie_hash) log('found unannotated index: {}'.format(index)) left_context, hour, right_context = get_utterance_for_web(index) - # log('get_next index: {}, score: {}'.format(index, - # r.zscore(UTT_SCORES, index))) + log('get_next index: {}, score: {}'.format(index, + r.zscore(UTT_SCORES, index))) return index, left_context, hour, right_context