Search in sources :

Example 41 with DataSet

use of org.idempiere.adInterface.x10.DataSet in project java-aiplatform by googleapis.

the class CreateDatasetSample method createDatasetSample.

static void createDatasetSample(String project, String datasetDisplayName, String metadataSchemaUri) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    DatasetServiceSettings datasetServiceSettings = DatasetServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (DatasetServiceClient datasetServiceClient = DatasetServiceClient.create(datasetServiceSettings)) {
        String location = "us-central1";
        LocationName locationName = LocationName.of(project, location);
        Dataset dataset = Dataset.newBuilder().setDisplayName(datasetDisplayName).setMetadataSchemaUri(metadataSchemaUri).build();
        OperationFuture<Dataset, CreateDatasetOperationMetadata> datasetFuture = datasetServiceClient.createDatasetAsync(locationName, dataset);
        System.out.format("Operation name: %s\n", datasetFuture.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        Dataset datasetResponse = datasetFuture.get(300, TimeUnit.SECONDS);
        System.out.println("Create Dataset Response");
        System.out.format("Name: %s\n", datasetResponse.getName());
        System.out.format("Display Name: %s\n", datasetResponse.getDisplayName());
        System.out.format("Metadata Schema Uri: %s\n", datasetResponse.getMetadataSchemaUri());
        System.out.format("Metadata: %s\n", datasetResponse.getMetadata());
        System.out.format("Create Time: %s\n", datasetResponse.getCreateTime());
        System.out.format("Update Time: %s\n", datasetResponse.getUpdateTime());
        System.out.format("Labels: %s\n", datasetResponse.getLabelsMap());
    }
}
Also used : DatasetServiceSettings(com.google.cloud.aiplatform.v1.DatasetServiceSettings) CreateDatasetOperationMetadata(com.google.cloud.aiplatform.v1.CreateDatasetOperationMetadata) Dataset(com.google.cloud.aiplatform.v1.Dataset) DatasetServiceClient(com.google.cloud.aiplatform.v1.DatasetServiceClient) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Example 42 with DataSet

use of org.idempiere.adInterface.x10.DataSet in project java-aiplatform by googleapis.

the class CreateDatasetTextSample method createDatasetTextSample.

static void createDatasetTextSample(String project, String datasetDisplayName) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    DatasetServiceSettings datasetServiceSettings = DatasetServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (DatasetServiceClient datasetServiceClient = DatasetServiceClient.create(datasetServiceSettings)) {
        String location = "us-central1";
        String metadataSchemaUri = "gs://google-cloud-aiplatform/schema/dataset/metadata/text_1.0.0.yaml";
        LocationName locationName = LocationName.of(project, location);
        Dataset dataset = Dataset.newBuilder().setDisplayName(datasetDisplayName).setMetadataSchemaUri(metadataSchemaUri).build();
        OperationFuture<Dataset, CreateDatasetOperationMetadata> datasetFuture = datasetServiceClient.createDatasetAsync(locationName, dataset);
        System.out.format("Operation name: %s\n", datasetFuture.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        Dataset datasetResponse = datasetFuture.get(180, TimeUnit.SECONDS);
        System.out.println("Create Text Dataset Response");
        System.out.format("\tName: %s\n", datasetResponse.getName());
        System.out.format("\tDisplay Name: %s\n", datasetResponse.getDisplayName());
        System.out.format("\tMetadata Schema Uri: %s\n", datasetResponse.getMetadataSchemaUri());
        System.out.format("\tMetadata: %s\n", datasetResponse.getMetadata());
        System.out.format("\tCreate Time: %s\n", datasetResponse.getCreateTime());
        System.out.format("\tUpdate Time: %s\n", datasetResponse.getUpdateTime());
        System.out.format("\tLabels: %s\n", datasetResponse.getLabelsMap());
    }
}
Also used : DatasetServiceSettings(com.google.cloud.aiplatform.v1.DatasetServiceSettings) CreateDatasetOperationMetadata(com.google.cloud.aiplatform.v1.CreateDatasetOperationMetadata) Dataset(com.google.cloud.aiplatform.v1.Dataset) DatasetServiceClient(com.google.cloud.aiplatform.v1.DatasetServiceClient) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Example 43 with DataSet

use of org.idempiere.adInterface.x10.DataSet in project OpenMUC by isc-konstanz.

the class Iec62056Connection method scanForChannels.

@Override
public List<ChannelScanInfo> scanForChannels(String settings) throws UnsupportedOperationException, ScanException, ConnectionException {
    List<DataSet> dataSets;
    DataMessage dataMessage;
    try {
        dataMessage = iec21Port.read();
    } catch (IOException e) {
        throw new ScanException(e);
    }
    dataSets = dataMessage.getDataSets();
    if (dataSets == null) {
        throw new ScanException("Read timeout.");
    }
    List<ChannelScanInfo> scanInfos = new ArrayList<>(dataSets.size());
    for (DataSet dataSet : dataSets) {
        try {
            Double.parseDouble(dataSet.getValue());
            scanInfos.add(new ChannelScanInfo(dataSet.getAddress(), "", ValueType.DOUBLE, null));
        } catch (NumberFormatException e) {
            scanInfos.add(new ChannelScanInfo(dataSet.getAddress(), "", ValueType.STRING, dataSet.getValue().length()));
        }
    }
    return scanInfos;
}
Also used : ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ScanException(org.openmuc.framework.config.ScanException) DataSet(org.openmuc.j62056.DataSet) DataMessage(org.openmuc.j62056.DataMessage) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 44 with DataSet

use of org.idempiere.adInterface.x10.DataSet in project OpenMUC by isc-konstanz.

the class Iec62056Driver method scanForDevices.

@Override
public void scanForDevices(String settings, DriverDeviceScanListener listener) throws UnsupportedOperationException, ArgumentSyntaxException, ScanException, ScanInterruptedException {
    handleScanParameter(settings);
    Iec21Port iec21Port = null;
    Builder iec21PortBuilder = getConfiguredBuilder();
    try {
        iec21Port = iec21PortBuilder.buildAndOpen();
    } catch (IOException e) {
        throw new ScanException("Failed to open serial port: " + e.getMessage());
    }
    try {
        DataMessage dataMessage = iec21Port.read();
        List<DataSet> dataSets = dataMessage.getDataSets();
        StringBuilder deviceSettings = new StringBuilder();
        if (baudRateChangeDelay > 0) {
            deviceSettings.append(' ').append(BAUD_RATE_CHANGE_DELAY).append(' ').append(baudRateChangeDelay);
        }
        String deviceSettingsString = deviceSettings.toString().trim();
        listener.deviceFound(new DeviceScanInfo(serialPortName, deviceSettingsString, dataSets.get(0).getAddress().replaceAll("\\p{Cntrl}", "")));
    } catch (IOException e) {
        throw new ScanException(e);
    } finally {
        iec21Port.close();
    }
}
Also used : DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) ScanException(org.openmuc.framework.config.ScanException) DataSet(org.openmuc.j62056.DataSet) DataMessage(org.openmuc.j62056.DataMessage) Builder(org.openmuc.j62056.Iec21Port.Builder) Iec21Port(org.openmuc.j62056.Iec21Port) IOException(java.io.IOException)

Example 45 with DataSet

use of org.idempiere.adInterface.x10.DataSet in project OpenMUC by isc-konstanz.

the class IecConnection method read.

@Override
public void read(List<ChannelRecordContainer> containers, int timeout) throws ConnectionException {
    logger.trace("reading channels");
    long timestamp = System.currentTimeMillis();
    try {
        byte[] frame = receiver.receiveMessage(timeout);
        ModeDMessage message = ModeDMessage.parse(frame);
        List<String> dataSets = message.getDataSets();
        Map<String, Value> values = new LinkedHashMap<>();
        for (String ds : dataSets) {
            DataSet dataSet = new DataSet(ds);
            String address = dataSet.getAddress();
            Value value = dataSet.parseValueAsDouble();
            values.put(address, value);
            logger.trace("{} = {}", address, value);
        }
        handleChannelRecordContainer(containers, values, timestamp);
    } catch (IOException e) {
        logger.error("read failed", e);
        disconnect();
        throw new ConnectionException(e);
    } catch (ParseException e) {
        logger.error("parsing failed", e);
    }
}
Also used : DataSet(org.openmuc.framework.driver.ehz.iec62056_21.DataSet) Value(org.openmuc.framework.data.Value) IOException(java.io.IOException) ParseException(java.text.ParseException) ModeDMessage(org.openmuc.framework.driver.ehz.iec62056_21.ModeDMessage) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

IOException (java.io.IOException)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 PrintStream (java.io.PrintStream)10 Before (org.junit.Before)10 Dataset (com.google.cloud.datalabeling.v1beta1.Dataset)9 ArrayList (java.util.ArrayList)9 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)8 Dataset (com.google.cloud.automl.v1.Dataset)8 LocationName (com.google.cloud.automl.v1.LocationName)7 DataLabelingServiceClient (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient)7 ProjectName (com.google.cloud.datalabeling.v1beta1.ProjectName)7 CreateDatasetOperationMetadata (com.google.cloud.aiplatform.v1.CreateDatasetOperationMetadata)6 Dataset (com.google.cloud.aiplatform.v1.Dataset)6 DatasetServiceClient (com.google.cloud.aiplatform.v1.DatasetServiceClient)6 DatasetServiceSettings (com.google.cloud.aiplatform.v1.DatasetServiceSettings)6 LocationName (com.google.cloud.aiplatform.v1.LocationName)6 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)6 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)6 Dataset (com.google.cloud.automl.v1beta1.Dataset)6 LocationName (com.google.cloud.automl.v1beta1.LocationName)6