Planning the future of Botwiki! - Help us bring Botwiki up to date, contribute to our strategy discussion, add bot scripts, and contribute manuals, guides, and tutorials! Almost anything related to bots, particularly those used to edit mediawiki, is welcome.
UNABLE TO EDIT? - We've experienced attacks by spambots lately and now require you to confirm your e-mail before you can edit (go to your preferences, enter an e-mail address, and request a confirmation e-mail, then go to your e-mail and click on the confirmation link). We also require new accounts to make a few edits and wait a few minutes before before you can create a page; however, if this is a problem contact us in #botwiki and we can manually confirm your account. Sorry for the inconvenience.
Python:Logstat local.py
| File: logstat_local.py; revision 0.2.0000 |
| Last update: DrTrigon 23:31, 28 December 2009 (UTC) |
| PAGE IS MODIFIED • (UPDATE) |
#!/usr/bin/env python import numpy as np import matplotlib.pyplot as plt import urllib2, time, re, os, sys req = urllib2.Request("http://toolserver.org/~drtrigon/cgi-bin/panel.py?action=logstat&format=plain") f = urllib2.urlopen(req) buffer = f.read() f.close() #def subst(matchobj): return "{" + matchobj.group(1) + "}" def subst(matchobj): result = matchobj.group(1) result = re.sub("=", "':", result) result = re.sub(",\s", ", '", result) return "{'" + result + "}" #buffer = re.sub("time.struct_time\(.*?\)", "None", buffer) buffer = re.sub("time.struct_time\((.*?)\)", subst, buffer) stat = eval(buffer) print "stat keys:", stat.keys() # create needed dirs basedir = os.path.realpath(os.curdir) workdir = os.path.join(basedir, "logstat_" + time.strftime("%Y%m%d%H%M")) try: os.chdir(workdir) except: os.makedirs(workdir) os.chdir(workdir) logstat = os.path.join(workdir, "logstat.txt") #logstat_plot = os.path.join(workdir, "logstat.png") logstat_plot = os.path.join(workdir, "logstat.pdf") f = open(logstat, "w") stat['diff'] = stat['run_count'] - stat['successful_count'] stat['warn_list'] = re.sub("\n\s", "\n", "\n".join(stat['warn_list']))[1:] + "\n" gettime = lambda a: str(time.strftime("%a %b %d %Y", (a['tm_year'], a['tm_mon'], a['tm_mday'], a['tm_hour'], a['tm_min'], a['tm_sec'], a['tm_wday'], a['tm_yday'], a['tm_isdst']))) stat['start_date'] = gettime(stat['start_date']) stat['end_date'] = gettime(stat['end_date']) stat['logstat_plot'] = logstat_plot stat['script'] = sys.argv[0] data = """Evaluated data period from %(start_date)s to %(end_date)s. Created by '%(script)s', see also 'http://toolserver.org/~drtrigon/cgi-bin/panel.py?action=logstat'. Total runs: %(run_count)s Successful runs: %(successful_count)s Difference: %(diff)s History compressed: %(histcomp_count)s (times) Problem rate (in %%): (siehe '%(logstat_plot)s') Warnings: %(warn_list)s """ % stat f.write( data ) f.close() # http://matplotlib.sourceforge.net/examples/api/barchart_demo.html x = [ item[1]*100 for item in stat['reliability_list'] ] N = len(x) ind = np.arange(N) # the x locations for the groups #width = 0.35 # the width of the bars #width = 0.4 # the width of the bars (ok for .png) width = 0.5 # the width of the bars (ok for .pdf) fig = plt.figure() ax = fig.add_subplot(111) #rects1 = ax.bar(ind, x, width, color='r') rects1 = ax.bar(ind, x, width) # add some # http://matplotlib.sourceforge.net/api/axes_api.html?highlight=set_xticks#matplotlib.axes.Axes.set_xticks ax.set_title('DrTrigonBot log statistics') ax.set_ylabel('Problem rate [%]') ax.set_xticks(7*np.arange(N/7)) #ax.set_xticklabels( ('G1', 'G2', 'G3', 'G4', 'G5') ) #ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') ) #ax.legend( (rects1[0],), ('x',) ) #def autolabel(rects): # # attach some text labels # for rect in rects: # height = rect.get_height() # ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height), # ha='center', va='bottom') # #autolabel(rects1) #autolabel(rects2) # http://matplotlib.sourceforge.net/api/pyplot_api.html?highlight=save#matplotlib.pyplot.savefig # http://matplotlib.sourceforge.net/api/pyplot_api.html?highlight=save#matplotlib.pyplot.imsave plt.savefig(logstat_plot) #plt.show()