1 | import collections |
---|
2 | |
---|
3 | def wrap(s,a,b): |
---|
4 | if type(s) == type( '' ): |
---|
5 | return a + s + b |
---|
6 | elif type(s) in [type([]), type(())]: |
---|
7 | return [a + x + b for x in s] |
---|
8 | |
---|
9 | class vgx1(object): |
---|
10 | def __init__(self,dq,nmx=-1,run=False): |
---|
11 | self.dq = dq |
---|
12 | if run: |
---|
13 | for i in dq.coll['requestVarGroup'].items[:nmx]: |
---|
14 | self.mxoGet(i) |
---|
15 | if self.mxo == None: |
---|
16 | print ( '%s, %s%s' % (i.label, i.title, ':: NONE') ) |
---|
17 | else: |
---|
18 | self.present(i,self.mxo) |
---|
19 | |
---|
20 | def present( self, rvg,mxo,odir='html/u' ): |
---|
21 | print ( '%s, %s' % (rvg.label, rvg.title ) ) |
---|
22 | cc = collections.defaultdict( dict ) |
---|
23 | s1 = set() |
---|
24 | s2 = set() |
---|
25 | mm = ['<h1>%s</h1>' % rvg.title, 'Summary of requests for Request Variable Group <a href="%s.html">%s</a>.<br/>' % (rvg.uid,rvg.title), '<table>'] |
---|
26 | for mip,eid in sorted( self.mxo.keys() ): |
---|
27 | ei = self.dq.inx.uid[eid] |
---|
28 | el = ei.label |
---|
29 | sect = ei._h.label |
---|
30 | elb = '%s:: %s' % (sect,el) |
---|
31 | cc[ mip ]['%s:: %s' % (sect,el) ] = ','.join( sorted( list(self.mxo[(mip,eid)]) ) ) |
---|
32 | s1.add(mip) |
---|
33 | s2.add(elb) |
---|
34 | ml = sorted( list( s1 ) ) |
---|
35 | el = sorted( list( s2 ) ) |
---|
36 | hr = ['<tr>'] + wrap( ['',] + ml, '<th>', '</th>') + ['</tr>'] |
---|
37 | mm.append( ' '.join(hr) ) |
---|
38 | |
---|
39 | for e in el: |
---|
40 | rr = [] |
---|
41 | for m in ml: |
---|
42 | if e in cc[m]: |
---|
43 | rr.append( cc[m][e] ) |
---|
44 | else: |
---|
45 | rr.append('') |
---|
46 | rr = ['<tr><th>%s</th>' % e,] + wrap( rr, '<td>', '</td>') + ['</tr>'] |
---|
47 | mm.append( ' '.join( rr ) ) |
---|
48 | mm.append( '</table>' ) |
---|
49 | bdy = '\n'.join( mm ) |
---|
50 | |
---|
51 | oo = open( '%s/%s__xx.html' % (odir,rvg.uid), 'w' ) |
---|
52 | oo.write( self.dq.pageTmpl % (rvg.title, '', '../', '../index.html', bdy ) ) |
---|
53 | oo.close() |
---|
54 | |
---|
55 | def mxoGet(self,i,present=True): |
---|
56 | """Find MIPs and experiments associated with a request variable group, and associated objectives""" |
---|
57 | if 'requestLink' not in self.dq.inx.iref_by_sect[i.uid].a: |
---|
58 | self.mxo = None |
---|
59 | return (False, '','') |
---|
60 | else: |
---|
61 | self.mxo = collections.defaultdict( set ) |
---|
62 | for u in self.dq.inx.iref_by_sect[i.uid].a['requestLink']: |
---|
63 | j = self.dq.inx.uid[u] |
---|
64 | mip = j.mip |
---|
65 | obj = j.objective |
---|
66 | if 'requestItem' in self.dq.inx.iref_by_sect[u].a: |
---|
67 | for uri in self.dq.inx.iref_by_sect[u].a['requestItem']: |
---|
68 | eid = self.dq.inx.uid[uri].esid |
---|
69 | self.mxo[(mip,eid)].add( obj ) |
---|
70 | |
---|
71 | if present: |
---|
72 | self.present(i, self.mxo ) |
---|
73 | return (True, '%s__xx.html' % i.uid, 'Usage summary for %s [%s]' % (i.title, i.label) ) |
---|
74 | |
---|
75 | |
---|