com.google.common.collect.ArrayTable Java Examples

The following examples show how to use com.google.common.collect.ArrayTable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FEAMatFileWriter.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
private MLDouble histoDataAsMLDouble(String name, ArrayTable<Integer, String, Float> histoData) {
    int rowsSize = histoData.rowKeySet().size();
    int colsSize = histoData.columnKeySet().size();
    MLDouble mlDouble = new MLDouble(name, new int[] {rowsSize, colsSize});
    int i = 0;
    for (Integer rowKey : histoData.rowKeyList()) {
        int j = 0;
        for (String colkey : histoData.columnKeyList()) {
            Float v = histoData.get(rowKey, colkey);
            mlDouble.set(new Double(v), i, j);
            j++;
        }
        i++;
    }
    return mlDouble;
}
 
Example #2
Source File: Utils.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
public static double[][] histoDataAsDoubleMatrixNew(ArrayTable<Integer, String, Float> hdTable) {
    int rowsSize = hdTable.rowKeySet().size();
    int colsSize = hdTable.columnKeySet().size();
    double[][] matFinal = new double[rowsSize][colsSize];
    int i = 0;
    for (Integer rowKey : hdTable.rowKeyList()) {
        int j = 0;
        for (String colkey : hdTable.columnKeyList()) {
            Float v = hdTable.get(rowKey, colkey);
            matFinal[i][j] = getCleanFloat(v);
            j = j + 1;
        }
        i = i + 1;
    }
    return matFinal;
}
 
Example #3
Source File: GuavaTableUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenArrayTable_whenGet_returnsSuccessfully() {
    final List<String> universityRowTable = Lists.newArrayList("Mumbai", "Harvard");
    final List<String> courseColumnTables = Lists.newArrayList("Chemical", "IT", "Electrical");
    final Table<String, String, Integer> universityCourseSeatTable = ArrayTable.create(universityRowTable, courseColumnTables);
    universityCourseSeatTable.put("Mumbai", "Chemical", 120);
    universityCourseSeatTable.put("Mumbai", "IT", 60);
    universityCourseSeatTable.put("Harvard", "Electrical", 60);
    universityCourseSeatTable.put("Harvard", "IT", 120);

    final int seatCount = universityCourseSeatTable.get("Mumbai", "IT");

    assertThat(seatCount).isEqualTo(60);
}
 
Example #4
Source File: ForecastErrorsHistoricalData.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
public ForecastErrorsHistoricalData(List<String> generatorsIds, List<String> loadsIds,
                                    List<StochasticVariable> stochasticVariables,
                                    ArrayTable<Integer, String, Float> forecastsData,
                                    ArrayTable<Integer, String, Float> snapshotsData) {
    this.generatorsIds = generatorsIds;
    this.loadsIds = loadsIds;
    this.stochasticVariables = stochasticVariables;
    this.forecastsData = forecastsData;
    this.snapshotsData = snapshotsData;
}
 
Example #5
Source File: Wp41HistoData.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
public Wp41HistoData(List<String> historicalGensIds,
                     List<String> historicalLoadsIds,
                     List<String> historicalDanglingLinesIds,
                     ArrayTable<Integer, String, Float> hdTable) {
    this.historicalGensIds = historicalGensIds;
    this.historicalLoadsIds = historicalLoadsIds;
    this.historicalDanglingLinesIds = historicalDanglingLinesIds;
    this.hdTable = hdTable;
}
 
Example #6
Source File: DataMiningFacadeHistodb.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
private Wp41HistoData parseData(DataMiningFacadeParams dmParams) throws IOException, InterruptedException {
    int rowCount = histoClient.queryCount(dmParams.getInterval(), HistoDbHorizon.SN);

    Set<HistoDbAttributeId> attributeIds = new LinkedHashSet<>((dmParams.getGensIds().size() +
                                                                dmParams.getLoadsIds().size() +
                                                                dmParams.getDanglingLinesIds().size()) * 2); // gens P, Q loads P, Q danglingLines P0, Q0
    for (String genId : dmParams.getGensIds()) {
        attributeIds.add(new HistoDbNetworkAttributeId(genId, HistoDbAttr.P));
        attributeIds.add(new HistoDbNetworkAttributeId(genId, HistoDbAttr.Q));
    }
    for (String loadId : dmParams.getLoadsIds()) {
        attributeIds.add(new HistoDbNetworkAttributeId(loadId, HistoDbAttr.P));
        attributeIds.add(new HistoDbNetworkAttributeId(loadId, HistoDbAttr.Q));
    }
    for (String dlId : dmParams.getDanglingLinesIds()) {
        attributeIds.add(new HistoDbNetworkAttributeId(dlId, HistoDbAttr.P0));
        attributeIds.add(new HistoDbNetworkAttributeId(dlId, HistoDbAttr.Q0));
    }

    List<Integer> rowIndexes;
    try (IntStream intStream = IntStream.range(0, rowCount)) {
        rowIndexes = intStream.boxed().collect(Collectors.toList());
    }
    List<String> colIndexes = attributeIds.stream().map(Object::toString).collect(Collectors.toList());

    ArrayTable<Integer, String, Float> hdTable = ArrayTable.create(rowIndexes, colIndexes);

    // parse csv generators
    try (InputStream is = histoClient.queryCsv(HistoQueryType.data, attributeIds, dmParams.getInterval(), HistoDbHorizon.SN, false, false)) {
        parseCsv(is, attributeIds, hdTable, rowCount);
    }

    return new Wp41HistoData(dmParams.getGensIds(), dmParams.getLoadsIds(), dmParams.getDanglingLinesIds(), hdTable);
}
 
Example #7
Source File: Utils.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
public static double[][] histoDataAsDoubleMatrix(ArrayTable<Integer, String, Float> hdTable) {

        int rowsSize = hdTable.rowKeySet().size();
        int colsSize = hdTable.columnKeySet().size();
        double[][] matFinal = new double[rowsSize][colsSize];
        for (int i = 0; i < rowsSize; i++) {
            for (int j = 0; j < colsSize; j++) {
                Float v = hdTable.get(i, j);
                matFinal[i][j] = getCleanFloat(v);
            }
        }
        return matFinal;
    }
 
Example #8
Source File: RedisPermissionsRepository.java    From fiat with Apache License 2.0 5 votes vote down vote up
private Table<String, ResourceType, Response<Map<String, String>>> getAllFromRedis(
    Set<String> userIds) {
  if (userIds.size() == 0) {
    return HashBasedTable.create();
  }

  try {
    final Table<String, ResourceType, Response<Map<String, String>>> responseTable =
        ArrayTable.create(
            userIds,
            new ArrayIterator<>(
                resources.stream().map(Resource::getResourceType).toArray(ResourceType[]::new)));
    for (List<String> userIdSubset : Lists.partition(new ArrayList<>(userIds), 10)) {
      redisClientDelegate.withMultiKeyPipeline(
          p -> {
            for (String userId : userIdSubset) {
              resources.stream()
                  .map(Resource::getResourceType)
                  .forEach(
                      r -> {
                        responseTable.put(userId, r, p.hgetAll(userKey(userId, r)));
                      });
            }
            p.sync();
          });
    }
    return responseTable;
  } catch (Exception e) {
    log.error("Storage exception reading all entries.", e);
  }
  return null;
}
 
Example #9
Source File: TradeReportFormatterTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
public void getColumnTypes() {
  ArrayTable<Integer, Integer, Result<?>> table = ArrayTable.create(INDICES, INDICES);
  table.put(0, 0, Result.success(1));
  table.put(0, 1, Result.success("abc"));
  table.put(1, 0, Result.success(2));
  table.put(1, 1, Result.success("def"));

  List<Class<?>> columnTypes = TradeReportFormatter.INSTANCE.getColumnTypes(report(table));
  assertThat(columnTypes).isEqualTo(ImmutableList.of(Integer.class, String.class));
}
 
Example #10
Source File: TradeReportFormatterTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
public void getColumnTypesWithSomeFailures() {
  ImmutableList<Integer> indices = ImmutableList.of(0, 1);
  ArrayTable<Integer, Integer, Result<?>> table = ArrayTable.create(indices, indices);
  table.put(0, 0, Result.failure(FailureReason.ERROR, "fail"));
  table.put(0, 1, Result.failure(FailureReason.ERROR, "fail"));
  table.put(1, 0, Result.success(2));
  table.put(1, 1, Result.success("def"));

  List<Class<?>> columnTypes = TradeReportFormatter.INSTANCE.getColumnTypes(report(table));
  assertThat(columnTypes).isEqualTo(ImmutableList.of(Integer.class, String.class));
}
 
Example #11
Source File: TradeReportFormatterTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
public void getColumnTypesWithAllFailures() {
  ImmutableList<Integer> indices = ImmutableList.of(0, 1);
  ArrayTable<Integer, Integer, Result<?>> table = ArrayTable.create(indices, indices);
  table.put(0, 0, Result.failure(FailureReason.ERROR, "fail"));
  table.put(0, 1, Result.failure(FailureReason.ERROR, "fail"));
  table.put(1, 0, Result.failure(FailureReason.ERROR, "fail"));
  table.put(1, 1, Result.failure(FailureReason.ERROR, "fail"));

  List<Class<?>> columnTypes = TradeReportFormatter.INSTANCE.getColumnTypes(report(table));
  assertThat(columnTypes).isEqualTo(ImmutableList.of(Object.class, Object.class));
}
 
Example #12
Source File: TradeReportFormatterTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
private TradeReport report(ArrayTable<Integer, Integer, Result<?>> table) {
  return TradeReport.builder()
      .columns(
          TradeReportColumn.builder().header("col0").build(),
          TradeReportColumn.builder().header("col1").build())
      .data(table)
      .valuationDate(LocalDate.now(ZoneOffset.UTC))
      .runInstant(Instant.now())
      .build();
}
 
Example #13
Source File: ExpressionUtilTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
static
InlineTable createInlineTable(List<List<String>> rows, List<String> columns){
	List<Integer> rowKeys = new ArrayList<>();

	for(int i = 0; i < rows.size(); i++){
		rowKeys.add(i + 1);
	}

	Table<Integer, String, String> table = ArrayTable.create(rowKeys, columns);

	for(int i = 0; i < rows.size(); i++){
		List<String> row = rows.get(i);

		for(int j = 0; j < columns.size(); j++){
			String column = columns.get(j);
			String value = row.get(j);

			if(value == null){
				continue;
			}

			table.put(rowKeys.get(i), column, value);
		}
	}

	return InlineTableUtil.format(table);
}
 
Example #14
Source File: ForecastErrorsHistoricalData.java    From ipst with Mozilla Public License 2.0 4 votes vote down vote up
public ArrayTable<Integer, String, Float> getForecastsData() {
    return forecastsData;
}
 
Example #15
Source File: ForecastErrorsHistoricalData.java    From ipst with Mozilla Public License 2.0 4 votes vote down vote up
public ArrayTable<Integer, String, Float> getSnapshotsData() {
    return snapshotsData;
}
 
Example #16
Source File: Wp41HistoData.java    From ipst with Mozilla Public License 2.0 4 votes vote down vote up
public ArrayTable<Integer, String, Float> getHdTable() {
    return hdTable;
}