use of org.structr.core.property.IntProperty in project structr by structr.
the class LogResource method histogram.
private Result histogram(final LogState state) throws FrameworkException {
// sort entries before creating the histogram
state.sortEntries();
final String dateFormat = state.aggregate();
final long startTimestamp = state.beginTimestamp();
final long endTimestamp = state.endTimestamp();
final GraphObjectMap result = new GraphObjectMap();
final long interval = findInterval(dateFormat);
final long start = alignDateOnFormat(dateFormat, startTimestamp);
final TreeMap<Long, Map<String, Object>> countMap = toHistogramCountMap(state);
final Set<String> countProperties = getCountProperties(countMap);
for (long current = start; current <= endTimestamp; current += interval) {
final Map<Long, Map<String, Object>> counts = countMap.subMap(current, true, current + interval, false);
final GraphObjectMap sum = new GraphObjectMap();
// whether there are actual values or not)
for (final String key : countProperties) {
sum.put(new IntProperty(key), 0);
}
// evaluate counts
for (final Map<String, Object> count : counts.values()) {
for (final String key : countProperties) {
final IntProperty prop = new IntProperty(key);
Integer sumValue = sum.get(prop);
if (sumValue == null) {
sumValue = 0;
}
Integer entryValue = (Integer) count.get(key);
if (entryValue == null) {
entryValue = 0;
}
sum.put(prop, sumValue + entryValue);
}
}
result.put(new GenericProperty(Long.toString(current)), sum);
}
return new Result(result, false);
}
use of org.structr.core.property.IntProperty in project structr by structr.
the class LogResource method aggregate.
private Result aggregate(final LogState state) throws FrameworkException {
// sort entries before aggregation
state.sortEntries();
final long startTimestamp = state.beginTimestamp();
final long endTimestamp = state.endTimestamp();
final GraphObjectMap result = new GraphObjectMap();
final long interval = findInterval(state.aggregate());
final long start = alignDateOnFormat(state.aggregate(), startTimestamp);
final TreeMap<Long, Map<String, Object>> countMap = toAggregatedCountMap(state);
final Set<String> countProperties = getCountProperties(countMap);
for (long current = start; current <= endTimestamp; current += interval) {
final Map<Long, Map<String, Object>> counts = countMap.subMap(current, true, current + interval, false);
final GraphObjectMap sum = new GraphObjectMap();
// whether there are actual values or not)
for (final String key : countProperties) {
sum.put(new IntProperty(key), 0);
}
// evaluate counts
for (final Map<String, Object> count : counts.values()) {
for (final String key : countProperties) {
final IntProperty prop = new IntProperty(key);
Integer sumValue = sum.get(prop);
if (sumValue == null) {
sumValue = 0;
}
Integer entryValue = (Integer) count.get(key);
if (entryValue == null) {
entryValue = 0;
}
sum.put(prop, sumValue + entryValue);
}
}
result.put(new GenericProperty(Long.toString(current)), sum);
}
return new Result(result, false);
}
use of org.structr.core.property.IntProperty in project structr by structr.
the class SystemTest method testFlawedParallelInstantiation.
/**
* disabled, failing test to check for (existing, confirmed) flaw in parallel node instantiation)
*/
@Test
public void testFlawedParallelInstantiation() {
final int nodeCount = 1000;
SchemaNode createTestType = null;
// setup: create dynamic type with onCreate() method
try (final Tx tx = app.tx()) {
createTestType = createTestNode(SchemaNode.class, "CreateTest");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
Class testType = StructrApp.getConfiguration().getNodeEntityClass("CreateTest");
assertNotNull("Type CreateTest should have been created", testType);
// second step: create 1000 test nodes
try (final Tx tx = app.tx()) {
createTestNodes(testType, nodeCount);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
try (final Tx tx = app.tx()) {
createTestType.setProperty(new StringProperty("_testCount"), "Integer");
createTestType.setProperty(new StringProperty("___onCreate"), "set(this, 'testCount', size(find('CreateTest')))");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
testType = StructrApp.getConfiguration().getNodeEntityClass("CreateTest");
NodeInterface node = null;
// third step: create a single node in a separate transaction
try (final Tx tx = app.tx()) {
node = createTestNode(testType, "Tester");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
// fourth step: check property value
try (final Tx tx = app.tx()) {
final Integer testCount = node.getProperty(new IntProperty("testCount"));
assertEquals("Invalid node count, check parallel instantiation!", (int) nodeCount + 1, (int) testCount);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
}
Aggregations