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