flight hours output

This commit is contained in:
Neil 2023-02-14 23:30:57 -08:00
parent a617ddf11c
commit e9dcc1d3bc
7 changed files with 67 additions and 23 deletions

View File

@ -64,10 +64,13 @@ struct flight_tree_iterator { struct tree_flight_iterator _; };
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- proto */
#include <stddef.h>
struct flights { struct flight_tree _; };
/*struct flight *flights_add(struct flights *, const union line64);*/
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 *,
const struct flight **);
#endif /* proto --> */
#ifdef BASE

View File

@ -239,16 +239,20 @@ finally:
return f;
}
#if 0
struct flight *flights_add(struct flights *const flights,
const union line64 line) {
struct flight *flight;
assert(flights);
/* We assert that the flights are unique. */
switch(flight_tree_try(&flights->_, line, &flight)) {
case TREE_PRESENT: errno = EDOM;
case TREE_ERROR: return 0;
case TREE_ABSENT: return flight;
}
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 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->_);
return 1;
}
#endif

View File

@ -10,6 +10,7 @@
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
int main(void) {
int success = EXIT_SUCCESS;
@ -19,24 +20,57 @@ int main(void) {
struct flights f = flights(&j);
if(errno) goto catch;
fprintf(stderr, "Journal: %s.\n", journal_to_string(&j));
fprintf(stderr, "Journal: %s.\n"
"Flights: %s.\n", journal_to_string(&j), flights_to_string(&f));
printf("set term postscript eps enhanced\n"
"set output \"flighthours.eps\"\n"
"$Data <<EOD\n"
"# date\tsource\tminutes\tcumulative\n");
"# 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;
}
}
printf("EOD\n"
"set monochrome\n"
"set xdata time\n"
"set timefmt \"%%Y-%%m-%%d\"\n"
"set xtics format \"%%Y-%%m-%%d\" rotate by -30\n"
"set ylabel \"hours\"\n"
"set format y \"%%g%%%%\"\n"
"set key top left\n"
"set grid\n"
"unset key\n"
"unset border\n"
"set xrange [*:'2001-09-11']\n"
"#set style fill solid 0.1 #pattern 5 (better, but restarts)\n"
"plot $Data using 1:($3) with fillsteps lw 2\n");
"plot $Data using 1:($6/60) with fillsteps lw 2\n");
goto finally;
catch:
success = EXIT_FAILURE;

View File

@ -35,7 +35,7 @@ struct journal { struct day_tree days; struct text backing; };
struct journal_iterator { struct day_tree_iterator _; };
struct journal journal(void);
void journal_(struct journal *);
int journal_is_valid(const struct journal *);
//int journal_is_valid(const struct journal *);
const char *journal_to_string(const struct journal *);
struct journal_iterator journal_iterator(struct journal *const j);
int journal_next(struct journal_iterator *, union date32 *, const char **);

View File

@ -111,6 +111,7 @@ struct kjv {
struct kjv kjv(void);
void kjv_(struct kjv *);
int kjv_is_valid(const struct kjv *const kjv);
/* Only used in test. */
int kjv_add(struct kjv *const kjv, const union kjvcite cite);
const char *kjv_to_string(const struct kjv *const kjv);
const char *kjv_set_to_string(const struct kjv *const kjv);

View File

@ -54,7 +54,7 @@ static void kjvset_to_string(const union kjvcite x, char (*const a)[12])
#define TABLE_NAME kjvset
#define TABLE_KEY union kjvcite
#define TABLE_UINT uint32_t
#define TABLE_INVERSE
#define TABLE_UNHASH
#define TABLE_TO_STRING
#include "../src/table.h"
@ -67,7 +67,7 @@ static void verse_to_string(const union kjvcite x, const unsigned count,
#define TABLE_KEY union kjvcite
#define TABLE_UINT uint32_t
#define TABLE_VALUE unsigned /* Count words. */
#define TABLE_INVERSE
#define TABLE_UNHASH
#define TABLE_DEFAULT 0
#define TABLE_TO_STRING
#include "../src/table.h"
@ -223,7 +223,8 @@ finally:
int kjv_is_valid(const struct kjv *const kjv)
{ return kjv && kjv->verses.buckets; }
/** Adds `cite` to `kjv` if not present. @return Is the kjv still valid. */
/** Adds `cite` to `kjv` if not present. Only used in test.
@return Is the kjv still valid. */
int kjv_add(struct kjv *const kjv, const union kjvcite cite) {
if(!kjv) return 0;
kjv->words.verse = verse_table_get(&kjv->verses, cite);

View File

@ -1,3 +1,4 @@
#define KJV_TEST
#include "../src/kjv.h"
#include <stdio.h>
#include <inttypes.h> /* C99 */