Commit b89e2c26 authored by bogdan's avatar bogdan

Merge branch 'dev' of workflow.ijs.si:mothra into searchFunct

parents 7dd33198 db580e10
......@@ -24,7 +24,7 @@ class DBConnection:
return sql.connect(user=self.user, password=self.password, host=self.host, database=self.database)
class DBContext:
def __init__(self, connection):
def __init__(self, connection, find_connections=False):
'''
Initializes the fields:
tables: list of selected tables
......@@ -36,7 +36,6 @@ class DBContext:
pkeys: private key for a given table
target_table: selected table for learning
target_att: selected column for learning
target_att_val: selected target att value
'''
self.connection = connection
con = connection.connect()
......@@ -54,18 +53,27 @@ class DBContext:
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]
print self.col_vals
self.connected = {}
cursor.execute(
"SELECT table_name, column_name, referenced_table_name, referenced_column_name \
FROM information_schema.KEY_COLUMN_USAGE \
WHERE referenced_table_name IS NOT NULL AND table_schema='%s'" % connection.database)
self.fkeys = defaultdict(set)
self.pkeys = {}
if find_connections:
for table in self.tables:
for col in self.cols[table]:
if col.endswith('_id'):
ref_table = (col[:-4] + 'ies') if col[-4] == 'y' else (col[:-3] + 's')
self.connected[(table, ref_table)] = (col, 'id')
self.connected[(ref_table, table)] = ('id', col)
self.fkeys[table].add(col)
if col == 'id':
self.pkeys[table] = col
for (table, col, ref_table, ref_col) in cursor:
self.connected[(table, ref_table)] = (col, ref_col)
self.connected[(ref_table, table)] = (ref_col, col)
self.fkeys[table].add(col)
self.pkeys = {}
cursor.execute(
"SELECT table_name, column_name \
FROM information_schema.KEY_COLUMN_USAGE \
......@@ -126,5 +134,7 @@ class DBContext:
return types
def __repr__(self):
return str((self.target_table, self.target_att, self.tables, self.cols, self.connected))
#import pprint
#return pprint.pformat((self.target_table, self.target_att, self.tables, self.cols, self.connected, self.pkeys, self.fkeys))
return 'fkeys : ' + str(self.fkeys)
[
{
"pk": 39,
"pk": 20,
"model": "workflows.category",
"fields": {
"uid": "b66b71b1-99d6-4efc-b264-a914a3e42911",
......@@ -12,10 +12,10 @@
}
},
{
"pk": 190,
"pk": 104,
"model": "workflows.abstractwidget",
"fields": {
"category": 39,
"category": 20,
"treeview_image": "",
"name": "Database Context",
"is_streaming": false,
......@@ -37,10 +37,10 @@
}
},
{
"pk": 443,
"pk": 213,
"model": "workflows.abstractinput",
"fields": {
"widget": 190,
"widget": 104,
"name": "connection",
"short_name": "con",
"uid": "6c23b4a2-a18e-498e-a22c-4de86932da3e",
......@@ -55,10 +55,28 @@
}
},
{
"pk": 216,
"pk": 236,
"model": "workflows.abstractinput",
"fields": {
"widget": 104,
"name": "Table connection from names",
"short_name": "tbc",
"uid": "be3718eb-062e-48f2-af2a-8c31e66524fe",
"default": "false",
"required": true,
"multi": false,
"parameter_type": "checkbox",
"variable": "find_connections",
"parameter": true,
"order": 1,
"description": "Tries to detect connections between tables solely by looking at the attribute names."
}
},
{
"pk": 117,
"model": "workflows.abstractoutput",
"fields": {
"widget": 190,
"widget": 104,
"name": "context",
"short_name": "cxt",
"variable": "context",
......@@ -68,10 +86,10 @@
}
},
{
"pk": 191,
"pk": 105,
"model": "workflows.abstractwidget",
"fields": {
"category": 39,
"category": 20,
"treeview_image": "",
"name": "Database To Aleph",
"is_streaming": false,
......@@ -93,10 +111,10 @@
}
},
{
"pk": 451,
"pk": 235,
"model": "workflows.abstractinput",
"fields": {
"widget": 191,
"widget": 105,
"name": "Target attribute value",
"short_name": "tgt",
"uid": "5b7354f1-35d8-41c8-a0ae-c3848855f29d",
......@@ -111,10 +129,10 @@
}
},
{
"pk": 444,
"pk": 214,
"model": "workflows.abstractinput",
"fields": {
"widget": 191,
"widget": 105,
"name": "context",
"short_name": "cxt",
"uid": "474e9673-9c55-48c5-bae8-a7b986aa0287",
......@@ -129,10 +147,10 @@
}
},
{
"pk": 217,
"pk": 118,
"model": "workflows.abstractoutput",
"fields": {
"widget": 191,
"widget": 105,
"name": "pos_examples",
"short_name": "pex",
"variable": "pos_examples",
......@@ -142,10 +160,10 @@
}
},
{
"pk": 218,
"pk": 119,
"model": "workflows.abstractoutput",
"fields": {
"widget": 191,
"widget": 105,
"name": "neg_examples",
"short_name": "nex",
"variable": "neg_examples",
......@@ -155,10 +173,10 @@
}
},
{
"pk": 219,
"pk": 120,
"model": "workflows.abstractoutput",
"fields": {
"widget": 191,
"widget": 105,
"name": "bk",
"short_name": "bk",
"variable": "bk",
......@@ -168,10 +186,10 @@
}
},
{
"pk": 192,
"pk": 106,
"model": "workflows.abstractwidget",
"fields": {
"category": 39,
"category": 20,
"treeview_image": "",
"name": "Database To Orange Table",
"is_streaming": false,
......@@ -193,10 +211,10 @@
}
},
{
"pk": 445,
"pk": 215,
"model": "workflows.abstractinput",
"fields": {
"widget": 192,
"widget": 106,
"name": "context",
"short_name": "cxt",
"uid": "1f9b5ccf-65c3-4ccc-818e-afb3a6ffee20",
......@@ -211,10 +229,10 @@
}
},
{
"pk": 220,
"pk": 121,
"model": "workflows.abstractoutput",
"fields": {
"widget": 192,
"widget": 106,
"name": "Data table",
"short_name": "odt",
"variable": "dataset",
......@@ -224,10 +242,10 @@
}
},
{
"pk": 193,
"pk": 107,
"model": "workflows.abstractwidget",
"fields": {
"category": 39,
"category": 20,
"treeview_image": "",
"name": "Database To RSD",
"is_streaming": false,
......@@ -249,10 +267,10 @@
}
},
{
"pk": 446,
"pk": 216,
"model": "workflows.abstractinput",
"fields": {
"widget": 193,
"widget": 107,
"name": "context",
"short_name": "cxt",
"uid": "4f1397a8-4e72-4b34-b31d-d09bf9a7e7d9",
......@@ -267,10 +285,10 @@
}
},
{
"pk": 221,
"pk": 122,
"model": "workflows.abstractoutput",
"fields": {
"widget": 193,
"widget": 107,
"name": "examples",
"short_name": "exm",
"variable": "examples",
......@@ -280,10 +298,10 @@
}
},
{
"pk": 222,
"pk": 123,
"model": "workflows.abstractoutput",
"fields": {
"widget": 193,
"widget": 107,
"name": "bk",
"short_name": "bk",
"variable": "bk",
......@@ -293,10 +311,10 @@
}
},
{
"pk": 194,
"pk": 108,
"model": "workflows.abstractwidget",
"fields": {
"category": 39,
"category": 20,
"treeview_image": "",
"name": "MySQL Connect",
"is_streaming": false,
......@@ -318,10 +336,10 @@
}
},
{
"pk": 447,
"pk": 217,
"model": "workflows.abstractinput",
"fields": {
"widget": 194,
"widget": 108,
"name": "user",
"short_name": "usr",
"uid": "0f36f10b-066f-4ad3-9fa8-39205440076a",
......@@ -336,10 +354,10 @@
}
},
{
"pk": 448,
"pk": 218,
"model": "workflows.abstractinput",
"fields": {
"widget": 194,
"widget": 108,
"name": "password",
"short_name": "pwd",
"uid": "8ead911a-3d1b-4e50-b56a-64873b85d3cf",
......@@ -354,10 +372,10 @@
}
},
{
"pk": 449,
"pk": 219,
"model": "workflows.abstractinput",
"fields": {
"widget": 194,
"widget": 108,
"name": "host",
"short_name": "hst",
"uid": "9812cc11-b21e-4444-8dfe-bc0c68fe79e8",
......@@ -372,10 +390,10 @@
}
},
{
"pk": 450,
"pk": 220,
"model": "workflows.abstractinput",
"fields": {
"widget": 194,
"widget": 108,
"name": "database",
"short_name": "db",
"uid": "d132adce-c3ec-411a-8ee7-906be4a99f61",
......@@ -390,10 +408,10 @@
}
},
{
"pk": 223,
"pk": 124,
"model": "workflows.abstractoutput",
"fields": {
"widget": 194,
"widget": 108,
"name": "connection",
"short_name": "con",
"variable": "connection",
......
......@@ -9,11 +9,11 @@ from context import DBContext
def mysql_db_context(request, input_dict, output_dict, widget):
con = input_dict['connection']
initial_context = DBContext(con)
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)
col_vals_dump = json.dumps(initial_context.col_vals)
return render(request, 'interactions/db_context.html', {'widget':widget, 'context': initial_context, 'target_cols' : initial_target_cols, 'cols' : cols_dump, 'col_vals' : col_vals_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, 'target_col_vals' : initial_target_col_vals})
......@@ -43,8 +43,6 @@
<script type="text/javascript">
// Columns data.
var cols = {{cols|safe}};
//var col_vals = {{col_vals|safe}};
console.log(col_vals);
$('select[name="target_table{{widget.pk}}"]').change(function () {
var selected_table = $(this).first('option:selected').val();
var available_cols = cols[selected_table];
......
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