-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[tradeoff-analytics] Call to dilemmas() failing in Google stack #306
Comments
package com.ibm.watson.developer_cloud.tradeoff_analytics.v1;
import com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.Dilemma;
import com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.Option;
import com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.Problem;
import com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.column.Column;
import com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.column.Column.Goal;
import com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.column.NumericColumn;
import com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.column.CategoricalColumn;
import com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.column.DateColumn;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class TradeoffAnalyticsExample {
public static void main(String[] args) {
TradeoffAnalytics service = new TradeoffAnalytics();
service.setUsernameAndPassword("username",
"password");
// Define the objectives.
String price = "price";
String weight = "weight";
String brand = "brand";
String rDate = "rDate";
List<String> categories = new ArrayList<String>();
categories.add("Apple");
categories.add("HTC");
categories.add("Samsung");
List<String> preferences = new ArrayList<String>();
preferences.add("Samsung");
preferences.add("Apple");
preferences.add("HTC");
NumericColumn priceColumn = new NumericColumn();
priceColumn.withKey(price);
priceColumn.withGoal(Goal.MIN);
priceColumn.withObjective(true);
priceColumn.withFullName("Price");
priceColumn.withRange(0, 400);
priceColumn.setFormat("number:2");
NumericColumn weightColumn = new NumericColumn();
weightColumn.withKey(weight);
weightColumn.withGoal(Goal.MIN);
weightColumn.withObjective(true);
weightColumn.withFullName("Weight");
weightColumn.setFormat("number:0");
CategoricalColumn brandColumn = new CategoricalColumn();
brandColumn.withKey(brand);
brandColumn.withGoal(Goal.MIN);
brandColumn.withObjective(true);
brandColumn.withFullName("Brand");
brandColumn.setRange(categories);
brandColumn.setPreference(preferences);
DateColumn rDateColumn = new DateColumn();
rDateColumn.withKey(rDate);
rDateColumn.withGoal(Goal.MAX);
rDateColumn.withFullName("Release Date");
rDateColumn.setFormat("date: 'MMM dd, yyyy'");
List<Column> columns = new ArrayList<Column>();
columns.add(priceColumn);
columns.add(weightColumn);
columns.add(brandColumn);
columns.add(rDateColumn);
Problem problem = new Problem("phones");
problem.setColumns(columns);
/*
columns.add(new NumericColumn().withKey(price).withGoal(Goal.MIN)
.withObjective(true).withFullName("Price").withRange(0, 400)
.withFormat("number:2"));
columns.add(new NumericColumn().withKey(weight).withGoal(Goal.MIN)
.withObjective(true).withFullName("Weight")
.withFormat("number:0"));
columns.add(new CategoricalColumn().withKey(brand).withGoal(Goal.MIN)
.withObjective(true).withFullName("Brand")
.withRange(categories)
.withPreference("Samsung", "Apple", "HTC"));
columns.add(new DateColumn().withKey(rDate).withGoal(Goal.MAX)
.withFullName("Release Date")
.withFormat("date: 'MMM dd, yyyy'"));
*/
// Define the options.
List<Option> options = new ArrayList<Option>();
problem.setOptions(options);
HashMap<String, Object> galaxySpecs = new HashMap<String, Object>();
galaxySpecs.put(price, 249);
galaxySpecs.put(weight, 130);
galaxySpecs.put(brand, "Samsung");
galaxySpecs.put(rDate, "2013-04-29T00:00:00Z");
options.add(new Option("1", "Samsung Galaxy S4").withValues(galaxySpecs));
HashMap<String, Object> iphoneSpecs = new HashMap<String, Object>();
iphoneSpecs.put(price, 449);
iphoneSpecs.put(weight, 112);
iphoneSpecs.put(brand, "Apple");
iphoneSpecs.put(rDate, "2012-09-21T00:00:00Z");
options.add(new Option("2", "Apple iPhone 5").withValues(iphoneSpecs));
HashMap<String, Object> oneSpecs = new HashMap<String, Object>();
oneSpecs.put(price, 299);
oneSpecs.put(weight, 143);
oneSpecs.put(brand, "HTC");
oneSpecs.put(rDate, "2013-03-01T00:00:00Z");
options.add(new Option("3", "HTC One").withValues(oneSpecs));
// Call the service and get the resolution
Dilemma dilemma = service.dilemmas(problem, false);
System.out.println(dilemma);
}
} |
This is a problem that was fixed in |
This issue is occurring with 3.6.0 also. Unable to invoke no-args constructor for class com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.column.Column. Register an InstanceCreator with Gson for this type may fix this problem.
|
The following simple Tradeoff Analytics Java program (renamed for attachment)TradeoffAnalyticsExample.txt appears to be valid. But it elicits a JsonParseException:
The JSON object that is failing appears to be valid. German's initial diagnosis was
The error is probably the service response. The TA team may have changed the response and that breaks the Java SDK because it can't transform the JSON into a POJO. The problem is on my side. I will probably switch the date column to be String instead of trying to parse it.
I also mentioned the following, probably gratuitous, points in email, which I include here just for the sake of completeness.:
German, I failed to mention this on yesterday's call, but the format field is really just a passthru to the widget. The service itself doesn't use or interpret the field at all; it just sends it as-is to the widget. The same is true for the full_name and description fields of columns and for the name, description_html, and app_data fields of options. So you can probably just ignore whatever is in these fields entirely as long as they're defined as valid JSON strings or, for app_data, as key/value pairs.
Testing with java-sdk-2.10.0-jar-with-dependencies.jar.
The text was updated successfully, but these errors were encountered: