Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/hecke_algebras/hecke_algebras_orbits.py
1128 views
1
# -*- coding: utf-8 -*-
2
r""" Import Hecke algebras.
3
4
Note: This code can be run on all files in any order. Even if you
5
rerun this code on previously entered files, it should have no affect.
6
This code checks if the entry exists, if so returns that and updates
7
with new information. If the entry does not exist then it creates it
8
and returns that.
9
10
"""
11
12
import sys
13
import re
14
import json
15
import os
16
import gzip
17
18
from lmfdb.base import getDBConnection
19
20
C= getDBConnection()
21
import yaml
22
pw_dict = yaml.load(open(os.path.join(os.getcwd(), "passwords.yaml")))
23
username = pw_dict['data']['username']
24
password = pw_dict['data']['password']
25
C['hecke_algebras'].authenticate('editor', password)
26
hecke_orb = C['hecke_algebras'].hecke_algebras_orbits
27
28
saving = True
29
30
def sd(f):
31
for k in f.keys():
32
print('%s ---> %s'%(k, f[k]))
33
34
def makels(li):
35
li2 = [str(x) for x in li]
36
return ','.join(li2)
37
38
def string2list(s):
39
s = str(s)
40
if s=='': return []
41
return [int(a) for a in s.split(',')]
42
43
44
45
# The following create_index command checks if there is an index on
46
# label, dimension, determinant and level.
47
48
hecke_orb.create_index('level')
49
hecke_orb.create_index('weight')
50
hecke_orb.create_index('parent_label')
51
52
print("finished indices")
53
54
55
## Main importing function
56
57
def do_import(ll):
58
level,weight,orbit,hecke_op,num_hecke_op,gen,num_gen,rel,parent_label,orbit_label= ll
59
mykeys = ['level','weight','orbit', 'hecke_op','num_hecke_op','gen','num_gen','rel','parent_label','orbit_label']
60
data = {}
61
for j in range(len(mykeys)):
62
data[mykeys[j]] = ll[j]
63
64
alg_orb = hecke_orb.find_one({'parent_label': parent_label, 'orbit_label': orbit_label})
65
66
if alg_orb is None:
67
print("new orbit")
68
alg_orb = data
69
else:
70
print("orbit already in the database")
71
alg_orb.update(data)
72
if saving:
73
hecke_orb.update({'orbit_label': orbit_label} , {"$set": alg_orb}, upsert=True)
74
75
76
77
# Loop over files
78
79
for path in sys.argv[1:]:
80
print(path)
81
filename = os.path.basename(path)
82
fn = gzip.open(path) if filename[-3:] == '.gz' else open(path)
83
for line in fn.readlines():
84
line.strip()
85
if re.match(r'\S',line):
86
l = json.loads(line)
87
do_import(l)
88
89