Search in sources :

Example 1 with com.google.api.services.sheets.v4.model

use of com.google.api.services.sheets.v4.model in project OpenRefine by OpenRefine.

the class SpreadsheetSerializer method cellData2sheetCellData.

private com.google.api.services.sheets.v4.model.CellData cellData2sheetCellData(CellData cellData) {
    com.google.api.services.sheets.v4.model.CellData sheetCellData = new com.google.api.services.sheets.v4.model.CellData();
    ExtendedValue ev = new ExtendedValue();
    if (cellData != null) {
        if (cellData.value instanceof String) {
            ev.setStringValue((String) cellData.value);
        } else if (cellData.value instanceof Integer) {
            ev.setNumberValue(new Double((Integer) cellData.value));
        } else if (cellData.value instanceof Double) {
            ev.setNumberValue((Double) cellData.value);
        } else if (cellData.value instanceof OffsetDateTime) {
            // supposedly started internally as a double, but not sure how to transform correctly
            // ev.setNumberValue((Double) cellData.value);
            ev.setStringValue(cellData.value.toString());
        } else if (cellData.value instanceof Boolean) {
            ev.setBoolValue((Boolean) cellData.value);
        } else if (cellData.value == null) {
            ev.setStringValue("");
        } else {
            ev.setStringValue(cellData.value.toString());
        }
    } else {
        ev.setStringValue("");
    }
    sheetCellData.setUserEnteredValue(ev);
    return sheetCellData;
}
Also used : ExtendedValue(com.google.api.services.sheets.v4.model.ExtendedValue) OffsetDateTime(java.time.OffsetDateTime)

Example 2 with com.google.api.services.sheets.v4.model

use of com.google.api.services.sheets.v4.model in project OpenRefine by OpenRefine.

the class SpreadsheetSerializerTests method testDataTypes.

@Test
public void testDataTypes() {
    // options is null, but unused
    SUT.startFile(options);
    List<CellData> row = new ArrayList<>();
    row.add(new CellData("null value", null, "null value", null));
    row.add(new CellData("string value", "a string", "a string as string", null));
    row.add(new CellData("integer value", 42, "42", null));
    row.add(new CellData("double value", new Double(42), "42.0", null));
    row.add(new CellData("boolean value", true, "true", null));
    OffsetDateTime now = OffsetDateTime.now(ZoneId.of("Z"));
    row.add(new CellData("datetime value", now, now.toString(), null));
    SUT.addRow(row, false);
    List<Request> requests = SUT.prepareBatch(SUT.getRows());
    assertEquals(requests.size(), 1);
    List<RowData> rows = requests.get(0).getAppendCells().getRows();
    assertEquals(rows.size(), 1);
    List<com.google.api.services.sheets.v4.model.CellData> values = rows.get(0).getValues();
    assertEquals(values.size(), 6);
    ExtendedValue value = values.get(0).getUserEnteredValue();
    assertEquals(value.getStringValue(), "");
    value = values.get(1).getUserEnteredValue();
    assertEquals(value.getStringValue(), "a string");
    value = values.get(2).getUserEnteredValue();
    assertEquals(value.getNumberValue(), new Double(42));
    value = values.get(3).getUserEnteredValue();
    assertEquals(value.getNumberValue(), new Double(42));
    value = values.get(4).getUserEnteredValue();
    assertEquals(value.getBoolValue(), Boolean.TRUE);
    value = values.get(5).getUserEnteredValue();
    assertEquals(value.getStringValue(), now.toString());
}
Also used : ArrayList(java.util.ArrayList) Request(com.google.api.services.sheets.v4.model.Request) AppendDimensionRequest(com.google.api.services.sheets.v4.model.AppendDimensionRequest) ExtendedValue(com.google.api.services.sheets.v4.model.ExtendedValue) CellData(com.google.refine.exporters.TabularSerializer.CellData) RowData(com.google.api.services.sheets.v4.model.RowData) OffsetDateTime(java.time.OffsetDateTime) Test(org.testng.annotations.Test)

Example 3 with com.google.api.services.sheets.v4.model

use of com.google.api.services.sheets.v4.model in project batfish by batfish.

the class Encoder method verify.

/**
 * Checks that a property is always true by seeing if the encoding is unsatisfiable. mkIf the
 * model is satisfiable, then there is a counter example to the property.
 *
 * @return A VerificationResult indicating the status of the check.
 */
public Tuple<VerificationResult, Model> verify() {
    EncoderSlice mainSlice = _slices.get(MAIN_SLICE_NAME);
    int numVariables = _allVariables.size();
    int numConstraints = _solver.getAssertions().length;
    int numNodes = mainSlice.getGraph().getConfigurations().size();
    int numEdges = 0;
    for (Map.Entry<String, Set<String>> e : mainSlice.getGraph().getNeighbors().entrySet()) {
        numEdges += e.getValue().size();
    }
    long start = System.currentTimeMillis();
    Status status = _solver.check();
    long time = System.currentTimeMillis() - start;
    VerificationStats stats = null;
    if (_question.getBenchmark()) {
        stats = new VerificationStats();
        stats.setAvgNumNodes(numNodes);
        stats.setMaxNumNodes(numNodes);
        stats.setMinNumNodes(numNodes);
        stats.setAvgNumEdges(numEdges);
        stats.setMaxNumEdges(numEdges);
        stats.setMinNumEdges(numEdges);
        stats.setAvgNumVariables(numVariables);
        stats.setMaxNumVariables(numVariables);
        stats.setMinNumVariables(numVariables);
        stats.setAvgNumConstraints(numConstraints);
        stats.setMaxNumConstraints(numConstraints);
        stats.setMinNumConstraints(numConstraints);
        stats.setAvgSolverTime(time);
        stats.setMaxSolverTime(time);
        stats.setMinSolverTime(time);
    }
    if (status == Status.UNSATISFIABLE) {
        VerificationResult res = new VerificationResult(true, null, null, null, null, null, stats);
        return new Tuple<>(res, null);
    } else if (status == Status.UNKNOWN) {
        throw new BatfishException("ERROR: satisfiability unknown");
    } else {
        VerificationResult result;
        Model m;
        while (true) {
            m = _solver.getModel();
            SortedMap<String, String> model = new TreeMap<>();
            SortedMap<String, String> packetModel = new TreeMap<>();
            SortedSet<String> fwdModel = new TreeSet<>();
            SortedMap<String, SortedMap<String, String>> envModel = new TreeMap<>();
            SortedSet<String> failures = new TreeSet<>();
            buildCounterExample(this, m, model, packetModel, fwdModel, envModel, failures);
            if (_previousEncoder != null) {
                buildCounterExample(_previousEncoder, m, model, packetModel, fwdModel, envModel, failures);
            }
            result = new VerificationResult(false, model, packetModel, envModel, fwdModel, failures, stats);
            if (!_question.getMinimize()) {
                break;
            }
            BoolExpr blocking = environmentBlockingClause(m);
            add(blocking);
            Status s = _solver.check();
            if (s == Status.UNSATISFIABLE) {
                break;
            }
            if (s == Status.UNKNOWN) {
                throw new BatfishException("ERROR: satisfiability unknown");
            }
        }
        return new Tuple<>(result, m);
    }
}
Also used : Status(com.microsoft.z3.Status) BatfishException(org.batfish.common.BatfishException) BoolExpr(com.microsoft.z3.BoolExpr) SortedSet(java.util.SortedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) SortedSet(java.util.SortedSet) SortedMap(java.util.SortedMap) Model(com.microsoft.z3.Model) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Tuple(org.batfish.symbolic.utils.Tuple)

Example 4 with com.google.api.services.sheets.v4.model

use of com.google.api.services.sheets.v4.model in project batfish by batfish.

the class PropertyChecker method checkDeterminism.

/*
   * Check if there exist multiple stable solutions to the network.
   * If so, reports the forwarding differences between the two cases.
   */
public AnswerElement checkDeterminism(HeaderQuestion q) {
    Graph graph = new Graph(_batfish);
    Encoder enc1 = new Encoder(_settings, graph, q);
    Encoder enc2 = new Encoder(enc1, graph, q);
    enc1.computeEncoding();
    enc2.computeEncoding();
    addEnvironmentConstraints(enc1, q.getBaseEnvironmentType());
    BoolExpr relatedFailures = relateFailures(enc1, enc2);
    BoolExpr relatedEnvs = relateEnvironments(enc1, enc2);
    BoolExpr relatedPkts = relatePackets(enc1, enc2);
    BoolExpr related = enc1.mkAnd(relatedFailures, relatedEnvs, relatedPkts);
    BoolExpr required = enc1.mkTrue();
    for (GraphEdge ge : graph.getAllRealEdges()) {
        SymbolicDecisions d1 = enc1.getMainSlice().getSymbolicDecisions();
        SymbolicDecisions d2 = enc2.getMainSlice().getSymbolicDecisions();
        BoolExpr dataFwd1 = d1.getDataForwarding().get(ge.getRouter(), ge);
        BoolExpr dataFwd2 = d2.getDataForwarding().get(ge.getRouter(), ge);
        assert dataFwd1 != null;
        assert dataFwd2 != null;
        required = enc1.mkAnd(required, enc1.mkEq(dataFwd1, dataFwd2));
    }
    enc1.add(related);
    enc1.add(enc1.mkNot(required));
    Tuple<VerificationResult, Model> tup = enc1.verify();
    VerificationResult res = tup.getFirst();
    Model model = tup.getSecond();
    SortedSet<String> case1 = null;
    SortedSet<String> case2 = null;
    Flow flow = null;
    CounterExample ce = new CounterExample(model);
    if (!res.isVerified()) {
        case1 = new TreeSet<>();
        case2 = new TreeSet<>();
        flow = ce.buildFlow(enc1.getMainSlice().getSymbolicPacket(), "(none)");
        for (GraphEdge ge : graph.getAllRealEdges()) {
            SymbolicDecisions d1 = enc1.getMainSlice().getSymbolicDecisions();
            SymbolicDecisions d2 = enc2.getMainSlice().getSymbolicDecisions();
            BoolExpr dataFwd1 = d1.getDataForwarding().get(ge.getRouter(), ge);
            BoolExpr dataFwd2 = d2.getDataForwarding().get(ge.getRouter(), ge);
            assert dataFwd1 != null;
            assert dataFwd2 != null;
            boolean b1 = ce.boolVal(dataFwd1);
            boolean b2 = ce.boolVal(dataFwd2);
            if (b1 != b2) {
                if (b1) {
                    String route = ce.buildRoute(enc1.getMainSlice(), ge);
                    String msg = ge + " -- " + route;
                    case1.add(msg);
                }
                if (b2) {
                    String route = ce.buildRoute(enc2.getMainSlice(), ge);
                    String msg = ge + " -- " + route;
                    case2.add(msg);
                }
            }
        }
    }
    // Ensure canonical order
    boolean less = (case1 == null || (case1.first().compareTo(case2.first()) < 0));
    if (less) {
        return new SmtDeterminismAnswerElement(flow, case1, case2);
    } else {
        return new SmtDeterminismAnswerElement(flow, case2, case1);
    }
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) Flow(org.batfish.datamodel.Flow) Graph(org.batfish.symbolic.Graph) Model(com.microsoft.z3.Model) SmtDeterminismAnswerElement(org.batfish.symbolic.answers.SmtDeterminismAnswerElement) GraphEdge(org.batfish.symbolic.GraphEdge)

Example 5 with com.google.api.services.sheets.v4.model

use of com.google.api.services.sheets.v4.model in project xtext-core by eclipse.

the class Bug305397Test method testBug.

@Test
public void testBug() throws Exception {
    with(new Bug305397StandaloneSetup());
    Model model = (Model) getModel("   a element \n   element X end\n element Y end \nend");
    Element outer = model.getElements().get(0);
    Element firstInner = outer.getElements().get(0);
    ICompositeNode outerNode = NodeModelUtils.getNode(outer);
    assertEquals(3, outerNode.getOffset());
    ICompositeNode firstInnerNode = NodeModelUtils.getNode(firstInner);
    assertEquals(17, firstInnerNode.getOffset());
}
Also used : Element(org.eclipse.xtext.parsetree.impl.bug305397.Element) Model(org.eclipse.xtext.parsetree.impl.bug305397.Model) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)77 Model (org.eclipse.xtext.valueconverter.bug250313.Model)30 Exchange (org.apache.camel.Exchange)29 DefaultExchange (org.apache.camel.support.DefaultExchange)29 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)19 Model (com.google.cloud.aiplatform.v1.Model)16 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)16 Model (com.google.cloud.automl.v1.Model)16 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)16 BatchUpdateSpreadsheetRequest (com.google.api.services.sheets.v4.model.BatchUpdateSpreadsheetRequest)14 ValueRange (com.google.api.services.sheets.v4.model.ValueRange)14 LocationName (com.google.cloud.aiplatform.v1.LocationName)14 PipelineServiceClient (com.google.cloud.aiplatform.v1.PipelineServiceClient)14 PipelineServiceSettings (com.google.cloud.aiplatform.v1.PipelineServiceSettings)14 TrainingPipeline (com.google.cloud.aiplatform.v1.TrainingPipeline)14 InputDataConfig (com.google.cloud.aiplatform.v1.InputDataConfig)13 ModelContainerSpec (com.google.cloud.aiplatform.v1.ModelContainerSpec)13 FilterSplit (com.google.cloud.aiplatform.v1.FilterSplit)11 FractionSplit (com.google.cloud.aiplatform.v1.FractionSplit)11