Subversion Repositories svn1-original

Rev

Rev 337 | Rev 339 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
95 - 1
/*************************************************************************
2
*           Copyright (C) 1995 Embedded Solutions
3
*                       All rights reserved
4
*
5
* file:     src\report.c
6
*
7
* purpose:  PREFIX -
8
*
9
* functions
10
*       report                  - Report menu
11
*       pri_team                - Print in team order
12
*       pri_leg                 - Print in given leg finishing time
13
*       p_place                 - Print place information
14
*       p_team                  - Print team information
15
*       pri_eleg                - Print on elapsed times for given leg
16
*       pe_place                - Print place and elapsed time information
17
*       pe_team                 - Print team and elapsed time information
18
*       pri_final               - Print final results
19
*       pri_interim             - Print interim results
20
*       print_class_header      - Print a class header
21
*       print_class_stats       - Generate the class stats
22
*       print_legend            - Print the legend
23
*       pi_place                - Return place data
24
*       pr_place                - Return place data
25
*       ck_data                 - Check data for bad times
26
*       srt_place               - Update placing information
27
*       do_big_sort             - Main sort routine for final data
28
*       sort                    - Sort in memory buffer
29
*       sort_comp               - qsort comparison function
30
*       load                    - load report data into memory
31
*       gen_stats               - Generate all the stats
32
*
33
* programmer: David Purdie
34
*
35
* revision  date        by      reason
36
*    e388   11-Oct-88           Option in the final printout to only
37
*                               produce the main result sheet. The leg
38
*                               placing printout is not produced.
39
*
40
*                               Changes to the display format of unknown
41
*                               times of disqualified teams. Only affects
42
*                               the leg-printouts.
43
*                               Disqualified teams show as -- -- --
44
*                               Otherwise they show as     ** ** **
45
*                               or a valid time.
46
*
47
*   e339    31-Oct-88   DDP     Added the "Interim Report" facility
48
*   00.0    27/01/95    DDP     Tidies up the program and formatted the file
49
*   00.1    06-sep-02   DDP     Added support for HTML report generation
50
*
51
**************************************************************************/
52
 
53
#include    <stdio.h>
54
#include    "consts.h"
55
#include    "structs.h"
56
#include    "proto.h"
174 - 57
#include    "mainwindow.h"
95 - 58
 
59
void pri_awards_html(void);
258 - 60
void pri_summary_html(void);
95 - 61
void pri_awards(void);
62
void pri_master_index(void);
63
char *placing ( int place );
64
void pri_name_index(void);
65
void pri_name_index_body( void );
66
void pri_all_reports (void );
67
void pri_leg_body(int leg);
68
void pri_eleg_body(int leg);
69
void pri_csv_data ( void );
70
 
71
 
72
#define MAX_PLACE 11
73
const char * place_text[] =
74
{
75
    "Zero'th",
76
    "First",
77
    "Second",
78
    "Third",
79
    "Fourth",
80
    "Fifth",
81
    "Sixth",
82
    "Seventh",
83
    "Eighth",
84
    "Ninth",
85
    "Tenth",
86
    "Eleventh"
87
};
88
 
89
int         sort_leg;
90
int         sort_mode;
336 david 91
bool        sort_withEquestrian;
95 - 92
report_type report_html = text;
93
bool        report_all = FALSE;
94
 
95
/* Parameters used by the sort routine to govern its actions */
96
 
97
#define S_L     1                                /* Elasped times */
98
#define S_LE    2                                /* Leg end time */
99
#define S_LC    3                                /* Elapsed times per class */
100
#define S_LEC   4                                /* Leg end time per class */
101
#define S_FIN   5                                /* Sort on finish time at given leg */
102
#define S_TEAM  6                                /* Sort on team order */
103
#define S_CLASS 7                                /* Sort on class/team order */
231 - 104
#define S_LC_NE 8                                /* Elapsed times per class, with NE sorted by real class */
250 - 105
#define S_IFIN  9                                /* Sort on elapsed time at given leg */
95 - 106
 
336 david 107
 
95 - 108
/*
109
**  Various checking modes
110
*/
111
#define C_ELAPSED   1                            /* Check elapsed times */
112
#define C_END       2                            /* Check end times */
113
#define C_DISQUAL   3                            /* Check disqualified teams */
114
 
115
/*
116
**  Data
117
*/
118
ty_s_data  *sort_data = 0;                       /* pointer to memory */
119
ty_s_aux   *sort_aux = 0;                        /* pointer to aux sort info */
199 david 120
ty_s_namedata *sort_name_data = 0;               /* pointer to name info */
121
unsigned    int sort_num;                        /* Number in the array */
122
unsigned    int sort_num_data;                   /* Number in the array */
95 - 123
ty_stats        stats;                           /* Holds statistics */
124
 
125
/*========================================================================
126
 *
127
 *  Print in team order
128
 *
129
 *  Purpose:
130
 *      This function is called to Print in team order
131
 *      This function may also be used to create an HTML suite of files
132
 *      within the result set
133
 *
134
 *  Parameters:
135
 *      None
136
 *
137
 *  Returns:
138
 *      Nothing
139
 *
140
 *========================================================================*/
141
 
142
void pri_team(void)
143
{
144
    int         i, k;
174 - 145
    team_type   team_buf;
95 - 146
 
147
    if( !open_printer( "", "name", 132, report_html, "Team Names" ) )
148
        return;
149
 
150
    /*
151
     * Print out the data 
152
     * Print out the header
153
     */
154
 
155
    print( "\n" );
156
 
157
    print_underline( TRUE );
158
    print( "%-*s %-*s %-*s", MAX_TM_NAME + 5, "Entry number and name",
159
               LEN_CLASS_NAME, "Category",
160
               config.num_countries == 0 ? 1 : LEN_CNTRY_NAME,
161
               config.num_countries == 0 ? "" : "Country" );
162
    for( k = 0; k < MAX_MEMB; k++ )
163
    {
164
        print( " %-*s", MAX_PERSON_NAME, config.leg_name[k] ? config.leg_name[k] : "Competitor"  );
165
    }
166
    print_underline( FALSE ) ;
167
    print( "\n" );
168
 
169
    for( i = config.min_team; i <= config.max_team; i++ )
170
    {
171
        if( valid_field( i ) && g_record( i, &team_buf ) )
172
        {
173
            /*
174
            **  If printing an HTML report then we need to mark
175
            **  the entry with a reference so that we can link to it
176
            */
177
            if ( report_html == html )
178
            {
179
                print( "<A NAME=\"Team_%04d\">",team_buf.numb );
180
                print( "</A>" );
181
            }
182
 
183
            /*
184
            **  Basic information
185
            **      - Team number - with Xref back to full result
186
            **      - Full team name
187
            **      - Full categoray name - with Xref to category results
188
            **      - Country name
189
            */
190
            if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "finish" ,"html")), team_buf.numb );
191
            print( "%4d",       team_buf.numb );
192
            if ( report_html == html ) print( "</A>" );
193
 
194
            print( " %-*s ",     MAX_TM_NAME, team_buf.name );
195
 
196
            if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">",url_encode(p_filename(filebase, config.team_class[team_buf.teamclass - 1].abr ,"html")), team_buf.numb );
197
            print( "%-*s",     LEN_CLASS_NAME, team_buf.teamclass == 0 ? "" : config.team_class[team_buf.teamclass - 1].full_name );
198
            if ( report_html == html ) print( "</A>" );
199
 
200
            print( " %-*s",     config.num_countries == 0 ? 1 : LEN_CNTRY_NAME,
201
                                config.num_countries == 0
202
                                || team_buf.country ==
203
 
204
 
205
            for( k = 0; k < MAX_MEMB; k++ )
206
                print( " %-*s", MAX_PERSON_NAME, team_buf.members[k].name );
207
 
208
            print( "\n" );
209
        }
210
    }
211
    close_printer();
212
}
213
 
214
/*========================================================================
215
 *
216
 *  Print in name order
217
 *
218
 *  Purpose:
219
 *      This function is called to print a list of all known competitors
220
 *      This function may also be used to create an HTML suite of files
221
 *      within the result set
222
 *
223
 *  Parameters:
224
 *      None
225
 *
226
 *  Returns:
227
 *      Nothing
228
 *
229
 *========================================================================*/
230
void pri_name_index_body( void )
231
{
232
    ty_s_namedata *ptr;
174 - 233
    team_type   team_buf;
95 - 234
    unsigned    num;
235
    int i;
236
    unsigned int k;
237
    int num_names;
238
 
239
    /*
240
    **  Determine the number of names to allow for
241
    *   Based on the total number of teams
242
    */
243
    num = config.max_team - config.min_team + 1 ;
244
    num *= MAX_MEMB;
245
 
246
    sort_name_data = ( ty_s_namedata * ) calloc ( num , sizeof( ty_s_namedata ) );
247
 
248
    if( sort_name_data == 0 )
249
    {
174 - 250
        MainWindow::showMessage("Error in allocating memory");
95 - 251
        return;
252
    }
253
 
254
    /*
255
    **  Read all teams an extract name information
256
    */
257
    ptr = sort_name_data;
258
    for( i = config.min_team; i <= config.max_team; i++ )
259
    {
260
        if( valid_field( i ) && g_record( i, &team_buf ) )
261
        {
262
            num_names = 0;
263
            for( k = 0; k < MAX_MEMB; k++ )
264
            {
265
                if ( team_buf.members[k].name[0] )
266
                {
267
                    ptr->team = i;
268
                    ptr->leg = k;
269
                    ptr->teamclass = team_buf.teamclass;
270
                    strncpy( ptr->name,team_buf.members[k].name, sizeof(team_buf.members[k].name));
271
                    ptr++;
272
                    num_names++;
273
                }
274
            }
275
 
276
            if ( num_names == 0 )
277
            {
278
                ptr->team = i;
279
                ptr->leg = 0;
280
                ptr->teamclass = team_buf.teamclass;
281
                strncpy( ptr->name,team_buf.name, sizeof(team_buf.members[k].name));
282
                ptr++;
283
            }
284
 
285
        }
286
    }
287
    sort_num_data = ptr - sort_name_data;
288
 
289
    /*
290
    **  Now stort the entries by name:team:leg
291
    */
292
    qsort( ( char * ) sort_name_data, sort_num_data, sizeof( ty_s_namedata ), sort_comp_cname );
293
 
294
    /*
295
    **  Now generate the report
296
    */
297
 
298
    if( !open_printer( "", "competitor", 80, report_html, "Competitor Names" ) )
299
        return;
300
 
301
    /*
302
     * Print out the data 
303
     * Print out the header
304
     */
305
    print( "\n" );
306
 
307
    print_underline( TRUE );
308
    print( "%-*s %-*s %-*s %-*s", MAX_TM_NAME + 5, "Competitor name",
309
               6, "Leg",
310
               5, "Team",
311
               LEN_CLASS_NAME, "Category"
312
               );
313
    print_underline( FALSE ) ;
314
    print( "\n" );
315
 
316
    ptr = sort_name_data;
317
    for( k = 1; k <= sort_num_data; k++, ptr++ )
318
    {
319
        print( "%-*s", MAX_TM_NAME + 5, ptr->name );
320
        print( " " );
321
 
322
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "finish" ,"html")), ptr->team );
323
        print( "%-*d", 6, ptr->leg + 1 );
324
        if ( report_html == html ) print( "</A>" );
325
        print( " " );
326
 
327
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "name" ,"html")), ptr->team );
328
        print( "%-*d", 5, ptr->team );
329
        if ( report_html == html ) print( "</A>" );
330
        print( " " );
331
 
332
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">",(p_filename(filebase, config.team_class[ptr->teamclass - 1].abr ,"html")), ptr->team );
333
        print( "%-*s", LEN_CLASS_NAME, ptr->teamclass == 0 ? "" : config.team_class[ptr->teamclass - 1].abr );
334
        if ( report_html == html ) print( "</A>" );
335
        print( " " );
336
 
337
        if ( ptr->multi ) print( "* ");
338
        print( "\n" );
339
    }
340
 
341
    print_legend( -1, 0 );
342
    close_printer();
343
 
344
}
345
 
346
/*========================================================================
347
 *
348
 *  Print in given leg finishing time
349
 *
350
 *  Purpose:
351
 *      This function is called to Print in given leg finishing time
352
 *
353
 *  Parameters:
354
 *      None
355
 *
356
 *  Returns:
357
 *      Nothing
358
 *
359
 *========================================================================*/
360
 
361
void pri_leg_body(int leg)    
362
{
363
    ty_s_data  *ptr;
364
    int         i, k;
199 david 365
 
95 - 366
    /*
367
     * Sort the data in finishing order 
368
     */
369
 
370
    if( ck_data( leg, C_END ) )
371
        return;                                  /* Check data for this leg */
336 david 372
    sort_team_data( leg, S_FIN, true );         /* Sort the data */
95 - 373
 
374
 
375
    /*
376
     * Now print the data on the printer 
377
     */
378
    if( !open_printer( "",
379
                        tprintf("lg%1.1d", leg ),
380
                        80,
381
                        report_html,
382
                        leg ? tprintf ("Finish order for Leg %d.", leg)
383
                            : "Final team finish order"
384
                     ) )
385
    {
386
        return;
387
    }
388
 
389
    /*
390
     * Print out the data 
391
     */
392
    print( "PRELIMINARY RESULTS ONLY\n\n" );
393
 
394
    print_underline( TRUE );
395
    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
396
    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
397
    print( "|" );
398
    print( "%4s %4s %-8s  ", "Team", "Plce", "Time" );
399
    print( "%4s %4s %-8s\n", "Team", "Plce", "Time" );
400
    print_underline( FALSE );
401
 
402
    for( ptr = sort_data, k = 0, i = config.min_team; i <= config.max_team; )
403
    {
404
        p_place( ptr++, leg, k++ );
405
        p_place( ptr++, leg, k++ );
406
        print( "|" );
407
        while( i <= config.max_team && !valid_field( i ) )
408
            i++;
409
        p_team( i++, leg );
410
        while( i <= config.max_team && !valid_field( i ) )
411
            i++;
412
        p_team( i++, leg );
413
        print( "\n" );
414
    }
415
 
416
    print_underline( TRUE );
417
    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
418
//    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
419
    print( "|" );
420
//    print( "%4s %4s %-8s  ", "Team", "Plce", "Time" );
421
    print( "%4s %4s %-8s\n", "Team", "Plce", "Time" );
422
    print_underline( FALSE );
423
 
424
    for( ptr = sort_data, k = 0, i = config.min_team; i <= config.max_team; )
425
    {
426
        p_place( ptr++, leg, k++ );
427
//        p_place( ptr++, leg, k++ );
428
        print( "|" );
429
        while( i <= config.max_team && !valid_field( i ) )
430
            i++;
431
        p_team( i++, leg );
432
//        while( i <= config.max_team && !valid_field( i ) )
433
//            i++;
434
//        p_team( i++, leg );
435
        print( "\n" );
436
    }
437
 
438
 
439
    /*
440
     * Insert the leg statistics 
441
     */
442
 
443
    gen_stats();                               /* Generate all stats */
444
    print( "\nLeg statistics\n" );
445
    print( "Fastest team: %4d time : %s.",
446
           stats.fast.team[leg][0], time_a( stats.fast.time[leg][0] ) );
447
    print( " Average time: %s\n", time_a( stats.average[leg][0] ) );
448
 
449
    close_printer();
450
}
451
 
452
/*========================================================================
453
 *
454
 *  Print place information
455
 *
456
 *  Purpose:
457
 *      This helper function is called to Print place information
458
 *      in a 20-character field
459
 *
460
 *  Parameters:
461
 *      ptr         Address of the place data
462
 *      leg         Leg to print
463
 *      k           Current index into sorted array. Simply
464
 *                  used to determine if the entry is valid
465
 *                  or if it should be space-filled
466
 *
467
 *  Returns:
468
 *      Nothing
469
 *
470
 *========================================================================*/
471
 
472
void p_place( ty_s_data * ptr, int leg, unsigned k )
473
{
474
    if( k < sort_num )
475
    {
476
        print( "%4.4s %4d %8s  ",
477
               pr_place( ptr->place, ptr->flags.bad_times ),
478
               ptr->team, time_fa( ptr->leg[leg], ptr->flags.disqualified ) );
479
    }
480
    else
481
    {
482
        print( "%20s", "" );
483
    }
484
}
485
 
486
/*========================================================================
487
 *
488
 *  Print team information
489
 *
490
 *  Purpose:
491
 *      This helper function is called to Print team information
492
 *      in a 20-character field
493
 *
494
 *  Parameters:
495
 *      i           team to print
496
 *      leg         Leg to print
497
 *
498
 *  Returns:
499
 *      Nothing
500
 *
501
 *========================================================================*/
502
 
503
void p_team( int i, int leg )
504
{
505
    ty_s_data  *ptra;                            /* Pointer to sort data */
506
    int         found = FALSE;
507
    unsigned    j;
508
 
509
    if( valid_field( i ) )
510
    {
511
        ptra = sort_data;
512
        for( j = 1; j <= sort_num; j++, ptra++ )
513
            if( i == ptra->team )
514
            {
515
                found = TRUE;
516
                break;
517
            }
518
    }
519
    if( found )
520
    {
521
        print( "%4d %4.4s %8s  ",
522
               ptra->team,
523
               pr_place( ptra->place, ptra->flags.bad_times ),
524
               time_fa( ptra->leg[leg], ptra->flags.disqualified ) );
525
    }
526
    else
527
    {
528
        print( "%20s", "" );
529
    }
530
}
531
 
532
/*========================================================================
533
 *
534
 *  Print on elapsed times for given leg
535
 *
536
 *  Purpose:
537
 *      This function is called to Print on elapsed times for given leg
538
 *
539
 *  Parameters:
199 david 540
 *      leg             - Leg number to print
95 - 541
 *
542
 *  Returns:
543
 *      Nothing
544
 *
545
 *========================================================================*/
546
 
547
void pri_eleg_body( int leg)
548
{
549
    ty_s_data  *ptr;
550
    int         i, k;
551
 
552
    /*
162 david 553
     * Sort the data in finishing order
95 - 554
     */
555
 
556
    if( ck_data( leg, C_ELAPSED ) )
557
        return;                                  /* Check data for this leg */
336 david 558
    sort_team_data( leg, S_IFIN, true );               /* Sort the data on elapsed time */
95 - 559
 
560
 
561
    /*
162 david 562
     * Now print the data on the printer
95 - 563
     */
564
    if( !open_printer( "", tprintf( "le%1.1d", leg ),
565
                       80,
566
                       report_html,
567
                       leg ? tprintf( "Elapsed time order for Leg %d.", leg )
568
                           : tprintf( "Final elapsed team finishing order." )
569
                     ) )
570
    {
571
        return;
572
    }
573
 
574
    /*
162 david 575
     * Print out the data
95 - 576
     */
577
    print( "PRELIMINARY RESULTS ONLY\n\n" );
578
 
579
    print_underline( TRUE );
580
    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
581
    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
582
    print( "|" );
583
    print( "%4s %4s %-8s  ", "Team", "Plce", "Time" );
584
    print( "%4s %4s %-8s\n", "Team", "Plce", "Time" );
585
    print_underline( FALSE );
586
 
587
 
588
    for( ptr = sort_data, k = 0, i = config.min_team; i <= config.max_team; )
589
    {
590
        pe_place( ptr++, leg, k++ );
591
        pe_place( ptr++, leg, k++ );
592
        print( "|" );
593
        while( i <= config.max_team && !valid_field( i ) )
594
            i++;
595
        pe_team( i++, leg );
596
        while( i <= config.max_team && !valid_field( i ) )
597
            i++;
598
        pe_team( i++, leg );
599
        print( "\n" );
600
    }
601
 
602
    print( "\n\n" );
603
    print_underline( TRUE );
604
    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
605
//    print( "%4s %4s %-8s  ", "Plce", "Team", "Time" );
606
    print( "|" );
607
//    print( "%4s %4s %-8s  ", "Team", "Plce", "Time" );
608
    print( "%4s %4s %-8s\n", "Team", "Plce", "Time" );
609
    print_underline( FALSE );
610
 
611
 
612
    for( ptr = sort_data, k = 0, i = config.min_team; i <= config.max_team; )
613
    {
614
        pe_place( ptr++, leg, k++ );
615
//        pe_place( ptr++, leg, k++ );
616
        print( "|" );
617
        while( i <= config.max_team && !valid_field( i ) )
618
            i++;
619
        pe_team( i++, leg );
620
//        while( i <= config.max_team && !valid_field( i ) )
621
//            i++;
622
//        pe_team( i++, leg );
623
        print( "\n" );
624
    }
625
 
626
 
627
    /*
162 david 628
     * Insert the leg statistics
95 - 629
     */
630
 
631
    gen_stats();                               /* Generate all stats */
632
    print( "\nLeg statistics\n" );
633
    print( "Fastest team: %4d time : %s.",
634
           stats.fast.team[leg][0], time_a( stats.fast.time[leg][0] ) );
635
    print( " Average time: %s\n", time_a( stats.average[leg][0] ) );
636
 
637
    close_printer();
638
}
639
 
162 david 640
///*========================================================================
641
// *
642
// *  Print place information
643
// *
644
// *  Purpose:
645
// *      This helper function is called to Print place and elapsed information
646
// *      in a 20-character field
647
// *
648
// *  Parameters:
649
// *      ptr         Address of the place data
650
// *      leg         Leg to print
651
// *      k           Current index into sorted array. Simply
652
// *                  used to determine if the entry is valid
653
// *                  or if it should be space-filled
654
// *
655
// *  Returns:
656
// *      Nothing
657
// *
658
// *========================================================================*/
95 - 659
 
660
void pe_place( ty_s_data * ptr, int leg, unsigned k )
661
{
662
    if( k < sort_num )
663
    {
664
        print( "%4.4s %4d %8s  ",
665
               pr_place( ptr->place, ptr->flags.bad_times ),
666
               ptr->team,
667
               time_fa( ptr->lege[leg], ptr->flags.disqualified ) );
668
    }
669
    else
670
    {
671
        print( "%20s", "" );
672
    }
673
}
674
 
675
/*========================================================================
676
 *
677
 *  Print team information
678
 *
679
 *  Purpose:
680
 *      This helper function is called to Print team and elapsed time
199 david 681
 *      information in a 20-character field
95 - 682
 *
683
 *  Parameters:
684
 *      i           Team to print
685
 *      leg         Leg to print
686
 *
687
 *  Returns:
688
 *      Nothing
689
 *
690
 *========================================================================*/
691
 
692
void pe_team( int i, int leg )
693
{
694
    ty_s_data  *ptra;                            /* Pointer to sort data */
695
    int         found = FALSE;
696
    unsigned    j;
697
 
698
    if( valid_field( i ) )
699
    {
700
        ptra = sort_data;
701
        for( j = 1; j <= sort_num; j++, ptra++ )
702
            if( i == ptra->team )
703
            {
704
                found = TRUE;
705
                break;
706
            }
707
    }
708
    if( found )
709
    {
710
        print( "%4d %4.4s %8s  ",
711
               ptra->team,
712
               pr_place( ptra->place, ptra->flags.bad_times ),
713
               time_fa( ptra->lege[leg], ptra->flags.disqualified ) );
714
    }
715
    else
716
    {
717
        print( "%20s", "" );
718
    }
719
}
720
 
721
/*========================================================================
722
 *
723
 *  Print final results in HTML
724
 *
725
 *  Purpose:
726
 *      This function is called to Print final results with HTML formatting
727
 *      All result files are created
728
 *
729
 *  Parameters:
730
 *      None
731
 *
732
 *  Returns:
733
 *      Nothing
734
 *
735
 *========================================================================*/
736
 
737
void pri_final_html(void)
738
{
739
    /*
740
    **  Generate ALL results with HTML tags
741
    */
742
    report_html = html;
743
    pri_final();
744
    report_html = printed;
745
    pri_final();
746
    report_html = text;
747
}
748
 
749
 
750
/*========================================================================
751
 *
752
 *  Print final results
753
 *
754
 *  Purpose:
755
 *      This function is called to Print final results
756
 *
757
 *  Parameters:
758
 *      None
759
 *
760
 *  Returns:
761
 *      Nothing
762
 *
763
 *========================================================================*/
764
 
765
void pri_final(void)
766
{
767
    ty_s_data  *ptr;
174 - 768
    team_type   team_buf;
95 - 769
    unsigned    i;
770
    int         j, last_class;
771
    char        *report_title;
772
    bool        class_done[MAX_CLASS+1];
773
    int         lcount;
338 david 774
    bool        isNeClass = false;
95 - 775
 
338 david 776
 
95 - 777
    if( ck_data( -1, C_ELAPSED ) )
778
        return;
779
    /*
780
    **  Sort on every thing
781
    **  Then generate all the stats too
782
    */
783
    do_big_sort();
784
    gen_stats();
785
 
786
    /*
787
     * Now print the data on the printer 
788
     */
789
    if( !open_printer( "", "finish", 132, report_html, "Finishing Order" ) )
790
        return;
791
 
792
    /*
793
     * Print out the data 
794
     */
795
    print_class_header( -1, TRUE );                      /* Print the header */
796
 
797
    ptr = sort_data;
336 david 798
    sort_team_data( 0, S_L, true );                     /* Re-sort on elapsed time */
95 - 799
    lcount = 0;
800
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
801
    {
802
        if ( ptr->teamclass == config.nonequestrian_class )
803
            continue;
804
 
805
        g_record( ptr->team, &team_buf );
806
 
807
        /*
338 david 808
        ** If this is a NE team then dummy up some of the data that hasn't been stored in team_buf
809
        */
810
        if (ptr->flags.non_equestrian)
811
        {
812
            team_buf.leg[0].l_place = sort_aux[ptr->team].lq_place[0];
813
            team_buf.leg[0].lc_place = sort_aux[ptr->team].leq_place[0];;
814
        }
815
 
816
        /*
95 - 817
        **  If printing an HTML report then we need to mark
818
        **  the entry with a reference so that we can link to it
819
        */
820
        if ( report_html == html )
821
        {
822
            print( "<A NAME=\"Team_%04d\"></A>",team_buf.numb );
823
        }
824
 
825
        /*
826
        **  Print the basics (Finishing order)
827
        **      - Place within complete field
828
        **      - Team number - with HTML reference to team file
829
        **      - Class
830
        */
831
        if ( report_html == printed && lcount %5 == 4 ) print_underline( TRUE );
337 david 832
        print( "%4.4s ", pn_place( team_buf.leg[0].l_place, ptr->flags.bad_times, ptr->flags.non_equestrian ) );
95 - 833
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "name" ,"html")), team_buf.numb );
834
        print( "%4d",  team_buf.numb );
835
        if ( report_html == html ) print( "</A>" );
836
 
837
        print( " %-*s", 3, team_buf.teamclass == 0 ? "" : config.team_class[team_buf.teamclass - 1].abr );
838
 
839
        /*
840
        **  Print the per-leg data
841
        **      - Time
842
        **      - Leg place
843
        **      - End place
844
        */
845
        for( j = 1; j <= config.num_legs; j++ )
846
        {
336 david 847
            bool isEquestrianLeg = (j == config.equestrian_leg && team_buf.flags.non_equestrian);
848
            bool afterEquestrianLeg = (team_buf.flags.non_equestrian && j > config.equestrian_leg);
95 - 849
            /*
850
            **  Ensure that non-equestrian leg data is not displayed
851
            */
336 david 852
            if ( isEquestrianLeg )
95 - 853
            {
854
                print( "  %-8s %4.4s %4.4s", "-- NE --", "NE","NE");
855
            }
856
            else
857
            {
858
                print( "  %-8s %4.4s %4.4s",
859
                    time_a( team_buf.leg[j].elapsed ),
336 david 860
                    pr_place( team_buf.leg[j].l_place, ptr->flags.bad_times ),
861
                    pn_place( team_buf.leg[j].le_place,ptr->flags.bad_times, afterEquestrianLeg )
95 - 862
                  );
863
            }
864
        }
865
 
866
       /*
867
        **  Print the trailer (Finishing order)
868
        **      - Total time
869
        **      - Category place - with reference to category file
870
        */
871
//        print( "  %-8s ",  time_a( team_buf.leg[0].elapsed ) );
872
        print( "  %-8s ", time_a( ptr->lege[0] ) );
873
 
874
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">",url_encode(p_filename(filebase, config.team_class[team_buf.teamclass - 1].abr ,"html")), team_buf.numb );
338 david 875
        print( "%-4.4s", pn_place( team_buf.leg[0].lc_place, ptr->flags.bad_times, ptr->flags.non_equestrian ) );
95 - 876
        if ( report_html == html ) print( "</A>" );
877
        if ( report_html == printed && lcount %5 == 4 ) print_underline( FALSE );
878
        lcount++;
879
        print( "\n" );
880
    }
881
 
882
    print_class_stats( -1, TRUE );              /* Print statistics */
883
    print_legend(-1, 1 );                       /* Print the legend */
884
    close_printer();                            /* Close the printer */
885
 
886
    /*
887
     * Now produce a breakdown on a class by class basis 
888
     * Now print out the class placement information
889
     */
890
 
338 david 891
    sort_team_data( 0, S_LC, true );           /* Generate class placement data */
95 - 892
    last_class = -1;                           /* Invalid class to start with */
893
    memset ( class_done, 0, sizeof(class_done));
894
 
895
 
896
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
897
    {
250 - 898
        int flags = 0;
337 david 899
        bool eflags;
250 - 900
 
95 - 901
        /*
902
        **  Detect a change in the "class"
903
        **  All data is within the one array of data
904
        **  Use the in-memory class as this MAY differ from that stored
905
        **  The non-equestrian class does this.
906
        */
907
        if( last_class != ptr->teamclass )
908
        {
909
            if( last_class >= 0 )
910
            {
911
                print_class_stats( last_class, TRUE );
912
                print_legend( last_class, 1 );
913
                close_printer();
914
            }
915
 
338 david 916
            /*
917
            ** Determine if this the crazy dummy Non-equestrian class
918
            */
919
            isNeClass = (ptr->teamclass == config.nonequestrian_class );
920
 
95 - 921
            report_title = tprintf( "Category results for : %-*s", LEN_CLASS_NAME, ptr->teamclass == 0 ? "" : config.team_class[ptr->teamclass - 1].full_name );
922
 
923
            if( !open_printer( "", config.team_class[ptr->teamclass - 1].abr, 132, report_html, report_title ) )
924
                continue;
925
            print_class_header( last_class = ptr->teamclass, TRUE );
926
 
927
            /*
928
            **  Mark the class as done
929
            */
930
            class_done[ptr->teamclass] = TRUE;
931
            lcount = 0;
932
        }
933
 
934
        /*
935
        **  Now read in the team record
936
        */
937
        g_record( ptr->team, &team_buf );
337 david 938
        flags = ptr->flags.bad_times;
939
        eflags = (ptr->teamclass != config.nonequestrian_class && ptr->flags.non_equestrian);
95 - 940
 
941
        /*
338 david 942
        ** Dummy up the data for the dummy nonEquestrian Class
943
        ** Its not stored in the team_buf for backwards compatability
944
        */
945
        if( isNeClass)
946
        {
947
            for( j = 0; j <= config.num_legs; j++ )
948
            {
949
                team_buf.leg[j].lc_place = sort_aux[ptr->team].lq_place[j];
950
                team_buf.leg[j].lec_place = sort_aux[ptr->team].leq_place[j];;
951
            }
952
        }
953
        else
954
        {
955
            if (ptr->flags.non_equestrian)
956
            {
957
                team_buf.leg[0].lc_place = sort_aux[ptr->team].lq_place[0];
958
                team_buf.leg[0].lec_place = sort_aux[ptr->team].leq_place[0];
959
                //eflags = false;
960
            }
961
        }
962
 
963
 
964
        /*
95 - 965
        **  If printing an HTML report then we need to mark
966
        **  the entry with a reference so that we can link to it
967
        */
968
        if ( report_html == html )
969
            print( "<A NAME=\"Team_%04d\"></A>",team_buf.numb );
970
 
971
        /*
972
        **  Print the basics
973
        **      - Place within the class
974
        **      - Team number - with HTML reference to team file
975
        **      - Class
976
        */
977
 
978
        if ( report_html == printed && lcount %5 == 4 ) print_underline( TRUE );
337 david 979
        print( "%4.4s ", pn_place( team_buf.leg[0].lc_place, flags , eflags ) );
95 - 980
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "name" ,"html")), team_buf.numb );
981
        print( "%4d",  team_buf.numb );
982
        if ( report_html == html ) print( "</A>" );
983
        print( " %-*s", 3, team_buf.teamclass == 0 ? "" : config.team_class[team_buf.teamclass - 1].abr );
984
 
985
        for( j = 1; j <= config.num_legs; j++ )
986
        {
336 david 987
            bool isEquestrianLeg = (j == config.equestrian_leg && (ptr->teamclass == config.nonequestrian_class || ptr->flags.non_equestrian));
988
            bool afterEquestrianLeg = ((ptr->teamclass == config.nonequestrian_class || ptr->flags.non_equestrian) && j > config.equestrian_leg);
989
 
95 - 990
            /*
991
            **  Ensure that non-equestrian leg data is not displayed
992
            */
336 david 993
            if ( isEquestrianLeg )
95 - 994
            {
995
                print( "  %-8s %4.4s %4.4s", "-- NE --", "NE","NE");
996
            }
997
            else
998
            {
999
                print( "  %-8s %4.4s %4.4s", time_a( team_buf.leg[j].elapsed ),
250 - 1000
                       pr_place( team_buf.leg[j].lc_place,  flags ),
336 david 1001
                       pn_place( team_buf.leg[j].lec_place, flags, afterEquestrianLeg ) );
95 - 1002
            }
1003
        }
1004
 
1005
        /*
1006
        **  Print the trailer
1007
        **      - Total time
1008
        **      - Overall place - with reference to overall place file
1009
        */
1010
        /* print( "  %-8s ", time_a( team_buf.leg[0].elapsed ) ); */
1011
        print( "  %-8s ", time_a( ptr->lege[0] ) );
1012
 
1013
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "finish" ,"html")), team_buf.numb );
338 david 1014
        print( "%4.4s", pn_place( team_buf.leg[0].l_place, flags , ptr->flags.non_equestrian));
95 - 1015
        if ( report_html == html ) print( "</A>" );
1016
 
1017
        if ( report_html == printed && lcount %5 == 4 ) print_underline( FALSE );
1018
        lcount++;
1019
        print( "\n" );
1020
    }
1021
 
1022
    print_class_stats( last_class, TRUE );
1023
    print_legend(last_class,1);
1024
    close_printer();
1025
 
1026
    /*
1027
    **  Pickup missed classes and create a report
1028
    */
1029
    for( j = 1; j <= config.num_class; j++ )
1030
    {
317 david 1031
        if ( class_done[j] || !config.team_class[j-1].abr[0] )
95 - 1032
        {
1033
            continue;
1034
        }
1035
        report_title = tprintf( "Category results for : %-*s", LEN_CLASS_NAME, config.team_class[j - 1].full_name );
1036
 
1037
        if( !open_printer( "", config.team_class[j - 1].abr, 132, report_html, report_title ) )
1038
            continue;
1039
        print_class_header( j-1, TRUE );
1040
        print( "\nThere were no competitors in this class\n" );
1041
        print_legend(j,1);
1042
        close_printer();
1043
    }
1044
 
1045
 
1046
    /*
1047
    **  If we are generating an HTML report then we need to create the file
1048
    **  that contains all the team names - the assumption is that this data
1049
    **  is available
1050
    */
295 david 1051
    if ( report_html == html || report_html == printed)
95 - 1052
    {
1053
        pri_team();
1054
    }
1055
 
1056
    /*
1057
    **  Generate the awards report.
1058
    **  This is only available as an HTML report
1059
    */
295 david 1060
    if ( report_html == html || report_html == printed)
95 - 1061
    {
1062
        pri_awards_html();
1063
    }
1064
 
1065
    /*
1066
    **  Generate the master index page
1067
    */
276 david 1068
    if ( report_html == html )
95 - 1069
    {
1070
        pri_master_index();
1071
    }
1072
 
1073
    pri_name_index_body();
1074
}
1075
 
1076
/*========================================================================
1077
 *
1078
 *  Place to text
1079
 *
1080
 *  Purpose:
1081
 *      This function is called to convert a place to text
1082
 *
1083
 *  Parameters:
1084
 *      place
1085
 *
1086
 *  Returns:
1087
 *      text
1088
 *
1089
 *========================================================================*/
1090
 
1091
char *placing ( int place )
1092
{
1093
    if ( place > MAX_PLACE )
1094
    {
1095
        return tprintf( "Place: %d", place);
1096
    }
1097
    return tprintf ("%s Place", place_text[place]);
1098
}
1099
 
1100
/*========================================================================
1101
 *
1102
 *  Print award results
1103
 *
1104
 *  Purpose:
1105
 *      This function is called to Print award results
1106
 *      Keep the page to 80 cols, so that it can be pronted on A4
1107
 *
1108
 *  Parameters:
1109
 *      None
1110
 *
1111
 *  Returns:
1112
 *      Nothing
1113
 *
1114
 *========================================================================*/
1115
void pri_awards_html(void)
1116
{
1117
    report_type saved = report_html;
1118
    /*
1119
    **  Generate ALL results with HTML tags
1120
    */
1121
    report_html = html;
1122
    pri_awards();
295 david 1123
    report_html = printed;
1124
    pri_awards();
95 - 1125
    report_html = saved;
1126
}
1127
 
1128
/*========================================================================
1129
 *
1130
 *  Print award results
1131
 *
1132
 *  Purpose:
1133
 *      This function is called to Print award results
1134
 *      Keep the page to 80 cols, so that it can be pronted on A4
1135
 *
1136
 *  Parameters:
1137
 *      None
1138
 *
1139
 *  Returns:
1140
 *      Nothing
1141
 *
1142
 *========================================================================*/
1143
void pri_awards(void)
1144
{
1145
    int j;
1146
    int i;
1147
    int k;
1148
    int windex;
1149
    int winmax;
1150
    ty_s_data  *ptr;
174 - 1151
    team_type   team_buf;
95 - 1152
    int         last_class;
1153
    char    solid_line[100];
288 david 1154
    bool header_done = false;
95 - 1155
 
1156
    /*
1157
    **  Calculate Summary information
1158
    **  Should cache the data
1159
    */
1160
    t_class_summary sdata;
1161
    calc_class_summary( & sdata );
1162
 
1163
 
1164
    if( !open_printer( "", "awards", 80, report_html, "Prizes and Awards" ) )
1165
        return;
1166
 
1167
    memset ( solid_line, 0, sizeof( solid_line ));
1168
    memset ( solid_line, '-', 80 );
1169
 
1170
    /*
1171
    **  Generate an index for this page
1172
    */
1173
    print( "\n");
1174
    if ( report_html == html )
1175
    {
1176
        print( "<hr>" );
1177
        print( "<A NAME=\"%s\"></A>",url_encode("INDEX"));
1178
    }
288 david 1179
    print( "Award Categories - Full Event");
95 - 1180
 
1181
    for( j = 1; j <= config.num_class; j++ )
1182
    {
1183
        /*
1184
        **  Header for the class
1185
        */
317 david 1186
        if (!config.team_class[j - 1].abr[0])
95 - 1187
            continue;
317 david 1188
        if (config.class_winners[j - 1] <= 0) 
1189
            continue;
95 - 1190
 
1191
        winmax = config.class_winners[j-1];
1192
        {
288 david 1193
            int valid =   sdata.teamclass[j].valid_ev;
95 - 1194
            if ( valid < winmax )
1195
                winmax = valid;
1196
        }
1197
 
1198
        print( "\n");
1199
        print( "    ");
1200
        if ( report_html == html ) print( "<A HREF=\"#%s\">",url_encode(config.team_class[j-1].full_name));
1201
        print( "%s",  tprintf( "%-*s", LEN_CLASS_NAME ,config.team_class[j-1].full_name ));
1202
        if ( report_html == html ) print( "</A>" );
1203
        print( "  %3d Awards", winmax );
1204
        if ( config.class_winners[j-1] != winmax )
1205
            print( " from a maximum of %3d", config.class_winners[j-1] );
288 david 1206
    }
95 - 1207
 
288 david 1208
    /*
1209
    **  NE Award Categories
1210
    */
1211
    if ( config.class_ne_winners_by_class )
1212
    {
1213
        print( "\n");
1214
        print( "Award Categories - Non Equestrian");
1215
 
1216
        for( j = 1; j <= config.num_class; j++ )
1217
        {
1218
            /*
1219
            **  Header for the class
1220
            */
317 david 1221
            if (!config.team_class[j - 1].abr[0])
1222
                continue;
288 david 1223
            if ( config.class_ne_winners[j-1] <= 0 )
1224
                continue;
1225
 
1226
            winmax = config.class_ne_winners[j-1];
1227
            {
1228
                int valid =   sdata.teamclass[j].valid_ne;
1229
                if ( valid < winmax )
1230
                    winmax = valid;
1231
            }
1232
 
1233
            print( "\n");
1234
            print( "    ");
1235
            if ( report_html == html ) print( "<A HREF=\"#%s_NE\">",url_encode(config.team_class[j-1].full_name));
1236
            print( "%s",  tprintf( "%-*s", LEN_CLASS_NAME ,config.team_class[j-1].full_name ));
1237
            if ( report_html == html ) print( "</A>" );
1238
            print( "  %3d Awards", winmax );
1239
            if ( config.class_ne_winners[j-1] != winmax )
1240
                print( " from a maximum of %3d", config.class_ne_winners[j-1] );
1241
        }
95 - 1242
    }
1243
 
1244
    /*
1245
    **  Manual entries
1246
    */
288 david 1247
    print( "\n");
1248
    print( "Miscellaneous");
1249
 
1250
        print( "\n");
1251
        print( "    ");
1252
        if ( report_html == html ) print( "<A HREF=\"#%s_by_cat\">",url_encode("Full Event"));
1253
        print( "%s",  tprintf( "%-*s", LEN_CLASS_NAME ,"Full Event"));
1254
        if ( report_html == html ) print( "</A>" );
1255
        print (" by Category");
1256
 
231 - 1257
    if ( config.class_ne_winners_by_class )
1258
    {
1259
        print( "\n");
1260
        print( "    ");
1261
        if ( report_html == html ) print( "<A HREF=\"#%s_by_cat\">",url_encode(config.team_class[config.nonequestrian_class-1].full_name));
1262
        print( "%s",  tprintf( "%-*s", LEN_CLASS_NAME ,config.team_class[config.nonequestrian_class-1].full_name ));
1263
        if ( report_html == html ) print( "</A>" );
1264
        print (" by Category");
1265
    }
1266
 
1267
 
95 - 1268
    print( "\n");
1269
    print( "    ");
1270
    if ( report_html == html ) print( "<A HREF=\"#%s\">",url_encode("Hall Of Fame"));
1271
    print( "%s",  "Hall Of Fame" );
1272
    if ( report_html == html ) print( "</A>" );
1273
 
1274
    print( "\n");
1275
    print( "    ");
1276
    if ( report_html == html ) print( "<A HREF=\"#%s\">",url_encode("FASTEST"));
1277
    print( "%s",  "FASTEST" );
1278
    if ( report_html == html ) print( "</A>" );
1279
 
1280
    /*
1281
    **  Sort the data by class
1282
    */
336 david 1283
    sort_team_data( 0, S_LC, true );     /* Generate class placement data */
95 - 1284
    last_class = -1;                /* Invalid class to start with */
1285
 
1286
    /*
1287
    **  Process each category
1288
    */
1289
    print( "\n");
1290
    for( j = 1; ; j++ )
1291
    {
317 david 1292
        if (!config.team_class[j - 1].abr[0])
1293
            continue;
1294
 
95 - 1295
        /*
1296
        **  Tail for previous entry
1297
        */
231 - 1298
        //if ( config.class_ne_winners_by_class && j == config.nonequestrian_class )
1299
        //    continue;
1300
 
95 - 1301
        if ( j != 1 )
1302
            if ( report_html == html ) print( "<A HREF=\"#%s\">Awards Index</A>",url_encode("INDEX"));
1303
 
1304
        if ( j > config.num_class  )
1305
            break;
1306
 
1307
        /*
1308
        **  Header for the class
1309
        */
1310
        print( "\n");
1311
        if ( report_html == html )
1312
        {
1313
            print( "<hr>" );
288 david 1314
 
1315
            if ( !header_done )
1316
            {
1317
                header_done = true;
1318
                if ( report_html == html )
1319
                {
1320
                    print( "<A name=\"%s_by_cat\"></A>",url_encode("Full Event"));
1321
                }
1322
            }
1323
 
95 - 1324
            print( "<A name=\"%s\"></A>",url_encode(config.team_class[j-1].full_name));
1325
        }
1326
        else
1327
        {
1328
            print( "%s\n", solid_line);
1329
        }
1330
        print( "Category: ");
1331
        if ( report_html == html ) print( "<A HREF=\"%s\">",url_encode(p_filename(filebase, config.team_class[j - 1].abr ,"html")));
1332
        print( "%s",  config.team_class[j-1].full_name );
1333
        if ( report_html == html ) print( "</A>" );
1334
 
1335
        if ( config.class_winners[j-1] <= 0 )
1336
        {
1337
            print( "\n");
1338
            print( "No winners awarded" );
288 david 1339
            if ( report_html == html ) print("<br>");
95 - 1340
            continue;
1341
        }
1342
 
1343
        /*
1344
        **  Enties for 'n' the best teams as configured
1345
        */
1346
        windex = 0;                     /* Winners done */
1347
        unsigned int i;
1348
        for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1349
        {
1350
            if ( ptr->teamclass != j )
1351
            {
1352
                continue;
1353
            }
1354
 
1355
            /*
1356
            **  Now read in the team record
1357
            */
1358
            if( valid_field( ptr->team ) && g_record( ptr->team, &team_buf ) )
1359
            {
1360
                /*
1361
                **  Ensure we have a valid team
1362
                **  Can't award disqualified teams
1363
                **  Can't award NE teams unless its a NE award
1364
                */
1365
                if ( ptr->flags.bad_times )
1366
                    break;
1367
 
1368
                if ( ptr->teamclass != config.nonequestrian_class  && ptr->flags.non_equestrian )
1369
                    break;
1370
 
1371
                /*
1372
                **  Count the entry
1373
                */
1374
                windex++;
1375
 
1376
                /*
1377
                **  If printing an HTML report then we need to mark
1378
                **  the entry with a reference so that we can link to it
1379
                */
1380
                print( "\n");
1381
                if ( report_html == html )
1382
                {
1383
                    print( "<A NAME=\"Team_%04d\">",team_buf.numb );
1384
                    print( "</A>" );
1385
                }
1386
 
1387
                /*
1388
                **  Basic information
1389
                **      - Team number - with Xref back to full result
1390
                **      - Full team name
1391
                **      - Full categoray name
1392
                */
1393
                print( "%s", placing(windex) );
1394
 
1395
                print( "  Team Name: ");
1396
                if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "name" ,"html")), team_buf.numb );
1397
                print( "%-*s ",     MAX_TM_NAME, team_buf.name );
1398
                    if ( report_html == html ) print( "</A>" );
1399
 
1400
                print( "  Number: ");
1401
                if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "finish" ,"html")), team_buf.numb );
1402
                print( "%4d",       team_buf.numb );
1403
                if ( report_html == html ) print( "</A>" );
1404
 
1405
 
1406
                for( k = 0; k < MAX_MEMB; k++ )
1407
                {
1408
 
1409
                    /*
1410
                    **  Skip equestrian leg in the non-equestion display
1411
                    */
1412
                    if ( k + 1 == config.equestrian_leg && ptr->teamclass == config.nonequestrian_class)
1413
                        continue;
1414
 
1415
                    print( "\n");
1416
                    print( "    ");
1417
                    print( "%-*s", MAX_PERSON_NAME, config.leg_name[k] ? config.leg_name[k] : "Competitor"  );
1418
                    print( " %-*s", MAX_PERSON_NAME, team_buf.members[k].name );
1419
 
1420
                    print( "  %-8s", time_a( team_buf.leg[k+1].elapsed ) );
1421
                }
1422
 
1423
                print( "\n");
1424
                print( "    ");
1425
                print_bold( TRUE );
1426
                print( "%-*s %-*s  %-8s", MAX_PERSON_NAME , "Total" ,MAX_PERSON_NAME, "",time_a( team_buf.leg[0].elapsed ) );
1427
                print_bold( FALSE );
1428
                print( "\n" );
1429
            }
1430
 
1431
 
1432
            /*
1433
            **  More to do
1434
            */
1435
            if ( windex >= config.class_winners[j-1] )
1436
            {
1437
                break;
1438
            }
1439
        }
1440
    }
1441
 
1442
    /*
231 - 1443
    ** Non Equestrian winners by category
1444
    */
1445
    if ( config.class_ne_winners_by_class)
1446
    {
288 david 1447
        header_done = false;
231 - 1448
 
1449
        /*
1450
        **  Sort the data by class with NE data sorted by real class
1451
        */
336 david 1452
        sort_team_data( 0, S_LC_NE, true );      /* Generate class placement data */
231 - 1453
        last_class = -1;                   /* Invalid class to start with */
1454
 
1455
        /*
1456
        **  Only process the Non Equestrian teams in this pass
1457
        */
1458
        print( "\n");
1459
        for( j = 1; ; j++ )
1460
        {
317 david 1461
            if (!config.team_class[j - 1].abr[0])
1462
                continue;
1463
 
231 - 1464
            /*
1465
            **  Tail for previous entry
1466
            */
1467
            if ( j == config.nonequestrian_class)
1468
                continue;
1469
 
1470
            if ( j != 1 )
1471
                if ( report_html == html ) print( "<A HREF=\"#%s\">Awards Index</A>",url_encode("INDEX"));
1472
 
1473
            if ( j > config.num_class  )
1474
                break;
1475
 
1476
            /*
1477
            **  Header for the (sub) class
1478
            */
1479
            if ( !header_done )
1480
            {
1481
                header_done = true;
1482
                if ( report_html == html )
1483
                {
1484
                    print( "<A name=\"%s_by_cat\"></A>",url_encode(config.team_class[config.nonequestrian_class-1].full_name));
1485
                }
1486
            }
1487
 
1488
            print( "\n");
1489
            if ( report_html == html )
1490
            {
1491
                print( "<hr>" );
288 david 1492
                print( "<A name=\"%s_NE\"></A>",url_encode(config.team_class[j-1].full_name));
231 - 1493
            }
1494
            else
1495
            {
1496
                print( "%s\n", solid_line);
1497
            }
1498
            print( "Category: ");
1499
            if ( report_html == html ) print( "<A HREF=\"%s\">",url_encode(p_filename(filebase, config.team_class[config.nonequestrian_class - 1].abr ,"html")));
1500
            print( "%s",  config.team_class[config.nonequestrian_class-1].full_name );
1501
            if ( report_html == html ) print( "</A>" );
1502
 
1503
            print (" :: ");
1504
 
1505
            if ( report_html == html ) print( "<A HREF=\"%s\">",url_encode(p_filename(filebase, config.team_class[j - 1].abr ,"html")));
1506
            print( "%s",  config.team_class[j-1].full_name );
1507
            if ( report_html == html ) print( "</A>" );
1508
 
1509
            if ( config.class_ne_winners[j-1] <= 0 )
1510
            {
1511
                print( "\n");
1512
                print( "No winners awarded" );
1513
                if ( report_html == html ) print("<br>");
1514
                continue;
1515
            }
1516
 
1517
            /*
1518
            **  Enties for 'n' the best teams as configured
1519
            */
1520
            windex = 0;                     /* Winners done */
1521
            unsigned int i;
1522
            for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1523
            {
1524
                if ( ptr->teamclass != config.nonequestrian_class ||  ptr->real_teamclass != j )
1525
                {
1526
                    continue;
1527
                }
1528
 
1529
                /*
1530
                **  Now read in the team record
1531
                */
1532
                if( valid_field( ptr->team ) && g_record( ptr->team, &team_buf ) )
1533
                {
1534
                    /*
1535
                    **  Ensure we have a valid team
1536
                    **  Can't award disqualified teams
1537
                    **  Can't award NE teams unless its a NE award
1538
                    */
1539
                    if ( ptr->flags.bad_times )
1540
                        break;
1541
 
1542
                    if ( ptr->teamclass != config.nonequestrian_class  && ptr->flags.non_equestrian )
1543
                        break;
1544
 
1545
                    /*
1546
                    **  Count the entry
1547
                    */
1548
                    windex++;
1549
 
1550
                    /*
1551
                    **  If printing an HTML report then we need to mark
1552
                    **  the entry with a reference so that we can link to it
1553
                    */
1554
                    print( "\n");
1555
                    if ( report_html == html )
1556
                    {
1557
                        print( "<A NAME=\"Team_%04d\">",team_buf.numb );
1558
                        print( "</A>" );
1559
                    }
1560
 
1561
                    /*
1562
                    **  Basic information
1563
                    **      - Team number - with Xref back to full result
1564
                    **      - Full team name
1565
                    **      - Full categoray name
1566
                    */
1567
                    print( "%s", placing(windex) );
1568
 
1569
                    print( "  Team Name: ");
1570
                    if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "name" ,"html")), team_buf.numb );
1571
                    print( "%-*s ",     MAX_TM_NAME, team_buf.name );
1572
                        if ( report_html == html ) print( "</A>" );
1573
 
1574
                    print( "  Number: ");
1575
                    if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "finish" ,"html")), team_buf.numb );
1576
                    print( "%4d",       team_buf.numb );
1577
                    if ( report_html == html ) print( "</A>" );
1578
 
1579
 
1580
                    for( k = 0; k < MAX_MEMB; k++ )
1581
                    {
1582
 
1583
                        /*
1584
                        **  Skip equestrian leg in the non-equestion display
1585
                        */
1586
                        if ( k + 1 == config.equestrian_leg && ptr->teamclass == config.nonequestrian_class)
1587
                            continue;
1588
 
1589
                        print( "\n");
1590
                        print( "    ");
1591
                        print( "%-*s", MAX_PERSON_NAME, config.leg_name[k] ? config.leg_name[k] : "Competitor"  );
1592
                        print( " %-*s", MAX_PERSON_NAME, team_buf.members[k].name );
1593
 
1594
                        print( "  %-8s", time_a( team_buf.leg[k+1].elapsed ) );
1595
                    }
1596
 
1597
                    print( "\n");
1598
                    print( "    ");
1599
                    print_bold( TRUE );
1600
                    print( "%-*s %-*s  %-8s", MAX_PERSON_NAME , "Total" ,MAX_PERSON_NAME, "",time_a( team_buf.leg[0].elapsed ) );
1601
                    print_bold( FALSE );
1602
                    print( "\n" );
1603
                }
1604
 
1605
 
1606
                /*
1607
                **  More to do
1608
                */
1609
                if ( windex >= config.class_ne_winners[j-1] )
1610
                {
1611
                    break;
1612
                }
1613
            }
1614
        }
1615
    }
1616
 
1617
    /*
95 - 1618
    **  Generate the Hall of Fame information
1619
    */
1620
    print( "\n");
1621
    if ( report_html == html )
1622
    {
1623
        print( "<hr>" );
1624
        print( "<A name=\"%s\"></A>",url_encode("Hall Of Fame"));
1625
    }
1626
    else
1627
    {
1628
        print( "%s\n", solid_line);
1629
    }
1630
    print( "%s",  "Hall of Fame" );
1631
 
1632
    if ( config.num_fame  )
1633
    {
1634
        for( i = 1; i <= config.num_fame; i++ )
1635
        {
1636
            print( "\n");
1637
            print( "    %-*s", MAX_PERSON_NAME, config.hall_fame[i-1] );
1638
        }
1639
    }
1640
    else
1641
    {
199 david 1642
        qDebug( "There are no new stars for the Hall of Fame");
95 - 1643
    }
1644
    if ( report_html == html ) print( "\n");
1645
    if ( report_html == html ) print( "<A HREF=\"#%s\">Awards Index</A>",url_encode("INDEX"));
1646
 
1647
    /*
1648
    **  Generate the FASTEST information
1649
    */
1650
    print( "\n" );
1651
    print( "\n");
1652
    if ( report_html == html )
1653
    {
1654
        print( "<hr>" );
1655
        print( "<A name=\"%s\"></A>",url_encode("FASTEST"));
1656
    }
1657
    else
1658
    {
1659
        print( "%s\n", solid_line);
1660
    }
1661
    print( "%s",  "FASTEST" );
1662
 
1663
    /*
1664
    **  Sort the data and then generate the stats - again
1665
    */
1666
    do_big_sort();
1667
    gen_stats();
1668
 
1669
    for( i = 1; i <= config.num_legs; i++ )
1670
    {
1671
        g_record( stats.fast.team[i][0], &team_buf );
1672
 
1673
        print( "\n");
1674
        print( "    %-13s ", config.leg_name[i - 1] );
1675
        print( "  Name: ");
1676
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "name" ,"html")), team_buf.numb );
1677
        print( "%-*s", MAX_PERSON_NAME, team_buf.members[i-1].name );
1678
        if ( report_html == html ) print( "</A>" );
246 - 1679
        print( "  Team:");
95 - 1680
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "finish" ,"html")), team_buf.numb );
1681
        print( "%4d" , stats.fast.team[i][0] );
1682
        if ( report_html == html ) print( "</A> " );
246 - 1683
        print( "  Time:%s ", time_a( stats.fast.time[i][0] ) );
95 - 1684
 
1685
    }
1686
 
1687
    if ( report_html == html ) print( "\n");
1688
    if ( report_html == html ) print( "<A HREF=\"#%s\">Awards Index</A>",url_encode("INDEX"));
1689
    print( "\n");
1690
    close_printer();
1691
}
1692
 
1693
/*========================================================================
1694
 *
1695
 *  pri_master_index
1696
 *
1697
 *  Purpose:
1698
 *      This function is called to create an HTML page that references all
1699
 *      the other pages that have been generated
1700
 *
1701
 *      Assume that they are in the same directory
1702
 *
1703
 *  Parameters:
1704
 *      None
1705
 *
1706
 *  Returns:
1707
 *      Nothing
1708
 *
1709
 *========================================================================*/
1710
void pri_master_index_entry(const char *name, const char *text)
1711
{
1712
    print( "<tr><td>");
1713
    print ("<A HREF=\"%s\">%s</A>\n", url_encode(p_filename(filebase, name ,"html")), text );
1714
}
1715
 
1716
 
1717
void pri_master_index(void)
1718
{
1719
    int j;
1720
 
1721
    report_html = html;
1722
    if( !open_printer( "", "index", 132, report_html, "Master Index" ) )
1723
        return;
1724
 
1725
    /*
1726
    **  Names
1727
    */
1728
    print( "<TABLE border=0 align=center>" );
1729
    pri_master_index_entry( "name", "Team list" );
1730
    pri_master_index_entry( "competitor", "Competitor list" );
1731
    pri_master_index_entry( "finish", "Finishing Order for all Teams" );
1732
    pri_master_index_entry( "awards", "Prizes and Awards" );
1733
    print( "<tr><td>\n" );
1734
 
1735
    print( "\n" );
1736
    for( j = 1; j <= config.num_class; j++ )
1737
    {
317 david 1738
        if (!config.team_class[j - 1].abr[0])
1739
            continue;
95 - 1740
        pri_master_index_entry( config.team_class[j - 1].abr, tprintf("Category Results for: %s", config.team_class[j-1].full_name) );
1741
    }
1742
 
1743
    print( "</TABLE>" );
1744
 
1745
    close_printer();
1746
 
1747
    /*
1748
    **  A small page to hold the Leg End displays
1749
    */
1750
 
1751
    if( !open_printer( "", "legindex", 132, report_html, "Master Index with trace data" ) )
1752
        return;
1753
 
1754
    /*
1755
    **  Names
1756
    */
1757
    print( "<TABLE border=0 align=center>" );
1758
#if 1
1759
    pri_master_index_entry( "name", "Team list" );
1760
    pri_master_index_entry( "competitor", "Competitor list" );
1761
    pri_master_index_entry( "finish", "Finishing Order for all Teams" );
1762
    pri_master_index_entry( "awards", "Prizes and Awards" );
1763
    print( "<tr><td>\n" );
1764
 
1765
    print( "\n" );
258 - 1766
    pri_master_index_entry( "summary", "Category Summary" );
95 - 1767
    for( j = 1; j <= config.num_class; j++ )
1768
    {
317 david 1769
        if (!config.team_class[j - 1].abr[0])
1770
            continue;
95 - 1771
        pri_master_index_entry( config.team_class[j - 1].abr, tprintf("Category Results for: %s", config.team_class[j-1].full_name) );
1772
    }
1773
#endif
1774
    print( "<tr><td>\n" );
1775
 
1776
    print( "\n" );
174 - 1777
    for ( int leg = 1; leg <= config.num_legs; leg ++ )
95 - 1778
    {
1779
        pri_master_index_entry( tprintf("lg%1.1d", leg), tprintf("Leg End Results for: %d", leg) );    
1780
    }
1781
 
1782
    print( "<tr><td>\n" );
1783
    print( "\n" );
1784
 
174 - 1785
    for ( int leg = 1; leg <= config.num_legs; leg ++ )
95 - 1786
    {
1787
        pri_master_index_entry( tprintf("le%1.1d", leg), tprintf("Leg Elapsed Time Results for: %d", leg) );
1788
    }    
1789
 
1790
 
1791
    print( "</TABLE>" );
1792
 
1793
    close_printer();
207 - 1794
    /*
1795
     ** Tell the main system about this new report
1796
     */
276 david 1797
    MainWindow::registerReport(getPrinterFile(), "Master Leg Index");
95 - 1798
 
1799
}
1800
 
1801
 
1802
/*========================================================================
1803
 *
1804
 *  Print interim results
1805
 *
1806
 *  Purpose:
1807
 *      This function is called to Print interim results
1808
 *
1809
 *  Parameters:
1810
 *      None
1811
 *
1812
 *  Returns:
1813
 *      Nothing
1814
 *
1815
 *========================================================================*/
1816
 
1817
void pri_interim(void)
1818
{
1819
    ty_s_data  *ptr;
174 - 1820
    team_type   team_buf;
95 - 1821
    unsigned    i;
1822
    int         j, last_class;
1823
    char       *report_title;
1824
 
1825
    if ( ! report_all )
1826
    {
199 david 1827
        ck_data( -1, C_DISQUAL );              /* Check the data - dummy check */
95 - 1828
    }
1829
    do_big_sort();                             /* Sort on every thing */
1830
    gen_stats();                               /* Generate the stats too */
1831
 
1832
    /*
1833
     * Now print the data on the printer 
1834
     */
1835
 
1836
    if( !open_printer( "", "int", 132, report_html, "Interim Results" ) )
1837
        return;
1838
 
1839
    /*
1840
     * Print out the data 
1841
     */
1842
    print_class_header( -1, FALSE );                     /* Print the header */
1843
 
1844
    ptr = sort_data;
336 david 1845
    sort_team_data( 0, S_TEAM, true );                   /* Re-sort on team number */
95 - 1846
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1847
    {
1848
        if ( ptr->teamclass == config.nonequestrian_class )
1849
            continue;
1850
 
1851
        g_record( ptr->team, &team_buf );
1852
 
1853
        print( "%4d %4.4s %-*s",
1854
               team_buf.numb,
1855
               pi_place( team_buf.leg[config.num_legs].le_place,
1856
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ),
1857
               3,
1858
               team_buf.teamclass ==
1859
 
1860
        for( j = 1; j <= config.num_legs; j++ )
1861
        {
1862
            print( "  %-8s %4.4s %4.4s",
1863
                   time_fa( team_buf.leg[j].elapsed,
1864
                            ptr->flags.disqualified ),
1865
                   pi_place( team_buf.leg[j].l_place, ptr->flags.disqualified,
1866
                             team_buf.leg[j].elapsed ),
1867
                   pi_place( team_buf.leg[j].le_place,
1868
                             ptr->flags.disqualified,
1869
                             team_buf.leg[j].elapsed ) );
1870
        }
1871
        print( "  %-8s %4.4s\n",
1872
               time_fa( team_buf.leg[0].elapsed, ptr->flags.disqualified ),
1873
               pi_place( team_buf.leg[config.num_legs].lec_place,
1874
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ) );
1875
    }
1876
 
1877
    print_class_stats( -1, FALSE );             /* Print statistics */
1878
    print_legend(-1, 1);                        /* Print the legend */
1879
    close_printer();                            /* Close the printer */
1880
 
1881
 
1882
    /*
1883
     * Now produce a breakdown on a class by class basis 
1884
     * Now print out the class placement information
1885
     */
1886
 
336 david 1887
    sort_team_data( 0, S_CLASS, true );              /* Generate class placement data */
95 - 1888
    last_class = -1;                             /* Invalid class to start with */
1889
 
1890
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1891
    {
1892
        /*
1893
        **  Detect a change in the "class"
1894
        **  All data is within the one array of data
1895
        **  Use the in-memory class as this MAY differ from that stored
1896
        **  The non-equestrian class does this.
1897
        */
1898
        if( last_class != ptr->teamclass )
1899
        {
1900
            if( last_class >= 0 )
1901
            {
1902
                print_class_stats( last_class, TRUE );
1903
                print_legend(last_class, 1);
1904
                close_printer();
1905
            }
1906
 
1907
            report_title = tprintf( "Interim Category results for : %-*s", LEN_CLASS_NAME, team_buf.teamclass == 0 ? "" : config.team_class[ptr->teamclass - 1].full_name );
1908
 
1909
            if( !open_printer( "", tprintf( "i%2s", config.team_class[ptr->teamclass - 1].abr ), 132, report_html, report_title ) )
1910
                continue;
1911
            print_class_header( last_class = ptr->teamclass, FALSE );
1912
        }
1913
 
1914
        /*
1915
        **  Now read in the team record
1916
        */
1917
        g_record( ptr->team, &team_buf );
1918
        print( "%4d %4.4s %-*s",
1919
               team_buf.numb,
1920
               pi_place( team_buf.leg[config.num_legs].lec_place,
1921
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ),
1922
               3,
1923
               team_buf.teamclass ==
1924
 
1925
        for( j = 1; j <= config.num_legs; j++ )
1926
        {
1927
            print( "  %-8s %4.4s %4.4s",
1928
                   time_fa( team_buf.leg[j].elapsed,
1929
                            ptr->flags.disqualified ),
1930
                   pi_place( team_buf.leg[j].lc_place,
1931
                             ptr->flags.disqualified,
1932
                             team_buf.leg[j].elapsed ),
1933
                   pi_place( team_buf.leg[j].lec_place,
1934
                             ptr->flags.disqualified,
1935
                             team_buf.leg[j].elapsed ) );
1936
        }
1937
        print( "  %-8s %4.4s\n",
1938
               time_fa( team_buf.leg[0].elapsed, ptr->flags.disqualified ),
1939
               pi_place( team_buf.leg[config.num_legs].le_place,
1940
                         ptr->flags.disqualified, team_buf.leg[0].elapsed ) );
1941
    }
1942
 
1943
    print_class_stats( last_class, FALSE );
1944
    print_legend(last_class, 1);
1945
    close_printer();
1946
 
1947
}
1948
 
1949
/*----------------------------------------------------------------------------
1950
** FUNCTION           : pri_csv_data
1951
**
1952
** DESCRIPTION        : Generate a CSV file of all the report data
1953
**                      It can then be used to play with the data externally
1954
**
1955
**
1956
** INPUTS             : None
1957
**
1958
** RETURNS            : Yes it does
1959
**
1960
----------------------------------------------------------------------------*/
1961
 
1962
 
1963
void pri_csv_data ( void )
1964
{
1965
    int i;
1966
    int j;
1967
    int age_sum;
174 - 1968
    team_type   team_buf;
95 - 1969
 
1970
    /*
1971
    **  Sort on every thing
1972
    **  Then generate all the stats too
1973
    */
1974
    do_big_sort();
1975
    gen_stats();
1976
 
1977
    /*
1978
     * Now print the data on the printer 
1979
     */
1980
 
1981
    if( !open_printer( "full_data", "csv", 2000, text, NULL ) )
1982
        return;
1983
 
1984
    /*
1985
    **  Print headings
1986
    */
1987
    csv_print( "%s",   "Team Number" );
1988
    csv_print( "%s",   "Team Name" );
1989
 
1990
    csv_print( "%s",    "Class Full");
1991
    csv_print( "%s",    "Class Abr");
1992
    csv_print( "%s",    "Class Start Time");
1993
    csv_print( "%s",    "Class Start Time Number");
1994
 
1995
    csv_print( "%s",    "Team Country");
1996
 
1997
    for( j = 1; j <= config.num_legs; j++ )
1998
    {
1999
        csv_print( "%s", "Leg Number" );
2000
        csv_print( "%s", "Leg Name");
2001
        csv_print( "%s", "Competitor Name");
2002
        csv_print( "%s", "Sex" );
2003
        csv_print( "%s", "Age");
2004
        csv_print( "%s", "Start Time");
2005
        csv_print( "%s", "Start Time Number");
2006
        csv_print( "%s", "End Time" );
2007
        csv_print( "%s", "End Time Number" );
2008
        csv_print( "%s", "Elapsed Time");
2009
        csv_print( "%s", "Elapsed Time Number");
2010
        csv_print( "%s", "Leg Place");
2011
        csv_print( "%s", "Leg End Place");
2012
        csv_print( "%s", "Leg Class Place");
2013
        csv_print( "%s", "Leg End Class Place");
2014
        csv_print( "%s", "Manual");
2015
    }
2016
 
2017
    j = 0;
2018
    csv_print( "%s", "Team Start Time");
2019
    csv_print( "%s", "Team Start Time Number");
2020
    csv_print( "%s", "Team End Time");
2021
    csv_print( "%s", "Team End Time Number");
2022
    csv_print( "%s", "Team Elapsed Time");
2023
    csv_print( "%s", "Team Elapsed Time Number");
2024
//            csv_print( "%s", team_buf.leg[j].l_place );
2025
    csv_print( "%s", "Team Leg End Place");
2026
//            csv_print( "%s", team_buf.leg[j].lc_place );
2027
    csv_print( "%s", "Team Leg Class Place");
2028
//            csv_print( "%s", team_buf.leg[j].manual );
2029
 
2030
    csv_print( "%s", "Total Team Age");
2031
    csv_print( "%s", "Flag:valid Team");
2032
    csv_print( "%s", "Flag:bad_times" );
2033
    csv_print( "%s", "Flag:disqualified" );
2034
    csv_print( "%s", "Flag:non_equestrian" );
250 - 2035
    csv_print( "%s", "Flag:vet_check" );
95 - 2036
    csv_print("\n");
2037
 
2038
 
2039
    for( i = config.min_team; i <= config.max_team; i++ )
2040
    {
2041
        if( valid_field( i ) && g_record( i, &team_buf ) )
2042
        {
2043
            /*
2044
            **  Basic information
2045
            **      - Team number - with Xref back to full result
2046
            **      - Full team name
2047
            **      - Full categoray name - with Xref to category results
2048
            **      - Country name
2049
            */
2050
            csv_print( "%d",   team_buf.numb );
2051
            csv_print( "%s",   team_buf.name );
2052
 
2053
            csv_print( "%s",    team_buf.teamclass == 0 ? "" : config.team_class[team_buf.teamclass - 1].full_name );
2054
            csv_print( "%s",    team_buf.teamclass == 0 ? "" : config.team_class[team_buf.teamclass - 1].abr );
2055
            csv_print( "%s",    time_a (team_buf.teamclass == 0 ? 0 : config.team_class[team_buf.teamclass - 1].start ));
2056
            csv_print( "%d",    team_buf.teamclass == 0 ? 0 : config.team_class[team_buf.teamclass - 1].start );
2057
 
2058
            csv_print( "%s",    config.num_countries == 0
2059
                                || team_buf.country ==
2060
 
2061
 
2062
            age_sum = 0;
2063
            for( j = 1; j <= config.num_legs; j++ )
2064
            {
2065
                csv_print( "%d", j );
2066
                csv_print( "%s", config.leg_name[j - 1] );
2067
                csv_print( "%s", team_buf.members[j-1].name );
2068
                csv_print( "%s", ( team_buf.members[j-1].sex == male ) ? "Male" : "Female" );
2069
                csv_print( "%d", team_buf.members[j-1].age );
2070
                if ( age_sum >= 0 )
2071
                {
2072
                    ushort age = team_buf.members[j-1].age;
2073
                    if ( age > 0 && age < 255 )
2074
                    {
2075
                        age_sum += age;
2076
                    }
2077
                    else
2078
                    {
2079
                        age_sum = -1;
2080
                    }
2081
                }
2082
 
2083
 
2084
                csv_print( "%s", time_a(team_buf.leg[j].start ));
2085
                csv_print( "%d", team_buf.leg[j].start );
2086
                csv_print( "%s", time_a(team_buf.leg[j].end ));
2087
                csv_print( "%d", team_buf.leg[j].end );
2088
                csv_print( "%s", time_a(team_buf.leg[j].elapsed ));
2089
                csv_print( "%d", team_buf.leg[j].elapsed );
2090
                csv_print( "%d", team_buf.leg[j].l_place );
2091
                csv_print( "%d", team_buf.leg[j].le_place );
2092
                csv_print( "%d", team_buf.leg[j].lc_place );
2093
                csv_print( "%d", team_buf.leg[j].lec_place );
2094
                csv_print( "%d", team_buf.leg[j].manual );
2095
            }
2096
 
2097
            j = 0;
2098
            csv_print( "%s", time_a(team_buf.leg[j].start ));
2099
            csv_print( "%d", team_buf.leg[j].start );
2100
            csv_print( "%s", time_a(team_buf.leg[j].end ));
2101
            csv_print( "%d", team_buf.leg[j].end );
2102
            csv_print( "%s", time_a(team_buf.leg[j].elapsed ));
2103
            csv_print( "%d", team_buf.leg[j].elapsed );
2104
//            csv_print( "%d", team_buf.leg[j].l_place );
2105
            csv_print( "%d", team_buf.leg[j].le_place );
2106
//            csv_print( "%d", team_buf.leg[j].lc_place );
2107
            csv_print( "%d", team_buf.leg[j].lec_place );
2108
//            csv_print( "%d", team_buf.leg[j].manual );
2109
 
2110
            csv_print( "%d", age_sum );
2111
            csv_print( "%d", team_buf.flags.valid );
2112
            csv_print( "%d", team_buf.flags.bad_times );
2113
            csv_print( "%d", team_buf.flags.disqualified );
2114
            csv_print( "%d", team_buf.flags.non_equestrian );
250 - 2115
            csv_print( "%d", team_buf.flags.vet_check );
95 - 2116
 
2117
//How about class placings
2118
 
2119
 
2120
            csv_print( "\n" );
2121
        }
2122
    }
2123
 
2124
    close_printer();
2125
}
2126
 
2127
 
2128
/*========================================================================
2129
 *
2130
 *  Print all reports at once
2131
 *  Its all so fast, these days ...
2132
 *
2133
 *  Purpose:
2134
 *      This function is called to print all reports at once
2135
 *
2136
 *  Parameters:
2137
 *      None
2138
 *
2139
 *  Returns:
2140
 *      Nothing
2141
 *
2142
 *========================================================================*/
2143
 
2144
void pri_all_reports ( void )
2145
{
2146
    int leg;
2147
    report_all = TRUE;
2148
 
2149
    pri_team();
2150
 
2151
    for ( leg = 1; leg <= config.num_legs; leg ++ )
2152
    {
2153
        pri_leg_body ( leg );
2154
        pri_eleg_body ( leg );
2155
 
2156
        report_html = html;
2157
 
2158
        pri_leg_body ( leg );
295 david 2159
        pri_eleg_body ( leg );
2160
 
2161
        //report_html = printed;
2162
        //
2163
        //pri_leg_body ( leg );
2164
        //pri_eleg_body ( leg );        
95 - 2165
 
2166
        report_html = text;
2167
    }
2168
 
2169
    pri_final();
2170
    pri_final_html();
2171
    pri_csv_data();
258 - 2172
    pri_summary_html();
95 - 2173
    pri_summary();
2174
    pri_awards_html();
2175
    pri_awards();
2176
    pri_master_index();
2177
 
172 david 2178
    pri_interim();
2179
 
95 - 2180
    report_all = FALSE;
2181
}
2182
 
2183
 
2184
/*========================================================================
2185
 *
2186
 *  Print a class header
2187
 *
2188
 *  Purpose:
2189
 *      This function is called to print a class header
2190
 *
2191
 *  Parameters:
2192
 *      class           Name of this class
2193
 *      final           False - prelim results
2194
 *
2195
 *  Returns:
2196
 *      Nothing
2197
 *
2198
 *========================================================================*/
2199
 
2200
void print_class_header( int teamclass, int final )
2201
{
2202
    int         j;
2203
 
2204
    /*
2205
    **  Give a clear indication that the report is preliminary
2206
    */
2207
 
2208
    if( !final )
2209
        print( "PRELIMINARY RESULTS ONLY\n\n" );
2210
 
2211
    /*
2212
    **  Now printout the column headings
2213
    **  This is a two line display
2214
    **
2215
    **  Line-1  Leg names
2216
    */
2217
    print( "%-*s %-*s %-*s", 4, "", 4, "", 3, "" );
2218
    for( j = 1; j <= config.num_legs; j++ )
2219
    {
2220
        print_bold( TRUE );
2221
        print( "  %-*s", 18, config.leg_name[j - 1] );
2222
        print_bold( FALSE );
2223
    }
2224
    print( "  %-8s %-4s\n", "Total", ( teamclass < 0 ) ? "Cat" : "Fin" );
2225
 
2226
 
2227
    /*
2228
    **  Line-2  Details
2229
    */
2230
    print_underline( TRUE );
2231
    print( "%-*s %*s %-*s", 4, final ? "Plce" : "Team",
2232
                            4, final ? "Team" : "Plce",
2233
                            3, "Cat" );
2234
 
2235
    for( j = 1; j <= config.num_legs; j++ )
2236
        print( "  %-8s %-4s %-4s", "Time", " LP", " EP" );
2237
 
2238
    print( "  %-8s %-4s\n", "Time", "Plce" );
2239
    print_underline( FALSE );
2240
}
2241
 
2242
/*========================================================================
2243
 *
2244
 *  Generate the class stats
2245
 *
2246
 *  Purpose:
2247
 *      This function is called to Generate the class stats
2248
 *
2249
 *  Parameters:
2250
 *      c           Class to print
2251
 *      final       TRUE: Final data
2252
 *                  FALSE: Interim data
2253
 *
2254
 *  Returns:
2255
 *      Nothing
2256
 *
2257
 *========================================================================*/
2258
 
2259
void print_class_stats( int c, int final )
2260
{
2261
    int         i, j;
2262
    const char        *title;
2263
 
2264
    if( c < 0 )
2265
    {
2266
        title = "Event";
2267
        c = 0;
2268
    }
2269
    else
2270
    {
2271
        title = "Category";
2272
    }
2273
 
2274
    print( "\n" );
2275
    if ( report_html ) print_underline(TRUE);
2276
    print( "%s statistics", title );
2277
    if ( report_html ) print_underline(FALSE);
2278
    print( "\n" );
2279
 
2280
 
2281
    /*
2282
    **  Print the names of the different legs
2283
    */
2284
    print( "%-*s       ", LEN_CLASS_NAME, "" );
2285
    for( i = 1; i <= config.num_legs; i++ )
2286
    {
2287
        print_bold( TRUE );
2288
        print( "%-13s  ", config.leg_name[i - 1] );
2289
        print_bold( FALSE );
2290
    }
2291
    print( "%-13s  \n", final ? "Total" : "" );
2292
 
2293
    /*
2294
    **  Print the fastest teams for each leg and overall
2295
    **  Add cross references to the team names for the fastest teams
2296
    */
2297
    print( "%*s : ", LEN_CLASS_NAME, "Fastest" );
2298
    for( i = 0; i <= config.num_legs; i++ )
2299
    {
2300
        j = i + 1;
2301
        if( i >= config.num_legs )
2302
        {
2303
            if( final )
2304
                j = 0;                           /* Leg-0 last */
2305
            else
2306
                break;
2307
        }
2308
 
2309
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "name" ,"html")), stats.fast.team[j][c] );
2310
        print( "%4d",  stats.fast.team[j][c] );
2311
        if ( report_html == html ) print( "</A>" );
2312
        print( " %s  ", time_a( stats.fast.time[j][c] ) );
2313
    }
2314
    print( "\n" );
2315
 
2316
    /*
2317
    **  Print the average time for each leg
2318
    */
2319
    print( "%*s : ", LEN_CLASS_NAME, "Average" );
2320
    for( i = 0; i <= config.num_legs; i++ )
2321
    {
2322
        j = i + 1;
2323
        if( i >= config.num_legs )
2324
        {
2325
            if( final )
2326
                j = 0;                           /* Leg-0 last */
2327
            else
2328
                break;
2329
        }
2330
        print( "     %s  ", time_a( stats.average[j][c] ) );
2331
    }
2332
}
2333
 
2334
/*========================================================================
2335
 *
2336
 *  Print the legend
2337
 *
2338
 *  Purpose:
2339
 *      This function is called to Print the legend
2340
 *
2341
 *  Parameters:
2342
 *      class       - Class currently being printed
2343
 *      full        - Display full legend
2344
 *
2345
 *  Returns:
2346
 *      Nothing
2347
 *
2348
 *========================================================================*/
2349
 
2350
void print_legend ( int teamclass, int full )
2351
{
2352
 
2353
    int         i;
2354
    char        line[201];
2355
    FILE       *adfile = NULL;
2356
    int         count;
2357
 
2358
    /*
2359
     * First the categories 
2360
     */
2361
    print( "\n\n" );
2362
    if ( report_html ) print_underline(TRUE);
2363
    print( "Category abbreviations" );
2364
    if ( report_html ) print_underline(FALSE);
2365
    print( "\n" );
2366
 
2367
 
2368
    for( i = 1, count = 0; i <= config.num_class; i++ )
2369
    {
317 david 2370
        if (!config.team_class[i - 1].abr[0])
2371
            continue;
95 - 2372
#if 0
2373
        /*
2374
        **  Skip any non-equestrian class in the legend
2375
        **  Don't want to tell the general user whats goes on, unless we actually
2376
        **  creating the non-equestrian report.
2377
        */
2378
        if ( class != config.nonequestrian_class  && i == config.nonequestrian_class )
2379
            continue;
2380
#endif
2381
        if ( report_html == html ) print( "<A HREF=\"%s\">",url_encode(p_filename(filebase, config.team_class[i - 1].abr ,"html")) );
2382
        print( "%-*s", 3, config.team_class[i - 1].abr );
2383
        if ( report_html == html ) print( "</A>" );
2384
        print( " : %-*s  ", LEN_CLASS_NAME, config.team_class[i - 1].full_name );
2385
 
2386
        if( !( ++count % 5 ) )
2387
            print( "\n" );
2388
    }
2389
 
2390
    /*
2391
    **  Add link to the finish order report
2392
    */
2393
    if ( report_html == html )
2394
    {
2395
        print( "<A HREF=\"%s\">", url_encode(p_filename(filebase, "finish" ,"html")) );
2396
        print( "%-*s", 3, "All" );
2397
        print( "</A>" );
2398
        print( " : %-*s  ", LEN_CLASS_NAME, "Finishing Order" );
2399
    }
2400
 
2401
    /*
2402
    **  Country data - if countries have been defined
2403
    */
2404
    if( config.num_countries )
2405
    {
2406
        print( "\n\n" );
2407
        if ( report_html ) print_underline(TRUE);
2408
        print( "Country abbreviations" );
2409
        if ( report_html ) print_underline(FALSE);
2410
        print( "\n" );
2411
 
2412
        for( i = 0, count = 0; i < MAX_COUNTRY; i++ )
2413
        {
2414
            if( config.country_name[i].abr[0] )
2415
            {
2416
                print( "%-*s : %-*s  ", 4, config.country_name[i].abr,
2417
                       LEN_CNTRY_NAME, config.country_name[i].full_name );
2418
                if( !( ++count % 5 ) )
2419
                    print( "\n" );
2420
            }
2421
        }
2422
    }
2423
    print( "\n" );
2424
 
2425
    /*
2426
     * Other comments 
2427
     */
2428
    if ( full )
2429
    {
2430
        print( "\nPlace numbers (LP and EP)\n" );
2431
        print( "LP - Placing based on elapsed time within the leg.                Cat Plce - Placing within the category.\n" );
2432
        print( "EP - Placing based on accumulated times to the end of that leg.   Fin Plce - Overall placing within the event.\n" );
2433
        print( "U  - Placing not available.\n" );
2434
    }
2435
 
2436
    /*
2437
     *  Insert the contents of the config.addendum file
2438
     *  or a defualt message
2439
     */
2440
    if( config.addendum[0] )
203 david 2441
    {
319 david 2442
        QString name = QmConfig::getAddendemFile(config.addendum);
2443
        if (! name.isEmpty())
2444
        {
2445
            adfile = fopen( qPrintable(name), "rt" );  /* Open the file for reading */
2446
        }
203 david 2447
    }
95 - 2448
 
2449
    if( adfile )
2450
    {
2451
        while( fgets( line, sizeof(line)-1, adfile ) )
2452
            print( "%s", line );
2453
    }
2454
    else
2455
    {
2456
        print( "\nTiming and Results by\n" );
2457
        print( "Embedded Solutions\n" );
2458
    }
2459
}
2460
 
2461
/*========================================================================
2462
 *
2463
 *  Return place data
2464
 *
2465
 *  Purpose:
2466
 *      This function is called to return place data
2467
 *
2468
 *      This routine is called to fill a print team_buffer - to allow for
2469
 *      multiple calls to this function ( before the data is used ) a number
2470
 *      of static team_buffers are maintained
2471
 *
2472
 *  Parameters:
2473
 *      num         place - if not bad_times
2474
 *      disq        Disqualified flag
2475
 *      time        Time data is based on
2476
 *
2477
 *  Returns:
2478
 *      This function returns a pointer to the character string for the
2479
 *      number or a pointer to a bad_times string.
2480
 *
2481
 *========================================================================*/
2482
 
2483
const char       *pi_place( int num, int disq, time_t time )
2484
{
2485
    static char store[2][5];                     /* 2 stores for 4 digit numbers */
2486
    static int  i = 0;                           /* Current index into store */
2487
    static const char *dis = "D";                      /* Disqualified */
2488
    static const char *non = "-";                      /* Invalid time */
2489
 
2490
    if( disq )                                   /* Disqualified team */
2491
        return ( dis );
2492
    if( time <= 0 )                              /* Unknown time */
2493
        return ( non );
2494
 
2495
    i++;
2496
    if( i >= 2 )
2497
        i = 0;                                   /* Select next entry */
2498
    sprintf( store[i], "%4d", num );
2499
    return ( store[i] );
2500
 
2501
}
2502
 
2503
/*========================================================================
2504
 *
2505
 *  Return place data
2506
 *
2507
 *  Purpose:
2508
 *      This function is called to Return place data
2509
 *
2510
 *      This routine is called to fill a print team_buffer - to allow for
2511
 *      multiple calls to this function ( before the data is used ) a number
2512
 *      of static team_buffers are maintained
2513
 *
2514
 *  Parameters:
2515
 *      num         place - if not bad_times
2516
 *      disq        Disqualified flag
2517
 *
2518
 *  Returns:
2519
 *      This function returns a pointer to the character string for the
2520
 *      number or a pointer to a bad_times string.
2521
 *
2522
 *========================================================================*/
2523
 
2524
const char *pr_place( int num, int disq )
2525
{
2526
    static char store[2][5];                     /* 2 stores for 4 digit numbers */
2527
    static int  i = 0;                           /* Current index into store */
2528
    static const char *dis = "U";
2529
 
2530
    if( disq )
2531
        return ( dis );
2532
 
2533
    i++;
2534
    if( i >= 2 )
2535
        i = 0;                                   /* Select next entry */
2536
    sprintf( store[i], "%4d", num );
2537
    return ( store[i] );
2538
 
2539
}
2540
 
2541
/*========================================================================
2542
 *
336 david 2543
 *  Return place data or NE flag
2544
 *
2545
 *  Purpose:
2546
 *      This function is called to Return place data
2547
 *
2548
 *      This routine is called to fill a print team_buffer - to allow for
2549
 *      multiple calls to this function ( before the data is used ) a number
2550
 *      of static team_buffers are maintained
2551
 *
2552
 *  Parameters:
2553
 *      num         place - if not bad_times
2554
 *      disq        Disqualified flag
2555
 *      flag        Flag NE data
2556
 *
2557
 *  Returns:
2558
 *      This function returns a pointer to the character string for the
2559
 *      number or a pointer to a bad_times string.
2560
 *
2561
 *========================================================================*/
2562
const char *pn_place( int num, int disq, bool flag )
2563
{
2564
    static char store[2][5];                     /* 2 stores for 4 digit numbers */
2565
    static int  i = 0;                           /* Current index into store */
2566
    static const char *dis = "U";
2567
    static const char *alt = "NE";
2568
 
2569
    if( disq )
2570
        return ( dis );
2571
    if (flag)
2572
        return ( alt );
2573
 
2574
    i++;
2575
    if( i >= 2 )
2576
        i = 0;                                   /* Select next entry */
2577
    sprintf( store[i], "%4d", num );
2578
    return ( store[i] );
2579
 
2580
}
2581
 
2582
/*========================================================================
2583
 *
95 - 2584
 *  Check data for bad times
2585
 *
2586
 *  Purpose:
2587
 *      This function is called to Check data for bad times
2588
 *      Scan the sort data structure and locate entries that have incorrect
2589
 *      times.
2590
 *      
2591
 *      Entries that have invalid leg times are displayed to the operator
2592
 *      and the report process can be aborted
2593
 *
2594
 *  Parameters:
193 - 2595
 *      leg             Leg to test
95 - 2596
 *      mode            Either end or elapsed times to be tested
2597
 *
2598
 *  Returns:
2599
 *      Returns FALSE if the report operation is to be aborted
2600
 *
2601
 *========================================================================*/
2602
 
2603
bool ck_data( int leg, int mode )
2604
{
2605
    ty_s_data  *ptr;
2606
    unsigned    i;
2607
    int         bad = 0;
193 - 2608
    int         k;
2609
    int         bad_leg;
95 - 2610
    time_t     *t;                               /* An array of times */
2611
 
2612
    ptr = sort_data;
2613
    for( i = 1; i <= sort_num; i++, ptr++ )
2614
    {
2615
        bad_leg = 0;
2616
        if( mode == C_DISQUAL )
2617
        {
2618
            ptr->flags.bad_times = ptr->flags.disqualified;
2619
            continue;
2620
        }
2621
 
2622
        if( mode == C_ELAPSED )
2623
            t = ptr->lege;
2624
        else
2625
            t = ptr->leg;
2626
 
2627
 
250 - 2628
        ptr->flags.bad_times = ptr->flags.disqualified;
95 - 2629
        if( ! ptr->flags.bad_times )
2630
        {
2631
            if( leg <= 0 )
2632
            {
2633
                for( k = 0; k <= config.num_legs; k++ )
2634
                {
2635
                    if ( !(config.equestrian_leg && ptr->flags.non_equestrian && config.equestrian_leg == k  ))
2636
                        bad_leg |= ( t[k] <= 0 );
2637
                }
2638
            }
2639
            else
2640
            {
2641
                bad_leg = t[leg] <= 0;
2642
            }
2643
 
2644
            if( bad_leg )
2645
            {
2646
                ptr->flags.bad_times = TRUE;
2647
 
2648
                if ( ! report_all )
2649
                {
318 david 2650
                    qDebug( "Team with incorrect time information: %d", ptr->team  );
95 - 2651
                    bad++;
2652
                }
2653
            }
2654
        }
2655
    }
2656
 
2657
    if( bad )
2658
    {
318 david 2659
        qDebug( "%d teams with incorrect times. These have been flagged as unplaced", bad );
95 - 2660
    }
2661
    return ( FALSE );
2662
}
2663
 
2664
/*========================================================================
2665
 *
2666
 *  Update placing information
2667
 *
2668
 *  Purpose:
2669
 *      This function is called to Update placing information
2670
 *
2671
 *      This routine will rip through the data generating the team placing in
2672
 *      a) Within a leg
2673
 *      b) At the end of a leg
2674
 *      c) Within a leg by  class
2675
 *      d) At the end of a leg by class
2676
 *
2677
 *      This function is provided to allow the display routines to
2678
 *      be accessed and updated without the need to run a report
2679
 *
2680
 *  Parameters:
2681
 *      xxxx        a ptr to the xxxx stuff
2682
 *
2683
 *  Returns:
2684
 *      Nothing
2685
 *
2686
 *========================================================================*/
2687
 
2688
void srt_place(void)
2689
{
2690
    if( ck_data( -1, C_ELAPSED ) )
2691
        return;
2692
    do_big_sort();
2693
 
2694
    /*
199 david 2695
     * Generate the stats
95 - 2696
     */
2697
    gen_stats();
2698
}
2699
 
2700
/*========================================================================
2701
 *
2702
 *  Calculate summary information
2703
 *
2704
 *  Purpose:
2705
 *      This function is called to calculate summary information
2706
 *
2707
 *  Parameters:
2708
 *      ptr         - Address of a summary structure to fill in
2709
 *
2710
 *  Returns:
2711
 *      Nothing
2712
 *
2713
 *========================================================================*/
2714
 
2715
void calc_class_summary( t_class_summary * ptr )
2716
{
2717
    int i;
174 - 2718
    team_type   team_buf;
95 - 2719
 
2720
    /*
2721
    **  Reset the data
2722
    */
2723
    memset ( ptr, 0, sizeof (*ptr ));
2724
 
2725
    /*
2726
     * Extract the required data from the data base
2727
     * Only save that information required for the operation
2728
     */
2729
 
2730
    for( i = config.min_team; i <= config.max_team; i++ )
2731
    {
2732
        if( valid_field( i ) && g_record( i, &team_buf ) )
2733
        {
231 - 2734
            bool valid = true;
288 david 2735
            bool valid_ne = true;
95 - 2736
 
2737
            if ( team_buf.flags.disqualified )
2738
            {
2739
                ptr->teamclass[team_buf.teamclass].disqualified++;
2740
                ptr->total.disqualified++;
231 - 2741
                valid = false;
288 david 2742
                valid_ne = false;
95 - 2743
            }
2744
 
229 - 2745
            if ( team_buf.flags.vet_check )
2746
            {
2747
                ptr->teamclass[team_buf.teamclass].vet_check++;
2748
                ptr->total.vet_check++;
231 - 2749
                valid = false;
288 david 2750
                valid_ne = false;
229 - 2751
            }
2752
 
95 - 2753
            if ( config.nonequestrian_class && team_buf.flags.non_equestrian )
2754
            {
2755
                ptr->teamclass[team_buf.teamclass].non_equestrian++;
2756
                ptr->total.non_equestrian++;
231 - 2757
                valid = false;
95 - 2758
            }
288 david 2759
            else
2760
            {
2761
                valid_ne = false;
2762
            }
231 - 2763
 
2764
            ptr->total.total++;
2765
            ptr->teamclass[team_buf.teamclass].total++;
2766
            if ( valid )
2767
            {
2768
                ptr->total.valid++;
2769
                ptr->teamclass[team_buf.teamclass].valid++;
288 david 2770
 
2771
                if ( ! team_buf.flags.bad_times )
2772
                {
2773
                    ptr->total.valid_ev++;
2774
                    ptr->teamclass[team_buf.teamclass].valid_ev++;
2775
                }
231 - 2776
            }
288 david 2777
 
2778
            if ( valid_ne )
2779
            {
2780
                if ( ! team_buf.flags.bad_times )
2781
                {
2782
                    ptr->total.valid_ne++;
2783
                    ptr->teamclass[team_buf.teamclass].valid_ne++;
2784
                }
2785
            }
95 - 2786
        }
2787
    }
2788
 
2789
    /*
2790
    **  Fix up the totals for the non equestrians
2791
    **  This is not a real category but a summary of the others.
2792
    */
2793
    if ( config.nonequestrian_class  )
2794
    {
2795
        ptr->teamclass[config.nonequestrian_class].total += ptr->total.non_equestrian;
231 - 2796
        ptr->teamclass[config.nonequestrian_class].valid += ptr->teamclass[config.nonequestrian_class].total;
95 - 2797
    }
2798
}
2799
 
2800
/*========================================================================
2801
 *
258 - 2802
 *  Print summary results
2803
 *
2804
 *  Purpose:
2805
 *      This function is called to Print summary results
2806
 *      Keep the page to 80 cols, so that it can be pronted on A4
2807
 *
2808
 *  Parameters:
2809
 *      None
2810
 *
2811
 *  Returns:
2812
 *      Nothing
2813
 *
2814
 *========================================================================*/
2815
void pri_summary_html(void)
2816
{
2817
    report_type saved = report_html;
2818
    /*
2819
    **  Generate ALL results with HTML tags
2820
    */
2821
    report_html = html;
2822
    pri_summary();
295 david 2823
    report_html = printed;
2824
    pri_summary();
258 - 2825
    report_html = saved;
2826
}
2827
 
2828
/*========================================================================
2829
 *
95 - 2830
 *  Print summary information
2831
 *
2832
 *  Purpose:
2833
 *      This function is called to print summary information
2834
 *
2835
 *  Parameters:
2836
 *      None
2837
 *
2838
 *  Returns:
2839
 *      Nothing
2840
 *
2841
 *========================================================================*/
2842
 
2843
void pri_summary (void)
2844
{
2845
 
2846
    t_class_summary data;
2847
    int         i;
2848
 
258 - 2849
    if( !open_printer( "", "summary", 80, report_html, "Summary Information" ) )
95 - 2850
        return;
2851
 
2852
    calc_class_summary( & data );
2853
 
2854
 
2855
    /*
2856
    **  Display summary stats
2857
    */
2858
 
288 david 2859
    print( "%*s : %-7s %-7s %-7s %-7s %-7s %-7s %-7s\n",
258 - 2860
                                      LEN_CLASS_NAME, "Category",
95 - 2861
                                      "Total",
257 - 2862
                                      "Valid",
95 - 2863
                                      "Disq",
257 - 2864
                                      "NonEq",
288 david 2865
                                      "VetChk",
2866
                                      "CompEv",
2867
                                      "CompNe"
257 - 2868
                                       );
95 - 2869
 
2870
    for( i = 0; i < config.num_class; i++ )
2871
    {
317 david 2872
        if (!config.team_class[i].abr[0])
2873
            continue;
95 - 2874
        /*
2875
        **  The non-equestrian leg does not have any data
317 david 2876
        **  Suppress the display
95 - 2877
        */
2878
        if ( config.nonequestrian_class == i+1  )
2879
            continue;
2880
 
258 - 2881
        if ( report_html == html ) print( "<A HREF=\"%s\">",url_encode(p_filename(filebase, config.team_class[i].abr ,"html")) );
2882
        print( "%*s ", LEN_CLASS_NAME, config.team_class[i].full_name );
2883
        if ( report_html == html ) print( "</A>" );
2884
 
288 david 2885
        print( ": %-7d %-7d %-7d %-7d %-7d %-7d %-7d\n",
95 - 2886
                                          data.teamclass[i+1].total,
257 - 2887
                                          data.teamclass[i+1].valid,
95 - 2888
                                          data.teamclass[i+1].disqualified,
257 - 2889
                                          data.teamclass[i+1].non_equestrian,
288 david 2890
                                          data.teamclass[i+1].vet_check,
2891
                                          data.teamclass[i+1].valid_ev,
2892
                                          data.teamclass[i+1].valid_ne
257 - 2893
                                          );
95 - 2894
    }
2895
 
2896
    print( "\n" );
288 david 2897
    print( "%*s : %-7d %-7d %-7d%-7d %-7d %-7d %-7d\n",
258 - 2898
                                      LEN_CLASS_NAME, "Totals",
95 - 2899
                                      data.total.total,
257 - 2900
                                      data.total.valid,
95 - 2901
                                      data.total.disqualified,
257 - 2902
                                      data.total.non_equestrian,
288 david 2903
                                      data.total.vet_check,
2904
                                      data.total.valid_ev,
2905
                                      data.total.valid_ne
257 - 2906
                                      );
95 - 2907
 
2908
    close_printer();
2909
}
2910
 
2911
 
2912
 
2913
/*========================================================================
2914
 *
2915
 *  Main sort routine for final data
2916
 *
2917
 *  Purpose:
2918
 *      This function is called to do the report sort routine for final data
2919
 *      This routine will fill all the gaps in the sort_aux structure
2920
 *
2921
 *  Parameters:
2922
 *      None
2923
 *
2924
 *  Returns:
2925
 *      Nothing
2926
 *
2927
 *========================================================================*/
2928
 
2929
void do_big_sort(void)
2930
{
338 david 2931
    int         i, k, q;                             /* Looooopy things */
95 - 2932
    unsigned    j;
338 david 2933
    ty_s_data  *ptr;                                 /* Pointer to sort data */
95 - 2934
    int         teamclass;                           /* Current class */
338 david 2935
    int         teamclassq;                          /* Current class */
174 - 2936
    team_type   team_buf;
95 - 2937
 
2938
    for( i = 0; i <= config.num_legs; i++ )
2939
    {
336 david 2940
        bool sortWithEq =  (i == 0);
338 david 2941
 
95 - 2942
        /*
2943
        **  Sort on leg elapsed time
2944
        **  Then save the teams elapsed place in each leg
2945
        */
336 david 2946
        sort_team_data( i, S_L, sortWithEq );
338 david 2947
        for( j = 1, k = 1, q = 1, ptr = sort_data; j <= sort_num; ptr++, j++ )
95 - 2948
        {
338 david 2949
            sort_aux[ptr->team].team = ptr->team;
336 david 2950
 
338 david 2951
            if (ptr->isNeData) {
2952
                sort_aux[ptr->team].lq_place[i] = q++;
2953
            } else {
2954
                sort_aux[ptr->team].l_place[i] = k++;
2955
            }
95 - 2956
        }
2957
 
2958
        /*
2959
        **  Sort on leg end time
2960
        **  Then save the teams place at the end of each leg
2961
        */
336 david 2962
        sort_team_data( i, S_LE, sortWithEq);
338 david 2963
        for( j = 1, k = 1, q = 1, ptr = sort_data; j <= sort_num; ptr++, j++ )
95 - 2964
        {
338 david 2965
            if (ptr->isNeData) {
2966
                sort_aux[ptr->team].leq_place[i] = q++;
2967
            }
2968
            else {
336 david 2969
 
338 david 2970
                sort_aux[ptr->team].le_place[i] = k++;
2971
            }
95 - 2972
        }
2973
 
2974
        /*
2975
        **  Sort on elapsed time per class
338 david 2976
        **  Then save the teams elapsed place in each leg per class
95 - 2977
        */
336 david 2978
        sort_team_data( i, S_LC, sortWithEq );
95 - 2979
        teamclass = -1;
338 david 2980
        teamclassq = -1;
2981
        for( k = 1, j = 1, q = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
95 - 2982
        {
338 david 2983
            bool isNe = false;
336 david 2984
            if ( sortWithEq && ptr->teamclass == config.nonequestrian_class  ) {
2985
                if ( !ptr->isNeData)
338 david 2986
                    isNe = true;
336 david 2987
            }
2988
            else {
2989
                if (ptr->isNeData)
338 david 2990
                    isNe = true;
336 david 2991
            }
2992
 
338 david 2993
            if (isNe) {
2994
                if( teamclassq != ptr->teamclass )
2995
                {
2996
                    q = 1;
2997
                    teamclassq = ptr->teamclass;
2998
                }
2999
                sort_aux[ptr->team].lq_place[i] = q++;
3000
 
95 - 3001
            }
338 david 3002
            else {
3003
 
3004
                if( teamclass != ptr->teamclass )
3005
                {
3006
                    k = 1;
3007
                    teamclass = ptr->teamclass;
3008
                }
3009
                sort_aux[ptr->team].lc_place[i] = k++;
3010
            }
95 - 3011
        }
3012
 
3013
        /*
3014
        **  Sort on end time per class
3015
        **  Then save the teams place at the end of each leg per class
3016
        */
336 david 3017
        sort_team_data( i, S_LEC, sortWithEq );
95 - 3018
        teamclass = -1;
338 david 3019
        teamclassq = -1;
3020
        for( k = 1, j = 1, q = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
95 - 3021
        {
338 david 3022
            bool isNe = false;
336 david 3023
            if ( sortWithEq &&  ptr->teamclass == config.nonequestrian_class  ) {
3024
                if ( !ptr->isNeData)
338 david 3025
                    isNe = true;
336 david 3026
            }
3027
            else {
3028
                if (ptr->isNeData)
338 david 3029
                    isNe = true;
336 david 3030
            }
3031
 
338 david 3032
            if (isNe) {
3033
                if( teamclassq != ptr->teamclass )
3034
                {
3035
                    q = 1;
3036
                    teamclassq = ptr->teamclass;
3037
                }
3038
                sort_aux[ptr->team].leq_place[i] = q++;
95 - 3039
            }
338 david 3040
            else {
3041
                if( teamclass != ptr->teamclass )
3042
                {
3043
                    k = 1;
3044
                    teamclass = ptr->teamclass;
3045
                }
3046
                sort_aux[ptr->team].lec_place[i] = k++;
3047
            }
95 - 3048
        }
3049
    }
3050
 
3051
    /*
3052
    **  Write the place information back to disk for use in the displays
3053
    */
3054
    for( i = config.min_team; i <= config.max_team; i++ )
3055
    {
3056
        if( sort_aux[i].team && valid_field( i ) && g_record( i, &team_buf ) )
3057
        {
3058
            for( k = 0; k <= config.num_legs; k++ )
3059
            {
3060
                team_buf.leg[k].l_place = sort_aux[i].l_place[k];
3061
                team_buf.leg[k].le_place = sort_aux[i].le_place[k];
3062
                team_buf.leg[k].lc_place = sort_aux[i].lc_place[k];
3063
                team_buf.leg[k].lec_place = sort_aux[i].lec_place[k];
3064
            }
3065
            put_team_record( i, &team_buf );
3066
        }
3067
    }
3068
}
3069
 
3070
/*========================================================================
3071
 *
3072
 *  Sort in memory buffer
3073
 *
3074
 *  Purpose:
3075
 *      This function is called to Sort in memory buffer
3076
 *
3077
 *  Parameters:
3078
 *      leg         Requested leg
3079
 *      mode        Defines the sort mode
336 david 3080
 *      withEq      Sort with equestrian data (True=Normal)
95 - 3081
 *
3082
 *  Returns:
3083
 *      Nothing
3084
 *
3085
 *========================================================================*/
3086
 
336 david 3087
void sort_team_data( int leg, int mode, bool withEq )
95 - 3088
{
3089
 
3090
    unsigned    j;
3091
    ty_s_data  *ptr;
3092
 
3093
    sort_leg = leg;                              /* Leg is global for the comparison function */
3094
    sort_mode = mode;                            /* Mode is global for compare function */
336 david 3095
    sort_withEquestrian = withEq;                /* Mode is global for compare function */
95 - 3096
 
3097
    qsort( ( char * ) sort_data, sort_num, sizeof( ty_s_data ), sort_comp );
3098
 
3099
    /*
3100
     * Insert "place data" into the sorted data
3101
     * This simply the index into the array of data - after its been
3102
     * sorted.
3103
     */
3104
    ptr = sort_data;
3105
    for( j = 1; j <= sort_num; j++, ptr++ )
250 - 3106
    {
95 - 3107
        ptr->place = j;
250 - 3108
    }
95 - 3109
 
3110
}
3111
 
3112
/*========================================================================
3113
 *
3114
 *  qsort comparison function
3115
 *
3116
 *  Purpose:
3117
 *      This function is called by qsort as a Sort comparison function
3118
 *
3119
 *  Parameters:
3120
 *      a       - 1st record
3121
 *      b       - 2nd record
3122
 *
3123
 *  Returns:
3124
 *      value to qsort
250 - 3125
 *      Return negative if 'a' is less than 'b',
3126
 *             zero if 'a' == 'b'
3127
 *             positive if 'a' > 'b'
95 - 3128
 *
3129
 *========================================================================*/
3130
 
3131
int sort_comp( const void * aa, const void * bb )
3132
{
3133
    const ty_s_data * a = (ty_s_data *)aa;
3134
    const ty_s_data * b = (ty_s_data *)bb;
3135
 
3136
 
3137
    int         i;                               /* One of those */
3138
    time_t      ta, tb;                          /* Leg times */
3139
    int         na, nb;                          /* Number of valid legs */
3140
    time_t      tta, ttb;                        /* Temp times */
3141
 
3142
    /*
3143
    **  Sorting on Team Number
3144
    */
3145
    if( sort_mode == S_TEAM )
3146
        return ( a->team - b->team );
3147
 
3148
    /*
3149
    **  Sorting on Class and Team Number
3150
    */
3151
    if( sort_mode == S_CLASS )
3152
    {
3153
        if( a->teamclass != b->teamclass )
3154
            return ( a->teamclass - b->teamclass );
3155
        else
3156
            return ( a->team - b->team );
3157
    }
3158
 
3159
    /*
3160
    **  Sorting within a class
3161
    **  First sort on the class
3162
    */
336 david 3163
    if( sort_mode == S_LEC || sort_mode == S_LC || sort_mode == S_LC_NE ) {  /* Sort within a class */
3164
        if (a->teamclass != b->teamclass)
95 - 3165
            return ( a->teamclass - b->teamclass );
336 david 3166
    }
95 - 3167
 
3168
    /*
3169
    **  Always put the nonequestrian_class at the end
3170
    **  Simplifies the creation of ordered lists as these
3171
    **  Entries are not present in the main body
3172
    */
336 david 3173
    if ( sort_withEquestrian && ( a->teamclass == config.nonequestrian_class ||  b->teamclass == config.nonequestrian_class ))
95 - 3174
    {
3175
        if ( a->teamclass == config.nonequestrian_class &&  b->teamclass == config.nonequestrian_class )
3176
        {
250 - 3177
            /*
3178
            **  Both are non equestrian
3179
            **      S_LC_NE - Elapsed times per class, with NE sorted by real class
3180
            **                Only used in awards
3181
            */
231 - 3182
            if (sort_mode == S_LC_NE )
3183
            {
3184
                if ( a->real_teamclass != b->real_teamclass )
3185
                {
3186
                    return ( a->real_teamclass - b->real_teamclass );
3187
                }
3188
            }
95 - 3189
        }
3190
        else
3191
        {
250 - 3192
            /*
3193
            **  Only one in non-equestrian
3194
            **  Place Non-equestrian AFTER equestrian
3195
            */
95 - 3196
            return ( a->teamclass == config.nonequestrian_class ? 1 : -1 );
3197
        }
3198
 
3199
    }
3200
 
336 david 3201
 
95 - 3202
    /*
3203
    **  Now we need to examine the times as we have sorted
3204
    **  on every thing else.
3205
    **
3206
    **  If one of the teams has bad_times, then that team is placed
3207
    **  lower in the sorting order. If both teams have bad times
3208
    **  then sort on team number. ie: Unplaced teams are sorted on
3209
    **  team number
3210
    **
3211
    **  If not sorting within a class (ie Overall), then Non_Equestrian
3212
    **  is better than a bad time. Places NE before disqualified
3213
    **
3214
    */
336 david 3215
    if( a->flags.bad_times || b->flags.bad_times || ( sort_withEquestrian && a->flags.non_equestrian) || (sort_withEquestrian && b->flags.non_equestrian))  /* Valid data has precedence */
95 - 3216
    {
3217
        if( a->flags.bad_times && b->flags.bad_times )
3218
        {
250 - 3219
            return ( a->team - b->team );
95 - 3220
        }
250 - 3221
        else if( a->flags.bad_times || b->flags.bad_times )
3222
        {
95 - 3223
            return ( a->flags.bad_times ? 1 : -1 );
250 - 3224
        }
3225
        if( sort_mode != S_FIN && sort_mode != S_IFIN )
95 - 3226
        {
3227
            if( a->flags.non_equestrian && b->flags.non_equestrian )
250 - 3228
            {
3229
                /*
3230
                **  Both are non equestrian
3231
                **  Let the time sort operate ...
3232
                */
3233
                //return ( a->team - b->team );
3234
            }
95 - 3235
            else
250 - 3236
            {
3237
                /* One is equestrian */
3238
                /* Good times better than NE */
95 - 3239
                return ( a->flags.non_equestrian ? 1 : -1 );
250 - 3240
            }
95 - 3241
        }
3242
    }
3243
 
3244
    /*
3245
    **  Before we sort on times we must determine which time to
3246
    **  use. Finish time, Leg end times, Leg Elapsed times.
3247
    */
3248
 
3249
    switch ( sort_mode )
3250
    {
3251
      /*
3252
      **    Sort on finish times
3253
      */
3254
      case S_FIN:
3255
        ta = a->leg[sort_leg];
3256
        tb = b->leg[sort_leg];
3257
        break;
3258
 
3259
 
3260
      /*
3261
      **    Sort on accumulated leg times
3262
      */
3263
      case S_LE:
3264
      case S_LEC:
3265
        if( sort_leg )
3266
        {
3267
            /*
3268
            **  Calculate accumulated time up to the desired leg
3269
            **  If the two teams have a different number of valid
3270
            **  leg times then order by the team that has completed
3271
            **  more legs.
3272
            */
3273
            ta = tb = ( time_t ) 0;
3274
            na = nb = 0;
3275
            for( i = 1; i <= sort_leg; i++ )
3276
            {
3277
                tta = a->lege[i];
3278
                ttb = b->lege[i];
3279
                if( tta > 0 )
3280
                {
3281
                    na++;
3282
                    ta += tta;
3283
                }
3284
                if( ttb > 0 )
3285
                {
3286
                    nb++;
3287
                    tb += ttb;
3288
                }
3289
            }
3290
            if( na != nb )
3291
                return ( nb - na );
3292
        }
3293
        else
3294
        {
3295
            ta = a->leg[sort_leg] - a->start;
3296
            tb = b->leg[sort_leg] - b->start;
3297
        }
3298
        break;
3299
 
3300
      /*
3301
      **    Sort on Elapsed times
3302
      */
231 - 3303
      case S_LC_NE:
95 - 3304
      case S_LC:
3305
      case S_L:
250 - 3306
      case S_IFIN:
95 - 3307
        ta = a->lege[sort_leg];
3308
        tb = b->lege[sort_leg];
3309
        break;
3310
 
3311
      /*
3312
      **    Just to be sure ...
3313
      */
3314
      default:
3315
        return ( 0 );
3316
    }
3317
 
3318
    /*
336 david 3319
     ** If we are ignore Equestrian config then place the Equestrian data last
3320
    */
3321
 
3322
#if 0
3323
    if (a->isNeData != b->isNeData) {
3324
         return ( a->isNeData ? 1 : -1 );
3325
    }
3326
#endif
3327
 
3328
#if 1
3329
    if (sort_withEquestrian) {
3330
        if (a->isNeData != b->isNeData)
3331
            return ( a->isNeData ? 1 : -1 );
3332
    }
3333
#endif
3334
 
3335
    if ( a->team == b->team) {
3336
        return ( a->isNeData ? 1 : -1 );
3337
    }
3338
 
3339
    /*
95 - 3340
    **  Finally. Compare the required team times
3341
    */
3342
    if( ta == tb )
3343
        return ( a->team - b->team );
3344
    if( ( ta > 0 ) && ( tb > 0 ) )
3345
        return ( ( int ) ( ta - tb ) );
3346
    return ( ( ta > 0 ) ? -1 : 1 );
3347
}
3348
 
3349
/*========================================================================
3350
 *
3351
 *  qsort comparison function - competitor names
3352
 *
3353
 *  Purpose:
3354
 *      This function is called by qsort as a Sort comparison function
3355
 *
3356
 *  Parameters:
3357
 *      a       - 1st record
3358
 *      b       - 2nd record
3359
 *
3360
 *  Returns:
3361
 *      value to qsort
3362
 *
3363
 *========================================================================*/
3364
 
3365
int sort_comp_cname( const void * aa, const void * bb )
3366
{
3367
    ty_s_namedata * a = (ty_s_namedata *)aa;
3368
    ty_s_namedata * b = (ty_s_namedata *)bb;
3369
 
3370
 
3371
    int         i;                               /* One of those */
3372
 
3373
    /*
3374
    **  Sort by name
3375
    */
3376
    i = strcmp ( a->name, b->name );
3377
    if ( i )
3378
        return ( i );
3379
    a->multi=1;
3380
    b->multi=1;
3381
 
3382
    /*
3383
    **  Sort by Leg
3384
    */
3385
    i = a->leg - b->leg;
3386
    if ( i )
3387
        return ( i );
3388
 
3389
    /*
3390
    **  Sorting on Team Number
3391
    */
3392
    return ( a->team - b->team );
3393
 
3394
}
3395
 
3396
/*========================================================================
3397
 *
3398
 *  load report data into memory
3399
 *
3400
 *  Purpose:
3401
 *      This routine will pull all the data into memory 
3402
 *      Not all the team data is loaded. Only that essential for the
3403
 *      operation of the sort routine is loaded
3404
 *
3405
 *  Parameters:
3406
 *      None
3407
 *
3408
 *  Returns:
3409
 *      TRUE - All is well
3410
 *
3411
 *========================================================================*/
3412
 
3413
bool load_report_data(void)
3414
{
3415
 
3416
    ty_s_data  *ptr;                             /* pointer to sort data type */
3417
    ty_s_data  *last;
3418
    int         j;
3419
    unsigned    num;
174 - 3420
    team_type   team_buf;
95 - 3421
 
3422
    /*
3423
     * Fetch memory for the data store
3424
     */
3425
 
3426
    if( sort_data )
3427
        free( ( char * ) sort_data );
3428
    sort_data = 0;
3429
 
3430
    if( sort_aux )
3431
        free( ( char * ) sort_aux );
3432
    sort_aux = 0;
3433
    sort_num = 0;                                /* Counter of records in the array */
3434
 
3435
    /*
3436
    **  Allocate memory for the data structures
3437
    **  This will be free'd
3438
    */
3439
    num = config.max_team - config.min_team + 1 ;
3440
 
3441
    /*
3442
    **  Allow for non-equestrian teams - since some of the data is loaded twice
317 david 3443
    **  OLD: Take a guess that at most 1/2 the teams will be non-equestrian
3444
    **  NEW: Memory is cheap. Assume all teams could be non-equestrian
95 - 3445
    */
317 david 3446
    // OLD: num = num * 3 / 2;
3447
    num = num * 2;
95 - 3448
 
3449
    sort_data = ( ty_s_data * ) calloc ( num , sizeof( ty_s_data ) );
3450
    sort_aux = ( ty_s_aux * ) calloc( num + 1, sizeof( ty_s_aux ) );
3451
 
3452
    if( sort_data == 0 || sort_aux == 0 )
3453
    {
174 - 3454
        MainWindow::showMessage("Error in allocating memory");
95 - 3455
        return ( FALSE );
3456
    }
3457
 
3458
    /*
3459
    **  Load data into the memory based data structure
3460
    **  Only load data for valid-teams
3461
    **  Load essential data
3462
    **      Team Number, class and flags
3463
    **      Leg end and elapsed times
3464
    */
3465
    ptr = sort_data;
174 - 3466
    for( int team = config.min_team; team <= config.max_team; team++ )
95 - 3467
    {
3468
        if( valid_field( team ) )
3469
        {
3470
            g_record( team, &team_buf );
3471
            if( team_buf.flags.valid )
3472
            {
3473
                last = ptr;
3474
                ptr->team = team;
336 david 3475
                ptr->isNeData = false;
95 - 3476
                for( j = 0; j < MAX_LEGS + 1; j++ )
3477
                {
3478
                    ptr->lege[j] = team_buf.leg[j].elapsed;
3479
                    ptr->leg[j] = team_buf.leg[j].end;
3480
                }
3481
                ptr->start = team_buf.leg[0].start;
3482
                ptr->teamclass = team_buf.teamclass;
231 - 3483
                ptr->real_teamclass = team_buf.teamclass;
95 - 3484
 
3485
                ptr->flags = team_buf.flags;
336 david 3486
 
250 - 3487
//                if (ptr->flags.non_equestrian)
3488
//                    ptr->flags.disqualified = true;
229 - 3489
                if (ptr->flags.vet_check)
3490
                    ptr->flags.disqualified = true;
250 - 3491
 
95 - 3492
                ptr++;
3493
                sort_num++;
3494
 
250 - 3495
 
95 - 3496
                /*
3497
                **  If non-equestrian support is enabled then
3498
                **  duplicate and modify data for the non-equestrian teams
3499
                **      - Change the class
3500
                **      - Modify the leg time
3501
                */
3502
#if 1
3503
                if ( config.nonequestrian_class && team_buf.flags.non_equestrian )
3504
                {
3505
                    ptr->team = team;
336 david 3506
                    ptr->isNeData = true;
95 - 3507
                    ptr->lege[0] = 0;
3508
 
3509
                    for( j = 0; j < MAX_LEGS + 1; j++ )
3510
                    {
3511
                        if ( j == config.equestrian_leg )
3512
                        {
3513
                            last->lege[j] = ptr->lege[j] = 0;
3514
                            if ( config.equestrian_leg > 1 )
3515
                                last->leg[j] = ptr->leg[j] = ptr->leg[j-1];
3516
                        }
3517
                        else
3518
                        {
3519
                            if ( j )
3520
                                last-> lege[j] = ptr->lege[j] = team_buf.leg[j].elapsed;
3521
                            last->leg[j] = ptr->leg[j] = team_buf.leg[j].end;
3522
                            ptr->lege[0] += ptr->lege[j] ;
3523
                            last->lege[0] = ptr->lege[0] ;
3524
                        }
3525
                    }
3526
 
3527
                    last->start = ptr->start = team_buf.leg[0].start;
3528
                    ptr->teamclass = config.nonequestrian_class;
231 - 3529
                    ptr->real_teamclass = team_buf.teamclass;
95 - 3530
                    ptr->flags = team_buf.flags;
250 - 3531
//                    ptr->flags.disqualified = false;
95 - 3532
 
3533
                    ptr++;
3534
                    sort_num++;
3535
                }
3536
#endif
3537
            }
3538
        }
3539
    }
3540
    return ( TRUE );
3541
}
3542
 
3543
/*========================================================================
3544
 *
3545
 *  Generate all the stats
3546
 *
3547
 *  Purpose:
3548
 *      This function is called to Generate all the stats
3549
 *
3550
 *  Parameters:
3551
 *      None
3552
 *
3553
 *  Returns:
3554
 *      Nothing
3555
 *
3556
 *========================================================================*/
3557
 
3558
void gen_stats(void)
3559
{
3560
    ty_s_data  *ptr;
3561
    unsigned    i;
3562
    int         j;
3563
    int         k;
3564
 
3565
    /*
3566
     * Init all the stats 
3567
     */
3568
    for( i = 0; i <= MAX_LEGS; i++ )
3569
    {
3570
        for( j = 0; j <= MAX_CLASS; j++ )
3571
        {
3572
            stats.team[i][j] = 0;
3573
            stats.fast.team[i][j] = 0;
3574
            stats.fast.time[i][j] = ( time_t ) - 1;
3575
            stats.average[i][j] = 0;
3576
        }
3577
    }
3578
 
3579
    for( i = 1, ptr = sort_data; i <= sort_num; i++, ptr++ )
3580
    {
3581
        /*
3582
        **  If there is any bad times in the team record, then none
3583
        **  of the data can be trusted.
3584
        **
3585
        **  If the team has been disqualified, then don't use any
3586
        **  of the data.
3587
        */
250 - 3588
        if( ptr->flags.bad_times || ptr->flags.disqualified  )
95 - 3589
            continue;
3590
 
250 - 3591
        /*
3592
        **  Ignore non-Equestrian, unless we are processing the psuedo NE class
3593
        */
3594
        if ( ptr->teamclass != config.nonequestrian_class && ptr->flags.non_equestrian)
3595
            continue;
3596
 
3597
 
95 - 3598
        for( j = 0; j <= config.num_legs; j++ )
3599
        {
3600
            if( ptr->lege[j] <= 0 )              /* Ignore bad data */
3601
                continue;
3602
 
3603
            /*
3604
            **  Determine fastest team : overall
3605
            **  Ignore the non-equestrian data as this is in the list twice
3606
            */
3607
            if( ( ptr->lege[j] < stats.fast.time[j][0] )
3608
                || ( stats.fast.time[j][0] < 0 ) )
3609
            {
3610
                if ( ptr->teamclass != config.nonequestrian_class )
3611
                {
3612
                    stats.fast.team[j][0] = ptr->team;
3613
                    stats.fast.time[j][0] = ptr->lege[j];
3614
                }
3615
            }
3616
 
3617
            /*
3618
            **  Determine fastest team : within a class
3619
            */
3620
            if( ( ptr->lege[j] < stats.fast.time[j][ptr->teamclass] )
3621
                || stats.fast.time[j][ptr->teamclass] < 0 )
3622
            {
3623
                stats.fast.team[j][ptr->teamclass] = ptr->team;
3624
                stats.fast.time[j][ptr->teamclass] = ptr->lege[j];
3625
            }
3626
 
3627
            /*
3628
            **  Sum the end times : overall
3629
            */
3630
            if ( ptr->teamclass != config.nonequestrian_class )
3631
            {
3632
                stats.average[j][0] += ptr->lege[j];
3633
                stats.team[j][0]++;
3634
            }
3635
 
3636
 
3637
            /*
3638
            **  Sum the end times : within a class
3639
            */
3640
            stats.average[j][ptr->teamclass] += ptr->lege[j];
3641
            stats.team[j][ptr->teamclass]++;
3642
        }
3643
    }
3644
 
3645
    /*
317 david 3646
     * Calculate the averages 
3647
     *      Can ignore that fact that some categories don't exists
3648
     *      The results will be -1
95 - 3649
     */
3650
    for( k = 0; k <= config.num_legs; k++ )
3651
    {
3652
        for( j = 0; j <= config.num_class; j++ )
3653
        {
3654
            if( stats.team[k][j] )
3655
                stats.average[k][j] /= stats.team[k][j];
3656
            else
3657
                stats.average[k][j] = ( time_t ) - 1;
3658
        }
3659
    }
3660
}
3661
 
3662
/********************************* EOF ***********************************/