]> git.itanic.dy.fi Git - emerge-timer/blobdiff - emerge-timer.py
Merge branch 'master' of itanic.dy.fi:/home/git/emerge-timer
[emerge-timer] / emerge-timer.py
index fb610c4f31f2596c66065261ab880c3922d5e4d5..a11acbdb4a8022e42ed8fe64ed119a4e86c0f247 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,24 @@ 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]")
+        plt.suptitle(self.name)
+        plt.grid()
+        fig.autofmt_xdate()
+        plt.show()
+
 
 
 def give_time(time, nocolor=False):
@@ -333,7 +356,8 @@ def search_log_for_all_packages():
 
                     all_packages.pop(all_packages.index(p))
 
-    print("\n" + GREEN(str(emerge_number)) + " packages in total.")
+
+    print("\n" + GREEN(str(emerge_number)) + " emerges in total found.")
 
 
 
@@ -496,6 +520,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.")
@@ -553,6 +580,8 @@ Options:
 \t-h, --help \t Show this helpscreen
 \t-q, --quiet \t Be less verbose
 \t--no-color \t Use colorless output
+\t--plot \t\t Plot emerge times into a 2D scatter plot
+\t\t\t (needs matlibplot installed for this to work)
 \t--simulate \t Do a simulation run"""
 
     print usage
@@ -566,6 +595,7 @@ if __name__ == "__main__":
     mode = "package"
     input_packages = None
     simulation = False
+    matplotWorking = False
 
     for arg in sys.argv[1:]:
 
@@ -589,6 +619,17 @@ if __name__ == "__main__":
 
             sys.argv.pop(sys.argv.index(arg))
 
+        if arg == "--plot":
+            try:
+                import matplotlib.pyplot as plt
+                matplotWorking = True
+            except ImportError:
+                print(RED("Cannot initialize matplotlib!"))
+                print(RED("Check that you have properly installed matplotlib.\n"))
+                matplotWorking = False
+
+            sys.argv.pop(sys.argv.index(arg))
+
         if arg == "--no-color":
             green_start = ""
             color_stop = ""