Search in sources :

Example 16 with Dataset

use of com.google.cloud.aiplatform.v1.Dataset in project java-aiplatform by googleapis.

the class CreateDatasetTabularGcsSample method createDatasetTableGcs.

static void createDatasetTableGcs(String project, String datasetDisplayName, String gcsSourceUri) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    DatasetServiceSettings settings = 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(settings)) {
        String location = "us-central1";
        String metadataSchemaUri = "gs://google-cloud-aiplatform/schema/dataset/metadata/tables_1.0.0.yaml";
        LocationName locationName = LocationName.of(project, location);
        String jsonString = "{\"input_config\": {\"gcs_source\": {\"uri\": [\"" + gcsSourceUri + "\"]}}}";
        Value.Builder metaData = Value.newBuilder();
        JsonFormat.parser().merge(jsonString, metaData);
        Dataset dataset = Dataset.newBuilder().setDisplayName(datasetDisplayName).setMetadataSchemaUri(metadataSchemaUri).setMetadata(metaData).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 Table GCS sample");
        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());
    }
}
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) Value(com.google.protobuf.Value) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Example 17 with Dataset

use of com.google.cloud.aiplatform.v1.Dataset in project OpenMUC by isc-konstanz.

the class Iec62056Listener method newRecord.

private synchronized void newRecord(List<DataSet> dataSets, long time) {
    List<ChannelRecordContainer> newContainers = new ArrayList<>();
    for (ChannelRecordContainer container : containers) {
        for (DataSet dataSet : dataSets) {
            if (dataSet.getAddress().equals(container.getChannelAddress())) {
                String value = dataSet.getValue();
                if (value != null) {
                    try {
                        container.setRecord(new Record(new DoubleValue(Double.parseDouble(dataSet.getValue())), time));
                        newContainers.add(container);
                    } catch (NumberFormatException e) {
                        container.setRecord(new Record(new StringValue(dataSet.getValue()), time));
                    }
                }
                break;
            }
        }
    }
    listener.newRecords(newContainers);
}
Also used : ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) DataSet(org.openmuc.j62056.DataSet) DoubleValue(org.openmuc.framework.data.DoubleValue) ArrayList(java.util.ArrayList) Record(org.openmuc.framework.data.Record) StringValue(org.openmuc.framework.data.StringValue)

Example 18 with Dataset

use of com.google.cloud.aiplatform.v1.Dataset in project OpenMUC by isc-konstanz.

the class IecConnection method scanForChannels.

@Override
public List<ChannelScanInfo> scanForChannels(int timeout) {
    List<ChannelScanInfo> channelInfos = new LinkedList<>();
    logger.debug("scanning channels");
    try {
        byte[] frame = receiver.receiveMessage(timeout);
        ModeDMessage message = ModeDMessage.parse(frame);
        List<String> dataSets = message.getDataSets();
        for (String data : dataSets) {
            DataSet dataSet = new DataSet(data);
            String channelAddress = dataSet.getAddress();
            String description = "Current value: " + dataSet.parseValueAsDouble() + dataSet.getUnit();
            ValueType valueType = ValueType.DOUBLE;
            Integer valueTypeLength = null;
            Boolean readable = true;
            Boolean writable = false;
            ChannelScanInfo channelInfo = new ChannelScanInfo(channelAddress, description, valueType, valueTypeLength, readable, writable);
            channelInfos.add(channelInfo);
        }
    } catch (ParseException | IOException e) {
        logger.warn("read failed", e);
    }
    return channelInfos;
}
Also used : DataSet(org.openmuc.framework.driver.ehz.iec62056_21.DataSet) ValueType(org.openmuc.framework.data.ValueType) IOException(java.io.IOException) LinkedList(java.util.LinkedList) ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ParseException(java.text.ParseException) ModeDMessage(org.openmuc.framework.driver.ehz.iec62056_21.ModeDMessage)

Example 19 with Dataset

use of com.google.cloud.aiplatform.v1.Dataset in project OpenMUC by isc-konstanz.

the class Iec62056Connection method read.

private List<DataSet> read(List<ChannelRecordContainer> containers) {
    List<DataSet> dataSetsRet = new ArrayList<>();
    DataMessage dataMessage;
    for (int i = 0; i <= retries; ++i) {
        try {
            dataMessage = iec21Port.read();
            List<DataSet> dataSets = dataMessage.getDataSets();
            if (dataSetsRet != null) {
                i = retries;
                dataSetsRet = dataSets;
            }
        } catch (IOException e) {
            if (i >= retries) {
                for (ChannelRecordContainer container : containers) {
                    container.setRecord(new Record(Flag.DRIVER_ERROR_READ_FAILURE));
                }
            }
        }
    }
    return dataSetsRet;
}
Also used : ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) DataSet(org.openmuc.j62056.DataSet) DataMessage(org.openmuc.j62056.DataMessage) ArrayList(java.util.ArrayList) Record(org.openmuc.framework.data.Record) IOException(java.io.IOException)

Example 20 with Dataset

use of com.google.cloud.aiplatform.v1.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));
                        }
                    }
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) DataSet(org.openmuc.j62056.DataSet) StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType) HashMap(java.util.HashMap) Map(java.util.Map) Iec6205621MeterBindingProvider(org.openhab.binding.iec6205621meter.Iec6205621MeterBindingProvider)

Aggregations

DatasetServiceClient (com.google.cloud.aiplatform.v1.DatasetServiceClient)15 DatasetServiceSettings (com.google.cloud.aiplatform.v1.DatasetServiceSettings)15 LocationName (com.google.cloud.aiplatform.v1.LocationName)14 IOException (java.io.IOException)14 GcsSource (com.google.cloud.aiplatform.v1.GcsSource)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 PrintStream (java.io.PrintStream)10 ArrayList (java.util.ArrayList)10 Before (org.junit.Before)10 DatasetName (com.google.cloud.aiplatform.v1.DatasetName)9 ImportDataConfig (com.google.cloud.aiplatform.v1.ImportDataConfig)8 ImportDataOperationMetadata (com.google.cloud.aiplatform.v1.ImportDataOperationMetadata)8 ImportDataResponse (com.google.cloud.aiplatform.v1.ImportDataResponse)8 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)8 Dataset (com.google.cloud.automl.v1.Dataset)8 LocationName (com.google.cloud.automl.v1.LocationName)7 Dataset (com.google.cloud.datalabeling.v1beta1.Dataset)7 CreateDatasetOperationMetadata (com.google.cloud.aiplatform.v1.CreateDatasetOperationMetadata)6 Dataset (com.google.cloud.aiplatform.v1.Dataset)6 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)6