Skip to content

Commit

Permalink
Add outputs field to Component model
Browse files Browse the repository at this point in the history
Related-Issue: #34
  • Loading branch information
travelist committed Sep 27, 2015
1 parent e53c9cd commit 072ec66
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 34 deletions.
2 changes: 2 additions & 0 deletions cognitive/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.db import models
from django.core.validators import validate_email
from django.core.exceptions import ValidationError
from jsonfield import JSONField
import string
import random

Expand Down Expand Up @@ -169,6 +170,7 @@ class Component(models.Model):
execution_end_time = models.DateField(blank=True, null=True)
data_location = models.CharField(max_length=50, blank=True, null=True)
preferred_data_location = models.CharField(max_length=50, blank=True, null=True)
outputs = JSONField()
# component_id = models.IntegerField(blank=True, null=True)


Expand Down
2 changes: 2 additions & 0 deletions cognitive/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Meta:
fields = ('function_subtype', 'function_subtype_arg')
model = Data_operation_type


class ComponentSerializer(serializers.ModelSerializer):
type = serializers.SerializerMethodField('component_type')
params = serializers.SerializerMethodField('component_params')
Expand All @@ -62,6 +63,7 @@ def component_params(self, obj):
# TODO(|Less Priority| All Data_operation_type.function_subtype_arg values should be JSON)
return data


class WorkflowSerializer(serializers.ModelSerializer):

class Meta:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
.on("dragend", finishDrawingConnection));

g.append('text')
.attr('x', '{{node.x - 15}}')
.attr('y', '{{node.y - 5}}')
.attr('ng-attr-x', '{{node.x - 15}}')
.attr('ng-attr-y', '{{node.y - 5}}')
.attr('font-family', 'FontAwesome')
.attr('class', 'node close-icon')
.attr('node', '{{node.id}}')
Expand Down
17 changes: 15 additions & 2 deletions cognitive/app/view/view_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@
from rest_framework.renderers import JSONRenderer
from pandas import read_csv, datetime
import json
import re
import urllib2

MAX_COMPONENTS_PER_EXP = 100

def get_csv_fields(csv_data):
for line in re.split('\n|\r', csv_data):
if line == '':
continue
parsed_line = line.split(',')
return [{'id': i,'name': parsed_line[i]} for i in range(len(parsed_line))]
return []

#####
# Operation function_type function_arg function_subtype function_arg_id function_subtype_arg
# mathformula Update {comp_type} {op_type} {comp_id} {op_constant}
Expand All @@ -35,7 +44,6 @@
# input Create Table Input - {filename}
# machine learning Create Model {model_type} {Train-test} {ML arguments}


class OperationViewSet(viewsets.ViewSet):

def set_operation(self, operation, data):
Expand Down Expand Up @@ -178,9 +186,14 @@ def create(self, request, operation):
print "Experiment ", exp_id, " Operation ", operation
op = self.set_operation(operation, data)

outputs = []
if operation == 'input' and data["input_file_type"] == "csv":
outputs = get_csv_fields(data["data_values"])

component = Component(
experiment=exp, created_time=datetime.now(),
modified_time=datetime.now(), operation_type=op)
modified_time=datetime.now(), operation_type=op, outputs=outputs)

component.save()
serializer = ComponentSerializer(component)
return send_response("GET", serializer)
Expand Down
54 changes: 27 additions & 27 deletions cognitive/app/view/view_result_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ def run(self):
input_data, model_type, train_data_percentage,
input_features, target_feature)
output_data = classifier.learn()
except ValueError as e:
except ValueError:
status = "failure"
err_msg = " Invalid input for the model training"
except KeyError as e:
except KeyError:
status = "failure"
err_msg = target_feature + " column is not available for Model Training"

Expand All @@ -132,72 +132,72 @@ def run(self):
column_id = float(op.function_arg_id)
column_name = feature_names[column_id]
if column_name not in input_data:
#print "Column name ", column_name, " not present. Skipping"
#continue # throw error in module status
# print "Column name ", column_name, " not present. Skipping"
# continue # throw error in module status
status = "failure"
err_msg = column_name + " column is not available for current operation"
elif input_data[column_name].dtype == 'object':
#print "Column name ", column_name, " is not integer/float. Skipping"
#continue # throw error in module status
# print "Column name ", column_name, " is not integer/float. Skipping"
# continue # throw error in module status
status = "failure"
err_msg = " Invalid input in column "+ column_name+ " for the current operation"
err_msg = " Invalid input in column " + column_name + " for the current operation"
else:
input_data[column_name] += constant_value
if op.function_subtype == 'Sub':
constant_value = float(op.function_subtype_arg)
column_id = float(op.function_arg_id)
column_name = feature_names[column_id]
if column_name not in input_data:
#print "Column name ", column_name, " not present. Skipping"
#continue # throw error in module status
# print "Column name ", column_name, " not present. Skipping"
# continue # throw error in module status
status = "failure"
err_msg = column_name + " column is not available for current operation"
elif input_data[column_name].dtype == 'object':
#print "Column name ", column_name, " is not integer/float. Skipping"
#continue # throw error in module status
# print "Column name ", column_name, " is not integer/float. Skipping"
# continue # throw error in module status
status = "failure"
err_msg = " Invalid input in column "+ column_name+ " for the current operation"
err_msg = " Invalid input in column " + column_name + " for the current operation"
else:
input_data[column_name] -= constant_value
if op.function_subtype == 'Mult':
constant_value = float(op.function_subtype_arg)
column_id = float(op.function_arg_id)
column_name = feature_names[column_id]
if column_name not in input_data:
#print "Column name ", column_name, " not present. Skipping"
#continue # throw error in module status
# print "Column name ", column_name, " not present. Skipping"
# continue # throw error in module status
status = "failure"
err_msg = column_name + " column is not available for current operation"
elif input_data[column_name].dtype == 'object':
#print "Column name ", column_name, " is not integer/float. Skipping"
#continue # throw error in module status
# print "Column name ", column_name, " is not integer/float. Skipping"
# continue # throw error in module status
status = "failure"
err_msg = " Invalid input in column "+ column_name+ " for the current operation"
err_msg = " Invalid input in column " + column_name + " for the current operation"
else:
input_data[column_name] *= constant_value
if op.function_subtype == 'Div':
constant_value = float(op.function_subtype_arg)
column_id = float(op.function_arg_id)
column_name = feature_names[column_id]
if column_name not in input_data:
#print "Column name ", column_name, " not present. Skipping"
#continue # throw error in module status
# print "Column name ", column_name, " not present. Skipping"
# continue # throw error in module status
status = "failure"
err_msg = column_name + " column is not available for current operation"
elif input_data[column_name].dtype == 'object':
#print "Column name ", column_name, " is not integer/float. Skipping"
#continue # throw error in module status
# print "Column name ", column_name, " is not integer/float. Skipping"
# continue # throw error in module status
status = "failure"
err_msg = " Invalid input in column "+ column_name+ " for the current operation"
err_msg = " Invalid input in column " + column_name + " for the current operation"
else:
input_data[column_name] /= constant_value
if op.function_subtype == 'Normalize':
column_id = float(op.function_arg_id)
column_name = feature_names[column_id]
sum_array = input_data.sum(axis=0)
if column_name not in sum_array:
#print "Column name ", column_name, " not present. Skipping"
#continue # throw error in module status
# print "Column name ", column_name, " not present. Skipping"
# continue # throw error in module status
status = "failure"
err_msg = column_name + " column is not available for current operation"
else:
Expand All @@ -222,8 +222,8 @@ def run(self):
for elem in column_id_list:
column_name = feature_names[elem]
if column_name not in input_data:
#print "Column name ", column_name, " not present. Skipping"
#continue # throw error in module status
# print "Column name ", column_name, " not present. Skipping"
# continue # throw error in module status
status = "failure"
err_msg = column_name + " column is not available for current operation"
else:
Expand Down Expand Up @@ -330,7 +330,7 @@ def run(self):
if self.cache_results is True:
CACHE[self.experiment] = input_data

#print self.result
# print self.result
print self.result["status"]
print self.result["message"]
break
Expand Down
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
Django==1.7.1
Django>=1.7.1
django-rest-swagger>=0.2.9
Markdown==2.5.1
Pygments==2.0.1
django-bower==5.0.1
django-bower>=5.0.1
django-mptt==0.6.1
django-treebeard==2.0
djangorestframework==2.4.4
hamlpy==0.82.2
hamlpy>=0.82.2
jasmine==2.3.0
jasmine-core==2.3.4
jsonfield>=1.0.3
numpy==1.9.1
pandas==0.15.1
python-dateutil==2.2
Expand Down

0 comments on commit 072ec66

Please sign in to comment.