Skip to content

Commit

Permalink
added few more features to new ux
Browse files Browse the repository at this point in the history
  • Loading branch information
upul committed Feb 4, 2015
1 parent c846560 commit 5a211c2
Show file tree
Hide file tree
Showing 10 changed files with 423 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ public List<FeatureSummary> getDefaultFeatures(String datasetId, int startIndex,
* @return A list of feature names
* @throws DatabaseHandlerException
*/
public List<String> getFeatureNames(String workflowID, String featureType)
throws DatabaseHandlerException;
public List<String> getFeatureNames(String workflowID) throws DatabaseHandlerException;

/**
* Retrieve and returns the Summary statistics for a given feature of a
Expand Down Expand Up @@ -376,4 +375,13 @@ public void createNewWorkflow(String workflowID, String parentWorkflowID, String
* @throws DatabaseHandlerException
*/
public void updateWorkdflowName(String workflowId, String name) throws DatabaseHandlerException;

/**
*
* @param workflowId
* @param featureName
* @return
* @throws DatabaseHandlerException
*/
public String getFeatureType(String workflowId, String featureName) throws DatabaseHandlerException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -630,37 +630,30 @@ public List<FeatureSummary> getDefaultFeatures(String datasetId, int startIndex,
* (Categorical/Numerical), of the work-flow.
*
* @param workflowID Unique identifier of the current work-flow
* @param featureType Data-type of the feature
* @return A list of feature names
* @throws DatabaseHandlerException
*/
public List<String> getFeatureNames(String workflowID, String featureType)
throws DatabaseHandlerException {
public List<String> getFeatureNames(String workflowID) throws DatabaseHandlerException {
Connection connection = null;
PreparedStatement getFeatureNamesStatement = null;
ResultSet result = null;
List<String> featureNames = new ArrayList<String>();
try {
connection = dbh.getDataSource().getConnection();
connection.setAutoCommit(true);

// Create a prepared statement and retrieve data-set configurations.
getFeatureNamesStatement = connection.prepareStatement(SQLQueries.GET_FEATURE_NAMES);
getFeatureNamesStatement.setString(1, workflowID);
// Select the data type.
if (featureType.equalsIgnoreCase(FeatureType.CATEGORICAL)) {
getFeatureNamesStatement.setString(2, FeatureType.CATEGORICAL);
} else {
getFeatureNamesStatement.setString(2, FeatureType.NUMERICAL);
}

result = getFeatureNamesStatement.executeQuery();
// Convert the result in to a string array to e returned.
while (result.next()) {
featureNames.add(result.getString(1));
}
return featureNames;
} catch (SQLException e) {
throw new DatabaseHandlerException( "An error occurred while retrieving feature " +
"names of the dataset for workflow: " + workflowID + ": " + e.getMessage(), e);
throw new DatabaseHandlerException("An error occurred while retrieving feature "
+ "names of the dataset for workflow: " + workflowID + ": " + e.getMessage(), e);
} finally {
// Close the database resources.
MLDatabaseUtils.closeDatabaseResources(connection, getFeatureNamesStatement, result);
Expand Down Expand Up @@ -1603,4 +1596,34 @@ public void setDefaultFeatureSettings(String datasetID, String workflowID)
}
}

@Override
public String getFeatureType(String workflowId, String featureName) throws DatabaseHandlerException {
Connection connection = null;
PreparedStatement insertStatement = null;
PreparedStatement getDefaultFeatureSettings = null;
ResultSet result = null;

try {
MLDataSource dbh = new MLDataSource();
connection = dbh.getDataSource().getConnection();

getDefaultFeatureSettings = connection.prepareStatement(SQLQueries.GET_FEATURE_TYPE);
getDefaultFeatureSettings.setString(1, workflowId);
getDefaultFeatureSettings.setString(2, featureName);

result = getDefaultFeatureSettings.executeQuery();

if (result.first()) {
return result.getString(1);
} else {
throw new DatabaseHandlerException("Invalid workflow Id: " + workflowId);
}
} catch (SQLException e) {
throw new DatabaseHandlerException("An error occurred while reading dataset type of feature: "
+ featureName + " of workflow Id: " + workflowId + e.getMessage(), e);
} finally {
// Close the database resources.
MLDatabaseUtils.closeDatabaseResources(connection, insertStatement, result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*/
public class SQLQueries {

public static final String GET_FEATURE_NAMES = "SELECT FEATURE_NAME FROM ML_FEATURE_SETTINGS WHERE WORKFLOW_ID=?" +
" AND TYPE=? AND INCLUDE=TRUE";
public static final String GET_FEATURE_NAMES = "SELECT FEATURE_NAME FROM ML_FEATURE_SETTINGS WHERE WORKFLOW_ID=? AND INCLUDE=TRUE";

public static final String GET_FEATURES = "SELECT DEFAULT.FEATURE_NAME, DEFAULT.SUMMARY, WORKFLOW_SETTINGS.TYPE, " +
"WORKFLOW_SETTINGS.INCLUDE, WORKFLOW_SETTINGS.IMPUTE_METHOD FROM (SELECT FEATURE_NAME, SUMMARY FROM " +
Expand Down Expand Up @@ -132,6 +131,8 @@ public class SQLQueries {
public static final String INSERT_FEATURE_SETTINGS = "INSERT INTO ML_FEATURE_SETTINGS (WORKFLOW_ID, FEATURE_NAME," +
" FEATURE_INDEX, TYPE, IMPUTE_METHOD, INCLUDE) VALUES(?,?,?,?,?,?)";

public static final String GET_FEATURE_TYPE = "SELECT TYPE FROM ML_FEATURE_SETTINGS WHERE WORKFLOW_ID = ? AND FEATURE_NAME = ?";

/*
* private Constructor to prevent any other class from instantiating.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,10 @@ public List<FeatureSummary> getDefaultFeatures(String datasetId, int startIndex,
* (Categorical/Numerical), of the work-flow.
*
* @param workflowID Unique identifier of the current work-flow
* @param featureType Data-type of the feature
* @return A list of feature names
* @throws DatasetServiceException
*/
public List<String> getFeatureNames(String workflowID, String featureType)
throws DatasetServiceException;
public List<String> getFeatureNames(String workflowID) throws DatasetServiceException;

/**
* Returns data points of the selected sample as coordinates of three
Expand Down Expand Up @@ -203,4 +201,13 @@ public JSONArray getChartSamplePoints(String datasetID, String featureListString
* @throws DatasetServiceException
*/
public String getDatasetId(String projectId) throws DatasetServiceException, DatabaseHandlerException;

/**
*
* @param workflowId
* @param featureName
* @return
* @throws DatasetServiceException
*/
public String getFeatureType(String workflowId, String featureName) throws DatasetServiceException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,10 @@ public List<FeatureSummary> getDefaultFeatures(String datasetId, int startIndex,
* @throws DatasetServiceException
*/
@Override
public List<String> getFeatureNames(String workflowID, String featureType)
throws DatasetServiceException {
public List<String> getFeatureNames(String workflowID) throws DatasetServiceException {
try {
DatabaseService dbService = MLDatasetServiceValueHolder.getDatabaseService();
return dbService.getFeatureNames(workflowID, featureType);
return dbService.getFeatureNames(workflowID);
} catch (DatabaseHandlerException e) {
throw new DatasetServiceException("Failed to retrieve feature names: "
+ e.getMessage(), e);
Expand Down Expand Up @@ -445,4 +444,16 @@ public String getDatasetId(String projectId) throws DatasetServiceException {
" project id: " + projectId, ex);
}
}

@Override
public String getFeatureType(String workflowId, String featureName) throws DatasetServiceException {
try {
DatabaseService dbService = MLDatasetServiceValueHolder.getDatabaseService();
return dbService.getFeatureType(workflowId, featureName);

} catch (DatabaseHandlerException ex) {
throw new DatasetServiceException("An error occurred while reading dataset type of feature: " + featureName
+ " of workflow Id: " + workflowId + ex.getMessage(), ex);
}
}
}
6 changes: 3 additions & 3 deletions modules/jaggeryapps/ml/site/preprocess/preprocess.jag
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ $( document ).ready(function() {

$('#title').text(projna);

$('.prev-btn').on('click', function(e){
$('.btn-prev').on('click', function(e){
e.preventDefault();
window.location.href = '../exprore/exprore.jag?projid='+projid+'&projna='+projna+
'&wfid='+wfid+'&wfname='+wfname;
});

$('.next-btn').on('click', function(e){
$('.btn-next').on('click', function(e){
e.preventDefault();
window.location.href = '../algorithm/algorithm.jag?projid='+projid+'&projna='+projna+
window.location.href = '../questions/questions.jag?projid='+projid+'&projna='+projna+
'&wfid='+wfid+'&wfname='+wfname;
});

Expand Down
31 changes: 31 additions & 0 deletions modules/jaggeryapps/ml/site/questions/ajax/CreateWorkflow.jag
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<%
var log = new Log();
var carbon = require('carbon');
var uuid = require('uuid');

var prjMgntServ = carbon.server.osgiService('org.wso2.carbon.ml.project.mgt.ProjectManagementService');

var projectId = request.getParameter('projid');
var workflowName = request.getParameter('wfname');

response.contentType = 'application/json';

try {
workflowId = uuid.generate();
prjMgntServ.createNewWorkflow(workflowId, workflowId, projectId, workflowName);
prjMgntServ.setDefaultFeatureSettings(projectId, workflowId);

response.status = 200;
response.content = { wfid : workflowId };

} catch(e) {
var errorMessage = 'An error has occurred while creating workflow for project id: ' + projectId +
' error message: ' + e.message;

log.error(errorMessage);

response.status = 500;
response.content = { message : errorMessage };
}

%>
28 changes: 28 additions & 0 deletions modules/jaggeryapps/ml/site/questions/ajax/DeleteWorkflow.jag
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<%
var log = new Log();
var carbon = require('carbon');

var prjMgntServ = carbon.server.osgiService('org.wso2.carbon.ml.project.mgt.ProjectManagementService');
var workflowId = request.getParameter('wfid');

var statusCode = 200;
var statusMsg = '';

try {
prjMgntServ.deleteWorkflow(workflowId);
statusMsg = 'workflow : ' + workflowId + ' successfully deleted';

} catch(e) {
var msg = 'An error has occurred, while deleting workflow :' + workflowId + ' error message: ' + e.message;
log.error(msg);

statusMsg = msg;
statusCode = 500; // internal server error

} finally {
response.contentType = 'application/json';
response.content = {status: statusMsg};
response.status = statusCode;
}

%>
34 changes: 34 additions & 0 deletions modules/jaggeryapps/ml/site/questions/ajax/GetVariables.jag
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%
var log = new Log();
var carbon = require('carbon');
var uuid = require('uuid');

var datasetServ = carbon.server.osgiService('org.wso2.carbon.ml.dataset.DatasetService');
var wfid = request.getParameter('wfid');
log.info(wfid);

response.contentType = 'application/json';

try {

var featues = datasetServ.getFeatureNames(wfid);
var allFeatues = [];
for( var i=0; i<featues.size(); i++) {
allFeatues.push(featues.get(i));
}
log.info('len: '+ allFeatues);

response.status = 200;
response.content = { names : allFeatues };

} catch(e) {
var errorMessage = 'An error has occurred while extracting featues for workflow id: ' + wfid +
' error message: ' + e.message;

log.error(errorMessage);

response.status = 500;
response.content = { message : errorMessage };
}

%>
Loading

0 comments on commit 5a211c2

Please sign in to comment.