2023-02-02 02:18:20 -05:00
|
|
|
/** @license 2023 Neil Edelman, distributed under the terms of the
|
|
|
|
[MIT License](https://opensource.org/licenses/MIT).
|
|
|
|
|
|
|
|
Date _vs_ hours flown. */
|
|
|
|
|
|
|
|
#include "journal.h"
|
2023-03-15 01:02:22 -04:00
|
|
|
#include "flights.h"
|
2023-02-12 23:53:15 -05:00
|
|
|
#include "source.h"
|
2023-02-02 02:18:20 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
2023-02-15 02:30:57 -05:00
|
|
|
#include <inttypes.h>
|
2023-02-02 02:18:20 -05:00
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
int success = EXIT_SUCCESS;
|
2023-02-12 23:53:15 -05:00
|
|
|
errno = 0;
|
2023-02-02 02:18:20 -05:00
|
|
|
struct journal j = journal();
|
2023-02-12 23:53:15 -05:00
|
|
|
struct sources s = sources(&j);
|
2023-02-02 02:18:20 -05:00
|
|
|
struct flights f = flights(&j);
|
2023-02-12 23:53:15 -05:00
|
|
|
|
|
|
|
if(errno) goto catch;
|
2023-02-15 02:30:57 -05:00
|
|
|
fprintf(stderr, "Journal: %s.\n"
|
|
|
|
"Flights: %s.\n", journal_to_string(&j), flights_to_string(&f));
|
2023-03-11 01:11:16 -05:00
|
|
|
printf("set terminal cairolatex standalone pdf size 16cm,10.5cm"
|
|
|
|
" dashed transparent\n"
|
|
|
|
"set output \"flight.tex\"\n");
|
|
|
|
/*printf("set term postscript eps enhanced\n"
|
|
|
|
"set output \"flighthours.eps\"\n");*/
|
|
|
|
printf("$Data <<EOD\n"
|
2023-02-15 02:30:57 -05:00
|
|
|
"# date\tsource\treg\tsic\tpic\ttotal\n");
|
|
|
|
struct flights_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);
|
|
|
|
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",
|
|
|
|
(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);
|
|
|
|
break;
|
|
|
|
case POWER:
|
|
|
|
total += flight->power.dual_min + flight->power.pilot_min;
|
|
|
|
printf("%.*s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\n",
|
|
|
|
(int)(flight->power.reg.b - flight->power.reg.a),
|
|
|
|
flight->power.reg.a,
|
|
|
|
flight->power.dual_min,
|
|
|
|
flight->power.pilot_min,
|
|
|
|
total);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-02-02 02:18:20 -05:00
|
|
|
printf("EOD\n"
|
2023-03-11 01:11:16 -05:00
|
|
|
"# 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,3)) 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 \"%%tH:%%tM\" timedate\n"
|
2023-02-02 02:18:20 -05:00
|
|
|
"set grid\n"
|
2023-03-11 01:11:16 -05:00
|
|
|
"set key out reverse Left noautotitle\n"
|
|
|
|
"set style fill solid 0.5\n"
|
2023-02-02 02:18:20 -05:00
|
|
|
"unset border\n"
|
2023-03-11 01:11:16 -05:00
|
|
|
"plot total=0 $Data u"
|
|
|
|
" (timecolumn(1,myTimeFmt)):(dy=($4+$5)*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"
|
|
|
|
" 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"
|
|
|
|
"plot $Data using 1:($6/60) with fillsteps lw 2\n"*/);
|
2023-02-02 02:18:20 -05:00
|
|
|
goto finally;
|
|
|
|
catch:
|
|
|
|
success = EXIT_FAILURE;
|
2023-02-12 23:53:15 -05:00
|
|
|
perror("flights");
|
2023-02-02 02:18:20 -05:00
|
|
|
finally:
|
2023-02-12 23:53:15 -05:00
|
|
|
flights_(&f);
|
|
|
|
sources_(&s);
|
2023-02-02 02:18:20 -05:00
|
|
|
journal_(&j);
|
|
|
|
return success;
|
|
|
|
}
|