From d7a290c5775f9fcd721c1b8cd28d2956846e2619 Mon Sep 17 00:00:00 2001 From: Esko Kokkonen Date: Thu, 5 Apr 2012 16:01:56 +0300 Subject: [PATCH] Add possibility to plot emerge times into a 2D scatter plot 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 | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/emerge-timer.py b/emerge-timer.py index baffb73..359beb0 100755 --- a/emerge-timer.py +++ b/emerge-timer.py @@ -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 = "" -- 2.44.0