File: weblog.py

package info (click to toggle)
swig 1.1p5-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 9,448 kB
  • ctags: 5,025
  • sloc: cpp: 21,599; ansic: 13,333; yacc: 3,297; python: 2,794; makefile: 2,197; perl: 1,984; tcl: 1,583; sh: 736; lisp: 201; objc: 143
file content (146 lines) | stat: -rw-r--r-- 3,192 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Make a plot from a web-server log

from image2d import *
from image3d import *
import string
import regex

class HitsPerDay(Image2D):
	def __init__(self,filename):
		Image2D.__init__(self,0,0,32,1)

	# Now read in a mesh file in pieces

		hits = [0]*32

	# Read in data points
		f = open(filename,"r")
		l = f.readline()
		while l:
			try:
				d = string.split(l)[3]
				fields = string.split(d[1:],"/")
				day = string.atoi(fields[0])
				hits[day] = hits[day] + 1
			except:
				pass
			l = f.readline()			
		f.close()
		self.hits = hits
		self.color = BLUE
		self.ymax = max(self.hits)
		self.xtick_spacing = 1.0
		self.ytick_spacing = self.ymax / 10.0
		self.xaxis_label = "Day"
		self.yaxis_label = "Total hits"

	def draw(self):
		self.newplot()
		self.plotbar(self.hits,0,31,self.color)
		self.plotarray(self.hits,0,31,WHITE,CROSS)
		self.drawaxis()


class HitsByHour(Image2D):
	def __init__(self,filename):
		Image2D.__init__(self,0,0,24,1)

	# Now read in a mesh file in pieces

		hits = [0]*24

	# Read in data points
		f = open(filename,"r")
		l = f.readline()
		while l:
			try:
				d = string.split(l)[3]
				fields = string.split(d[1:],"/")
				t = string.split(fields[2][5:],":")
				hour = string.atoi(t[0])
				hits[hour] = hits[hour]+1
			except:
				pass
			l = f.readline()			
		f.close()
		self.hits = hits
		self.color = BLUE
		self.ymax = max(self.hits)
		self.ytick_spacing = self.ymax / 10.0
		self.xtick_spacing = 1.0
		self.xaxis_label = "Hour"
		self.yaxis_label = "Total hits"
	def draw(self):
		self.newplot()
		self.plotbar(self.hits,0,24,self.color)
		self.plotarray(self.hits,0,24,WHITE,CROSS)
		self.drawaxis()

class HitsPerHour(Image3D):
	def __init__(self,filename):

	# Now read in a mesh file in pieces
		hits = []
		for i in range(0,31):
			hits.append([0]*24)

	# Read in data points
		f = open(filename,"r")
		l = f.readline()
		while l:
			try:
				d = string.split(l)[3]
				fields = string.split(d[1:],"/")
				day = string.atoi(fields[0])
				t = string.split(fields[2][5:],":")
				hour = string.atoi(t[0])
				hits[day][hour] = hits[day][hour]+1
			except:
				pass
			l = f.readline()			
		f.close()
		Image3D.__init__(self,0,0,0,31,24,10.0)
		self.max = max(map(max,hits))
		self.min = 0
		self.hits = hits
		self.title = "Hits per hour"
		self.draw_box = 0
		self.lookat(50)
		self.autoperspective(40)
	def draw(self):
		self.newplot()
		zscale = 239.0/self.max
		zscale2 = 10.0/self.max
		for i in xrange(0,30):
			for j in xrange(0,23):
				z1 = self.hits[i][j]
				z2 = self.hits[i+1][j]
				z3 = self.hits[i+1][j+1]
				z4 = self.hits[i][j+1]
				c1 = z1*zscale+16
				c2 = z2*zscale+16
				c3 = z3*zscale+16
				c4 = z4*zscale+16
				self.interpquad(i,j,z1*zscale2,c1,i+1,j,z2*zscale2,c2,
						i+1,j+1,z3*zscale2,c3,i,j+1,z4*zscale2,c4)


l = HitsPerDay("../Data/logs.9604")
l.title = "Hits per Day (April 1996)"
l.filename = "hits_day.gif"
l.show()

t = HitsByHour("../Data/logs.9604")
t.title = "Hits by hour (April 1996)"
t.filename = "hits_time.gif"
t.show()

p = HitsPerHour("../Data/logs.9604")
p.title = "Hits per hour (April 1996)"
p.filename = "hits_hour.gif"
p.rotu(50)
p.rotr(20)
p.right(5)
p.up(15)
p.zoom(120)
p.show()