need some advice on x y plot
Kent Johnson
kent37 at tds.net
Thu Oct 20 14:01:59 EDT 2005
nephish at xit.net wrote:
> how ?
> i have tried to use unix timestamps, and i have also tried with
> DateTime objects
> do i need to use a scale that isn't linear (default in most) ?
> how do i putt this off ?
Here is some code that works for me. It plots multiple datasets against time. The input data looks like this:
2005-04-04 16:00:00 141.154.195.129 - W3SVC1 SP6018ASP2 208.254.37.191 443 GET /rkadqsr/newskills/newskills.cfm selectedTab=1 200 0 53440 599 1594 HTTP/1.1 adqsr.skillport.com Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) CookiesEnabled=1;+ASPSESSIONIDACTSSRAT=MCNLNLGADPOFGFKAHJHLDDKG;+CFID=785030;+CFTOKEN=27203160 https://adqsr.skillport.com/rkadqsr/login/login.cfm
2005-04-04 16:00:00 208.254.38.216 - W3SVC1 SP6018ASP2 208.254.37.191 443 POST /_rkadqsrBackend_od_cgi/aiccisapi.dll - 200 0 372 274 4547 HTTP/1.0 adqsr.skillport.com aiccisapi - -
2005-04-04 16:00:00 208.254.38.240 - W3SVC1 SP6018ASP2 208.254.37.191 443 POST /_rkadqsrBackend_od_cgi/aiccisapi.dll - 200 0 372 3019 250 HTTP/1.0 adqsr.skillport.com aiccisapi - -
import datetime, time
import Gnuplot
dataPath = 'ex05040416.log'
datasets = {}
startTime = None
f = open(dataPath)
for line in f:
try:
dat, tim, c_ip, cs_username, s_sitename, s_computername, s_ip, s_port, \
cs_method, cs_uri_stem, cs_uri_query, sc_status, sc_win32_status, sc_bytes, \
cs_bytes, time_taken, cs_version, cs_host, cs_User_Agent, cs_Cookie, cs_Referer = line.split()
except ValueError:
print "Can't parse", line
continue
tim = time.mktime(time.strptime(dat+' '+tim, "%Y-%m-%d %H:%M:%S"))
delay = int(time_taken)
if startTime is None:
startTime = tim
tim -= startTime
# print tim, delay
datasets.setdefault(sc_status, []).append([tim, delay])
g = Gnuplot.Gnuplot(debug=1)
plotter = g.plot
for key, values in datasets.items():
plotter(values)
plotter = g.replot
raw_input('Please press return to continue...\n')
More information about the Python-list
mailing list