Subversion Repositories svn1

Rev

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

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