CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
selectionParser.py
Go to the documentation of this file.
1 import json
2 class selectionParser(object):
3  def __init__(self,selectStr):
4  self.__result={}
5  self.__strresult={}
6  strresult=json.loads(selectStr)
7  for k,v in strresult.items():
8  expandedvalues=[]
9  for w in v:
10  if len(w)==0:
11  self.__result[int(k)]=expandedvalues
12  self.__strresult[k]=[]
13  continue
14  ###weed out [10]-like stuff just in case they exist
15  elif len(w)==1:
16  expandedvalues.append(w[0])
17  ##weed out [10,10]-like stuff
18  elif len(w)==2 and w[0]==w[1]:
19  expandedvalues.append(w[0])
20  else:
21  for i in range(w[0],w[1]+1):
22  expandedvalues.append(i)
23  self.__result[int(k)]=expandedvalues
24  self.__strresult[k]=[str(x) for x in expandedvalues]
25  def runs(self):
26  return self.__result.keys()
27  def runsandls(self):
28  '''return expanded {run:lslist}
29  '''
30  return self.__result
31  def runsandlsStr(self):
32  '''return expanded {'run':lslist}
33  '''
34  return self.__strresult
35  def numruns(self):
36  return len(self.__result.keys())
37  def numls(self,run):
38  return len(self.__result[run])
39 if __name__ == "__main__":
40  s=selectionParser('{"1":[[3,45]],"2":[[4,8],[10,10]],"3":[[]]}')
41  print 'runs : ',s.runs()
42  print 'full result : ',s.runsandls()
43  print 'str result : ',s.runsandlsStr()
44  print 'num runs : ',s.numruns()
45  print 'numls in run : ',s.numls(1)