项目:jaf-examples
文件:MyPersonCaclByArrayTable.java
private static void loadFromDb(ArrayTable<Integer,Character,List<Person>> personsTable) throws IOException {
long start = System.currentTimeMillis();
File dbFile = new File(Config.DB_FILE_NAME);
LineIterator it = FileUtils.lineIterator(dbFile,"UTF-8");
while(it.hasNext()) {
String line = it.next();
Person person = parseStringTokenizer(line);
char fc = person.name.charat(0);
List<Person> persons = personsTable.get(person.age,fc);
if(persons == null) {
persons = new ArrayList<>();
personsTable.put(person.age,person.name.charat(0),persons);
}
persons.add(person);
}
System.out.println("load data elapsed time : " + (System.currentTimeMillis() - start));
}
项目:ipst
文件:FEAMatFileWriter.java
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;
}
项目:ipst
文件:Utils.java
public static double[][] histoDataAsDoubleMatrixNew(ArrayTable<Integer,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;
}
private Table<String,ResourceType,Response<Map<String,String>>> getAllFromredis(Set<String> userIds) {
if (userIds.size() == 0) {
return HashBasedTable.create();
}
try (Jedis jedis = jedisSource.getJedis()) {
Table<String,String>>> responseTable =
ArrayTable.create(userIds,new ArrayIterator<>(ResourceType.values()));
Pipeline p = jedis.pipelined();
for (String userId : userIds) {
for (ResourceType r : ResourceType.values()) {
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;
}
项目:gwthtml5apps
文件:GridPaint.java
public GridImageData(String fileName,String dataUrl,int gridSize,int row,int col,int imageWidth,int imageHeight) {
super();
this.fileName = fileName;
this.dataUrl = dataUrl;
this.gridSize=gridSize;
this.row=row;
this.col=col;
this.imageHeight=imageHeight;
this.imageWidth=imageWidth;
Collection<Integer> rowValues=new ArrayList<Integer>();
Collection<Integer> colValues=new ArrayList<Integer>();
for(int i=0;i<row;i++){
rowValues.add(i);
}
for(int i=0;i<col;i++){
colValues.add(i);
}
gridTable=ArrayTable.create(rowValues,colValues);
}
项目:jaf-examples
文件:MyPersonCaclByArrayTable.java
private static void arrayTable() throws IOException {
List<Integer> ages = new ArrayList<>();
for(int i = 1; i <= 18; i++) {
ages.add(i);
}
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMnopQRSTUVWXYZ0123456789";
List<Character> chapters = new ArrayList<>();
for(int i = 0; i < str.length(); i++) {
chapters.add(str.charat(i));
}
ArrayTable<Integer,List<Person>> personsTable = ArrayTable.create(ages,chapters);
loadFromDb(personsTable);
for(char c = 'a'; c <= 'e'; c++) {
Map<Integer,List<Person>> rowsPerson = personsTable.column(c);
long count6_11 = rowsPerson.keySet()
.stream()
.filter(r -> r >= 6 && r <= 11)
.map(r -> rowsPerson.get(r).size()).reduce(0,Integer::sum);
System.out.println("[6-11]-" + c + " : " + count6_11);
long count16_18 = rowsPerson.keySet()
.stream()
.filter(r -> r >= 16 && r <= 18)
.map(r -> rowsPerson.get(r).size()).reduce(0,Integer::sum);
System.out.println("[16-18]-" + c + " : " + count16_18);
}
}
项目:ipst
文件:ForecastErrorsHistoricalData.java
public ForecastErrorsHistoricalData(List<String> generatorsIds,List<String> loadsIds,List<stochasticVariable> stochasticVariables,Float> forecastsData,Float> snapshotsData) {
this.generatorsIds = generatorsIds;
this.loadsIds = loadsIds;
this.stochasticVariables = stochasticVariables;
this.forecastsData = forecastsData;
this.snapshotsData = snapshotsData;
}
项目:ipst
文件:Wp41HistoData.java
public Wp41HistoData(List<String> historicalGensIds,List<String> historicalLoadsIds,List<String> historicalDanglingLinesIds,Float> hdTable) {
this.historicalGensIds = historicalGensIds;
this.historicalLoadsIds = historicalLoadsIds;
this.historicalDanglingLinesIds = historicalDanglingLinesIds;
this.hdTable = hdTable;
}
项目:ipst
文件:DataMiningFacadeHistodb.java
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,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,hdTable,rowCount);
}
return new Wp41HistoData(dmParams.getGensIds(),dmParams.getLoadsIds(),dmParams.getDanglingLinesIds(),hdTable);
}
项目:ipst
文件:Utils.java
public static double[][] histoDataAsDoubleMatrix(ArrayTable<Integer,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;
}
项目:director-aws-plugin
文件:NetworkRules.java
/**
* Parses a HOCON config to a table of network rules.
*/
private static Table<Direction,Accesstype,Iterable<NetworkRule>> parse(Config config) {
Table<Direction,Iterable<NetworkRule>> rules =
ArrayTable.create(EnumSet.allOf(Direction.class),EnumSet.allOf(Accesstype.class));
for (Direction direction: Direction.values()) {
for (Accesstype access: Accesstype.values()) {
populateRules(config,direction,access,rules);
}
}
return rules;
}
项目:FinanceAnalytics
文件:SimpleResultBuilder.java
/**
* Builds a {@link ScenarioResultModel} from the data calculated in a single cycle.
* @param resultModel the results calculated by the engine in a single calculation cycle
* @param columnNames column name overrides
* @return A simple result model built from the results
* @throws IllegalArgumentException if the number of column names doesn't match the number of columns
*/
public SimpleResultModel build(ViewResultModel resultModel,List<String> columnNames) {
ArgumentChecker.notNull(columnNames,"columnNames");
ArgumentChecker.notNull(resultModel,"resultModel");
if (columnNames.size() != _columnNames.size()) {
throw new IllegalArgumentException("Wrong number of column names. expected: " + _columnNames.size() +
",actual: " + columnNames.size());
}
int rowCount = _idToIndex.size();
int colCount = columnNames.size();
ContiguousSet<Integer> rowIndices = ContiguousSet.create(Range.closedOpen(0,rowCount),discreteDomain.integers());
ContiguousSet<Integer> colIndices = ContiguousSet.create(Range.closedOpen(0,colCount),discreteDomain.integers());
Table<Integer,Integer,Object> table = ArrayTable.create(rowIndices,colIndices);
for (ViewResultEntry entry : resultModel.getAllResults()) {
String calcConfigName = entry.getCalculationConfiguration();
ComputedValueResult value = entry.getComputedValue();
ValueSpecification valueSpec = value.getSpecification();
CompiledViewCalculationConfiguration calcConfig = _compiledViewDef.getCompiledCalculationConfiguration(calcConfigName);
Set<ValueRequirement> valueReqs = calcConfig.getTerminalOutputSpecifications().get(valueSpec);
for (ValueRequirement valueReq : valueReqs) {
ColumnSpec colSpec = new ColumnSpec(calcConfigName,valueReq.getValueName(),valueReq.getConstraints());
Integer colIndex = _colToIndex.get(colSpec);
Integer rowIndex = _idToIndex.get(valueReq.getTargetReference().getSpecification().getUniqueId().getobjectId());
// there won't be a row or column index for specific outputs (e.g. curves)
if (colIndex != null && rowIndex != null) {
table.put(rowIndex,colIndex,value);
}
// Todo handle specific outputs
}
}
return new SimpleResultModel(_targets,columnNames,table,resultModel.getViewCycleExecutionoptions());
}
StateMachineserviceBuilder(@NonNull final Class<S> states,@NonNull final Class<E> events) {
stateClass = requireNonNull(states);
eventClass = requireNonNull(events);
transitions = ArrayTable.create(EnumSet.allOf(stateClass),EnumSet.allOf(eventClass));
actions = ArrayTable.create(EnumSet.allOf(stateClass),EnumSet.allOf(eventClass));
noStateTransitions = newEnumMap(eventClass);
noStateActions = newEnumMap(eventClass);
}
项目:kidneyExchange
文件:AggregateTrialReport.java
public AggregateTrialReport(boolean showOutcomeNames,boolean showAttributeNames,boolean outcomesAreRows,List<SimulationInputs> simulationInputs,int numTrialsPerSimulation) {
this.showAttributeNames = showAttributeNames;
this.showOutcomeNames = showOutcomeNames;
this.outcomesAreRows = outcomesAreRows;
List<Integer> columns = Lists.newArrayList();
for (int i = 0; i < numTrialsPerSimulation; i++) {
columns.add(i);
}
trialOutcomes = ArrayTable.create(simulationInputs,columns);
nodeAggregationAttributes = Lists.newArrayList();
}
public void getColumnTypes() {
ArrayTable<Integer,Result<?>> table = ArrayTable.create(INDICES,INDICES);
table.put(0,Result.success(1));
table.put(0,1,Result.success("abc"));
table.put(1,Result.success(2));
table.put(1,Result.success("def"));
List<Class<?>> columnTypes = TradeReportFormatter.INSTANCE.getColumnTypes(report(table));
assertthat(columnTypes).isEqualTo(ImmutableList.of(Integer.class,String.class));
}
public void getColumnTypesWithSomeFailures() {
ImmutableList<Integer> indices = ImmutableList.of(0,1);
ArrayTable<Integer,Result<?>> table = ArrayTable.create(indices,indices);
table.put(0,Result.failure(FailureReason.ERROR,"fail"));
table.put(0,"fail"));
table.put(1,String.class));
}
public void getColumnTypesWithAllFailures() {
ImmutableList<Integer> indices = ImmutableList.of(0,"fail"));
List<Class<?>> columnTypes = TradeReportFormatter.INSTANCE.getColumnTypes(report(table));
assertthat(columnTypes).isEqualTo(ImmutableList.of(Object.class,Object.class));
}
private TradeReport report(ArrayTable<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();
}
项目:jpmml-evaluator
文件:ExpressionUtilTest.java
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> 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);
}
项目:Leveled-Storage
文件:ArrayTableStorage.java
public ArrayTableStorage(ArrayTable<R,C,V> table) {
super(table);
}
项目:Leveled-Storage
文件:ArrayTableStorage.java
@Override
public StorageObject delegate() {
return new ArrayTableStorage(ArrayTable.create(getValue()));
}
项目:ipst
文件:ForecastErrorsHistoricalData.java
public ArrayTable<Integer,Float> getForecastsData() {
return forecastsData;
}
项目:ipst
文件:ForecastErrorsHistoricalData.java
public ArrayTable<Integer,Float> getSnapshotsData() {
return snapshotsData;
}
项目:ipst
文件:Wp41HistoData.java
public ArrayTable<Integer,Float> getHdTable() {
return hdTable;
}
private CostMatrix(Collection<INode> children1,Collection<INode> children2) {
costMatrix = ArrayTable.create(children1,children2);
}
项目:swmutsel
文件:GuavaUtils.java
public static <R,V> Table<R,V> getColumnSubset(Table<R,V> table,Collection<C> columns) {
Collection<R> rows = table.rowKeySet();
Table<R,V> subTable = ArrayTable.create(rows,columns);
for (R row : rows) {
for (C column : columns) {
subTable.put(row,table.get(row,column));
}
}
return subTable;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。