forked from lazy20017/python_TCPserver_Thread
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.py
More file actions
222 lines (185 loc) · 6.71 KB
/
3.py
File metadata and controls
222 lines (185 loc) · 6.71 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import pymssql
import re
import pandas as pd
from pandas import Series,DataFrame
class MSSQL:
def __init__(self,host,user,pwd,db): #类的构造函数,初始化数据库连接ip或者域名,以及用户名,密码,要连接的数据库名称
self.host=host
self.user=user
self.pwd=pwd
self.db=db
def __GetConnect(self): #得到数据库连接信息函数, 返回: conn.cursor()
if not self.db:
print(NameError,"没有设置数据库信息")
self.conn=pymssql.connect(host=self.host,user=self.user,password=self.pwd,database=self.db,charset='utf8')
cur=self.conn.cursor() #将数据库连接信息,赋值给cur。
if not cur:
raise(NameError,"连接数据库失败")
else:
return cur
#执行查询语句,返回的是一个包含tuple的list,list的元素是记录行,tuple的元素是每行记录的字段
def ExecQuery(self,sql): #执行Sql语句函数,返回结果
cur = self.__GetConnect() #获得数据库连接信息
cur.execute(sql) #执行Sql语句
resList = cur.fetchall() #获得所有的查询结果
#查询完毕后必须关闭连接
self.conn.close() #返回查询结果
return resList
def ExecNonQuery(self,sql):
cur = self.__GetConnect()
cur.execute(sql)
self.conn.commit()
self.conn.close()
def main():
ms=MSSQL(host="127.0.0.1",user="sa",pwd="ncist123456",db="istudy_p03") #实例化类对象,连接数据对象
getdata =ms.ExecQuery("select * from TB_examescore")
myrow=len(getdata)
mycolomn=len(getdata[0])
print(myrow,mycolomn)
xx_select1=[]
xx_word10=[]
xx_word20 = []
xx_excel1=[]
xx_ppt1=[]
xx_windows1=[]
for i in range(0,myrow):
xx1=str(getdata[i][8])
xx_select1.append(re.findall(r"单项选择题,第\d+套,第\d+题\D+总分\D+\d+\D+得分\D+\d+",xx1))
xx_word10.append(re.findall(r"Word表格操作,第\d+套,第\d+题\D+总分\D+\d+\D+得分\D+\d+",xx1))
xx_word20.append(re.findall(r"Word编辑操作,第\d+套,第\d+题\D+总分\D+\d+\D+得分\D+\d+", xx1))
xx_excel1.append(re.findall(r"Excel题,第\d+套,第\d+题\D+总分\D+\d+\D+得分\D+\d+", xx1))
xx_ppt1.append(re.findall(r"PowerPoint题,第\d+套,第\d+题\D+总分\D+\d+\D+得分\D+\d+", xx1))
xx_windows1.append(re.findall(r"Windows题,第\d+套,第\d+题\D+总分\D+\d+\D+得分\D+\d+", xx1))
print(len(xx_select1),len(xx_select1[0]))
print(len(xx_word10), len(xx_word10[0]))
print(len(xx_word20), len(xx_word20[0]))
print(len(xx_excel1), len(xx_excel1[0]))
print(len(xx_ppt1), len(xx_ppt1[0]))
print(len(xx_windows1), len(xx_windows1[0]))
print("###################")
print(xx_excel1[100])
print("###################")
xx_select2=[]
xx_word12=[]
xx_word22=[]
xx_excel2=[]
xx_ppt2=[]
xx_windows2=[]
for yy in range(0,len(xx_select1)):
for kk in range(0,len(xx_select1[yy])):
pass
t1=re.findall(r"第\d+套",str(xx_select1[yy][kk]))[0]
t2=re.findall(r"第\d+题",str(xx_select1[yy][kk]))[0]
t3=re.findall(r"得分\D+\d+",str(xx_select1[yy][kk]))
t3=t3[0][-1]
#print(t1,t2,t3)
t0=[]
t0.append(t1)
t0.append(t2)
t0.append(int(t3))
#print(t0)
xx_select2.append(t0)
for yy in range(0,len(xx_word10)):
t1 = re.findall(r"第\d+套",str(xx_word10[yy]))
t2 = re.findall(r"第\d+题", str(xx_word10[yy]))
t3 = re.findall(r"得分\D+\d+", str(xx_word10[yy]))
if len(t1)!=0:
t1=t1[0]
t2=t2[0]
t3 = t3[0][-2:]
t3=int(t3)
t0 = []
t0.append(t1)
#t0.append(t2)
t0.append(t3)
xx_word12.append(t0)
else:
print(str(yy),t1,t2,t3)
##################################
for yy in range(0,len(xx_word20)):
t1 = re.findall(r"第\d+套",str(xx_word20[yy]))
t2 = re.findall(r"第\d+题", str(xx_word20[yy]))
t3 = re.findall(r"得分\D+\d+", str(xx_word20[yy]))
if len(t1)!=0:
t1=t1[0]
t2=t2[0]
t3 = t3[0][-2:]
t3=int(t3)
t0 = []
t0.append(t1)
#t0.append(t2)
t0.append(t3)
xx_word22.append(t0)
else:
print(str(yy),t1,t2,t3)
for yy in range(0,len(xx_excel1)):
t1 = re.findall(r"第\d+套",str(xx_excel1[yy]))
t2 = re.findall(r"第\d+题", str(xx_excel1[yy]))
t3 = re.findall(r"得分\D+\d+", str(xx_excel1[yy]))
if len(t1)!=0:
t1=t1[0]
t2=t2[0]
t3 = t3[0][-2:]
t3=int(t3)
t0 = []
t0.append(t1)
#t0.append(t2)
t0.append(t3)
xx_excel2.append(t0)
else:
print(str(yy), t1, t2, t3)
for yy in range(0,len(xx_ppt1)):
t1 = re.findall(r"第\d+套",str(xx_ppt1[yy]))
t2 = re.findall(r"第\d+题", str(xx_ppt1[yy]))
t3 = re.findall(r"得分\D+\d+", str(xx_ppt1[yy]))
if len(t1)!=0:
t1=t1[0]
t2=t2[0]
t3 = t3[0][-2:]
t3=int(t3)
t0 = []
t0.append(t1)
#t0.append(t2)
t0.append(t3)
xx_ppt2.append(t0)
else:
print(str(yy),t1,t2,t3)
for yy in range(0,len(xx_windows1)):
t1 = re.findall(r"第\d+套",str(xx_windows1[yy]))
t2 = re.findall(r"第\d+题", str(xx_windows1[yy]))
t3 = re.findall(r"得分\D+\d+", str(xx_windows1[yy]))
if len(t1)!=0:
t1=t1[0]
t2=t2[0]
t3 = t3[0][-2:]
t3=int(t3)
t0 = []
t0.append(t1)
#t0.append(t2)
t0.append(t3)
xx_windows2.append(t0)
else:
print(str(yy),t1,t2,t3)
print('###############################3')
print(xx_select2[100])
print(xx_word12[100])
print(xx_word22[100])
print(xx_excel2[100])
print(xx_ppt2[100])
print(xx_windows2[100])
############################
print("############pandas##########")
#print(xx_word12)
#########pandas#############################
yy0=[]
yy1=[]
yy2=[]
for i in range(0,len(xx_select2)):
yy0.append(xx_select2[i][0])
yy1.append(xx_select2[i][1])
yy2.append(int(xx_select2[i][2]))
xx2={'select':yy0,'select_num':yy1,'value':yy2}
mydata=DataFrame(xx2)
print(mydata)
print(mydata.groupby(['select','select_num']).mean())
main()