Search in sources :

Example 51 with Dataset

use of com.google.cloud.datalabeling.v1beta1.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 52 with Dataset

use of com.google.cloud.datalabeling.v1beta1.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)

Example 53 with Dataset

use of com.google.cloud.datalabeling.v1beta1.Dataset in project java-datalabeling by googleapis.

the class DataLabelingServiceClientTest method listAnnotatedDatasetsTest.

@Test
public void listAnnotatedDatasetsTest() throws Exception {
    AnnotatedDataset responsesElement = AnnotatedDataset.newBuilder().build();
    ListAnnotatedDatasetsResponse expectedResponse = ListAnnotatedDatasetsResponse.newBuilder().setNextPageToken("").addAllAnnotatedDatasets(Arrays.asList(responsesElement)).build();
    mockDataLabelingService.addResponse(expectedResponse);
    DatasetName parent = DatasetName.of("[PROJECT]", "[DATASET]");
    String filter = "filter-1274492040";
    ListAnnotatedDatasetsPagedResponse pagedListResponse = client.listAnnotatedDatasets(parent, filter);
    List<AnnotatedDataset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getAnnotatedDatasetsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDataLabelingService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListAnnotatedDatasetsRequest actualRequest = ((ListAnnotatedDatasetsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListAnnotatedDatasetsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListAnnotatedDatasetsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 54 with Dataset

use of com.google.cloud.datalabeling.v1beta1.Dataset in project java-datalabeling by googleapis.

the class CreateDatasetIT method tearDown.

@After
public void tearDown() {
    System.setOut(null);
    bout.reset();
    // Delete the Dataset
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create()) {
        ProjectName projectName = ProjectName.of(PROJECT_ID);
        ListDatasetsRequest listRequest = ListDatasetsRequest.newBuilder().setParent(projectName.toString()).build();
        ListDatasetsPagedResponse response = dataLabelingServiceClient.listDatasets(listRequest);
        for (Dataset dataset : response.getPage().iterateAll()) {
            if (dataset.getDisplayName().equals(datasetName)) {
                dataLabelingServiceClient.deleteDataset(dataset.getName());
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) ListDatasetsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListDatasetsPagedResponse) ProjectName(com.google.cloud.datalabeling.v1beta1.ProjectName) Dataset(com.google.cloud.datalabeling.v1beta1.Dataset) IOException(java.io.IOException) ListDatasetsRequest(com.google.cloud.datalabeling.v1beta1.ListDatasetsRequest) After(org.junit.After)

Example 55 with Dataset

use of com.google.cloud.datalabeling.v1beta1.Dataset in project java-datalabeling by googleapis.

the class ImportDataIT method setUp.

@Before
public void setUp() throws IOException {
    bout = new ByteArrayOutputStream();
    System.setOut(new PrintStream(bout));
    CreateDataset.createDataset(PROJECT_ID, datasetName);
    // Get the Dataset
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create()) {
        ProjectName projectName = ProjectName.of(PROJECT_ID);
        ListDatasetsRequest listRequest = ListDatasetsRequest.newBuilder().setParent(projectName.toString()).build();
        ListDatasetsPagedResponse response = dataLabelingServiceClient.listDatasets(listRequest);
        for (Dataset returnedDataset : response.getPage().iterateAll()) {
            if (returnedDataset.getDisplayName().equals("IMPORT_DATASET_NAME")) {
                dataset = returnedDataset;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : PrintStream(java.io.PrintStream) DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) ListDatasetsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListDatasetsPagedResponse) ProjectName(com.google.cloud.datalabeling.v1beta1.ProjectName) Dataset(com.google.cloud.datalabeling.v1beta1.Dataset) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ListDatasetsRequest(com.google.cloud.datalabeling.v1beta1.ListDatasetsRequest) Before(org.junit.Before)

Aggregations

IOException (java.io.IOException)20 DataLabelingServiceClient (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient)13 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 Test (org.junit.Test)9 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)8 Dataset (com.google.cloud.automl.v1.Dataset)8 ProjectName (com.google.cloud.datalabeling.v1beta1.ProjectName)8 LocationName (com.google.cloud.automl.v1.LocationName)7 ListDatasetsPagedResponse (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListDatasetsPagedResponse)7 AbstractMessage (com.google.protobuf.AbstractMessage)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