Mercurial > code > home > repos > light9
annotate light8/sub_analyzer.py @ 2405:69ca2b2fc133
overcomplicated attempt at persisting the pane layout in the rdf graph
this was hard because we have to somehow wait for the graph to load before config'ing the panes
author | drewp@bigasterisk.com |
---|---|
date | Fri, 17 May 2024 16:58:26 -0700 |
parents | a995fd1a8f03 |
children |
rev | line source |
---|---|
101 | 1 #!/usr/bin/python |
0 | 2 from Subs import * |
3 from Patch import * | |
4 from types import TupleType | |
5 | |
6 from Config import patch, subs | |
7 | |
8 import re | |
9 import Patch | |
10 Patch.reload_data(0) | |
11 | |
12 subusage = {} | |
13 | |
14 # colors = 'ROGBVndcihs' | |
15 colors = 'ndcihs' | |
16 | |
17 color_chart = { | |
18 '1-01' : 'ROYd', # broadway (morning - afternoon) | |
19 '1-02' : 'i', # int. mission | |
20 '1-03' : 'R', # phone booth | |
21 '1-04' : 'RBVh', # hotbox | |
22 '1-05' : 'RBd', # off broadway | |
23 '1-06' : 'ROYd', # ext. mission | |
24 '1-07' : 'ROYn', # gambler intro, off broadway | |
25 '1-08' : 'ROBIVc', # havana, clubs | |
26 '1-09' : 'ROYBIVc', # havana, outside, night | |
27 '1-10' : 'BVn', # ext. mission, night (4am) | |
28 | |
29 '2-01' : 'RBIVh', # hotbox | |
30 '2-02' : 'RBn', # more can i wish you | |
31 '2-03' : 'GBs', # sewer (crap game) | |
32 '2-04' : 'Bn', # sue me | |
33 '2-05' : 'i', # int. mission | |
34 '2-06' : '', # marry | |
35 '2-07' : 'd', # broadway finale | |
36 } | |
37 | |
38 scene_names = { | |
39 '1-01' : 'broadway (morning to afternoon)', | |
40 '1-02' : 'int. mission', | |
41 '1-03' : 'phone booth', | |
42 '1-04' : 'hotbox', | |
43 '1-05' : 'guys and dolls (off broadway)', | |
44 '1-06' : 'ext. mission, lunch time', | |
45 '1-07' : 'gambler intro, off broadway', | |
46 '1-08' : 'havana, clubs', | |
47 '1-09' : 'havana, outside, night', | |
48 '1-10' : 'ext. mission, night (4am)', | |
49 | |
50 '2-01' : 'hotbox', | |
51 '2-02' : 'more can i wish you', | |
52 '2-03' : 'sewer (crap game)', | |
53 '2-04' : 'sue me', | |
54 '2-05' : 'rock the boat (int. mission)', | |
55 '2-06' : 'marry (trav)', | |
56 '2-07' : 'finale (broadway)', | |
57 } | |
58 | |
59 sub_to_scene = {} | |
60 | |
85
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
73
diff
changeset
|
61 # blacklist is a list of *prefixes* to light names that won't be shown |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
73
diff
changeset
|
62 blacklist = 'god upfill red blue cyc oran sidefill'.split() |
0 | 63 blacklist.extend(['side l','side r']) |
64 | |
65 for subname, levdict in subs.items(): | |
66 if type(subname) == TupleType: | |
67 subname = subname[0] | |
68 oldname = subname | |
69 subname = re.sub(r'\*(\d-\d+)-.*', r'\1', subname) | |
70 if oldname == subname: continue | |
71 sub_to_scene[oldname] = subname | |
72 subname = oldname # restore 'em. restore 'em good. | |
73 if not levdict: | |
74 print "Warning: %s is useless (empty sub)." % subname | |
75 else: | |
76 for ch, lev in levdict.items(): | |
77 if lev: | |
78 ch = resolve_name(ch) | |
79 subusage.setdefault(ch, []) | |
80 subusage[ch].append((lev, subname)) | |
81 | |
82 def twist(l): | |
83 return [(b,a) for a,b in l] | |
84 | |
85 def format_usage(ch, usage): | |
85
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
73
diff
changeset
|
86 if max([ch.startswith(pre) for pre in blacklist]): |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
73
diff
changeset
|
87 return |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
73
diff
changeset
|
88 |
0 | 89 usage=twist(usage) |
90 usage.sort() | |
91 # usage.reverse() | |
92 usage=twist(usage) | |
93 print "======= %s ======= (%d uses)" % (ch, len(usage)) | |
94 if 1: | |
95 use_str = '' | |
96 for lev, sub in usage: | |
97 if lev>30: | |
98 if sub_to_scene[sub] in color_chart: | |
99 subcolors = color_chart[sub_to_scene[sub]] | |
100 col_str = '' | |
101 for c in colors: | |
102 if c in subcolors: col_str += c | |
103 else: col_str += ' ' | |
104 print col_str, | |
105 else: | |
106 print ' ' * len(colors), | |
107 scenename = scene_names.get(sub_to_scene[sub], '') | |
108 levbar="*"*(lev//5) | |
109 print ' %3d %-20s\t%-30s %s' % (lev, levbar,sub, scenename) | |
110 else: | |
111 use_str = '\n '.join(["%d\t%s" % (lev, sub) for lev, sub in usage]) | |
112 print ' ' + use_str | |
113 | |
114 subitems = subusage.items() | |
115 subitems.sort() | |
116 for ch, usage in subitems: | |
117 if 0: | |
118 usedict = {} | |
119 for lev, subname in usage: # remove duplicates | |
120 usedict[subname] = max(lev, usedict.get(subname, 0)) | |
121 | |
122 newusage = [(lev, sub) for sub, lev in usedict.items()] | |
123 | |
124 format_usage(ch, newusage) | |
125 else: | |
126 format_usage(ch, usage) |