forked from esitarski/CrossMgr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhotoFinish.py
78 lines (62 loc) · 1.98 KB
/
PhotoFinish.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
import os
import wx
import sys
import math
import shutil
from GetResults import GetResultsCore
from SendPhotoRequests import getPhotoDirName, SendPhotoRequests, PhotoAcknowledge
import Utils
import Model
def formatTime( secs ):
return Utils.formatTime(
secs,
highPrecision=False, extraPrecision=True,
forceHours=True, twoDigitHours=True,
).replace(':','-').replace('.','-')
def GetPhotoFName( dirName, bib, raceSeconds, i ):
return os.path.join(dirName, 'bib-{:04d}-time-{}-{}.jpg'.format(int(bib or 0), formatTime(raceSeconds or 0), i+1))
photoCache = set()
def updatePhotoFNameCache():
global photoCache
photoCache = set()
race = Model.race
if not race or not race.enableUSBCamera or not race.startTime:
return
photoDir = getPhotoDirName( Utils.getFileName() )
try:
photoCache = { fname[:-6] for fname in os.listdir(photoDir) if fname.startswith('bib') and fname.endswith('.jpg') }
except Exception as e:
pass
def HasPhotoCache():
global photoCache
return photoCache
def hasPhoto( bib, t ):
global photoCache
race = Model.race
if not photoCache or not race or not race.enableUSBCamera or not race.startTime:
return False
try:
return os.path.basename(GetPhotoFName(getPhotoDirName(Utils.getFileName()), bib, t, 0))[:-6] in photoCache
except Exception as e:
return False
def HasCamera():
return PhotoAcknowledge()[0]
def okTakePhoto( num, t ):
race = Model.race
if not race or not race.enableUSBCamera or not race.isRunning():
return False
if not race.photosAtRaceEndOnly or race.isTimeTrial or num == 9999 or not t:
return True
results = GetResultsCore( race.getCategory(num) )
try:
return t > results[0].raceTimes[-1] - 60.0
except:
return False
def DeletePhotos( raceFileName ):
dirName = getPhotoDirName( raceFileName )
try:
shutil.rmtree( dirName, True )
except Exception as e:
logException( e, sys.exc_info() )
def TakePhoto( bib, raceSeconds, includeFTP=False ):
return 2 if SendPhotoRequests( [(bib, raceSeconds)] )[0] else 0