Simplified flights.
This commit is contained in:
parent
cb32313387
commit
b8b216b37a
|
@ -16,61 +16,63 @@ int main(void) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
struct journal j = journal();
|
struct journal j = journal();
|
||||||
struct sources s = sources(&j);
|
struct sources s = sources(&j);
|
||||||
struct flights f = flights(&j);
|
struct flight_tree f = flights(&j);
|
||||||
|
|
||||||
if(errno) goto catch;
|
if(errno) goto catch;
|
||||||
fprintf(stderr, "Journal: %s.\n"
|
fprintf(stderr, "Journal: %s.\n"
|
||||||
"Flights: %s.\n", journal_to_string(&j), flights_to_string(&f));
|
"Flights: %s.\n", journal_to_string(&j), flights_to_string(&f));
|
||||||
printf("set terminal cairolatex standalone pdf size 16cm,10.5cm"
|
printf("set terminal pngcairo dashed transparent truecolor"
|
||||||
|
" size 840, 480 fontscale 1\n"
|
||||||
|
"set output \"flight.png\"\n");
|
||||||
|
/*printf("set terminal cairolatex standalone pdf size 16cm,10.5cm"
|
||||||
" dashed transparent\n"
|
" dashed transparent\n"
|
||||||
"set output \"flight.tex\"\n");
|
"set output \"flight.tex\"\n");*/
|
||||||
/*printf("set term postscript eps enhanced\n"
|
/*printf("set term postscript eps enhanced\n"
|
||||||
"set output \"flighthours.eps\"\n");*/
|
"set output \"flighthours.eps\"\n");*/
|
||||||
printf("$Data <<EOD\n"
|
printf("$Data <<EOD\n"
|
||||||
"# date\tsource\treg\tsic\tpic\ttotal\n");
|
"# date, reg, sic, pic, source\n");
|
||||||
struct flights_iterator it = flights_iterator(&f);
|
struct flight_tree_iterator it = flights_iterator(&f);
|
||||||
union line64 line;
|
union line64 line;
|
||||||
const struct flight *flight;
|
const struct flight *flight;
|
||||||
uint32_t total = 0;
|
|
||||||
while(flights_next(&it, &line, &flight)) {
|
while(flights_next(&it, &line, &flight)) {
|
||||||
char datestr[12];
|
char datestr[12];
|
||||||
date32_to_string(line.date, &datestr);
|
date32_to_string(line.date, &datestr);
|
||||||
const struct source *src = source_lookup(&s, line);
|
const struct source *src = source_lookup(&s, line);
|
||||||
assert(src); if(!src->name.a) { errno = EDOM; goto catch; }
|
assert(src); if(!src->name.a) { errno = EDOM; goto catch; }
|
||||||
printf("%s\t%.*s\t",
|
printf("%s, ", datestr);
|
||||||
datestr, (int)(src->name.b - src->name.a), src->name.a);
|
|
||||||
assert(flight); switch(flight->type) {
|
assert(flight); switch(flight->type) {
|
||||||
case GLIDER:
|
case GLIDER:
|
||||||
total += flight->glider.dual_min + flight->glider.pilot_min
|
printf("%.*s, %" PRIu32 ", %" PRIu32,
|
||||||
+ flight->glider.instr_min;
|
|
||||||
printf("%.*s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\n",
|
|
||||||
(int)(flight->glider.reg.b - flight->glider.reg.a),
|
(int)(flight->glider.reg.b - flight->glider.reg.a),
|
||||||
flight->glider.reg.a,
|
flight->glider.reg.a,
|
||||||
flight->glider.dual_min,
|
flight->glider.dual_min,
|
||||||
flight->glider.pilot_min + flight->glider.instr_min,
|
flight->glider.pilot_min + flight->glider.instr_min);
|
||||||
total);
|
|
||||||
break;
|
break;
|
||||||
case POWER:
|
case POWER:
|
||||||
total += flight->power.dual_min + flight->power.pilot_min;
|
printf("%.*s, %" PRIu32 ", %" PRIu32,
|
||||||
printf("%.*s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\n",
|
|
||||||
(int)(flight->power.reg.b - flight->power.reg.a),
|
(int)(flight->power.reg.b - flight->power.reg.a),
|
||||||
flight->power.reg.a,
|
flight->power.reg.a,
|
||||||
flight->power.dual_min,
|
flight->power.dual_min,
|
||||||
flight->power.pilot_min,
|
flight->power.pilot_min);
|
||||||
total);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
printf(", %.*s\n", (int)(src->name.b - src->name.a), src->name.a);
|
||||||
}
|
}
|
||||||
printf("EOD\n"
|
printf("EOD\n"
|
||||||
"# theozh https://stackoverflow.com/a/75466214/2472827\n"
|
"# theozh https://stackoverflow.com/a/75466214/2472827\n"
|
||||||
"# get a unique list from datablock\n"
|
"# get a unique list from datablock\n"
|
||||||
"addToList(list,col) = list.( strstrt(list,'\"'.strcol(col).'\"') > 0 "
|
"addToList(list,col) = list.( strstrt(list,'\"'.strcol(col).'\"') \\\n"
|
||||||
"? \\\n"
|
" > 0 ? '' : ' \"'.strcol(col).'\"')\n"
|
||||||
" '' : ' \"'.strcol(col).'\"')\n"
|
|
||||||
"Uniqs = ''\n"
|
"Uniqs = ''\n"
|
||||||
"stats $Data u (Uniqs=addToList(Uniqs,3)) nooutput\n"
|
"stats $Data u (Uniqs=addToList(Uniqs,2)) nooutput\n"
|
||||||
"Uniq(i) = word(Uniqs,i)\n"
|
"Uniq(i) = word(Uniqs,i)\n"
|
||||||
"getIndex(s) = sum [_i=1:words(Uniqs)] s eq word(Uniqs,_i) ? _i : 0\n"
|
"getIndex(s) = sum [_i=1:words(Uniqs)] s eq word(Uniqs,_i) ? _i : 0\n"
|
||||||
|
"\n"
|
||||||
|
"stats $Data u 3 nooutput\n"
|
||||||
|
"sicsum = STATS_sum\n"
|
||||||
|
"stats $Data u 4 nooutput\n"
|
||||||
|
"picsum = STATS_sum\n"
|
||||||
|
"\n"
|
||||||
"myTimeFmt = \"%%Y-%%m-%%d\"\n"
|
"myTimeFmt = \"%%Y-%%m-%%d\"\n"
|
||||||
"set format x myTimeFmt timedate\n"
|
"set format x myTimeFmt timedate\n"
|
||||||
"set xtics format myTimeFmt rotate by -30\n"
|
"set xtics format myTimeFmt rotate by -30\n"
|
||||||
|
@ -80,11 +82,11 @@ int main(void) {
|
||||||
"set style fill solid 0.5\n"
|
"set style fill solid 0.5\n"
|
||||||
"unset border\n"
|
"unset border\n"
|
||||||
"plot total=0 $Data u"
|
"plot total=0 $Data u"
|
||||||
" (timecolumn(1,myTimeFmt)):(dy=($4+$5)*60,total=total+dy)"
|
" (timecolumn(1,myTimeFmt)):(dy=($3+$4)*60,total=total+dy)"
|
||||||
" w steps lc \"black\" dt 3, \\\n"
|
" w steps lc \"black\" dt 3, \\\n"
|
||||||
" total=0 '' u (timecolumn(1,myTimeFmt)):"
|
" total=0 '' u (timecolumn(1,myTimeFmt)):"
|
||||||
"(dy=($4+$5)*60,total=total+dy,total-dy/2.): \\\n"
|
"(dy=($3+$4)*60,total=total+dy,total/2.): \\\n"
|
||||||
" (43200):(dy/2.):(getIndex(strcol(3))) w boxxy lc var, \\\n"
|
" (43200):(total/2.):(getIndex(strcol(2))) w boxxy lc var, \\\n"
|
||||||
" for [i=1:words(Uniqs)] keyentry w boxxy lc i ti Uniq(i)\n"
|
" for [i=1:words(Uniqs)] keyentry w boxxy lc i ti Uniq(i)\n"
|
||||||
/*"set xrange [*:'2001-09-11']\n"*/
|
/*"set xrange [*:'2001-09-11']\n"*/
|
||||||
/*"#set style fill solid 0.1 #pattern 5 (better, but restarts)\n"
|
/*"#set style fill solid 0.1 #pattern 5 (better, but restarts)\n"
|
||||||
|
|
|
@ -49,11 +49,9 @@ struct flight {
|
||||||
#define TREE_HEAD
|
#define TREE_HEAD
|
||||||
#include "../src/tree.h"
|
#include "../src/tree.h"
|
||||||
|
|
||||||
struct flights { struct flight_tree _; };
|
struct flight_tree flights(/*const*/ struct journal *);
|
||||||
struct flights_iterator { struct flight_tree_iterator _; };
|
void flights_(struct flight_tree *);
|
||||||
struct flights flights(/*const*/ struct journal *);
|
const char *flights_to_string(const struct flight_tree *);
|
||||||
void flights_(struct flights *);
|
struct flight_tree_iterator flights_iterator(struct flight_tree *);
|
||||||
const char *flights_to_string(const struct flights *);
|
int flights_next(struct flight_tree_iterator *, union line64 *,
|
||||||
struct flights_iterator flights_iterator(struct flights *);
|
|
||||||
int flights_next(struct flights_iterator *, union line64 *,
|
|
||||||
const struct flight **);
|
const struct flight **);
|
||||||
|
|
|
@ -22,7 +22,7 @@ static int flight_compare(const union line64 a, const union line64 b)
|
||||||
|
|
||||||
/*!conditions:re2c*/
|
/*!conditions:re2c*/
|
||||||
|
|
||||||
static int scan(struct flights *const f,
|
static int scan(struct flight_tree *const f,
|
||||||
union date32 date, const char *const text) {
|
union date32 date, const char *const text) {
|
||||||
const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *s0, *s1, *t0, *t1;
|
const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *s0, *s1, *t0, *t1;
|
||||||
enum YYCONDTYPE condition = yycline;
|
enum YYCONDTYPE condition = yycline;
|
||||||
|
@ -75,7 +75,7 @@ static int scan(struct flights *const f,
|
||||||
= {{ (uint32_t)line, {{ date.day, date.month, date.year }} }};
|
= {{ (uint32_t)line, {{ date.day, date.month, date.year }} }};
|
||||||
assert(!flight);
|
assert(!flight);
|
||||||
if(line > UINT32_MAX) { why = "line overflow"; goto catch; }
|
if(line > UINT32_MAX) { why = "line overflow"; goto catch; }
|
||||||
switch(flight_tree_try(&f->_, key, &flight)) {
|
switch(flight_tree_try(f, key, &flight)) {
|
||||||
case TREE_PRESENT: why = "duplicate key";
|
case TREE_PRESENT: why = "duplicate key";
|
||||||
case TREE_ERROR: goto catch;
|
case TREE_ERROR: goto catch;
|
||||||
case TREE_ABSENT: flight->type = GLIDER; break;
|
case TREE_ABSENT: flight->type = GLIDER; break;
|
||||||
|
@ -148,7 +148,7 @@ static int scan(struct flights *const f,
|
||||||
= {{ (uint32_t)line, {{ date.day, date.month, date.year }} }};
|
= {{ (uint32_t)line, {{ date.day, date.month, date.year }} }};
|
||||||
assert(!flight);
|
assert(!flight);
|
||||||
if(line > UINT32_MAX) { why = "line overflow"; goto catch; }
|
if(line > UINT32_MAX) { why = "line overflow"; goto catch; }
|
||||||
switch(flight_tree_try(&f->_, key, &flight)) {
|
switch(flight_tree_try(f, key, &flight)) {
|
||||||
case TREE_PRESENT: why = "duplicate key";
|
case TREE_PRESENT: why = "duplicate key";
|
||||||
case TREE_ERROR: goto catch;
|
case TREE_ERROR: goto catch;
|
||||||
case TREE_ABSENT: flight->type = POWER; break;
|
case TREE_ABSENT: flight->type = POWER; break;
|
||||||
|
@ -210,20 +210,13 @@ catch:
|
||||||
fprintf(stderr, "%s line %zu: %s.\n", datestr, line, why);
|
fprintf(stderr, "%s line %zu: %s.\n", datestr, line, why);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/** Dynamic memory allocation for `f` will be zero, <fn:flights_is_valid> will
|
void flights_(struct flight_tree *const f) { flight_tree_(f); }
|
||||||
be false. */
|
struct flight_tree flights(struct journal *const j) {
|
||||||
void flights_(struct flights *const f) {
|
struct flight_tree f = flight_tree();
|
||||||
if(!f) return;
|
|
||||||
flight_tree_(&f->_);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct flights flights(/*const*/ struct journal *const j) {
|
|
||||||
struct flights f;
|
|
||||||
struct journal_iterator it;
|
struct journal_iterator it;
|
||||||
union date32 date;
|
union date32 date;
|
||||||
const char *text;
|
const char *text;
|
||||||
assert(j);
|
assert(j);
|
||||||
f._ = flight_tree();
|
|
||||||
it = journal_iterator(j);
|
it = journal_iterator(j);
|
||||||
while(journal_next(&it, &date, &text)) if(!scan(&f, date, text)) goto catch;
|
while(journal_next(&it, &date, &text)) if(!scan(&f, date, text)) goto catch;
|
||||||
goto finally;
|
goto finally;
|
||||||
|
@ -232,21 +225,15 @@ catch:
|
||||||
finally:
|
finally:
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
const char *flights_to_string(const struct flight_tree *const f)
|
||||||
const char *flights_to_string(const struct flights *const f)
|
{ return flight_tree_to_string(f); }
|
||||||
{ return flight_tree_to_string(&f->_); }
|
struct flight_tree_iterator flights_iterator(struct flight_tree *const f)
|
||||||
|
{ return flight_tree_iterator(f); }
|
||||||
struct flights_iterator flights_iterator(struct flights *const f) {
|
int flights_next(struct flight_tree_iterator *const it, union line64 *const k,
|
||||||
struct flights_iterator it = { flight_tree_iterator(&f->_) };
|
|
||||||
assert(f);
|
|
||||||
return it;
|
|
||||||
}
|
|
||||||
|
|
||||||
int flights_next(struct flights_iterator *const it, union line64 *const k,
|
|
||||||
const struct flight **const v) {
|
const struct flight **const v) {
|
||||||
assert(it && k && v);
|
assert(it && k && v);
|
||||||
if(!flight_tree_next(&it->_)) return 0;
|
if(!flight_tree_next(it)) return 0;
|
||||||
*k = flight_tree_key(&it->_);
|
*k = flight_tree_key(it);
|
||||||
*v = flight_tree_value(&it->_);
|
*v = flight_tree_value(it);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -303,9 +303,8 @@ int main(void) {
|
||||||
printf("EOD\n"
|
printf("EOD\n"
|
||||||
"# theozh https://stackoverflow.com/a/75466214/2472827\n"
|
"# theozh https://stackoverflow.com/a/75466214/2472827\n"
|
||||||
"# get a unique list from datablock\n"
|
"# get a unique list from datablock\n"
|
||||||
"addToList(list,col) = list.( strstrt(list,'\"'.strcol(col).'\"') > 0 "
|
"addToList(list,col) = list.( strstrt(list,'\"'.strcol(col).'\"') \\\n"
|
||||||
"? \\\n"
|
" > 0 ? '' : ' \"'.strcol(col).'\"')\n"
|
||||||
" '' : ' \"'.strcol(col).'\"')\n"
|
|
||||||
"Uniqs = ''\n"
|
"Uniqs = ''\n"
|
||||||
"stats $Data u (Uniqs=addToList(Uniqs,5)) nooutput\n"
|
"stats $Data u (Uniqs=addToList(Uniqs,5)) nooutput\n"
|
||||||
"Uniq(i) = word(Uniqs,i)\n"
|
"Uniq(i) = word(Uniqs,i)\n"
|
||||||
|
|
Loading…
Reference in New Issue