Commit 4154207f authored by Anze Vavpetic's avatar Anze Vavpetic
Browse files

fixed a bug when converting to internal orange tables

parent 5b5ad6c7
......@@ -4,6 +4,7 @@ from django.db.models.signals import post_save
import workflows.library
import time
import random
from picklefield.fields import PickledObjectField
......@@ -215,7 +216,7 @@ class Workflow(models.Model):
#check if we have an input
input_seed = int(fi.outputs.all()[2].outer_input.value)
else:
input_seed = 0
input_seed = random.randint(0, 10**9)
# Special case when reading from a DB
input_type = input_list.__class__.__name__
......@@ -236,7 +237,7 @@ class Workflow(models.Model):
if hasattr(input_list, "get_items_ref"):
import orange
# Orange table on input, so we cannot do slices
indices = orange.MakeRandomIndicesCV(input_list, randseed=input_seed, folds=input_fold)
indices = orange.MakeRandomIndicesCV(input_list, randseed=input_seed, folds=input_fold, stratified=orange.MakeRandomIndices.Stratified)
for i in range(input_fold):
output_train = input_list.select(indices, i, negate=1)
output_test = input_list.select(indices, i)
......@@ -264,7 +265,6 @@ class Workflow(models.Model):
if hasattr(input_list, "get_items_ref"):
output_test = folds[i][1]
output_train = folds[i][0]
print len(output_train), len(output_test)
else:
output_train = folds[:i] + folds[i+1:]
output_test = folds[i]
......@@ -281,11 +281,9 @@ class Workflow(models.Model):
fo.unfinish() # resets widgets, (read all widgets.finished=false)
proper_output = fi.outputs.all()[0] # inner output
proper_output.value = output_train
print len(output_train.orng_tables[context.target_table])
proper_output.save()
proper_output = fi.outputs.all()[1] # inner output
proper_output.value = output_test
print len(output_test.orng_tables[context.target_table])
proper_output.save()
fi.finished=True # set the input widget as finished
fi.save()
......
......@@ -94,15 +94,16 @@ class DBContext:
con.close()
self.orng_tables = None
if in_memory:
self.orng_tables = self.read_into_orange()
self.in_memory = in_memory
def read_into_orange(self):
conv = converters.Orange_Converter(self)
tables = {
self.target_table: conv.target_Orange_table()
}
tables.update(zip(self.tables[1:], conv.other_Orange_tables()))
other_tbl_names = [table for table in self.tables if table != self.target_table]
other_tables = dict(zip(other_tbl_names, conv.other_Orange_tables()))
tables.update(other_tables)
return tables
def update(self, postdata):
......@@ -128,6 +129,8 @@ class DBContext:
self.cols[table] = postdata.get('%s_columns%s' % (table, widget_id), [])
if table == self.target_table and self.target_att not in self.cols[table]:
raise Exception('The selected target attribute ("%s") is not among the columns selected for the target table ("%s").' % (self.target_att, self.target_table))
if self.in_memory:
self.orng_tables = self.read_into_orange()
def fmt_cols(self, cols):
return ','.join(["`%s`" % col for col in cols])
......
......@@ -228,11 +228,10 @@ class Orange_Converter(Converter):
def target_Orange_table(self):
table, cls_att = self.db.target_table, self.db.target_att
return self.convert_table(table, cls_att)
return self.convert_table(table, cls_att=cls_att)
def other_Orange_tables(self):
target_table = self.db.target_table
return[ self.convert_table(table,None) for table in self.db.tables if table!=target_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