Revision: | 1.2 |
Committed: | Wed Mar 7 14:33:14 2012 UTC (13 years, 1 month ago) by grchrist |
Content type: | text/x-python |
Branch: | MAIN |
CVS Tags: | V00-02-06, V00-02-05, V00-02-04, V00-02-03, V00-02-01, V00-01-10, V-00-01-10, V00-01-09, V00-01-08, V00-01-07, V00-01-06, V00-01-05, V00-01-04, V00-01-03, V00-01-02, V00-01-01, V00-00-34, V00-00-33, MenuAnalyzer_V00-00-02, MenuAnalyzer_V00-00-01, MenuAnalyzer_V1, V00-00-32, V00-00-31, V00-00-30, V00-00-29, V00-00-28, V00-00-27, V00-00-26, V00-00-24, V00-00-23, V00-00-22, V00-00-21, V00-00-20, V00-00-19, V00-00-18, V00-00-17, V00-00-16, V00-00-15, V00-00-14, V00-00-13, V00-00-12, V00-00-11, V00-00-10, HEAD |
Changes since 1.1: | +41 -0 lines |
Log Message: | added files |
# | User | Rev | Content |
---|---|---|---|
1 | grchrist | 1.2 | 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) |