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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
from django.core import serializers
from models import Equation, Variable, Symbol
from django.http import HttpResponse
def all_variables(request):
data = serializers.serialize("json", Variable.objects.all())
return HttpResponse(data, mimetype="text/javascript")
def all_symbols(request):
data = serializers.serialize("json", Symbol.objects.all())
return HttpResponse(data, mimetype="text/javascript")
def equs_by_vars(request, whichvars):
vars = whichvars.split(',')
if len(vars) < 1 or whichvars == '':
return HttpResponse('[]', mimetype="text/javascript")
if vars[-1] == '/' or vars[-1] == '':
vars = vars[:-1]
returnables = Equation.objects.filter(variables=vars[0])
if len(vars) > 1:
for r in returnables:
for i in vars[1:]:
if len(r.variables.filter(id=i)) == 0:
returnables = returnables.exclude(id=r.id)
if len(returnables) < 1:
break
data = serializers.serialize("json", returnables)
return HttpResponse(data, mimetype="text/javascript")
def vars_by_symbs(request, which_symbols):
vars = which_symbols.split(',')
if len(vars) < 1 or which_symbols == '':
return HttpResponse('[]', mimetype="text/javascript")
if vars[-1] == '/' or vars[-1] == '':
vars = vars[:-1]
#vkeys = list()
returnables = list()
for v in vars:
returnables.append([r for r in Symbol.get_by_id(int(v)).variable_set.run()])
print returnables
#vkeys.append(str(Symbol.get_by_id(int(v)).key()))
#returnables = Variable.objects.all().filter('symbol IN ', vkeys).run()
data = [serializers.serialize("json", r) for r in returnables]
return HttpResponse(data, mimetype="text/javascript")
#return HttpResponse(returnables, mimetype="text/javascript")
def import_symbols(filename):
infile = open(filename)
stuff = infile.readlines()
infile.close()
l = eval(stuff[0])
for symb in l:
vals = symb['fields']
newsymb = Symbol(latex=vals['latex'], unicode=vals['unicode'],
name=vals['name'])
newsymb.save()
def import_equations(filename):
infile = open(filename)
stuff = infile.readlines()
infile.close()
l = eval(stuff[0])
for symb in l:
vals = symb['fields']
newsymb = Symbol(latex=vals['latex'], unicode=vals['unicode'],
name=vals['name'])
newsymb.save()
def import_variables(filename):
infile = open(filename)
stuff = infile.readlines()
infile.close()
l = eval(stuff[0], {'true':True, 'false':False})
for vari in l:
vals = vari['fields']
newvar = Variable(latex=vals['latex'], unicode=vals['unicode'],
name=vals['name'], description=vals['description'],
reference=vals['reference'])
newvar.save()
def match_var_symb():
vs = Variable.objects.all().run()
for v in vs:
try:
vname = v.name.split("Generic ")[1]
s = Symbol.all().filter('name =', vname).run().next()
v.symbol = s
v.save()
except:
print "Error assigning symbol to value: %s " % v
|