Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/hecke_algebras/hecke_algebras.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_algebras = C['hecke_algebras'].hecke_algebras
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
49
hecke_algebras.create_index('level')
50
hecke_algebras.create_index('weight')
51
hecke_algebras.create_index('num_orbits')
52
hecke_algebras.create_index('label')
53
54
print("finished indices")
55
56
57
## Main importing function
58
59
def do_import(ll):
60
level,weight,num_orbits,label = ll
61
mykeys = ['level','weight','num_orbits','label']
62
data = {}
63
for j in range(len(mykeys)):
64
data[mykeys[j]] = ll[j]
65
66
alg = hecke_algebras.find_one({'label': label})
67
68
if alg is None:
69
print("new hecke algebra")
70
alg = data
71
else:
72
print("hecke algebra already in the database")
73
alg.update(data)
74
if saving:
75
hecke_algebras.update({'label': label} , {"$set": alg}, upsert=True)
76
77
78
79
# Loop over files
80
81
for path in sys.argv[1:]:
82
print(path)
83
filename = os.path.basename(path)
84
fn = gzip.open(path) if filename[-3:] == '.gz' else open(path)
85
for line in fn.readlines():
86
line.strip()
87
if re.match(r'\S',line):
88
l = json.loads(line)
89
do_import(l)
90
91