interaction_views.py 2.7 KB
Newer Older
1
import sys
Janez K's avatar
Janez K committed
2
from django.shortcuts import render
3

4
from workflows import module_importer
5 6
def setattr_local(name, value, package):
    setattr(sys.modules[__name__], name, value)
7
module_importer.import_all_packages_libs("interaction_views",setattr_local)
Janez K's avatar
Janez K committed
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

def test_interaction(request,input_dict,output_dict,widget):
    return render(request, 'interactions/test_interaction.html',{'widget':widget})

def filter_integers(request,input_dict,output_dict,widget):
    return render(request, 'interactions/filter_integers.html',{'widget':widget,'integers':input_dict['integers']})
    
def noiserankview(request,input_dict,output_dict,widget):
    dataset = input_dict['data']
    allnoise = output_dict['allnoise']
    return render(request, 'interactions/noise_rank.html',{'widget':widget,'allnoise':allnoise, 'data': dataset})    
    
def select_attrs(request, input_dict, output_dict, widget):
    import orange, Orange
    data = Orange.data.Table(input_dict['data'])
    d = data.domain

    classes = d.class_var.name

    metas = []
    for m in d.getmetas().values():
        metas.append(str(m.name))

    attrs = {}
    for a in d.attributes:
        attrs[a.name] = a.varType    
        
    sorted_attrs = sorted(attrs.items())        

    input_dict = {'ca':classes, 'ma':metas, 'attrs':attrs, 'data':input_dict['data'],'sorted_attrs':sorted_attrs}
    return render(request, 'interactions/select_attrs.html',{'widget':widget, 'input_dict':input_dict})

def select_data(request, input_dict, output_dict, widget):
    
    import Orange

    data = Orange.data.Table(input_dict['data'])

    attrs = {}

    for a in data.domain.variables:
        values = []
        try:
            for v in a.values:
                values.append(v)
        except:
            pass
 
        attrs[a.name] = {'feature':1, 'type':str(a.var_type), 'values':values}

    for a in data.domain.get_metas():
        meta = data.domain.get_meta(a)
        
        values = []
        try:
            for v in meta.values:
                values.append(v)
        except:
            pass

        attrs[meta.name] = {'feature':0, 'type':str(meta.var_type), 'values':values}

    sorted_attrs = sorted(attrs.items())
    input_dict = {'data': data, 'attrs':attrs, 'sorted_attrs':sorted_attrs}
    return render(request, 'interactions/select_data.html',{'widget':widget, 'input_dict':input_dict})
    
74 75 76 77
def alter_table(request, input_dict, output_dict, widget):
    from visualization_views import orng_table_to_dict
    data = input_dict['data']
    return render(request, 'interactions/alter_table.html', {'widget' : widget,'input_dict' : input_dict,'output_dict' : orng_table_to_dict(data)})