def main(): ''' Counts number of users/tests per day ''' syslog.openlog('count.py', syslog.LOG_PERROR, syslog.LOG_USER) count_users = False outfile = None try: options, arguments = getopt.getopt(sys.argv[1:], 'o:u') except getopt.error: sys.exit('Usage: count.py [-o file] [-u] file') if len(arguments) != 1: sys.exit('Usage: count.py [-o file] [-u] file') for name, value in options: if name == '-o': outfile = value elif name == '-u': count_users = True connection = sqlite3.connect(arguments[0]) data = collections.defaultdict(list) for table in ('speedtest', 'bittorrent'): cursor = connection.cursor() cursor.execute('SELECT timestamp, uuid FROM %s;' % table) for result in cursor: timestamp = int(pylab.epoch2num(result[0])) data[timestamp].append(result[1]) connection.close() xdata, ydata = [], [] for timestamp in sorted(data.keys()): xdata.append(timestamp) uuid_list = data[timestamp] if count_users: uuid_list = set(uuid_list) ydata.append(len(uuid_list)) result = pylab.plot_date(xdata, ydata) pylab.grid(True, color='black') pylab.xlabel('Date', fontsize=16) if count_users: pylab.suptitle('Number of neubots per day', fontsize=20) pylab.ylabel('Number of neubots', fontsize=16) else: pylab.suptitle('Number of tests per day', fontsize=20) pylab.ylabel('Number of tests', fontsize=16) # Pretty dates pylab.gcf().autofmt_xdate() if outfile: pylab.savefig(outfile, dpi=256, transparent=True) else: pylab.show()
def availabe_jds(self, datadir=None, filestamp="nwa_avg_*.nc"): """List the julian dates for all available fields in datadir""" datadir = self.datadir if datadir==None else datadir flist = glob.glob(os.path.join(datadir, filestamp)) eplist = [] baseep = pl.num2epoch(pl.datestr2num("1900-01-01")) for fn in flist: with Dataset(fn) as nc: eplist.append(nc.variables['ocean_time'][:] + baseep) return np.squeeze(np.array(pl.epoch2num(eplist)))
def count(dir, pattern): p = os.popen('wc -l `find %s -name %s` | tail -1' % (dir, pattern), 'r') return int(p.read().split()[0]) os.chdir('..') libxc = count('c/libxc', '\\*.[ch]') ch = count('c', '\\*.[ch]') - libxc test = count('gpaw/test', '\\*.py') py = count('gpaw', '\\*.py') - test import pylab # Update the stat.dat file: dir = '/scratch/jensj/nightly-test/' f = open(dir + 'stat.dat', 'a') print >> f, pylab.epoch2num(time.time()), libxc, ch, py, test f.close() # Construct the stat.png file: lines = open(dir + 'stat.dat').readlines() date, libxc, c, code, test = zip(*[[float(x) for x in line.split()] for line in lines[1:]]) date = pylab.array(date) code = pylab.array(code) test = pylab.array(test) c = pylab.array(c) def polygon(x, y1, y2, *args, **kwargs): x = pylab.concatenate((x, x[::-1])) y = pylab.concatenate((y1, y2[::-1])) pylab.fill(x, y, *args, **kwargs)