Printing of User Statistics looks strange
rkaminsk opened this issue · comments
I was experimenting with the new interface to extend the statistics. Somehow I can't decipher the output. Adding a recursive structure like
{ "a": 10
, "b": [1, 2, 3]
, "c":
{ "d": 1
, "e": [1,2,3]
}
}
I get the output
...
a : 10
[b]
[0]: 1
[1]: 2
[2]: 3
[c]
d : 1
[e]
[0]: 1
[1]: 2
[2]: 3
The indentation of d
looks wrong. I am also not sure if the spacing for the colons is intended like this. Would it make sense to use the same spacing clasp uses for the inbuilt statistics output?
What about the following function to print the statistics (pre
is a default argument set to ""
)?
void TextOutput::printChildren(const StatisticObject& s, unsigned level, char const *pre) {
unsigned indent = level * 2;
for (uint32 i = 0; i != s.size(); ++i) {
const char* key = s.type() == Potassco::Statistics_t::Map ? s.key(i) : 0;
StatisticObject child = key ? s.at(key) : s[i];
if (child.type() == Potassco::Statistics_t::Array && key) {
printChildren(child, level, key);
}
else if (child.type() == Potassco::Statistics_t::Value) {
printf("%s%-*.*s", format[cat_comment], indent, indent, " ");
int align = 13 - (int)indent;
if (key) {
align -= printf("%s", key);
}
else if (pre) {
align -= printf("[%s %u]", pre, i);
}
else {
align -= printf("[%u]", i);
}
printf("%-*s: %g\n", std::max(0, align), "", child.value());
}
else if (child.size() > 0) {
printf("%s%-*.*s", format[cat_comment], indent, indent, " ");
if (!key) {
if (pre) { printf("[%s %u]\n", pre, i); }
else { printf("[%u]\n", i); }
}
else {
printf("%s\n", key);
}
printChildren(child, level + 1);
}
}
}
It produces output like
test : 65
[x 0] : 99
[x 1] : 9
[x 2] : 3
[x 3] : 4
[x 4] : 5
[x 5] : 6
[x 6] : 4
[x 7] : 5
[x 8] : 6
[z 0]
a : 1
b : 2
[z 1] : 2
[z 2] : 3
y
a : 42
[b 0] : 0
[b 1] : 2
[b 2] : 3
c : 99
[xz 0] : 1
[xz 1] : 2
[xz 2]
[0] : 1
[1] : 2
It combines keys of maps with contained arrays, which was inspired by the thread output of the normal clasp output.
Thanks. Fixed in dev.
Thanks.
(And 👍 for factoring out printChildKey. I am always missing something when quickly putting code online before going home.)