1 /** @file triphistory_cmd.cpp */
4 #include "triphistory.h"
5 #include "table/strings.h"
8 TripHistory::AddValue( Money mvalue
, Date dvalue
) {
10 t
[ 0 ].profit
+= mvalue
;
16 TripHistory::NewRound( ) {
18 for ( int i
= TRIP_LENGTH
- 1; i
> 0; i
-- ) {
19 this->t
[ i
] = this->t
[ i
- 1 ];
20 //this->trip_history_date_array[ i ] = this->trip_history_date_array[ i - 1 ];
23 this->t
[ 0 ].profit
= 0;
24 this->t
[ 0 ].date
= this->t
[ 1 ].date
;
26 //t.push_front( TripHistoryEntry( ) );
30 TripHistory::UpdateCalculated( ) {
32 this->total_profit
= 0;
33 this->total_change
= 0;
34 this->avg_daylength
= 0;
35 this->profit_per_day
= 0;
39 while ( i
< TRIP_LENGTH
&& t
[ i
].date
) {
42 t
[ i
- 1 ].profit_change
=
43 FindPercentChange( t
[ i
- 1 ].profit
, t
[ i
].profit
);
44 t
[ i
- 1 ].TBT
= t
[ i
- 1 ].date
- t
[ i
].date
;
46 if ( i
> 1 ) t
[ i
- 2 ].TBT_change
= t
[ i
- 2 ].TBT
- t
[ i
- 1 ].TBT
;//bad line i don't like it
48 //omit first -100% row
49 if ( i
> 1 || t
[ 0 ].profit_change
!= -100 )
50 this->total_change
+= t
[ i
- 1 ].profit_change
;
51 this->avg_daylength
+= t
[ i
- 1 ].TBT
;
57 this->total_profit
+= t
[ i
].profit
;
61 if ( i
== 0 ) return 0 ;
63 this->avg_daylength
/= --i
+ 1;
65 if ( t
[ 0 ].date
!= t
[ i
].date
) {
66 this->profit_per_day
= total_profit
/ ( t
[ 0 ].date
- t
[ i
].date
);
71 Trips::reverse_iterator i = t.rbegin( );
72 while ( i < t.rend( ) ) {
74 if ( i + 1 != t.rend( ) ) {
75 (*( i + 1 )).profit_change =
76 FindPercentChange( ( *i ).profit, ( *( i + 1 ) ).profit ); // reverse_itenrator
78 ( *( i + 1 ) ).TBT = ( *i ).date - ( *( i + 1 ) ).date;
80 if ( ( *i ).TBT ) ( *( i + 1 ) ).TBT_change = ( *i ).TBT - ( *( i + 1 ) ).TBT;
82 //omit first -100% row
83 this->total_change += ( *i ).profit_change;
87 this->total_profit += ( *i ).profit;
88 this->avg_daylength += ( *i ).TBT;
93 this->avg_daylength /= t.size( );
95 if ( t.front( ).date != t.back( ).date ) {
96 this->profit_per_day = total_profit / ( t.front( ).date - t.back( ).date );