use of com.google.cloud.aiplatform.v1beta1.Dataset in project openhab1-addons by openhab.
the class Iec6205621MeterBinding method execute.
/**
* @{inheritDoc
*/
@Override
protected void execute() {
// the frequently executed code (polling) goes here ...
Map<String, Map<String, DataSet>> cache = new HashMap<String, Map<String, DataSet>>();
for (Iec6205621MeterBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
for (Entry<String, Meter> entry : meterDeviceConfigurtions.entrySet()) {
Meter reader = entry.getValue();
String meterName = provider.getMeterName(itemName);
if (meterName != null && meterName.equals(entry.getKey())) {
Map<String, DataSet> dataSets;
if ((dataSets = cache.get(meterName)) == null) {
if (logger.isDebugEnabled()) {
logger.debug("Read meter: {}; {}", meterName, reader.getConfig().getSerialPort());
}
dataSets = reader.read();
cache.put(meterName, dataSets);
}
String obis = provider.getObis(itemName);
if (obis != null && dataSets.containsKey(obis)) {
DataSet dataSet = dataSets.get(obis);
if (logger.isDebugEnabled()) {
logger.debug("Updating item {} with OBIS code {} and value {}", itemName, obis, dataSet.getValue());
}
Class<? extends Item> itemType = provider.getItemType(itemName);
if (itemType.isAssignableFrom(NumberItem.class)) {
eventPublisher.postUpdate(itemName, new DecimalType(dataSet.getValue()));
}
if (itemType.isAssignableFrom(StringItem.class)) {
String value = dataSet.getValue();
eventPublisher.postUpdate(itemName, new StringType(value));
}
}
}
}
}
}
}
use of com.google.cloud.aiplatform.v1beta1.Dataset in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850ClientSSLDEventListener method newReport.
@Override
public void newReport(final Report report) {
final DateTime timeOfEntry = this.getTimeOfEntry(report);
final String reportDescription = this.getReportDescription(report, timeOfEntry);
this.logger.info("newReport for {}", reportDescription);
boolean skipRecordBecauseOfOldSqNum = false;
if (report.isBufOvfl()) {
this.logger.warn("Buffer Overflow reported for {} - entries within the buffer may have been lost.", reportDescription);
}
if (this.firstNewSqNum != null && report.getSqNum() != null && report.getSqNum() < this.firstNewSqNum) {
skipRecordBecauseOfOldSqNum = true;
}
this.logReportDetails(report);
final DataSet dataSet = report.getDataSet();
if (dataSet == null) {
this.logger.warn("No DataSet available for {}", reportDescription);
return;
}
final List<FcModelNode> members = dataSet.getMembers();
if (members == null || members.isEmpty()) {
this.logger.warn("No members in DataSet available for {}", reportDescription);
return;
} else {
this.logger.debug("Handling {} DataSet members for {}", members.size(), reportDescription);
}
for (final FcModelNode member : members) {
if (member == null) {
this.logger.warn("Member == null in DataSet for {}", reportDescription);
continue;
}
this.logger.info("Handle member {} for {}", member.getReference(), reportDescription);
try {
if (skipRecordBecauseOfOldSqNum) {
this.logger.warn("Skipping report because SqNum: {} is less than what should be the first new value: {}", report.getSqNum(), this.firstNewSqNum);
} else {
this.addEventNotificationForReportedData(member, timeOfEntry, reportDescription);
}
} catch (final Exception e) {
this.logger.error("Error adding event notification for member {} from {}", member.getReference(), reportDescription, e);
}
}
}
use of com.google.cloud.aiplatform.v1beta1.Dataset in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850ClientSSLDEventListener method logReportDetails.
private void logReportDetails(final Report report) {
final StringBuilder sb = new StringBuilder("Report details for device ").append(this.deviceIdentification).append(System.lineSeparator());
sb.append("\t RptId:\t").append(report.getRptId()).append(System.lineSeparator());
sb.append("\t DataSetRef:\t").append(report.getDataSetRef()).append(System.lineSeparator());
sb.append("\t ConfRev:\t").append(report.getConfRev()).append(System.lineSeparator());
sb.append("\t BufOvfl:\t").append(report.isBufOvfl()).append(System.lineSeparator());
sb.append("\t EntryId:\t").append(report.getEntryId()).append(System.lineSeparator());
sb.append("\tInclusionBitString:\t").append(Arrays.toString(report.getInclusionBitString())).append(System.lineSeparator());
sb.append("\tMoreSegmentsFollow:\t").append(report.isMoreSegmentsFollow()).append(System.lineSeparator());
sb.append("\t SqNum:\t").append(report.getSqNum()).append(System.lineSeparator());
sb.append("\t SubSqNum:\t").append(report.getSubSqNum()).append(System.lineSeparator());
sb.append("\t TimeOfEntry:\t").append(report.getTimeOfEntry()).append(System.lineSeparator());
if (report.getTimeOfEntry() != null) {
sb.append("\t \t(").append(new DateTime(report.getTimeOfEntry().getTimestampValue() + IEC61850_ENTRY_TIME_OFFSET)).append(')').append(System.lineSeparator());
}
final List<BdaReasonForInclusion> reasonCodes = report.getReasonCodes();
if (reasonCodes != null && !reasonCodes.isEmpty()) {
sb.append("\t ReasonCodes:").append(System.lineSeparator());
for (final BdaReasonForInclusion reasonCode : reasonCodes) {
sb.append("\t \t").append(reasonCode.getReference() == null ? HexConverter.toHexString(reasonCode.getValue()) : reasonCode).append("\t(").append(new Iec61850BdaReasonForInclusionHelper(reasonCode).getInfo()).append(')').append(System.lineSeparator());
}
}
sb.append("\t optFlds:").append(report.getOptFlds()).append("\t(").append(new Iec61850BdaOptFldsHelper(report.getOptFlds()).getInfo()).append(')').append(System.lineSeparator());
final DataSet dataSet = report.getDataSet();
if (dataSet == null) {
sb.append("\t DataSet:\tnull").append(System.lineSeparator());
} else {
sb.append("\t DataSet:\t").append(dataSet.getReferenceStr()).append(System.lineSeparator());
final List<FcModelNode> members = dataSet.getMembers();
if (members != null && !members.isEmpty()) {
sb.append("\t DataSet members:\t").append(members.size()).append(System.lineSeparator());
for (final FcModelNode member : members) {
sb.append("\t member:\t").append(member).append(System.lineSeparator());
if (member.getReference().toString().contains("CSLC.EvnRpn")) {
sb.append(this.evnRpnInfo("\t \t\t", member));
}
}
}
}
this.logger.info(sb.append(System.lineSeparator()).toString());
}
use of com.google.cloud.aiplatform.v1beta1.Dataset in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850ClientRTUEventListener method logReportDetails.
private void logReportDetails(final Report report) {
final StringBuilder sb = new StringBuilder("Report details for device ").append(this.deviceIdentification).append(System.lineSeparator());
sb.append("\t RptId:\t").append(report.getRptId()).append(System.lineSeparator());
sb.append("\t DataSetRef:\t").append(report.getDataSetRef()).append(System.lineSeparator());
sb.append("\t ConfRev:\t").append(report.getConfRev()).append(System.lineSeparator());
sb.append("\t BufOvfl:\t").append(report.isBufOvfl()).append(System.lineSeparator());
sb.append("\t EntryId:\t").append(report.getEntryId()).append(System.lineSeparator());
sb.append("\tInclusionBitString:\t").append(Arrays.toString(report.getInclusionBitString())).append(System.lineSeparator());
sb.append("\tMoreSegmentsFollow:\t").append(report.isMoreSegmentsFollow()).append(System.lineSeparator());
sb.append("\t SqNum:\t").append(report.getSqNum()).append(System.lineSeparator());
sb.append("\t SubSqNum:\t").append(report.getSubSqNum()).append(System.lineSeparator());
sb.append("\t TimeOfEntry:\t").append(report.getTimeOfEntry()).append(System.lineSeparator());
if (report.getTimeOfEntry() != null) {
sb.append("\t \t(").append(new DateTime(report.getTimeOfEntry().getTimestampValue() + IEC61850_ENTRY_TIME_OFFSET)).append(')').append(System.lineSeparator());
}
final List<BdaReasonForInclusion> reasonCodes = report.getReasonCodes();
if ((reasonCodes != null) && !reasonCodes.isEmpty()) {
sb.append("\t ReasonCodes:").append(System.lineSeparator());
for (final BdaReasonForInclusion reasonCode : reasonCodes) {
sb.append("\t \t").append(reasonCode.getReference() == null ? HexConverter.toHexString(reasonCode.getValue()) : reasonCode).append("\t(").append(new Iec61850BdaReasonForInclusionHelper(reasonCode).getInfo()).append(')').append(System.lineSeparator());
}
}
sb.append("\t optFlds:").append(report.getOptFlds()).append("\t(").append(new Iec61850BdaOptFldsHelper(report.getOptFlds()).getInfo()).append(')').append(System.lineSeparator());
final DataSet dataSet = report.getDataSet();
if (dataSet == null) {
sb.append("\t DataSet:\tnull").append(System.lineSeparator());
} else {
sb.append("\t DataSet:\t").append(dataSet.getReferenceStr()).append(System.lineSeparator());
final List<FcModelNode> members = dataSet.getMembers();
if ((members != null) && !members.isEmpty()) {
sb.append("\t DataSet members:\t").append(members.size()).append(System.lineSeparator());
for (final FcModelNode member : members) {
sb.append("\t member:\t").append(member).append(System.lineSeparator());
sb.append("\t \t\t").append(member);
}
}
}
this.logger.info(sb.append(System.lineSeparator()).toString());
}
use of com.google.cloud.aiplatform.v1beta1.Dataset in project java-datalabeling by googleapis.
the class LabelVideoIT method setUp.
@Before
public void setUp() {
System.setOut(new PrintStream(new ByteArrayOutputStream()));
try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create()) {
// Create the dataset
CreateDataset.createDataset(PROJECT_ID, datasetName);
ProjectName projectName = ProjectName.of(PROJECT_ID);
// Get the Dataset
ListDatasetsRequest datasetsRequest = ListDatasetsRequest.newBuilder().setParent(projectName.toString()).build();
ListDatasetsPagedResponse datasetsResponse = dataLabelingServiceClient.listDatasets(datasetsRequest);
for (Dataset returnedDataset : datasetsResponse.getPage().iterateAll()) {
if (returnedDataset.getDisplayName().equals("LABEL_VIDEO_DATASET_NAME")) {
dataset = returnedDataset;
}
}
// Import the images
// ImportData.importData(dataset.getName(), DATASET_GCS_SOURCE_URI);
GcsSource gcsSource = GcsSource.newBuilder().setInputUri(DATASET_GCS_SOURCE_URI).setMimeType("text/csv").build();
InputConfig inputConfig = InputConfig.newBuilder().setDataType(// DataTypes: AUDIO, IMAGE, VIDEO, TEXT
DataType.VIDEO).setGcsSource(gcsSource).build();
ImportDataRequest importDataRequest = ImportDataRequest.newBuilder().setName(dataset.getName()).setInputConfig(inputConfig).build();
ImportDataOperationResponse response = dataLabelingServiceClient.importDataAsync(importDataRequest).get();
System.out.format("Imported items: %d\n", response.getImportCount());
// Create the instruction
CreateInstruction.createInstruction(PROJECT_ID, INSTRUCTION_GCS_SOURCE_URI);
// Create the annotation spec set
CreateAnnotationSpecSet.createAnnotationSpecSet(PROJECT_ID);
// Get the instruction
ListInstructionsRequest instructionsRequest = ListInstructionsRequest.newBuilder().setParent(projectName.toString()).build();
ListInstructionsPagedResponse instructionsResponse = dataLabelingServiceClient.listInstructions(instructionsRequest);
for (Instruction returnedInstruction : instructionsResponse.getPage().iterateAll()) {
if (returnedInstruction.getDisplayName().equals("YOUR_INSTRUCTION_DISPLAY_NAME")) {
instruction = returnedInstruction;
}
}
// Get the annotation spec set
ListAnnotationSpecSetsRequest annotationRequest = ListAnnotationSpecSetsRequest.newBuilder().setParent(projectName.toString()).build();
ListAnnotationSpecSetsPagedResponse annotationsResponse = dataLabelingServiceClient.listAnnotationSpecSets(annotationRequest);
for (AnnotationSpecSet returnedAnnotation : annotationsResponse.getPage().iterateAll()) {
if (returnedAnnotation.getDisplayName().equals("YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME")) {
annotationSpecSet = returnedAnnotation;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations