def test_pantone(self): from Goulib.table import Table,Cell from Goulib.itertools2 import reshape t=[Cell(name,style={'background-color':pantone[name].hex}) for name in sorted(pantone)] t=Table(reshape(t,(0,10))) with open(path+'\\results\\colors.pantone.html', 'w') as f: f.write(t.html())
def test_pantone(self): from Goulib.table import Table, Cell from Goulib.itertools2 import reshape t = [ Cell(name, style={'background-color': pantone[name].hex}) for name in sorted(pantone) ] t = Table(reshape(t, (0, 10))) with open(path + '\\results\\colors.pantone.html', 'w') as f: f.write(t.html())
def setup_class(cls): cls.t = Table(path + '/data/expr.csv') for e in cls.t: e[0] = Expr(e[0]) cls.f = Expr('3*x+2') cls.f1 = Expr(1) cls.fx = Expr('x') cls.fx2 = Expr('x**2') cls.fs = Expr('sin(x)') cls.fb1 = Expr('x>1') cls.fb2 = Expr('x>2') cls.fb3 = Expr('a==a') # any way to simplify it to constant True ? cls.e1 = Expr('3*x+2') # a very simple expression cls.e2 = Expr(cls.fs) cls.e3 = Expr(sqrt)(cls.e1) # Expr can be composed cls.xy = Expr('x*y') cls.long = Expr('(x*3+(a+b)*y)/x**(3*a*y)') cls.true = Expr(True) # make sure it works cls.false = Expr('False') # make sure it creates a bool cls.sqrt = Expr(sqrt) cls.euler = Expr("e**(i*pi)")
def test_blackbody2color(self): from Goulib.table import Table, Cell from Goulib.itertools2 import arange Table([ Cell(str(t), style={'background-color': blackBody2Color(t).hex}) for t in arange(500, 12000, 500) ]).save(path + '\\results\\colors.blackbody.html')
def ColorTable(colors, key=None, width=10): from Goulib.table import Table, Cell from Goulib.itertools2 import reshape def tooltip(c): return '\n'.join('%s = %s' % (k, v) for k, v in c._values.items()) labels = (color['black'], color['white']) #possible colors for labels t = [] colors = colors.values() if key: colors = list(colors) colors.sort(key=key) for c in colors: c2 = nearest_color( c, labels, opt=max ) #chose the label color with max difference to pantone color s = '<span title="%s" style="color:%s">%s</span>' % (tooltip(c), c2.hex, c.name) t.append(Cell(s, style={'background-color': c.hex})) return Table(reshape(t, (0, width)))
return except: pass if __name__ == "__main__": n = list(range(1, 30, 2)) for e in seq(n, [], '+', False): print(e) exit() from Goulib.table import Table max = 100 t = Table(range(max + 1), titles=['n']) def column(n, monadic='-s', dyadic='+-*/^_', permut=False): t.addcol(n) col = len(t.titles) - 1 for e in seq(n, monadic, dyadic, permut): n = int(e[0]) # h(e[0],'=',e[1]) if n <= max: e = e[1] old = t.get(n, col) if old is None or old.complexity() > e.complexity(): t.set(n, col, e) column(2018, permut=True) # yeargame column(2019, permut=True) #yeargame
colors=list(colors) colors.sort(key=key) for c in colors: c2=nearest_color(c,labels,opt=max) #chose the label color with max difference to pantone color s='<span title="%s" style="color:%s">%s</span>'%(tooltip(c),c2.hex,c.name) t.append(Cell(s,style={'background-color':c.hex})) return Table(reshape(t,(0,width))) # dictionaries of standardized colors from Goulib.table import Table path=os.path.dirname(os.path.abspath(__file__)) # http://blog.brunonuttens.com/206-conversion-couleurs-pantone-lab-rvb-hexa-liste-sql-csv/ table=Table(path+'/colors.csv') table.applyf('hex',lambda x:x.lower()) table=table.groupby('System') color=Palette() #dict of HTML / matplotlib colors, which seem to be the same color_lookup=Palette() # reverse color dict indexed by hex pantone=Palette() #dict of pantone colors # http://www.w3schools.com/colors/colors_names.asp for c in table['websafe'].asdict(): id=c['name'].lower() hex=c['hex'] c=Color(hex,name=id,illuminant='D65') color[id]=c color_lookup[c.hex]=c
c, labels, opt=max ) #chose the label color with max difference to pantone color s = '<span title="%s" style="color:%s">%s</span>' % (tooltip(c), c2.hex, c.name) t.append(Cell(s, style={'background-color': c.hex})) return Table(reshape(t, (0, width))) # dictionaries of standardized colors from Goulib.table import Table path = os.path.dirname(os.path.abspath(__file__)) # http://blog.brunonuttens.com/206-conversion-couleurs-pantone-lab-rvb-hexa-liste-sql-csv/ table = Table(path + '/colors.csv') table.applyf('hex', lambda x: x.lower()) table = table.groupby('System') color = Palette() #dict of HTML / matplotlib colors, which seem to be the same color_lookup = Palette() # reverse color dict indexed by hex pantone = Palette() #dict of pantone colors # http://www.w3schools.com/colors/colors_names.asp for c in table['websafe'].asdict(): id = c['name'].lower() hex = c['hex'] c = Color(hex, name=id, illuminant='D65') color[id] = c color_lookup[c.hex] = c
acteurs = {} for node in root.findall('acteurs/acteur'): uid = node.find('uid').text ident = node.find('etatCivil/ident') nom = ident.find('prenom').text + ' ' + ident.find('nom').text acteurs[uid] = nom for m in node.findall('mandats/mandat'): for o in m.find('organes'): ref = o.text organes[ref].append(uid) # parse the votes and build table res = Table() tree = ET.parse('Scrutins_XIV.xml') root = tree.getroot() for scrutin in root: line = OrderedDict() # so that id,date and title stay in the first cols line['id'] = scrutin.find('uid').text line['date'] = scrutin.find('dateScrutin').text line['titre'] = scrutin.find('titre').text groupes = scrutin.find('ventilationVotes/organe/groupes') for groupe in groupes: ref = groupe.find('organeRef').text pm = groupe.find('vote/positionMajoritaire').text votes = ['contre', 'abstention', 'pour'] default = votes.index(pm) - 1 # against=-1, no vote=0