This will not work; dates are not packed.
This commit is contained in:
parent
311316ef88
commit
45c667cdda
@ -44,6 +44,10 @@ int main(void) {
|
||||
if(!freopen(intent, "w", stdout)) goto catch;
|
||||
scan_kjv_graph(&scn);
|
||||
|
||||
intent = "derived/dream.gnu";
|
||||
if(!freopen(intent, "w", stdout)) goto catch;
|
||||
scan_dream_graph(&scn);
|
||||
|
||||
intent = 0;
|
||||
goto finally;
|
||||
catch:
|
||||
|
@ -155,3 +155,4 @@ void scan_score_graph(struct scan *);
|
||||
void scan_glider_graph(struct scan *);
|
||||
void scan_flight_graph(struct scan *);
|
||||
void scan_kjv_graph(struct scan *);
|
||||
void scan_dream_graph(struct scan *);
|
||||
|
@ -1352,3 +1352,62 @@ finally:
|
||||
kjv_count_(&count);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
void scan_dream_graph(struct scan *const scan) {
|
||||
assert(scan);
|
||||
fprintf(stderr, "*** Dream graph: %s.\n",
|
||||
linepair_tree_to_string(&scan->dreams));
|
||||
|
||||
struct linepair_tree_iterator it = linepair_tree_iterator(&scan->dreams);
|
||||
|
||||
/* https://stackoverflow.com/a/12601553 */
|
||||
printf("set terminal pngcairo dashed transparent truecolor"
|
||||
" size 840, 480 fontscale 1\n"
|
||||
"set output \"dream.png\"\n"
|
||||
"$Data <<EOD\n"
|
||||
"# date\n");
|
||||
struct { union date32 date; size_t count; } accum = { {{0}}, 0 };
|
||||
while(linepair_tree_next(&it)) {
|
||||
/* Bin by month. */
|
||||
const union date32
|
||||
now = { .u32 = linepair_tree_key(&it).date.u32 & ~31u };
|
||||
/* Next month; output the last. */
|
||||
if(accum.date.u32 < now.u32) {
|
||||
if(accum.count) {
|
||||
printf("%" PRIu32 "-%.2" PRIu32 ", %zu\n",
|
||||
accum.date.year, accum.date.month, accum.count);
|
||||
/* If we skip a month, output zero as dummy. */
|
||||
union date32 next = { .u32 = accum.date.u32 + 32 };
|
||||
if(next.u32 < now.u32) {
|
||||
printf("%" PRIu32 "-%.2" PRIu32 ", 0\n",
|
||||
next.year, next.month);
|
||||
/* Skip more than a month, place dummy output on both. */
|
||||
union date32 last = { .u32 = now.u32 - 32 };
|
||||
if(next.u32 < last.u32)
|
||||
printf("%" PRIu32 "-%.2" PRIu32 ", 0\n",
|
||||
last.year, last.month);
|
||||
/* fixme: this will not work because it's not packed. */
|
||||
}
|
||||
}
|
||||
accum.date = now;
|
||||
accum.count = 1;
|
||||
} else {
|
||||
accum.count++;
|
||||
}
|
||||
//date32_to_string(line.date, &datestr); /* Date. */
|
||||
//printf("%s, %.*s\n", datestr, (int)(dream->b - dream->a), dream->a);
|
||||
//printf("%s\n", datestr);
|
||||
}
|
||||
if(accum.count) printf("%" PRIu32 "-%.2" PRIu32 ", %zu\n",
|
||||
accum.date.year, accum.date.month, accum.count);
|
||||
printf("EOD\n"
|
||||
"\n"
|
||||
"set xdata time\n"
|
||||
"set timefmt \"%%Y-%%m\"\n"
|
||||
"set format x \"%%Y-%%m\"\n"
|
||||
"set style fill transparent solid 0.3\n"
|
||||
"\n"
|
||||
"plot $Data using 1:2 with boxes notitle\n" /*lc rgb "blue"?*/);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user