Skip to content

Commit 14fefbd

Browse files
committed
feat(Visual Recognition v4): Add getTrainingUsage method
1 parent ee3298d commit 14fefbd

File tree

4 files changed

+357
-5
lines changed

4 files changed

+357
-5
lines changed

visual-recognition/src/main/java/com/ibm/watson/visual_recognition/v4/VisualRecognition.java

+46-5
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@
3636
import com.ibm.watson.visual_recognition.v4.model.GetCollectionOptions;
3737
import com.ibm.watson.visual_recognition.v4.model.GetImageDetailsOptions;
3838
import com.ibm.watson.visual_recognition.v4.model.GetJpegImageOptions;
39+
import com.ibm.watson.visual_recognition.v4.model.GetTrainingUsageOptions;
3940
import com.ibm.watson.visual_recognition.v4.model.ImageDetails;
4041
import com.ibm.watson.visual_recognition.v4.model.ImageDetailsList;
4142
import com.ibm.watson.visual_recognition.v4.model.ImageSummaryList;
4243
import com.ibm.watson.visual_recognition.v4.model.ListCollectionsOptions;
4344
import com.ibm.watson.visual_recognition.v4.model.ListImagesOptions;
4445
import com.ibm.watson.visual_recognition.v4.model.TrainOptions;
4546
import com.ibm.watson.visual_recognition.v4.model.TrainingDataObjects;
47+
import com.ibm.watson.visual_recognition.v4.model.TrainingEvents;
4648
import com.ibm.watson.visual_recognition.v4.model.UpdateCollectionOptions;
4749
import java.io.InputStream;
4850
import java.util.Map;
@@ -53,11 +55,6 @@
5355
* Provide images to the IBM Watson™ Visual Recognition service for analysis. The service detects objects based on
5456
* a set of images with training data.
5557
*
56-
* **Beta:** The Visual Recognition v4 API and Object Detection model are beta features. For more information about beta
57-
* features, see the [Release
58-
* notes](https://cloud.ibm.com/docs/services/visual-recognition?topic=visual-recognition-release-notes#beta).
59-
* {: important}.
60-
*
6158
* @version v4
6259
* @see <a href=
6360
* "https://cloud.ibm.com/docs/services/visual-recognition?topic=visual-recognition-object-detection-overview">
@@ -560,6 +557,50 @@ public ServiceCall<TrainingDataObjects> addImageTrainingData(
560557
return createServiceCall(builder.build(), responseConverter);
561558
}
562559

560+
/**
561+
* Get training usage.
562+
*
563+
* Information about the completed training events. You can use this information to determine how close you are to the
564+
* training limits for the month.
565+
*
566+
* @param getTrainingUsageOptions the {@link GetTrainingUsageOptions} containing the options for the call
567+
* @return a {@link ServiceCall} with a response type of {@link TrainingEvents}
568+
*/
569+
public ServiceCall<TrainingEvents> getTrainingUsage(GetTrainingUsageOptions getTrainingUsageOptions) {
570+
String[] pathSegments = { "v4/training_usage" };
571+
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getServiceUrl(), pathSegments));
572+
builder.query("version", versionDate);
573+
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "getTrainingUsage");
574+
for (Entry<String, String> header : sdkHeaders.entrySet()) {
575+
builder.header(header.getKey(), header.getValue());
576+
}
577+
builder.header("Accept", "application/json");
578+
if (getTrainingUsageOptions != null) {
579+
if (getTrainingUsageOptions.startTime() != null) {
580+
builder.query("start_time", String.valueOf(getTrainingUsageOptions.startTime()));
581+
}
582+
if (getTrainingUsageOptions.endTime() != null) {
583+
builder.query("end_time", String.valueOf(getTrainingUsageOptions.endTime()));
584+
}
585+
}
586+
ResponseConverter<TrainingEvents> responseConverter = ResponseConverterUtils.getValue(
587+
new com.google.gson.reflect.TypeToken<TrainingEvents>() {
588+
}.getType());
589+
return createServiceCall(builder.build(), responseConverter);
590+
}
591+
592+
/**
593+
* Get training usage.
594+
*
595+
* Information about the completed training events. You can use this information to determine how close you are to the
596+
* training limits for the month.
597+
*
598+
* @return a {@link ServiceCall} with a response type of {@link TrainingEvents}
599+
*/
600+
public ServiceCall<TrainingEvents> getTrainingUsage() {
601+
return getTrainingUsage(null);
602+
}
603+
563604
/**
564605
* Delete labeled data.
565606
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* (C) Copyright IBM Corp. 2019.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.ibm.watson.visual_recognition.v4.model;
14+
15+
import java.util.Date;
16+
17+
import com.ibm.cloud.sdk.core.service.model.GenericModel;
18+
19+
/**
20+
* The getTrainingUsage options.
21+
*/
22+
public class GetTrainingUsageOptions extends GenericModel {
23+
24+
private Date startTime;
25+
private Date endTime;
26+
27+
/**
28+
* Builder.
29+
*/
30+
public static class Builder {
31+
private Date startTime;
32+
private Date endTime;
33+
34+
private Builder(GetTrainingUsageOptions getTrainingUsageOptions) {
35+
this.startTime = getTrainingUsageOptions.startTime;
36+
this.endTime = getTrainingUsageOptions.endTime;
37+
}
38+
39+
/**
40+
* Instantiates a new builder.
41+
*/
42+
public Builder() {
43+
}
44+
45+
/**
46+
* Builds a GetTrainingUsageOptions.
47+
*
48+
* @return the getTrainingUsageOptions
49+
*/
50+
public GetTrainingUsageOptions build() {
51+
return new GetTrainingUsageOptions(this);
52+
}
53+
54+
/**
55+
* Set the startTime.
56+
*
57+
* @param startTime the startTime
58+
* @return the GetTrainingUsageOptions builder
59+
*/
60+
public Builder startTime(Date startTime) {
61+
this.startTime = startTime;
62+
return this;
63+
}
64+
65+
/**
66+
* Set the endTime.
67+
*
68+
* @param endTime the endTime
69+
* @return the GetTrainingUsageOptions builder
70+
*/
71+
public Builder endTime(Date endTime) {
72+
this.endTime = endTime;
73+
return this;
74+
}
75+
}
76+
77+
private GetTrainingUsageOptions(Builder builder) {
78+
startTime = builder.startTime;
79+
endTime = builder.endTime;
80+
}
81+
82+
/**
83+
* New builder.
84+
*
85+
* @return a GetTrainingUsageOptions builder
86+
*/
87+
public Builder newBuilder() {
88+
return new Builder(this);
89+
}
90+
91+
/**
92+
* Gets the startTime.
93+
*
94+
* The earliest day to include training events. If empty or not specified, the earliest training event is included.
95+
*
96+
* @return the startTime
97+
*/
98+
public Date startTime() {
99+
return startTime;
100+
}
101+
102+
/**
103+
* Gets the endTime.
104+
*
105+
* The most recent day to include training events. All events for the day are included. If empty or not specified, the
106+
* current day is used. Specify the same value as `start_time` to request events for a single day.
107+
*
108+
* @return the endTime
109+
*/
110+
public Date endTime() {
111+
return endTime;
112+
}
113+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* (C) Copyright IBM Corp. 2019.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.ibm.watson.visual_recognition.v4.model;
14+
15+
import java.util.Date;
16+
17+
import com.google.gson.annotations.SerializedName;
18+
import com.ibm.cloud.sdk.core.service.model.GenericModel;
19+
20+
/**
21+
* Details about the training event.
22+
*/
23+
public class TrainingEvent extends GenericModel {
24+
25+
/**
26+
* Trained object type. Only `objects` is currently supported.
27+
*/
28+
public interface Type {
29+
/** objects. */
30+
String OBJECTS = "objects";
31+
}
32+
33+
/**
34+
* Training status of the training event.
35+
*/
36+
public interface Status {
37+
/** failed. */
38+
String FAILED = "failed";
39+
/** succeeded. */
40+
String SUCCEEDED = "succeeded";
41+
}
42+
43+
private String type;
44+
@SerializedName("collection_id")
45+
private String collectionId;
46+
@SerializedName("completion_time")
47+
private Date completionTime;
48+
private String status;
49+
@SerializedName("image_count")
50+
private Long imageCount;
51+
52+
/**
53+
* Gets the type.
54+
*
55+
* Trained object type. Only `objects` is currently supported.
56+
*
57+
* @return the type
58+
*/
59+
public String getType() {
60+
return type;
61+
}
62+
63+
/**
64+
* Gets the collectionId.
65+
*
66+
* Identifier of the trained collection.
67+
*
68+
* @return the collectionId
69+
*/
70+
public String getCollectionId() {
71+
return collectionId;
72+
}
73+
74+
/**
75+
* Gets the completionTime.
76+
*
77+
* Date and time in Coordinated Universal Time (UTC) that training on the collection finished.
78+
*
79+
* @return the completionTime
80+
*/
81+
public Date getCompletionTime() {
82+
return completionTime;
83+
}
84+
85+
/**
86+
* Gets the status.
87+
*
88+
* Training status of the training event.
89+
*
90+
* @return the status
91+
*/
92+
public String getStatus() {
93+
return status;
94+
}
95+
96+
/**
97+
* Gets the imageCount.
98+
*
99+
* The total number of images that were used in training for this training event.
100+
*
101+
* @return the imageCount
102+
*/
103+
public Long getImageCount() {
104+
return imageCount;
105+
}
106+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* (C) Copyright IBM Corp. 2019.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.ibm.watson.visual_recognition.v4.model;
14+
15+
import java.util.Date;
16+
import java.util.List;
17+
18+
import com.google.gson.annotations.SerializedName;
19+
import com.ibm.cloud.sdk.core.service.model.GenericModel;
20+
21+
/**
22+
* Details about the training events.
23+
*/
24+
public class TrainingEvents extends GenericModel {
25+
26+
@SerializedName("start_time")
27+
private Date startTime;
28+
@SerializedName("end_time")
29+
private Date endTime;
30+
@SerializedName("completed_events")
31+
private Long completedEvents;
32+
@SerializedName("trained_images")
33+
private Long trainedImages;
34+
private List<TrainingEvent> events;
35+
36+
/**
37+
* Gets the startTime.
38+
*
39+
* The starting day for the returned training events in Coordinated Universal Time (UTC). If not specified in the
40+
* request, it identifies the earliest training event.
41+
*
42+
* @return the startTime
43+
*/
44+
public Date getStartTime() {
45+
return startTime;
46+
}
47+
48+
/**
49+
* Gets the endTime.
50+
*
51+
* The ending day for the returned training events in Coordinated Universal Time (UTC). If not specified in the
52+
* request, it lists the current time.
53+
*
54+
* @return the endTime
55+
*/
56+
public Date getEndTime() {
57+
return endTime;
58+
}
59+
60+
/**
61+
* Gets the completedEvents.
62+
*
63+
* The total number of training events in the response for the start and end times.
64+
*
65+
* @return the completedEvents
66+
*/
67+
public Long getCompletedEvents() {
68+
return completedEvents;
69+
}
70+
71+
/**
72+
* Gets the trainedImages.
73+
*
74+
* The total number of images that were used in training for the start and end times.
75+
*
76+
* @return the trainedImages
77+
*/
78+
public Long getTrainedImages() {
79+
return trainedImages;
80+
}
81+
82+
/**
83+
* Gets the events.
84+
*
85+
* The completed training events for the start and end time.
86+
*
87+
* @return the events
88+
*/
89+
public List<TrainingEvent> getEvents() {
90+
return events;
91+
}
92+
}

0 commit comments

Comments
 (0)