Coi统计数据程序:修订间差异
来自RIA | Wiki
更多操作
无编辑摘要 |
分类... |
||
| (未显示2个用户的4个中间版本) | |||
| 第1行: | 第1行: | ||
== 主程序·RIA_COI_MAIN == | |||
<pre> | |||
import tkinter as tk | |||
import tkinter.messagebox | |||
import os | import os | ||
import os.path | import os.path | ||
import tkinter.messagebox | |||
from PIL import ImageTk, Image | |||
from tkinter import filedialog | |||
import base64 | |||
logID="" | |||
root="" | |||
TimeLog1=0 | |||
TimeLog2=0 | |||
config="" | |||
def is_number(s): | def is_number(s): | ||
| 第41行: | 第65行: | ||
break | break | ||
def go(): | |||
logID=str(entry.get()) | |||
root=filedialog.askopenfilename() | |||
TimeLog1=float( | TimeLog1=float(entry_TimeLog1.get()) | ||
TimeLog2=float( | TimeLog2=float(entry_TimeLog2.get()) | ||
config= | config=tkinter.messagebox.askquestion("选择","是否删除x54的数据") | ||
data=open(str(root | data=open(str(root),"r",encoding="UTF-8") | ||
len_logID=len(logID) | len_logID=len(logID) | ||
| 第69行: | 第93行: | ||
tag=[] | tag=[] | ||
for | for mine in data: | ||
coi.append(str( | coi.append(str(mine)) | ||
for i in range(len(coi)): | for i in range(len(coi)): | ||
if len(coi[i])<=39: | |||
continue | |||
linex=coi[i].split(" ") | |||
if len(linex)<7: | |||
if | continue | ||
linex=linex[4:] | |||
if linex[0]=="*" and linex[1]==logID and linex[2]=="统计结束\n": | |||
break | break | ||
elif linex[0]=="*" and linex[1]==logID and linex[2][:3]=="统计:": | |||
tag.append( | tag.append(linex[2][3:].rstrip("\n")) | ||
coi2=[] | coi2=[] | ||
| 第93行: | 第125行: | ||
for l in range(i+1,len(coi)): | for l in range(i+1,len(coi)): | ||
if coi[l][40:45+ | if coi[l][40:45+len(logID)]=="* "+logID+" 统计": | ||
break | break | ||
| 第99行: | 第131行: | ||
else: | else: | ||
t_f = is_number(coi[l][ | t_f = is_number(coi[l][40]) | ||
if t_f == True: | if t_f == True: | ||
liney=coi[l][40:] | |||
linex_list= | linex_list=liney.split(" ") | ||
time=float(linex_list[0].rstrip("/h")) | time=float(linex_list[0].rstrip("/h")) | ||
| 第223行: | 第255行: | ||
for i in range(len(all_coi_value)): | for i in range(len(all_coi_value)): | ||
change.append( | change.append(-(all_coi_value[i])) | ||
all_coi_value=change | all_coi_value=change | ||
log=open(str(root+" | log=open(str(root.rstrip("coi.txt")+"result.txt"),"w+",encoding="UTF-8") | ||
btpr="" | btpr="" | ||
| 第236行: | 第268行: | ||
log.write(btpr) | log.write(btpr) | ||
change1=[] | change1=[] | ||
| 第270行: | 第300行: | ||
dic[n]=all_coi_value[l] | dic[n]=all_coi_value[l] | ||
for m in range(len(dic)): | for m in range(len(dic)): | ||
| 第298行: | 第326行: | ||
log.close() | log.close() | ||
tkinter.messagebox.showinfo("Congratulations!","数据处理完毕。") | |||
roo = tk.Tk() | |||
roo.title('RIA 援建数据处理系统GUI by Arthals') | |||
canvas = tk.Canvas(roo, width=769,height=432,bd=0, highlightthickness=0) | |||
from RIABG_png import img as socket | |||
imp = open('RIABG.png', 'wb') | |||
imp.write(base64.b64decode(socket)) | |||
imp.close() | |||
imgpath = 'RIABG.png' | |||
img = Image.open(imgpath) | |||
photo = ImageTk.PhotoImage(img) | |||
canvas.create_image(0, 0, anchor="nw", image=photo) | |||
canvas.pack() | |||
entry=tk.Entry(roo,insertbackground='blue', highlightthickness =2) | |||
''' | |||
entry_root=tk.Entry(roo,insertbackground='blue', highlightthickness =2) | |||
''' | |||
entry_TimeLog1=tk.Entry(roo,insertbackground='blue', highlightthickness =2) | |||
entry_TimeLog2=tk.Entry(roo,insertbackground='blue', highlightthickness =2) | |||
''' | |||
entry_config=tk.Entry(roo,insertbackground='blue', highlightthickness =2) | |||
''' | |||
entry.pack() | |||
''' | |||
entry_root.pack() | |||
''' | |||
entry_TimeLog1.pack() | |||
entry_TimeLog2.pack() | |||
''' | |||
entry_config.pack() | |||
''' | |||
button=tkinter.Button(roo,text="进行统计",font=('黑体', 20),bg="green",command=go) | |||
button.pack() | |||
canvas.create_window(60, 50, anchor="nw",width=100, height=30,window=entry) | |||
''' | |||
canvas.create_window(120, 120, width=100, height=20,window=entry_root) | |||
''' | |||
canvas.create_window(60, 130, anchor="nw",width=70, height=25,window=entry_TimeLog1) | |||
canvas.create_window(60, 190, anchor="nw",width=70, height=25,window=entry_TimeLog2) | |||
''' | |||
canvas.create_window(120, 160, width=100, height=20,window=entry_config) | |||
''' | |||
canvas.create_window(720, 350,anchor="ne", width=235, height=60,window=button) | |||
roo.mainloop() | |||
</pre> | |||
== 图片转换程序 == | |||
<pre> | |||
import base64 | |||
def pic2py(picture_name): | |||
""" | |||
将图像文件转换为py文件 | |||
:param picture_name: | |||
:return: | |||
""" | |||
open_pic = open("%s" % picture_name, 'rb') | |||
b64str = base64.b64encode(open_pic.read()) | |||
open_pic.close() | |||
# 注意这边b64str一定要加上.decode() | |||
write_data = 'img = "%s"' % b64str.decode() | |||
f = open('%s.py' % picture_name.replace('.', '_'), 'w+') | |||
f.write(write_data) | |||
f.close() | |||
if __name__ == '__main__': | |||
pics = ["RIABG.png"] | |||
for i in pics: | |||
pic2py(i) | |||
print("ok") | |||
</pre> | |||
<!-- 分类 --> | |||
[[Category:怪东西]] | |||
[[Category:程序源代码]] | |||
2021年3月27日 (六) 22:25的最新版本
主程序·RIA_COI_MAIN
import tkinter as tk
import tkinter.messagebox
import os
import os.path
import tkinter.messagebox
from PIL import ImageTk, Image
from tkinter import filedialog
import base64
logID=""
root=""
TimeLog1=0
TimeLog2=0
config=""
def is_number(s):
try:
float(s)
return True
except ValueError:
return False
def replaceList(list1, num, replace):
list2 =[]
for i in range(len(list1)):
if i == num:
list2.append(replace)
else:
list2.append(list1[i])
return list2
def part(num,list1):
for i in range(len(list1)):
if num<=list1[i]:
return i
break
def go():
logID=str(entry.get())
root=filedialog.askopenfilename()
TimeLog1=float(entry_TimeLog1.get())
TimeLog2=float(entry_TimeLog2.get())
config=tkinter.messagebox.askquestion("选择","是否删除x54的数据")
data=open(str(root),"r",encoding="UTF-8")
len_logID=len(logID)
coi=[]
all_coi_name=[]
all_coi_value=[]
count=[]
all_coi={}
tag=[]
for mine in data:
coi.append(str(mine))
for i in range(len(coi)):
if len(coi[i])<=39:
continue
linex=coi[i].split(" ")
if len(linex)<7:
continue
linex=linex[4:]
if linex[0]=="*" and linex[1]==logID and linex[2]=="统计结束\n":
break
elif linex[0]=="*" and linex[1]==logID and linex[2][:3]=="统计:":
tag.append(linex[2][3:].rstrip("\n"))
coi2=[]
how={}
for l in range(i+1,len(coi)):
if coi[l][40:45+len(logID)]=="* "+logID+" 统计":
break
else:
t_f = is_number(coi[l][40])
if t_f == True:
liney=coi[l][40:]
linex_list=liney.split(" ")
time=float(linex_list[0].rstrip("/h"))
if TimeLog1<=time<=TimeLog2:
linex_list.remove("ago")
linex_list.remove("-")
linex_list.pop()
if config=="yes" and linex_list[3]=="x54":
continue
if linex_list[2]=="removed":
if linex_list[1] in how:
how[linex_list[1]]=how[linex_list[1]]-int(linex_list[3].lstrip("x"))
elif linex_list[1] not in how:
how[linex_list[1]]=-int(linex_list[3].lstrip("x"))
else:
print("Error")
break
if linex_list[2]=="added":
if linex_list[1] in how:
how[linex_list[1]]=how[linex_list[1]]+int(linex_list[3].lstrip("x"))
elif linex_list[1] not in how:
how[linex_list[1]]=int(linex_list[3].lstrip("x"))
else:
print("Error")
break
name=list(how.keys())
count.append(len(name))
for y in range(len(name)):
all_coi_name.append(name[y])
value=list(how.values())
for y in range(len(value)):
all_coi_value.append(value[y])
sort=[]
for i in range(len(all_coi_name)):
if all_coi_name[i] in sort:
continue
else:
sort.append(all_coi_name[i])
sort.sort()
all_count=[]
for i in range(len(count)):
if i==0:
all_count.append(count[i])
else:
all_count.append("0")
all_count=replaceList(all_count,i,int(count[i]+all_count[i-1]))
all_count_change=[]
for i in range(len(all_count)):
all_count_change.append(int(all_count[i]-1))
all_count=all_count_change
bt=[]
for i in range(len(tag)+2):
if i==0:
bt.append("ID\t")
elif i != len(tag)+1:
bt.append(str(tag[i-1])+"\t")
else:
bt.append(str("\n"))
change=[]
for i in range(len(all_coi_value)):
change.append(-(all_coi_value[i]))
all_coi_value=change
log=open(str(root.rstrip("coi.txt")+"result.txt"),"w+",encoding="UTF-8")
btpr=""
for i in range(len(bt)):
btpr=btpr+str(bt[i])
log.write(btpr)
change1=[]
for i in range(len(all_coi_value)):
if all_coi_value[i]!=0:
change1.append(all_coi_value[i])
else:
change1.append("")
all_coi_value=change1
for i in range(len(sort)):
pr=str(sort[i]+"\t")
dic={}
for x in range(len(tag)):
dic[x]="\t"
for l in range(len(all_coi_name)):
if all_coi_name[l]==sort[i]:
n=part(l,all_count)
dic[n]=all_coi_value[l]
for m in range(len(dic)):
if m !=len(dic)-1:
if str(list(dic.values())[m])=="\t":
pr=pr+str(list(dic.values())[m])
else:
pr=pr+str(list(dic.values())[m])+"\t"
else:
if str(list(dic.values())[m])=="\t":
pr=pr+"\n"
else:
pr=pr+str(list(dic.values())[m])+"\n"
log.write(pr)
log.close()
tkinter.messagebox.showinfo("Congratulations!","数据处理完毕。")
roo = tk.Tk()
roo.title('RIA 援建数据处理系统GUI by Arthals')
canvas = tk.Canvas(roo, width=769,height=432,bd=0, highlightthickness=0)
from RIABG_png import img as socket
imp = open('RIABG.png', 'wb')
imp.write(base64.b64decode(socket))
imp.close()
imgpath = 'RIABG.png'
img = Image.open(imgpath)
photo = ImageTk.PhotoImage(img)
canvas.create_image(0, 0, anchor="nw", image=photo)
canvas.pack()
entry=tk.Entry(roo,insertbackground='blue', highlightthickness =2)
'''
entry_root=tk.Entry(roo,insertbackground='blue', highlightthickness =2)
'''
entry_TimeLog1=tk.Entry(roo,insertbackground='blue', highlightthickness =2)
entry_TimeLog2=tk.Entry(roo,insertbackground='blue', highlightthickness =2)
'''
entry_config=tk.Entry(roo,insertbackground='blue', highlightthickness =2)
'''
entry.pack()
'''
entry_root.pack()
'''
entry_TimeLog1.pack()
entry_TimeLog2.pack()
'''
entry_config.pack()
'''
button=tkinter.Button(roo,text="进行统计",font=('黑体', 20),bg="green",command=go)
button.pack()
canvas.create_window(60, 50, anchor="nw",width=100, height=30,window=entry)
'''
canvas.create_window(120, 120, width=100, height=20,window=entry_root)
'''
canvas.create_window(60, 130, anchor="nw",width=70, height=25,window=entry_TimeLog1)
canvas.create_window(60, 190, anchor="nw",width=70, height=25,window=entry_TimeLog2)
'''
canvas.create_window(120, 160, width=100, height=20,window=entry_config)
'''
canvas.create_window(720, 350,anchor="ne", width=235, height=60,window=button)
roo.mainloop()
图片转换程序
import base64
def pic2py(picture_name):
"""
将图像文件转换为py文件
:param picture_name:
:return:
"""
open_pic = open("%s" % picture_name, 'rb')
b64str = base64.b64encode(open_pic.read())
open_pic.close()
# 注意这边b64str一定要加上.decode()
write_data = 'img = "%s"' % b64str.decode()
f = open('%s.py' % picture_name.replace('.', '_'), 'w+')
f.write(write_data)
f.close()
if __name__ == '__main__':
pics = ["RIABG.png"]
for i in pics:
pic2py(i)
print("ok")