/
submission.py
805 lines (623 loc) · 25 KB
/
submission.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
#!/usr/bin/env python
# encoding: utf-8
# The MIT License (MIT)
# Copyright (c) 2015 CNRS
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# AUTHORS
# Hervé BREDIN - http://herve.niderb.fr
# CHANGELOG
# Version 0.1.2 (2015-07-01)
# fix: upload evidences one video at a time
# Version 0.1.1 (2015-06-26)
# fix: missing submission type for incomplete submissions
"""
MediaEval Person Discovery Task submission manager.
- date Print the current date
- list Print the list of submissions.
- delete Delete submissions (interactive).
- check Validate submission files content.
- primary Submit primary run.
- contrastive Submit contrastive run.
Usage:
submission [options] date
submission [options] list
submission [options] delete
submission [options] check <run.label> <run.evidence>
submission [options] primary <run.label> <run.evidence>
submission [options] contrastive <run> <run.label> <run.evidence>
Options:
-h --help Show this screen.
--version Show version.
--dev Development set.
--debug Show debug information.
--url=URL Submission server URL
[default: http://api.mediaeval.niderb.fr]
--login=LOGIN Username.
--password=P45sw0Rd Password.
Arguments:
<run.label> Path to label submission file.
<run.evidence> Path to evidence submission file.
<run> Set name for contrastive run.
"""
from docopt import docopt
from getpass import getpass
from camomile import Camomile
from common import loadLabel, loadEvidence
import pandas as pd
import sys
from progressbar import ProgressBar, Percentage
# pretty pandas display
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)
# name conventions
CORPUS_NAME_DEV = 'mediaeval.development'
CORPUS_NAME_TEST = 'mediaeval.test'
SUBMISSION_STATUS_WIP = 'incomplete'
SUBMISSION_STATUS_OK = 'complete'
GROUP_ORGANIZER = 'organizer'
USER_ROBOT_SUBMISSION = 'robot_submission'
USER_ROBOT_LEADERBOARD = 'robot_leaderboard'
LAYER_SUBMISSION_SHOT = 'mediaeval.submission_shot'
QUEUE_SUBMISSION = 'mediaeval.submission.in'
DATATYPE_EVIDENCE = "mediaeval.persondiscovery.evidence"
DATATYPE_LABEL = "mediaeval.persondiscovery.label"
FRAGMENTTYPE_SUBMISSION = "mediaeval.persondiscovery._id_shot"
# Camomile client
GLOBAL_CLIENT = None
# submission shots
GLOBAL_DEV_OR_TEST = None
GLOBAL_CORPUS = None
GLOBAL_VIDEO_MAPPING = None
GLOBAL_SHOT_MAPPING = None
# users
GLOBAL_USERS = None
GLOBAL_ME = None
GLOBAL_ROBOT_SUBMISSION = None
GLOBAL_ROBOT_LEADERBOARD = None
# groups
GLOBAL_GROUPS = None
GLOBAL_TEAM = None
GLOBAL_ORGANIZER = None
# queues
GLOBAL_SUBMISSION_QUEUE = None
GLOBAL_DEBUG = False
# -----------------------------------------------------------------------------
# UTILITY FUNCTIONS
# -----------------------------------------------------------------------------
# error reporting
def reportErrorAndExit(message):
sys.stderr.write(message)
sys.stderr.flush()
sys.exit(-1)
def debug(message):
sys.stdout.write('DEBUG: ' + message + '\n')
sys.stdout.flush()
# find user name by its user id
def findUsername(id_user):
for user in GLOBAL_USERS:
if user._id == id_user:
return user.username
return '?'
def printSubmissions(submissions):
if submissions.empty:
return
columns = ['type', 'name', 'user', 'date', 'status']
print submissions[columns]
# -----------------------------------------------------------------------------
# INITIALIZATION
# -----------------------------------------------------------------------------
def initialize(url, username=None, password=None):
if GLOBAL_DEBUG:
debug('initialize')
global GLOBAL_CLIENT
global GLOBAL_CORPUS
global GLOBAL_USERS
global GLOBAL_GROUPS
global GLOBAL_ME
global GLOBAL_TEAM
global GLOBAL_SUBMISSION_QUEUE
# -------------------------------------------------------------------------
# connect to Camomile server
# -------------------------------------------------------------------------
GLOBAL_CLIENT = Camomile(url)
if username is None:
username = raw_input('Login: ')
if password is None:
password = getpass()
try:
GLOBAL_CLIENT.login(username, password)
GLOBAL_ME = GLOBAL_CLIENT.me()
except Exception:
reportErrorAndExit(
'Unable to connect to %s with login %s' % (url, username))
# -------------------------------------------------------------------------
# find corpus identifier (development or test set)
# -------------------------------------------------------------------------
try:
name = (CORPUS_NAME_DEV
if GLOBAL_DEV_OR_TEST == "dev"
else CORPUS_NAME_TEST)
corpora = GLOBAL_CLIENT.getCorpora(name=name)
GLOBAL_CORPUS = corpora[0]._id
except Exception:
reportErrorAndExit(
'Unable to identify %s corpus.' % GLOBAL_DEV_OR_TEST)
# -------------------------------------------------------------------------
# get list of users and groups
# -------------------------------------------------------------------------
try:
GLOBAL_GROUPS = GLOBAL_CLIENT.getGroups()
GLOBAL_USERS = GLOBAL_CLIENT.getUsers()
except Exception:
reportErrorAndExit('Unable to obtain list of users and groups.')
# -------------------------------------------------------------------------
# get (supposedly unique) team of current user
# -------------------------------------------------------------------------
try:
GLOBAL_TEAM = None
userGroups = GLOBAL_CLIENT.getMyGroups()
for group in GLOBAL_GROUPS:
if group._id in userGroups and group.name.startswith('team_'):
GLOBAL_TEAM = group
break
except Exception:
pass
if GLOBAL_TEAM is None:
reportErrorAndExit('Unable to identify your team.')
# -------------------------------------------------------------------------
# identify submission queue
# -------------------------------------------------------------------------
if GLOBAL_DEBUG:
debug('locate submission queue.')
try:
queues = [queue._id
for queue in GLOBAL_CLIENT.getQueues()
if queue.name == QUEUE_SUBMISSION]
GLOBAL_SUBMISSION_QUEUE = queues[0]
except Exception:
reportErrorAndExit('Unable to locate submission queue.')
def initializeForSubmission():
if GLOBAL_DEBUG:
debug('initializeForSubmission')
global GLOBAL_ORGANIZER
global GLOBAL_ROBOT_LEADERBOARD
global GLOBAL_ROBOT_SUBMISSION
global GLOBAL_SHOT_MAPPING
global GLOBAL_VIDEO_MAPPING
global GLOBAL_SUBMISSION_QUEUE
# -------------------------------------------------------------------------
# find 'organizer' group
# -------------------------------------------------------------------------
if GLOBAL_DEBUG:
debug('find %s group.' % GROUP_ORGANIZER)
GLOBAL_ORGANIZER = None
for group in GLOBAL_GROUPS:
if group.name == GROUP_ORGANIZER:
GLOBAL_ORGANIZER = group
break
if GLOBAL_ORGANIZER is None:
reportErrorAndExit('Unable to find %s group.' % GROUP_ORGANIZER)
# -------------------------------------------------------------------------
# find 'robot_submission' user
# -------------------------------------------------------------------------
if GLOBAL_DEBUG:
debug('find %s user.' % USER_ROBOT_SUBMISSION)
GLOBAL_ROBOT_SUBMISSION = None
for user in GLOBAL_USERS:
if user.username == USER_ROBOT_SUBMISSION:
GLOBAL_ROBOT_SUBMISSION = user
break
if GLOBAL_ROBOT_SUBMISSION is None:
reportErrorAndExit('Unable to find %s user.' % USER_ROBOT_SUBMISSION)
# -------------------------------------------------------------------------
# find 'robot_leaderboard' user
# -------------------------------------------------------------------------
if GLOBAL_DEBUG:
debug('find %s user.' % USER_ROBOT_LEADERBOARD)
GLOBAL_ROBOT_LEADERBOARD = None
for user in GLOBAL_USERS:
if user.username == USER_ROBOT_LEADERBOARD:
GLOBAL_ROBOT_LEADERBOARD = user
break
if GLOBAL_ROBOT_LEADERBOARD is None:
reportErrorAndExit('Unable to find %s user.' % USER_ROBOT_LEADERBOARD)
# -------------------------------------------------------------------------
# get mapping for list of media
# -------------------------------------------------------------------------
if GLOBAL_DEBUG:
debug('build mediumID ==> videoID mapping')
try:
media = GLOBAL_CLIENT.getMedia(corpus=GLOBAL_CORPUS)
GLOBAL_VIDEO_MAPPING = {medium.name: medium._id for medium in media}
except Exception:
reportErrorAndExit('Unable to build mediumID ==> videoID mapping')
# -------------------------------------------------------------------------
# get mapping for (supposedly unique) list of submission shots
# -------------------------------------------------------------------------
if GLOBAL_DEBUG:
debug('build (videoID, shotNumber) ==> annotationID mapping.')
try:
layers = GLOBAL_CLIENT.getLayers(
GLOBAL_CORPUS, name=LAYER_SUBMISSION_SHOT)
shotLayer = layers[0]._id
widgets = ['Downloading shots: ', Percentage()]
progress = ProgressBar(widgets=widgets,
maxval=len(GLOBAL_VIDEO_MAPPING)).start()
GLOBAL_SHOT_MAPPING = {}
for i, (name, medium) in enumerate(GLOBAL_VIDEO_MAPPING.iteritems()):
shots = GLOBAL_CLIENT.getAnnotations(layer=shotLayer,
medium=medium)
for s in shots:
GLOBAL_SHOT_MAPPING[name, s.fragment.shot_number] = s._id
progress.update(i)
progress.finish()
except Exception:
reportErrorAndExit(
'Unable to build (videoID, shotNumber) ==> annotationID mapping.')
def createNewSubmission(submissionType, submissionName, label, evidence):
global GLOBAL_CLIENT
global GLOBAL_TEAM
global GLOBAL_CORPUS
global GLOBAL_ORGANIZER
global GLOBAL_ROBOT_SUBMISSION
global GLOBAL_ROBOT_LEADERBOARD
# -------------------------------------------------------------------------
# create empty (evidence and label) submission layers
# -------------------------------------------------------------------------
if GLOBAL_DEBUG:
debug('create submission layers.')
try:
# create empty evidence layer
evidenceLayer = GLOBAL_CLIENT.createLayer(
GLOBAL_CORPUS, submissionName,
data_type=DATATYPE_EVIDENCE,
fragment_type=FRAGMENTTYPE_SUBMISSION,
description={
"submission": submissionType,
"status": SUBMISSION_STATUS_WIP,
"id_user": GLOBAL_ME._id,
"id_team": GLOBAL_TEAM._id
},
returns_id=True
)
# set permissions on evidence layer
# * team: ADMIN
# * organizer: READ
# * robot: READ
GLOBAL_CLIENT.setLayerPermissions(
evidenceLayer, GLOBAL_CLIENT.ADMIN,
group=GLOBAL_TEAM._id)
GLOBAL_CLIENT.setLayerPermissions(
evidenceLayer, GLOBAL_CLIENT.READ,
group=GLOBAL_ORGANIZER._id)
GLOBAL_CLIENT.setLayerPermissions(
evidenceLayer, GLOBAL_CLIENT.READ,
user=GLOBAL_ROBOT_SUBMISSION._id)
GLOBAL_CLIENT.setLayerPermissions(
evidenceLayer, GLOBAL_CLIENT.READ,
user=GLOBAL_ROBOT_LEADERBOARD._id)
# create empty label layer
labelLayer = GLOBAL_CLIENT.createLayer(
GLOBAL_CORPUS, submissionName,
data_type=DATATYPE_LABEL,
fragment_type=FRAGMENTTYPE_SUBMISSION,
description={
"submission": submissionType,
"status": SUBMISSION_STATUS_WIP,
"id_evidence": evidenceLayer,
"id_user": GLOBAL_ME._id,
"id_team": GLOBAL_TEAM._id
},
returns_id=True
)
# set permissions on label layer
# * team: ADMIN
# * organizer: READ
# * robot: READ
GLOBAL_CLIENT.setLayerPermissions(
labelLayer, GLOBAL_CLIENT.ADMIN,
group=GLOBAL_TEAM._id)
GLOBAL_CLIENT.setLayerPermissions(
labelLayer, GLOBAL_CLIENT.READ,
group=GLOBAL_ORGANIZER._id)
GLOBAL_CLIENT.setLayerPermissions(
labelLayer, GLOBAL_CLIENT.READ,
user=GLOBAL_ROBOT_SUBMISSION._id)
GLOBAL_CLIENT.setLayerPermissions(
labelLayer, GLOBAL_CLIENT.READ,
user=GLOBAL_ROBOT_LEADERBOARD._id)
# cross-reference evidence and label layers
GLOBAL_CLIENT.updateLayer(
evidenceLayer,
description={
"submission": submissionType,
"status": SUBMISSION_STATUS_WIP,
"id_label": labelLayer,
"id_user": GLOBAL_ME._id,
"id_team": GLOBAL_TEAM._id
}
)
except Exception:
reportErrorAndExit('Unable to create submission layers.')
# -------------------------------------------------------------------------
# fill (evidence and label) submission layers
# -------------------------------------------------------------------------
if GLOBAL_DEBUG:
debug('upload submissions.')
try:
# prepare list of evidences in Camomile format
evidences = {}
for _, row in evidence.iterrows():
(personName, videoID, shotNumber, source) = tuple(row)
annotation = {
"id_layer": evidenceLayer,
"id_medium": GLOBAL_VIDEO_MAPPING[videoID],
"fragment": GLOBAL_SHOT_MAPPING[videoID, shotNumber],
"data": {
"person_name": personName,
"source": source
}
}
evidences.setdefault(videoID, []).append(annotation)
# submit evidences video by video
widgets = ['Uploading evidences: ', Percentage()]
progress = ProgressBar(widgets=widgets, maxval=len(evidences)).start()
for v, videoID in enumerate(evidences):
GLOBAL_CLIENT.createAnnotations(evidenceLayer, evidences[videoID])
progress.update(v)
progress.finish()
# prepare one list of label per video in Camomile format
labels = {}
for _, row in label.iterrows():
(videoID, shotNumber, personName, confidence) = tuple(row)
annotation = {
"id_layer": labelLayer,
"id_medium": GLOBAL_VIDEO_MAPPING[videoID],
"fragment": GLOBAL_SHOT_MAPPING[videoID, shotNumber],
"data": {
"person_name": personName,
"confidence": confidence
}
}
labels.setdefault(videoID, []).append(annotation)
widgets = ['Uploading labels: ', Percentage()]
progress = ProgressBar(widgets=widgets, maxval=len(labels)).start()
# submit labels video by video
for v, videoID in enumerate(labels):
GLOBAL_CLIENT.createAnnotations(labelLayer, labels[videoID])
progress.update(v)
progress.finish()
except Exception:
reportErrorAndExit('Unable to upload submissions.')
# -------------------------------------------------------------------------
# update (evidence and label) status and push to submission queue
# -------------------------------------------------------------------------
if GLOBAL_DEBUG:
debug('finalize submissions.')
try:
GLOBAL_CLIENT.updateLayer(
evidenceLayer,
description={
"submission": submissionType,
"status": SUBMISSION_STATUS_OK,
"id_label": labelLayer,
"id_user": GLOBAL_ME._id,
"id_team": GLOBAL_TEAM._id
}
)
GLOBAL_CLIENT.updateLayer(
labelLayer,
description={
"submission": submissionType,
"status": SUBMISSION_STATUS_OK,
"id_evidence": evidenceLayer,
"id_user": GLOBAL_ME._id,
"id_team": GLOBAL_TEAM._id
}
)
GLOBAL_CLIENT.enqueue(
GLOBAL_SUBMISSION_QUEUE,
{
"submittedBy": GLOBAL_ME._id,
"id_team": GLOBAL_TEAM._id,
"team": GLOBAL_TEAM.name,
"user": GLOBAL_ME.username,
"date": GLOBAL_CLIENT.getDate().date,
"type": submissionType,
"name": submissionName,
"id_evidence": evidenceLayer,
"id_label": labelLayer
})
except Exception:
reportErrorAndExit('Unable to finalize submissions.')
def getSubmissions():
# get all readable layers
allLayers = GLOBAL_CLIENT.getLayers(GLOBAL_CORPUS, history=True)
submissionLayers = []
for layer in allLayers:
data_type = layer.get('data_type', None)
if data_type != DATATYPE_LABEL:
continue
submissionLayers.append({
'date': layer.history[-1].date,
'user': findUsername(layer.history[-1].id_user),
'type': layer.description.get('submission', None),
'name': layer.name,
'label': layer._id,
'evidence': layer.description.id_evidence,
'status': layer.description.status,
})
df = pd.DataFrame(submissionLayers)
return df
def checkSubmission(label, evidence):
shots = set(GLOBAL_SHOT_MAPPING)
# check that labels are only provided for selected shots
labelShots = set(tuple(s)
for _, s in label[['videoID', 'shotNumber']].iterrows())
if not labelShots.issubset(shots):
msg = ('Labels should only be computed for provided shots.')
raise ValueError(msg)
# check that evidence is provided for every unique label
labelNames = set(label['personName'].unique())
evidenceNames = set(evidence['personName'].unique())
if labelNames != evidenceNames:
msg = ('There must be exactly one evidence '
'per unique name in label submission.')
raise ValueError(msg)
# check that there is no more than one evidence per label
if len(evidenceNames) != len(evidence):
msg = ('There must be exactly one evidence '
'per unique name in label submission.')
raise ValueError(msg)
# check that evidences are chosen among selected shots
evidenceShots = set(
tuple(s) for _, s in evidence[['videoID', 'shotNumber']].iterrows())
if not evidenceShots.issubset(shots):
msg = ('Evidences should only be chosen among provided shots.')
raise ValueError(msg)
def modeDate():
print GLOBAL_CLIENT.getDate().date
def modeList():
submissions = getSubmissions()
printSubmissions(submissions)
def modeDelete():
while True:
# print list of submissions
submissions = getSubmissions()
printSubmissions(submissions)
# ask user which submission to delete
nSubmissions = len(submissions)
if nSubmissions == 0:
print 'No submissions.'
break
choices = range(nSubmissions)
strChoices = '|'.join(str(i) for i in range(nSubmissions))
userInput = raw_input('Delete submission [%s]: ' % strChoices).strip()
# check user input
try:
submissionIndex = int(userInput)
assert submissionIndex in choices
except Exception:
break
# actual submission deletion
submission = dict(submissions.iloc[submissionIndex])
labelLayer = submission['label']
evidenceLayer = submission['evidence']
try:
GLOBAL_CLIENT.deleteLayer(labelLayer)
GLOBAL_CLIENT.deleteLayer(evidenceLayer)
GLOBAL_CLIENT.enqueue(
GLOBAL_SUBMISSION_QUEUE,
{
"deletedBy": GLOBAL_ME._id,
"id_team": GLOBAL_TEAM._id,
"team": GLOBAL_TEAM.name,
"user": GLOBAL_ME.username,
"date": GLOBAL_CLIENT.getDate().date,
"id_evidence": evidenceLayer,
"id_label": labelLayer
})
except Exception:
reportErrorAndExit('Unable to delete submission.')
def modeCheck(pathToLabel, pathToEvidence):
initializeForSubmission()
label = loadLabel(pathToLabel)
evidence = loadEvidence(pathToEvidence)
try:
checkSubmission(label, evidence)
except ValueError, e:
reportErrorAndExit(e.message)
def modePrimary(pathToLabel, pathToEvidence):
# get list of submission
submissions = getSubmissions()
if not submissions.empty:
nPrimary = len(submissions[submissions.type == 'primary'])
if nPrimary > 0:
reportErrorAndExit(
'Please delete your existing '
'primary submission first.')
initializeForSubmission()
# load evidence/label files and check their validity
label = loadLabel(pathToLabel)
evidence = loadEvidence(pathToEvidence)
try:
checkSubmission(label, evidence)
except ValueError, e:
reportErrorAndExit(e.message)
createNewSubmission('primary', 'primary', label, evidence)
submissions = getSubmissions()
printSubmissions(submissions)
def modeContrastive(pathToLabel, pathToEvidence, submissionName):
# get list of submission
submissions = getSubmissions()
if submissionName == 'primary':
reportErrorAndExit(
'Please use a different name for your contrastive submission.')
if not submissions.empty:
nContrastive = len(submissions[submissions.type == 'contrastive'])
if nContrastive > 3:
reportErrorAndExit(
'Please delete one of your existing '
'contrastive submissions first.')
nSameName = len(submissions[submissions.name == submissionName])
if nSameName > 0:
reportErrorAndExit(
'Please choose a different name or '
'delete the existing submission with same name.')
initializeForSubmission()
# load evidence/label files and check their validity
label = loadLabel(pathToLabel)
evidence = loadEvidence(pathToEvidence)
try:
checkSubmission(label, evidence)
except ValueError, e:
reportErrorAndExit(e.message)
createNewSubmission('contrastive', submissionName, label, evidence)
submissions = getSubmissions()
printSubmissions(submissions)
if __name__ == '__main__':
arguments = docopt(__doc__, version='0.1.2')
GLOBAL_DEV_OR_TEST = 'test'
if arguments['--dev']:
GLOBAL_DEV_OR_TEST = 'dev'
GLOBAL_DEBUG = False
if arguments['--debug']:
GLOBAL_DEBUG = True
url = arguments['--url']
username = arguments['--login']
password = arguments['--password']
initialize(url, username=username, password=password)
if arguments['date']:
modeDate()
if arguments['list']:
modeList()
if arguments['delete']:
modeDelete()
if arguments['check']:
pathToLabel = arguments['<run.label>']
pathToEvidence = arguments['<run.evidence>']
modeCheck(pathToLabel, pathToEvidence)
if arguments['primary']:
pathToLabel = arguments['<run.label>']
pathToEvidence = arguments['<run.evidence>']
modePrimary(pathToLabel, pathToEvidence)
if arguments['contrastive']:
submissionName = arguments['<run>']
pathToLabel = arguments['<run.label>']
pathToEvidence = arguments['<run.evidence>']
modeContrastive(pathToLabel, pathToEvidence, submissionName)