Commit 1a015c90 authored by Matic Perovšek's avatar Matic Perovšek
Browse files

- traceback v konzoli za errorje

- premaknjeno iskanje vseh vrednosti iz Database Context v Database to Orange Table
parent 4126b009
......@@ -48,11 +48,7 @@ class DBContext:
self.cols[table] = [col for (col,) in cursor]
self.all_cols = dict(self.cols)
self.col_vals = {}
for table, cols in self.cols.items():
self.col_vals[table] = {}
for col in cols:
cursor.execute("SELECT DISTINCT `%s` FROM `%s` LIMIT 51" % (col, table))
self.col_vals[table][col] = [val for (val,) in cursor]
self.connected = {}
cursor.execute(
"SELECT table_name, column_name, referenced_table_name, referenced_column_name \
......@@ -133,6 +129,20 @@ class DBContext:
con.close()
return types
def compute_col_vals(self):
import time
con = self.connection.connect()
cursor = con.cursor()
for table, cols in self.cols.items():
self.col_vals[table] = {}
now=time.time()
for col in cols:
cursor.execute("SELECT DISTINCT `%s` FROM `%s`" % (col, table))
print str(table),str(col),str(time.time()-now)
self.col_vals[table][col] = [val for (val,) in cursor]
now=time.time()
con.close()
def __repr__(self):
#import pprint
#return pprint.pformat((self.target_table, self.target_att, self.tables, self.cols, self.connected, self.pkeys, self.fkeys))
......
......@@ -181,12 +181,14 @@ class Orange_Converter(Converter):
def __init__(self, *args, **kwargs):
Converter.__init__(self, *args, **kwargs)
self.types = self.db.fetch_types(self.db.target_table, self.db.cols[self.db.target_table])
self.db.compute_col_vals()
def target_table(self):
'''
Returns the target table as an orange example table.
'''
import orange
import string
from mysql.connector import FieldType
table, cls_att = self.db.target_table, self.db.target_att
cols = self.db.cols[table]
......@@ -195,7 +197,7 @@ class Orange_Converter(Converter):
att_type = self.orng_type(col)
if att_type == 'd':
att_vals = self.db.col_vals[table][col]
att_var = orange.EnumVariable(str(col), values=[str(val) for val in att_vals])
att_var = orange.EnumVariable(str(col), values=[str(val).encode('ascii', 'ignore') for val in att_vals])
elif att_type == 'c':
att_var = orange.FloatVariable(str(col))
else:
......@@ -213,10 +215,14 @@ class Orange_Converter(Converter):
for meta in metas:
domain.addmeta(orange.newmetaid(), meta)
dataset = orange.ExampleTable(domain)
aa=[a for a in domain.attributes[1].values if a[0]=="G" and len(a)>2 and a[1]=="o"and a[2]=="n"]
#print domain['last_name'].values
print 'Gonzalez' in [a.name for a in domain['last_name'].values]
for row in self.db.rows(table, cols):
example = orange.Example(domain)
for col, val in zip(cols, row):
example[str(col)] = str(val)
example[str(col)] = str(val).encode('ascii', 'ignore')
dataset.append(example)
return dataset
......
......@@ -12,8 +12,7 @@ def mysql_db_context(request, input_dict, output_dict, widget):
find_con = input_dict['find_connections'] == 'true'
initial_context = DBContext(con, find_connections=find_con)
initial_target_cols = initial_context.cols[initial_context.target_table]
initial_target_col_vals = initial_context.col_vals[initial_context.target_table][initial_target_cols[0]]
cols_dump = json.dumps(initial_context.cols)
return render(request, 'interactions/db_context.html', {'widget':widget, 'context': initial_context, 'target_cols' : initial_target_cols, 'cols' : cols_dump, 'target_col_vals' : initial_target_col_vals})
return render(request, 'interactions/db_context.html', {'widget':widget, 'context': initial_context, 'target_cols' : initial_target_cols, 'cols' : cols_dump})
......@@ -9,6 +9,7 @@ from workflows.helpers import *
import workflows.interaction_views
import workflows.visualization_views
import sys
import traceback
# modeli
from workflows.models import *
......@@ -810,13 +811,15 @@ def run_widget(request):
data = simplejson.dumps({'status':'ok','message':'Widget '+w.name+' executed successfully.'})
else:
data = simplejson.dumps({'status':'ok','message':'Widget '+w.name+' executed successfully.'})
except:
except Exception,e:
mimetype = 'application/javascript'
w.error = True
w.running = False
w.finished = False
w.save()
print traceback.format_exc(e)
#raise
for o in w.outputs.all():
o.value=None
......@@ -855,6 +858,7 @@ def run_tree(request):
w.running = False
w.finished = False
w.save()
print traceback.format_exc(e)
raise
for o in w.outputs.all():
o.value=None
......@@ -882,8 +886,6 @@ def reset_widget(request):
w.running = False
w.finished = False
w.save()
import traceback
print "asdfasdf"
print traceback.format_exc(e)
raise
......@@ -1111,13 +1113,14 @@ def finish_interaction(request):
w.save()
mimetype = 'application/javascript'
data = simplejson.dumps({'status':'ok','message':'Widget '+w.name+' executed successfully.','widget_id':w.id})
except:
except Exception,e:
mimetype = 'application/javascript'
w.error = True
w.running = False
w.finished = False
w.interaction_waiting = False
w.save()
print traceback.format_exc(e)
raise
for o in w.outputs.all():
o.value=None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment