-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpro_data.py
More file actions
171 lines (150 loc) · 4.31 KB
/
pro_data.py
File metadata and controls
171 lines (150 loc) · 4.31 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
File:
Author:
Email:
Github:
Description:
"""
import os
import matplotlib.pyplot as plt
from matplotlib import pylab
import numpy as np
def autolabel(rects):
for rect in rects:
height = rect.get_height()
if not height:
height = 0
plt.text(rect.get_x() + rect.get_width()/2., 1.05*(height+1), '%d'%int(height),
ha='center', va='bottom')
continue
plt.text(rect.get_x() + rect.get_width()/2., 1.05*(height), '%d'%int(height),
ha='center', va='bottom')
def pro_data(file):
times = 0
read_one_all = []
read_three_all = []
assert(os.path.isfile(file))
fin = open(file)
for line in fin:
line = line.strip()
line = line.replace("ALL TAG","ALL")
a = line.split(" ")
read_three = {}
read_one = {}
if a[3] == "ALL":
dt = "2015-" + a[1] + " " + a[2]
read_three["datetime"] = dt
a[5] = a[5][:-1]
read_three["tag_num"] = a[5]
print a[6]
if a[6]:
read_three["tag"] = a[6].split(",")
else:
read_three["tag"] = []
#read_three["tag"] = filter(lambda e:e=='',read_three["tag"])
read_three_all.append(read_three)
if a[3] == "TAG":
dt = "2015-" + a[1] + " " + a[2]
read_one["datetime"] = dt
a[5] = a[5][:-1]
read_one["tag_num"] = a[5]
a[6] = a[6][:-1]
read_one["tag"] = a[6].split(":")
#read_one["tag"] = filter(lambda e:e=='',read_one["tag"])
read_one_all.append(read_one)
#file
file_one = "./read_one.pro"
file_three = "./read_three.pro"
if os.path.isfile(file_one):
os.remove(file_one)
fp = open(file_one,"w")
for line in read_one_all:
line = str(line) + "\n"
fp.write(line)
fp = open(file_three,"w")
for line in read_three_all:
line = str(line) + "\n"
fp.write(line)
#picture
#read_one
lg = len(read_one_all)
dates = []
data = []
cal_data = {}
for read_one in read_one_all:
dates.append(read_one["datetime"])
data.append(read_one["tag_num"])
#if read_one["tag_num"] == '7':
# print read_one
# continue
if not cal_data.has_key(read_one["tag_num"]):
cal_data[read_one["tag_num"]] = 0
cal_data[read_one["tag_num"]] = cal_data[read_one["tag_num"]] + 1
x = cal_data.keys()
y = cal_data.values()
x.sort()
p_read_one = {}
for i in x:
p_read_one[i] = cal_data[i]
#read_three
lg = len(read_three_all)
dates = []
data = []
cal_data = {}
for read_three in read_three_all:
dates.append(read_three["datetime"])
data.append(read_three["tag_num"])
#if read_three["tag_num"] == '7':
# print read_three
# continue
if not cal_data.has_key(read_three["tag_num"]):
cal_data[read_three["tag_num"]] = 0
cal_data[read_three["tag_num"]] = cal_data[read_three["tag_num"]] + 1
x = cal_data.keys()
y = cal_data.values()
x.sort()
p_read_three = {}
for i in x:
p_read_three[i] = cal_data[i]
x1 = p_read_one.keys()
x2 = p_read_three.keys()
x = list( set( x1 + x2))
for i in x:
if not p_read_one.has_key(i):
p_read_one[i] = 0
if not p_read_three.has_key(i):
p_read_three[i] = 0
x.sort()
y1 = []
y2 = []
for i in x:
y1.append(p_read_one[i])
y2.append(p_read_three[i])
print "y1:", y1
print "y2:", y2
"""
pylab.xlabel("read_num")
pylab.ylabel("count_num")
pylab.title("test")
pylab.gca().set_yscale('log')
dim = len(x)
w = 0.35
ind = np.arange(dim)
p1 = plt.bar(ind, y1, w,color='y')
p2 = plt.bar(ind+w, y2, w,color='r')
plt.ylabel('Count')
plt.xlabel('read num')
plt.xticks(ind+w/2.,x)
#plt.yticks(np.arange(0,700,50))
plt.legend( (p1[0],p2[0]), ('read_one','read_three'),loc = 'upper center')
autolabel(p1)
autolabel(p2)
plt.show()
"""
#tag analysis
# print read_three_all
if __name__ == "__main__":
file = "./tag_reader.log"
pro_data(file)