Author: tian
Date: Sun Dec 14 20:26:04 2014
New Revision: 2251

URL: http://svn.gna.org/viewcvs/gcstar?rev=2251&view=rev
Log:
Option to group statistics per dates

Modified:
    trunk/gcstar/lib/gcstar/GCStats.pm
    trunk/gcstar/lib/gcstar/GCUtils.pm

Modified: trunk/gcstar/lib/gcstar/GCStats.pm
URL: 
http://svn.gna.org/viewcvs/gcstar/trunk/gcstar/lib/gcstar/GCStats.pm?rev=2251&r1=2250&r2=2251&view=diff
==============================================================================
--- trunk/gcstar/lib/gcstar/GCStats.pm  (original)
+++ trunk/gcstar/lib/gcstar/GCStats.pm  Sun Dec 14 20:26:04 2014
@@ -66,6 +66,7 @@
     {
         my ($self, $items, $sort, $type, $useNumbers) = @_;
         my %stats;
+        $self->{yMax} = 0;
         foreach my $item(@$items)
         {
             if (ref($item) eq 'ARRAY')
@@ -94,7 +95,9 @@
             $val = $key;
             $val .= ' ('.$stats{$key}.')' if $useNumbers;
             push @val1, $val;
-            push @val2, $stats{$key};
+            my $stat = $stats{$key};
+            push @val2, $stat;
+            $self->{yMax} = $stat if $stat > $self->{yMax};
         }
         $self->{data} = [\@val1, \@val2];
     }
@@ -155,6 +158,7 @@
                     $_ += $prev;
                     $prev = $_;
                 }
+                $self->{yMax} = $prev;
             }
             # Transform dates into numbers of days
             # Reference is the 1st one as they are ordered
@@ -171,6 +175,7 @@
                 @refDate = Date::Calc::Add_Delta_Days(@refDate, -1);
                 $self->{data}->[0]->[0] = sprintf('%d/%02d/%02d', @refDate);
             }
+            @refDate = GCPreProcess::completePartialDate(@refDate);
             my $prev = -1;
             my @newDates;
             my $dateFormat = $self->{parent}->{options}->dateFormat;
@@ -183,6 +188,7 @@
                     next;
                 }
                 my @cmpDate = split m|/|, $date;
+                @cmpDate = GCPreProcess::completePartialDate(@cmpDate);
                 my $diff = Date::Calc::Delta_Days(@refDate, @cmpDate);
                 if ($diff > $prev + 1)
                 {
@@ -245,8 +251,9 @@
             l_margin    => 20,
             r_margin    => 20,
             text_space  => 20,
+            y_max_value => $self->{yMax},
+            y_number_format => "%d",
         );
-      
         my $gd = $graph->plot($self->{data});
         
         # Now, resample the graph down to the desired size, effectively 
anti-aliasing the sharp edges
@@ -300,6 +307,15 @@
         $self->{accumulateOption}->setValue(1);
         $self->{useNumberOption} = new 
GCCheckBox($parent->{lang}->{StatsDisplayNumber});
         $self->{useNumberOption}->setValue(0);
+        
+        $self->{groupDatesByChoices} = [
+            {value => 'days', displayed => 'Days'},
+            {value => 'months', displayed => 'Months'},
+            {value => 'years', displayed => 'Years'},
+        ];        
+        $self->{groupDatesByOption} = new 
GCMenuList($self->{groupDatesByChoices});
+        $self->{groupDatesByOption}->setValue('days');
+        my $groupDatesByLabel = new GCLabel('Group dates by');
 
         my $widthLabel = new GCLabel($parent->{lang}->{StatsWidth});
         $self->{widthOption} = new GCCheckedText('0-9');
@@ -334,6 +350,8 @@
         $table->attach($self->{sortByNumberOption}, 3, 5, 1, 2, 'fill', 
'fill', 0, 0);
         $table->attach($self->{accumulateOption}, 3, 5, 1, 2, 'fill', 'fill', 
0, 0);
         $table->attach($self->{useNumberOption}, 6, 8, 1, 2, 'fill', 'fill', 
0, 0);
+        $table->attach($groupDatesByLabel, 9, 10, 1, 2, 'fill', 'fill', 0, 0);
+        $table->attach($self->{groupDatesByOption}, 10, 11, 1, 2, 'fill', 
'fill', 0, 0);
  
         $self->{image} = Gtk2::Image->new;
 
@@ -412,6 +430,7 @@
         my $accumulate = $self->{accumulateOption}->getValue;
         my $useNumber = ($graphType =~ /pie/) && 
$self->{useNumberOption}->getValue;
         my $showValues = ($graphType !~ /pie/) && 
$self->{useNumberOption}->getValue;
+        my $groupDatesBy = $self->{groupDatesByOption}->getValue;
         my $width = $self->{widthOption}->getValue;
         my $height = $self->{heightOption}->getValue;
         my $fontSize = $self->{fontOption}->getValue;
@@ -420,7 +439,10 @@
         my @valuesList;
         if ($type eq 'date')
         {
-            @valuesList = map {GCPreProcess::reverseDate($_->{$sortField})} 
@{$self->{data}};
+            @valuesList = map {GCPreProcess::cutReversedDate(
+                                    
GCPreProcess::reverseDate($_->{$sortField}),
+                                    $self->{groupDatesByOption}->getValue)}
+                              @{$self->{data}};
         }
         else
         {

Modified: trunk/gcstar/lib/gcstar/GCUtils.pm
URL: 
http://svn.gna.org/viewcvs/gcstar/trunk/gcstar/lib/gcstar/GCUtils.pm?rev=2251&r1=2250&r2=2251&view=diff
==============================================================================
--- trunk/gcstar/lib/gcstar/GCUtils.pm  (original)
+++ trunk/gcstar/lib/gcstar/GCUtils.pm  Sun Dec 14 20:26:04 2014
@@ -317,6 +317,23 @@
         return $text;        
     }
     
+    sub cutReversedDate
+    {
+        my ($date, $group) = @_;
+        return $date if $group eq 'days';
+        $date =~ m|([0-9]{4})/([0-9]{2})/([0-9]{2})|;
+        my $result = $1;
+        $result .= "/$2" if $group eq 'months';
+        return $result;
+    }
+    
+    sub completePartialDate
+    {
+        my (@date) = @_;
+        push @date, "01" while @date < 3;
+        return @date;
+    }
+    
     # Useful to compare date
     sub reverseDate
     {


_______________________________________________
GCstar-commits mailing list
[email protected]
https://mail.gna.org/listinfo/gcstar-commits

Reply via email to