ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/selectionParser.py
(Generate patch)

Comparing UserCode/RateMonShiftTool_dev/selectionParser.py (file contents):
Revision 1.1 by abrinke1, Wed Mar 7 11:42:19 2012 UTC vs.
Revision 1.2 by grchrist, Wed Mar 7 14:33:14 2012 UTC

# Line 0 | Line 1
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 +            ###weed out [10]-like stuff just in case they exist
11 +                if len(w)==1:
12 +                    expandedvalues.append(w[0])
13 +            ##weed out [10,10]-like stuff
14 +                elif len(w)==2 and w[0]==w[1]:
15 +                    expandedvalues.append(w[0])
16 +                else:
17 +                    for i in range(w[0],w[1]+1):
18 +                        expandedvalues.append(i)
19 +            self.__result[int(k)]=expandedvalues
20 +            self.__strresult[k]=[str(x) for x in expandedvalues]
21 +    def runs(self):
22 +        return self.__result.keys()
23 +    def runsandls(self):
24 +        '''return expanded {run:lslist}
25 +        '''
26 +        return self.__result
27 +    def runsandlsStr(self):
28 +        '''return expanded {'run':lslist}
29 +        '''
30 +        return self.__strresult
31 +    def numruns(self):
32 +        return len(self.__result.keys())
33 +    def numls(self,run):
34 +        return len(self.__result[run])
35 + if __name__ == "__main__":
36 +    s=selectionParser('{"1":[[3,45]],"2":[[4,8],[10,10]]}')
37 +    print 'runs : ',s.runs()
38 +    print 'full result : ',s.runsandls()
39 +    print 'str result : ',s.runsandlsStr()
40 +    print 'num runs : ',s.numruns()
41 +    print 'numls in run : ',s.numls(1)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines