-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmp_to_db.py
45 lines (35 loc) · 1.5 KB
/
tmp_to_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from __future__ import print_function
columns = ["color", "chr", "v", "k", "lambda", "mu", "r_power_f", "s_power_g", "comments"]
with open('brouwer.tmp') as f:
lines = f.readlines()
data = [dict(zip(columns,l.strip().split('|'))) for l in lines]
color_to_status = {'#b0ffb0':'exists', '#ffb0b0':'impossible', '#ffffb0':'open'}
for i,x in enumerate(data):
x['status'] = color_to_status[x.pop('color')]
if x['v'] == '':
x['v'] = data[i-1]['v']
for key in ['v','k','lambda','mu']:
x[key] = int(x[key])
data = {(x.pop('v'),x.pop('k'),x.pop('lambda'),x.pop('mu')):x
for x in data}
# Text output
with open('brouwer_srg_database.txt','w') as output:
for (v,k,l,mu),dic in sorted(data.items()):
output.write("{:<4} {:<4} {:<4} {:<4} {:<10} {}\n".format(v,k,l,mu,dic['status'],dic['comments']))
print ("'brouwer_srg_database.txt' file written.")
# Json output
import json
json_list = [[v,k,l,mu,dic['status'],dic['comments']]
for (v,k,l,mu),dic in sorted(data.items())]
with open('brouwer_srg_database.json', 'w') as output:
json.dump(json_list, output)
print ("'brouwer_srg_database.json' file written.")
# sobj output
#from sage.structure.sage_object import save
#save(data,'brouwer.sobj')
print ("'brouwer.sobj' file written.")
stats = [x['status'] for x in data.values()]
print ("statistics:")
print (" - {} impossible".format(stats.count('impossible')))
print (" - {} open".format(stats.count('open')))
print (" - {} realizable".format(stats.count('exists')))