]> git.itanic.dy.fi Git - emerge-timer/commitdiff
Add possibility to plot emerge times into a 2D scatter plot
authorEsko Kokkonen <esko.kokkonen@gmail.com>
Thu, 5 Apr 2012 13:01:56 +0000 (16:01 +0300)
committerEsko Kokkonen <esko.kokkonen@gmail.com>
Thu, 5 Apr 2012 13:01:56 +0000 (16:01 +0300)
Using python package matplotlib we can plot emerge times of a certain
package into a 2D scatter plot that has the emerge date in the x-axis
and emerge time in seconds at the y-axis. This feature is entirely
voluntary, which means that matplotlib doesn't need to be installed in
order to use the other, simpler, features.

emerge-timer.py

index baffb73669612958934b2f090fd86a002d53e2ef..359beb0e493911f6f08a6ffc687446b1654d4c56 100755 (executable)
@@ -30,6 +30,8 @@ class package:
         self.versions = []
         self.emerge_time = "infinity"
 
+        self.plotData = []
+
 
     def add_version(self, version, emerge_time, emerge_date):
         """Add version to the class version list"""
@@ -133,6 +135,9 @@ class package:
                 if len(give_time(p[1], True)) > time_length:
                     time_length = len(give_time(p[1], True))
 
+                # Create the data for plotting in the format (emerge time, emerge date)
+                self.plotData.append((p[1], p[2]))
+
             dots =  (version_length + time_length + len(self.name)
                      + len(give_date(self.versions[0][2])) + 14)
 
@@ -194,6 +199,22 @@ class package:
               "\nIn total spent:\t" + give_time(total) +
               "emerging " + GREEN(self.name))
 
+    def plotToScreen(self):
+        dates = []
+        times = []
+
+        for i in self.plotData:
+            dates.append(datetime.date.fromtimestamp(i[1]))
+            times.append(i[0])
+
+        fig = plt.figure()
+
+        plt.plot_date(dates, times, xdate=True, ydate=False)
+
+        plt.ylabel("Emerge time [s]")
+        fig.autofmt_xdate()
+        plt.show()
+
 
 
 def give_time(time, nocolor=False):
@@ -500,6 +521,9 @@ def _main(status, user_package=None):
                 pack.print_versions()
                 pack.print_min_max_ave()
 
+                if matplotWorking:
+                    pack.plotToScreen()
+
             else:
                 print("Package " + GREEN(pack.name)
                       + " has never been emerged.")
@@ -557,6 +581,7 @@ Options:
 \t-h, --help \t Show this helpscreen
 \t-q, --quiet \t Be less verbose
 \t--no-color \t Use colorless output
+\--plot \t Plot emerge times into a 2D scatter plot
 \t--simulate \t Do a simulation run"""
 
     print usage
@@ -570,6 +595,7 @@ if __name__ == "__main__":
     mode = "package"
     input_packages = None
     simulation = False
+    matplotWorking = False
 
     for arg in sys.argv[1:]:
 
@@ -593,6 +619,15 @@ if __name__ == "__main__":
 
             sys.argv.pop(sys.argv.index(arg))
 
+        if arg == "--plot":
+            try:
+                import matplotlib.pyplot as plt
+                matplotWorking = True
+            except Exception:
+                print "Cannot initialize matplotlib!"
+                print "Check that you have properly installet matplotlib."
+                matplotWorking = False
+
         if arg == "--no-color":
             green_start = ""
             color_stop = ""