graphed better

This commit is contained in:
Neil 2023-03-22 22:31:49 -07:00
parent 7c8f0a63e9
commit 09cd40399d

View File

@ -265,42 +265,43 @@ int main(void) {
struct kjvline_tree_iterator it = kjv_line_iterator(&lines);
union line64 line;
const struct kjvrange *range;
struct kjvset_table set = kjv_set();
printf("set term postscript eps enhanced\n"
"set output \"kjv.eps\"\n"
"$Data <<EOD\n"
"# date, source, verse, words, set / %zu\n", no_total);
/*printf("set term postscript eps enhanced\n"
"set output \"kjv.eps\"\n");*/
/*printf("set terminal cairolatex standalone pdf size "
"16cm,10.5cm dashed transparent\n"
"set output \"kjv.tex\"\n");*/
/*printf("set terminal png transparent truecolor\n"
"set output \"kjv.png\"\n");*/
/* https://stackoverflow.com/a/12601553 */
printf("set terminal pngcairo dashed transparent truecolor\n"
"set output \"kjv.png\"\n");
printf("$Data <<EOD\n"
"# date, verse, words, set / %zu, source\n", no_total);
while(kjv_line_next(&it, &line, &range)) {
char citestr[12], datestr[12];
size_t words = 0, newwords = 0;
const struct source *src = source_lookup(&srcs, line); /* Source. */
if(!src || !src->name.a) { errno = EDOM; goto catch; }
date32_to_string(line.date, &datestr); /* Date. */
kjvcite_to_string(range->start, &citestr); /* KJV cite. */
for(uint32_t c = range->start.verse; ; c++) {
//if(!kjv_add(kj, cite)) return 0;
if(!range->verse_end || range->verse_end <= c) break;
for(union kjvcite c = range->start; ; c.verse++) {
size_t w = kjv_count_get(&count, c);
words += w;
switch (kjv_set_add(&set, c)) {
case TABLE_ERROR: goto catch;
case TABLE_ABSENT: newwords += w;
case TABLE_PRESENT: break;
} /* while(); */
if(!range->verse_end || range->verse_end <= c.verse) break;
}
printf("%s, %.*s, %s", datestr,
(int)(src->name.b - src->name.a), src->name.a, citestr);
printf("%s, %s", datestr, citestr);
if(range->verse_end) printf("-%" PRIu32, range->verse_end);
printf(", \n");
#if 0
//fixme
for( ; ; cite.verse++) {
if(!kjv_add(kj, cite)) return 0;
if(!verse_end || verse_end <= cite.verse) break;
}
printf("%s\t%zu\t%zu\t%zu\t# ",
datestr, kj->words.verse, kj->words.set, kj->words.cumulative);
if(verse_end) {
printf("%s-%" PRIu32 "\n", citestr, verse_end);
} else {
printf("%s\n", citestr);
}
printf("%d-%.2d-%.2d:%u-%u %s\n");
#endif
printf(", %zu, %zu, %.*s\n",
words, newwords, (int)(src->name.b - src->name.a), src->name.a);
}
printf("EOD\n"
/*printf("EOD\n"
"set monochrome\n"
"set xdata time\n"
"set timefmt \"%%Y-%%m-%%d\"\n"
@ -313,7 +314,40 @@ int main(void) {
"#set style fill solid 0.1 #pattern 5 (better, but restarts)\n"
"plot $Data using 1:($3)*100/%zu with fillsteps lw 2 title \"set\", \\\n"
"$Data using 1:($4)*100/%zu with steps lw 1 title \"cumulative\"\n",
no_total, no_total);
no_total, no_total);*/
printf("EOD\n"
"# theozh https://stackoverflow.com/a/75466214/2472827\n"
"# get a unique list from datablock\n"
"addToList(list,col) = list.( strstrt(list,'\"'.strcol(col).'\"') > 0 "
"? \\\n"
" '' : ' \"'.strcol(col).'\"')\n"
"Uniqs = ''\n"
"stats $Data u (Uniqs=addToList(Uniqs,5)) nooutput\n"
"Uniq(i) = word(Uniqs,i)\n"
"getIndex(s) = sum [_i=1:words(Uniqs)] s eq word(Uniqs,_i) ? _i : 0\n"
"myTimeFmt = \"%%Y-%%m-%%d\"\n"
"set format x myTimeFmt timedate\n"
"set xtics format myTimeFmt rotate by -30\n"
"set format y \"%%g%%%%\"\n"
"set grid\n"
"set key out reverse Left noautotitle\n"
"set style fill solid 0.5\n"
"unset border\n"
"plot \\\n"
" total=0 $Data u"
" (timecolumn(1,myTimeFmt)):(dy=$3*100/%zu,total=total+dy) \\\n"
" w steps lc \"grey\" dt 2, \\\n" /* `pngcairo` has trouble :[. */
" total=0 $Data u"
" (timecolumn(1,myTimeFmt)):(dy=$4*100/%zu,total=total+dy) \\\n"
" w steps lc \"black\" dt 3, \\\n"
" total=0 '' u \\\n"
" (timecolumn(1,myTimeFmt)): \\\n"
" (dy=$4*100/%zu,total=total+dy,total-dy/2.): \\\n"
" (43200): \\\n"
" (dy/2.): \\\n"
" (getIndex(strcol(5))) w boxxy lc var, \\\n"
" for [i=1:words(Uniqs)] keyentry w boxxy lc i ti Uniq(i)\n",
no_total, no_total, no_total);
goto finally;
catch:
success = EXIT_FAILURE;