-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc3lingo.py
executable file
·151 lines (119 loc) · 5.8 KB
/
c3lingo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python
import argparse
from datetime import timedelta
from extract import extract_talks
from prepare_toot import format_toot
from tallyUpHours import tally_up
def timesheet(args):
all_talks = [t for f in args.infile
for t in extract_talks(f, f.name)]
scoreboard = tally_up(all_talks)
nicks = list(scoreboard.keys())
nicks.sort()
for nick in nicks:
print('{},{}'.format(nick, scoreboard[nick][0]))
if args.verbose:
for talk in scoreboard[nick][1]:
print('\t* {}: {}'.format(talk.title, talk.duration))
def leaderboard(args):
all_talks = [t for f in args.infile
for t in extract_talks(f, f.name)]
scoreboard = tally_up(all_talks)
hours = {}
talks_count = {}
for nick in scoreboard:
nick_hours = scoreboard[nick][0]
if nick_hours in hours:
hours[nick_hours].append(nick)
else:
hours[nick_hours] = [nick]
nick_talks = len(scoreboard[nick][1])
if nick_talks in talks_count:
talks_count[nick_talks].append(nick)
else:
talks_count[nick_talks] = [nick]
print("Most active by time")
sorted_hours = list(hours.keys())
sorted_hours.sort()
sorted_hours.reverse()
for h in sorted_hours:
hours[h].sort()
for nick in hours[h]:
print('{},{}'.format(nick, h))
if args.verbose:
for talk in scoreboard[nick][1]:
print('\t* {}: {}'.format(talk.title, talk.duration))
print('-'*40)
print("Most active by number of talks")
sorted_talks_count = list(talks_count.keys())
sorted_talks_count.sort()
sorted_talks_count.reverse()
for c in sorted_talks_count:
talks_count[c].sort()
for nick in talks_count[c]:
print('{},{}'.format(nick, c))
def print_toots(args):
for talk in [t for f in args.infile
for t in extract_talks(f, f.name)]:
for lang in talk.translations:
print(format_toot(talk, lang))
def stats(args):
all_talks = [t for f in args.infile
for t in extract_talks(f, f.name)]
interpreted_talks = [t for t in all_talks if t.translations]
print("All translatable talks", len(all_talks))
print("Talks interpreted: ", len(interpreted_talks))
print("Percentage: ", (float(len(interpreted_talks))/len(all_talks))*100)
print("Total hours: ", sum((talk.duration for talk in interpreted_talks), timedelta()))
all_translators = set(translator for talk in all_talks
for translator in talk.translators)
if args.verbose:
for t in all_translators:
print('\t* ', t)
print("Size of team: ", len(all_translators))
def untranslated(args):
untranslated = [t for f in args.infile
for t in extract_talks(f, f.name)
if not t.translations]
for talk in untranslated:
print("* [{talk.title}]({talk.fahrplan_url})".format(talk=talk))
def validate(args):
[t for f in args.infile
for t in extract_talks(f, f.name)]
if __name__ == '__main__':
# Create the top level parser
parser = argparse.ArgumentParser(description="C3lingo utility script")
subparsers = parser.add_subparsers()
# Create the subparser for the stats
parser_timesheet = subparsers.add_parser('timesheet', description="Create a timesheet for a day")
parser_timesheet.add_argument("infile", type=argparse.FileType(), nargs='+', help="The files containing the shift assignments (multiple files possible)")
parser_timesheet.add_argument("-v", "--verbose", action="store_true", help="Print the talks and duration for checking")
parser_timesheet.set_defaults(func=timesheet)
# Create the subparser for the leaderboard
parser_leaderboard = subparsers.add_parser('leaderboard', description="Show who translated most")
parser_leaderboard.add_argument("infile", type=argparse.FileType(), nargs='+', help="The files containing the shift assignments (multiple files possible)")
parser_leaderboard.add_argument("-v", "--verbose", action="store_true", help="Print the talks and duration for checking")
parser_leaderboard.set_defaults(func=leaderboard)
# Create the parser for the toots
parser_toot = subparsers.add_parser('toot', description='Print the announcements to toot')
parser_toot.add_argument("infile", type=argparse.FileType(), nargs='+', help="The files containing the shift assignments (multiple files possible)")
parser_toot.set_defaults(func=print_toots)
# Create the parser for the stats
parser_stats = subparsers.add_parser('stats', description="Show statistics about translations")
parser_stats.add_argument("infile", type=argparse.FileType(), nargs='+', help="The files containing the shift assignments (multiple files possible)")
parser_stats.add_argument("-v", "--verbose", action="store_true", help="Print the details")
parser_stats.set_defaults(func=stats)
# Create the parse for the untranslated talks
parser_untranslated = subparsers.add_parser('untranslated', description="List the untranslated talks")
parser_untranslated.add_argument("infile", type=argparse.FileType(), nargs='+', help="The files containing the shift assignments (multiple files possible)")
parser_untranslated.set_defaults(func=untranslated)
# Create the subparser for the leaderboard
parser_validate = subparsers.add_parser('validate', description="Validate input files")
parser_validate.add_argument("infile", type=argparse.FileType(), nargs='+', help="The files containing the shift assignments (multiple files possible)")
parser_validate.set_defaults(func=validate)
# go for it
args = parser.parse_args()
if hasattr(args, 'func'):
args.func(args)
else:
parser.print_help()