Visualization of the last actions on directory files

import matplotlib.pyplot as plt from os import listdir, stat, walk from os.path import exists, isdir, join import datetime action_types = ('last access', 'last modification', 'last metadata change') colors = ('green', 'red', 'blue') action_colors = dict(zip(action_types, colors)) markersize, markeralpha = 4, 0.5 seen_actions = set() base = '/var/www/html/prototypes' timest = datetime.date.fromtimestamp pl = plt.plot for unit in listdir(base): path = join(base, unit) if isdir(path): for _, _, files in walk(path): for f in files: fpath = join(path, f) if exists(fpath): stats = stat(fpath) atime = stats.st_atime mtime = stats.st_mtime ctime = stats.st_ctime filesize = stats.st_size for action_time, action_type in zip((atime, mtime, ctime), action_types): if action_type not in seen_actions: pl(timest(action_time), filesize, '.', markersize=markersize, alpha=markeralpha, color=action_colors[action_type], label=action_type) seen_actions.add(action_type) else: pl(timest(action_time), filesize, '.', markersize=markersize, alpha=markeralpha, color=action_colors[action_type]) plt.xlabel('Time') plt.ylabel('File size') plt.legend(loc='best', frameon=False, markerscale=4) plt.tight_layout() plt.show() Visualization of the last actions in a sample directory