forked from cms-tsg-fog/RateMon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectionParser.py
More file actions
executable file
·41 lines (41 loc) · 1.42 KB
/
selectionParser.py
File metadata and controls
executable file
·41 lines (41 loc) · 1.42 KB
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
import json
class selectionParser(object):
def __init__(self,selectStr):
self.__result={}
self.__strresult={}
strresult=json.loads(selectStr)
for k,v in strresult.items():
expandedvalues=[]
for w in v:
###weed out [10]-like stuff just in case they exist
if len(w)==1:
expandedvalues.append(w[0])
##weed out [10,10]-like stuff
elif len(w)==2 and w[0]==w[1]:
expandedvalues.append(w[0])
else:
for i in range(w[0],w[1]+1):
expandedvalues.append(i)
self.__result[int(k)]=expandedvalues
self.__strresult[k]=[str(x) for x in expandedvalues]
def runs(self):
return self.__result.keys()
def runsandls(self):
'''return expanded {run:lslist}
'''
return self.__result
def runsandlsStr(self):
'''return expanded {'run':lslist}
'''
return self.__strresult
def numruns(self):
return len(self.__result.keys())
def numls(self,run):
return len(self.__result[run])
if __name__ == "__main__":
s=selectionParser('{"1":[[3,45]],"2":[[4,8],[10,10]]}')
print 'runs : ',s.runs()
print 'full result : ',s.runsandls()
print 'str result : ',s.runsandlsStr()
print 'num runs : ',s.numruns()
print 'numls in run : ',s.numls(1)