Is there any Java client example for the Update of a Google Prediction TrainedModel? - google-prediction

I am using the Google Prediction v1.5 Java Client with the "PredictionSample.java" sample program. I want to know that is there any jave example for creating the "com.google.api.services.prediction.model.Update" object. I have trained a model with the "language_id.txt" file and want to update the trained model using new training instances.
It seems that I could use
prediction.trainedmodels().update(String id, Update content)
to create a "com.google.api.services.prediction.model.Update" object,
but it is not clear how to use the "Update" object's "setCsvInstance" and "setOutput" methods to properly input a new training instance. Moreover, it's not clear how to differentiate "regression" numerical value from "classification" string value in "setOutput" method as this method seems only accept Java "String" value.
Could anyone suggest codes for this usage. Thanks for any suggestion.

I didn´t find any example too. But I implemented the following code in my application and it is working. Hope this helps.
final String label = "My Label";
final List<java.lang.Object> csvInstance = new ArrayList<Object>();
// add your model´s features related to your label
csvInstance.add( "feature1" );
csvInstance.add( "feature2" );
csvInstance.add( "feature3" );
final Update update = new Update();
update.setCsvInstance( csvInstance );
update.setOutput( label );
final Prediction prediction = new Prediction.Builder( httpTransport, jsonFactory, credential ).setApplicationName( applicationName ).build();
prediction.trainedmodels().update( projectNumber, modelId, update ).execute();

Related

Flutter GetX variable changes but UI does not

I have two RxLists containing custom models:
var openDepartures = RxList<Departure>([]);
var finishedDepartures = RxList<Departure>([]);
I bind a stream to populate these RxLists with values from firebase. Since my Stream(which I am binding to the variables) changes according to the user's choice, I bind the new stream to the same variable, but since that would result in two streams controlling one variable, I "reset" the variable before that:
openDepartures = RxList<Departure>();
finishedDepartures = RxList<Departure>();
....
openDepartures.bindStream(
Database().getOpenDepartures(
userController.userLocation.value,
),
);
finishedDepartures.bindStream(
Database().getFinishedDepartures(
userController.userLocation.value,
),
);
The problem is that the UI is not refreshing, but when I do not "reset" the variables, everything works fine. What's weird as well is that the variable does get populated with the correct data. It is just not shown in the UI.
What I have tried to fix that:
update() method
Get.reloadAll()
call .refresh() on the variables
disposing and initializing the controller again
My question is now, how do I get the screen to refresh, or does anyone have an idea how to bind a new stream without "resetting" the old one and having multiple streams on one variable?
I finally solved my problem. The underlying problem was that I was binding multiple streams to one variable and therefore the variable was updated whenever one of the streams fired. The solution was the following:
Create an RxList of the variable:
final _openDepartureList = RxList<RxList<Departure>>();
Create a getter for the last element of that list:
RxList<Departure> get openDepartures => _openDepartureList.last;
Remove the old items:
if (_openDepartureList.length >= 2) {
_openDepartureList.removeRange(0, _openDepartureList.length - 1);
}
Add an empty RxList to the List
_openDepartureList.add(RxList.empty());
Bind the stream to the last element of the List, hence the one just added
_openDepartureList.last.bindStream():
That was it! I now always have the right stream bound to the variable I want and do not have multiple streams controlling one variable.
use update() like
void() { foo = newData; update(); }
or use ProgressIndicator
like
RxBool loading = false.obs
void Foo() { loading.value = true; your logic... loading.value = false; }
and use controller.loading.value in UI for check progress and show when loading is complete

Meteor - Reactive Objects/Classes

TLDR
I like to really focus on keeping business logic away from the view model / controller. I find this sometimes rather hard in Meteor. Maybe I'm missing the point but I am after one of two things really:
1) A really good document explaining at a really low level how reactive values are being used.
2) A package that somehow manages an object so that if any of the setters are altered, they notify all of the get functions that would change as a result.
Unfortunately I've not seen either.
My Example
I have a fair bit ob business logic sitting behind a dialog used to document a consultation. I might have an event that sets a change of state.
I'd like to do something like this in the event:
const cc = new ConsultationEditor();
cc.setChiefComplaint(event.target.value);
console.log(cc.data());
ConsultationDict.set("consEdit", cc.data() );
When the user has updated this value, I'd then like to show a number of fields, based on the change. For this I have a helper with the following:
fields: function(){
console.log("trying to get fields");
const obj = ConsultationDict.get('consEdit');
cc = new ConsultationEditor(obj);
return cc.getFields();
}
But unfortunately this does not work for me.
What is your ConsultationDict?
The way you describe it, you want it to be a ReactiveDict as in the official ReactiveDict package.
https://atmospherejs.com/meteor/reactive-dict
Check this tutorial for examples:
https://themeteorchef.com/snippets/reactive-dict-reactive-vars-and-session-variables/
If you really need more fine tuning in your reactivity, you can also set a dependency tracker tracker = new Tracker.Dependency, and then refer to it wherever you change a variable with tracker.changed() and where the data needs to be notified with tracker.depend() like this:
var favoriteFood = "apples";
var favoriteFoodDep = new Tracker.Dependency;
var getFavoriteFood = function () {
favoriteFoodDep.depend();
return favoriteFood;
};
var setFavoriteFood = function (newValue) {
favoriteFood = newValue;
favoriteFoodDep.changed();
};
getFavoriteFood();
See the full Tracker doc here:
https://github.com/meteor/meteor/wiki/Tracker-Manual
I also found this gist to be useful to build reactive objects:
https://gist.github.com/richsilv/7d66269aab3552449a4c
and for a ViewModel type of behavior, check out
https://viewmodel.meteor.com/
I hope this helps.

access defects from HP quality center using com4j (java)

i have been able to connect with HP QC project using com4j.
But now i want to be able to access the Defects using filters.
I dont know the actual field names of all the fields as i do not have admin rights for QC, so i cannot go to customization tab.
I want to know, how can i retrieve a defect record and output that record's columns using fieldnames.
later i want to save those records in an excel file! but that is for later.
please help me up with the CODE !
MY PROGRESS:
import ota.*;
public class comqc {
public void login(){
ITDConnection4 td = ClassFactory.createTDConnection();
td.initConnectionEx("https://qcbt10.saas.hp.com/qcbin");
System.out.println(td.connected());
td.connectProjectEx("domain", "project", "user", "pass");
System.out.println(td.dbName());
IBugFactory bugfactory = td.bugFactory().queryInterface(IBugFactory.class);
ITDFilter fil = bugfactory.filter().queryInterface(ITDFilter.class);
ITDField field = bugfactory.fields().queryInterface(ITDField.class);
}
public static void main(String args[]){
comqc obj = new comqc();
obj.login();
}
}
Thanks in advance!
was able to retrieve the defect by their fieldname! used this code!
IBug bug = bugfactory.item(55203).queryInterface(IBug.class);
System.out.println(bug.assignedTo());
earlier i was trying the first expression with item(1) or item(2) etc, and it was giving an error!
'item index' value is actually the 'defect ID' for the bug, so just needed to enter the correct defect ID and it worked!
but i can print values for only limited number of columns for a bug, not all, FOR NOW (Maybe they are not the predefined fields) !

Multiple instances of views in PureMVC: Am I doing this right?

What I'm doing NOW:
Often multiple instances of the view component would be used in multiple places in an application. Each time I do this, I register the same mediator with a different name.
When a notification is dispatched, I attach the name of the mediator to the body of the notification, like so:
var obj:Object = new Object();
obj.mediatorName = this.getMediatorName();
obj.someParameter = someParameter;
sendNotification ("someNotification", obj);
Then in the Command class, I parse the notification body and store the mediatorName in the proxy.
var mediatorName:String = notification.getBody().mediatorName;
var params:String = notification.getBody().someParameter;
getProxy().someMethod(params, mediatorName);
On the return notification, the mediatorName is returned with it.
var obj:Object = new Object();
obj.mediatorName = mediatorName;
obj.someReturnedValue= someReturnedValue;
sendNotification ("someReturnedNotification", obj);
In the multiple mediators that might be watching for "someReturnedNotification," in the handleNotification(), it does an if statement, to see
if obj.mediatorName == this.getMediatorName
returns true. If so, process the info, if not, don't.
My Question is:
Is this the right way of using Multiton PureMVC? My gut feeling is not. I am sure there's a better way of architecting the application so that I don't have to test for the mediator's name to see if the component should be updated with the returned info.
Would someone please help and give me some direction as to what is a better way?
Thanks.
I checked with Cliff (the puremvc.org guy) and he said it's fine.

Committing new data to database via EF, Errors ensue with Attaching/Adding

So I'm starting out with EF on my website (C#) and Ive run into a bit of a snag. A user can either create or modify data and they will do that with the selection screen (page 1). If a user selects to create new data, I will perform the following code:
Program newProg = new Program();
using (DatabaseEntities context = new DatabaseEntities())
{
Guid id = new Guid(list.SelectedValue);
var itemString = from item in context.Set where item.Id == id select item;
Item selectedItem = itemString.ToList()[0];
newProg.Items.Add(selectedItem);
context.AddToProgramSet(newProg);
context.Detach(newProg);
}
Pretty much creating a new instance of the 'Program' which will be passed along each user control until the user is ready to submit to the database. At that point the following code will be executed:
using (DatabaseEntities context = new DatabaseEntities())
{
context.AddToProgramSet(this.SummaryControl.SelectedProgram);
context.SaveChanges();
}
Unfortunately when I get there, I receive the following message:
The object cannot be added to the ObjectStateManager because it already has an EntityKey. Use ObjectContext.Attach to attach an object that has an existing key.
at this line:
context.AddToProgramSet(this.SummaryControl.SelectedProgram);
Also, when I add the following line prior to the previous:
context.Attach(this.SummaryControl.SelectedProgram);
I get this error:
An object with a null EntityKey value cannot be attached to an object context.
Any help would be greatly appreciated. Thanks.
The root cause of this error is that you are attempting to add an Entity as a new Entity that already has its primary key set.
At what point do you add the Entities to your SummaryControl? Your first code snippet shows you adding the Entity:
...
newProg.Items.Add(selectedItem);
context.AddToProgramSet(newProg);
context.Detach(newProg);
...
Then you appear to add it again:
using (DatabaseEntities context = new DatabaseEntities())
{
context.AddToProgramSet(this.SummaryControl.SelectedProgram);
context.SaveChanges();
}
If newProg and this.SummaryControl.SelectedProgram are the same Entity, you've attempted to add it twice. Remove the context.AddToProgramSet(newProg); from the first snippet, do you work on the Entity, then add it to the ProgramSet.
Dave is right that the root cause is that the entity already has a primary key.
One thing that you do not show in your code is how:
Program newProg = new Program();
Becomes:
this.SummaryControl.SelectedProgram
One way that you could fix it is by saving newProg to the database before you start adding Items to it.

Resources