好友
阅读权限10
听众
最后登录1970-1-1
|
本帖最后由 zohoChou 于 2022-6-20 17:34 编辑
2022.6.20更新。(更新说明在最后)
苦于班级事务繁多,在大学里有一堆的表要填,同时总是有同学没看到消息而不填表,本工具诞生于这样的条件下。根本目的为了知道谁没填表,谁重复填表了。
不仅如此,很多需要平均分配的任务还需要随机抽人(注:因为我们班有几个去教改班的同学,有些事情还算原班级,有些时候就不算,所以要分开处理)
所以说因为自己忍不住而做了一个python,后来因为嫌弃python太丑又做了一个aardio的界面。现开源如下
运行页面:
需要:python(或嵌入式python【抽空开个坑说说嵌入式python以及代码的相关实现(可以自己找知乎的大神分析)】) 【直接下载最下方的文件即可使用】
需要的库:
pandas【核心】(同时因为pandas的原因需要numpy与openpyxl……实在没法缩减体积了)
os(获取程序运行路径、删除旧文件)
sys(接收参数)
random(随机抽人、排序等)
目录架构及解释说明:
__Python比较与抽取.exe:主程序,当然你也可以根据python的传参自行调用,随便你
compare.py:核心文件,主要的运算均在此处
in.xlsx:输入要进行运算的学生姓名(重复无所谓,但不允许出现输入姓名错误的情况)
例:
ref.xlsx:参考用的表格
格式如下:
out.xlsx:输出用的表格(均为姓名)
Python源码:
注:python因为个人习惯的原因写了一大堆传参……
在我看来python就应该专注于运算,别的GUI,判断运行环境啥的还是交给aardio(粘合剂)吧
[Python] 纯文本查看 复制代码 [/font][/size]
[size=4][font=微软雅黑]import os[/font][/size][size=4][font=微软雅黑]import random
import sys
import pandas as pd
def Initialize():
ref_t_lack = pd.read_excel(
os.getcwd() + "\\ref.xlsx",
header=None
)
ref_s_lack = set()
for i in range(len(ref_t_lack)):
ref_s_lack.add(ref_t_lack.iloc[i][0])
ref_s_all = ref_s_lack.copy()
for i in ["AAA", "BBB", "CCC", "DDD", "EEE"]:
ref_s_all.add(i)
in_t = pd.read_excel(os.getcwd() + "\\in.xlsx", header=None)
in_s = set()
for i in range(len(in_t)):
in_s.add(in_t.iloc[i][0])
try:
os.remove(os.getcwd() + "\\out.xlsx")
except:
pass
out_t = pd.DataFrame()
return ref_s_lack, ref_t_lack, ref_s_all, in_t, in_s, out_t
def filter(mode: int,
ref_s_lack: set,
ref_t_lack: pd.DataFrame,
ref_s_all: set,
in_t: pd.DataFrame,
in_s: set,
out_t: pd.DataFrame,
num_pick: int):
re = in_t.duplicated()
for i in range(len(re)):
temp = re.iloc[i]
if(temp == True):
print(in_t.iloc[i][0] + "重复")
if(i == (len(re) - 1)):
print("查重已完成", end="\n\n")
result_lack = ref_s_lack - in_s
result_all = ref_s_all - in_s
if (mode == 0): # 查人除教改班
out_t = pd.concat([out_t, pd.Series(list(result_lack))],
axis=0, ignore_index=True)
print("除教改查人完毕")
elif (mode == 1): # 查人全体
out_t = pd.concat([out_t, pd.Series(list(result_all))],
axis=0, ignore_index=True)
print("全体查人完毕")
if (mode == 20): # 混排除教改班(剩)
temp = list(result_lack)
random.shuffle(temp)
temp = pd.DataFrame(temp)
out_t = pd.concat([out_t, temp], axis=0, ignore_index=True)
print("剩下的同学混排完毕(除教改)")
elif (mode == 21): # 混排全体(剩)
temp = list(result_all)
random.shuffle(temp)
temp = pd.DataFrame(temp)
out_t = pd.concat([out_t, temp], axis=0, ignore_index=True)
print("剩下的同学混排完毕(全体)")
if (mode == 30): # 混排输入(全)
temp = list(in_s)
random.shuffle(temp)
temp = pd.DataFrame(temp)
out_t = pd.concat([out_t, temp], axis=0, ignore_index=True)
print("输入名单混排完毕")
elif (mode == 31): # 混排全体(除教改)(全)
temp = list(ref_s_lack)
random.shuffle(temp)
temp = pd.DataFrame(temp)
out_t = pd.concat([out_t, temp], axis=0, ignore_index=True)
print("全体混排完毕(除教改)")
elif (mode == 32): # 混排全体(全)(全)
temp = list(ref_s_all)
random.shuffle(temp)
temp = pd.DataFrame(temp)
out_t = pd.concat([out_t, temp], axis=0, ignore_index=True)
print("全体混排完毕(含教改)")
if (mode == 40): # 随机抽人(除教改)
out_t = pd.concat([out_t, pd.DataFrame(random.sample(list(ref_s_lack), k=num_pick))],
axis=0, ignore_index=True)
print("随机抽人(除教改)已完成,共抽取{}人".format(num_pick))
elif (mode == 41): # 随机抽人(全)
out_t = pd.concat([out_t, pd.DataFrame(random.sample(list(ref_s_all), k=num_pick))],
axis=0, ignore_index=True)
print("随机抽人(全)已完成,共抽取{}人".format(num_pick))
elif (mode == 42): # 随机抽人(男)(除教改)
temp_list = []
for i in range(len(ref_t_lack)):
if (ref_t_lack.iloc[i][1] == "男"):
temp_list.append(ref_t_lack.iloc[i][0])
out_t = pd.concat([out_t, pd.DataFrame(random.sample(temp_list, k=num_pick))],
axis=0, ignore_index=True)
print("随机抽人(男)(除教改)已完成,共抽取{}人".format(num_pick))
elif (mode == 43): # 随机抽人(女)(除教改)
temp_list = []
for i in range(len(ref_t_lack)):
if (ref_t_lack.iloc[i][1] == "女"):
temp_list.append(ref_t_lack.iloc[i][0])
out_t = pd.concat([out_t, pd.DataFrame(random.sample(temp_list, k=num_pick))],
axis=0, ignore_index=True)
print("随机抽人(女)(除教改)已完成,共抽取{}人".format(num_pick))
out_t.to_excel(os.getcwd() + "\\out.xlsx", header=None, index=False)
mode = int(sys.argv[1])
try:
num_pick = int(sys.argv[2])
except:
num_pick = pd.NA
ref_s_lack, ref_t_lack, ref_s_all, in_t, in_s, out_t = Initialize()
filter(mode, ref_s_lack, ref_t_lack, ref_s_all, in_t, in_s, out_t, num_pick)
aardio源码:
注:
因为我在aardio的资源文件中写了相关的班级信息,故只放出main.aardio的源码,目录架构请自行参考图中所示。
最后的程序为不附带任何资源文件的纯程序(即纯传参GUI界面)
更新(说明):
其实aardio的传参完全无需如此复杂,其主要原因在于我为了在程序传参到python执行时主程序页面不会卡住而专门使用了多线程进行处理。如果不在意aardio的程序执行界面卡住的话可以直接这么写
mainForm.button_40.oncommand = function(id,event){
mainForm.button_40.disabled = true
io.open()
if(mainForm.edit.text == "" or tonumber(mainForm.edit.text) > 45){
win.msgboxErr("Num > 45 Or Num == Null")
mainForm.button_40.disabled = false
} else {
io.open()
prcs = process(python_path,io.joinpath(io._exedir,"\compare.py"),"40",mainForm.edit.text)
while(prcs.wait() == true){
mainForm.button_40.disabled = false
if(win.msgbox("是否打开输出","Notice",4,mainForm.hwnd) == 6){
process("explorer.exe",io.joinpath(io._exedir,"out.xlsx"))
}
io.close()
break
}
}
}```
更新日志:
1.修复while逻辑bug
2.修复tonumber()bug
3.增加判定逻辑
4.修改文件信息
5.增加更新日志
6.使用7z格式压缩文件体积
注,实际发布时未带ref文件。
下为main.aardio
import win.ui
import fsys
import process
/*DSG{{*/
mainForm = win.form(cls="CMP_FORM";text="Python比较与抽取";right=455;bottom=415;border="dialog frame";max=false)
mainForm.add(
button_0={cls="button";text="查人(除教改)";left=32;top=76;right=216;bottom=120;font=LOGFONT(h=-19;name='梦源黑体 CN W9';weight=420);z=2};
button_1={cls="button";text="查人(全)";left=244;top=76;right=428;bottom=120;font=LOGFONT(h=-19;name='梦源黑体 CN W9';weight=420);z=3};
button_20={cls="button";text="剩 混排除教改班";left=32;top=136;right=216;bottom=180;font=LOGFONT(h=-19;name='梦源黑体 CN W9';weight=420);z=4};
button_21={cls="button";text="剩 混排除全";left=244;top=136;right=428;bottom=180;font=LOGFONT(h=-19;name='梦源黑体 CN W9';weight=420);z=5};
button_30={cls="button";text="混排输入";left=20;top=196;right=124;bottom=240;font=LOGFONT(h=-19;name='梦源黑体 CN W9';weight=420);z=6};
button_31={cls="button";text="混排全体(除教改)";left=136;top=196;right=320;bottom=240;font=LOGFONT(h=-19;name='梦源黑体 CN W9';weight=420);z=7};
button_32={cls="button";text="混排全体";left=332;top=196;right=436;bottom=240;font=LOGFONT(h=-19;name='梦源黑体 CN W9';weight=420);z=8};
button_40={cls="button";text="随机抽人(除教改)";left=28;top=276;right=232;bottom=320;font=LOGFONT(h=-19;name='梦源黑体 CN W9';weight=420);z=10};
button_41={cls="button";text="随机全体";left=260;top=276;right=352;bottom=320;font=LOGFONT(h=-19;name='梦源黑体 CN W9';weight=420);z=11};
button_42={cls="button";text="随机抽人男(除教改)";left=12;top=332;right=220;bottom=376;font=LOGFONT(h=-19;name='梦源黑体 CN W9';weight=420);z=12};
button_43={cls="button";text="随机抽人女(除教改)";left=236;top=332;right=444;bottom=376;font=LOGFONT(h=-19;name='梦源黑体 CN W9';weight=420);z=13};
button_in={cls="button";text="输入数据";left=140;top=16;right=324;bottom=60;font=LOGFONT(h=-19;name='梦源黑体 CN W9';weight=420);z=14};
edit={cls="edit";left=376;top=280;right=428;bottom=316;align="center";autohscroll=false;autovscroll=false;edge=1;font=LOGFONT(h=-21;name='梦源黑体 CN W9';weight=420);multiline=1;num=1;z=9};
groupbox={cls="groupbox";text="随机抽取";left=8;top=250;right=448;bottom=382;edge=1;font=LOGFONT(h=-14;name='梦源黑体 CN W9';weight=420);z=1};
static={cls="static";text="History";left=386;top=384;right=456;bottom=416;align="center";center=1;font=LOGFONT(h=-19;name='梦源黑体 CN W9';weight=420);notify=1;transparent=1;z=15};
static2={cls="static";text="请勿关闭黑色窗口";left=0;top=384;right=168;bottom=416;align="center";center=1;font=LOGFONT(h=-19;name='梦源黑体 CN W9';weight=420);transparent=1;z=16}
)
/*}}*/
if((not io.exist(io.joinpath(io._exedir,"python.exe"))) and (io.exist(io.joinpath(io._exedir,"pythonw.exe")))){
win.msgboxErr("Python Not Found","Error")
mainForm.close()
} else {
if(io.exist(io.joinpath(io._exedir,"pythonw.exe"))){
python_path = io.joinpath(io._exedir,"python.exe")
} else {
python_path = "python.exe"
}
python_path = "python.exe"
if(not io.exist(io.joinpath(io._exedir,"in.xlsx"),4)){
string.save(io.joinpath(io._exedir,"in.xlsx"),$"\res\in.xlsx")
}
if(io.exist(io.joinpath(io._exedir,"ref.xlsx"),4)){
fsys.delete(io.joinpath(io._exedir,"ref.xlsx"))
string.save(io.joinpath(io._exedir,"ref.xlsx"),$"\res\ref.xlsx")
} else {
string.save(io.joinpath(io._exedir,"ref.xlsx"),$"\res\ref.xlsx")
}
if(io.exist(io.joinpath(io._exedir,"out.xlsx"),4)){
fsys.delete(io.joinpath(io._exedir,"out.xlsx"))
string.save(io.joinpath(io._exedir,"out.xlsx"),$"\res\out.xlsx")
} else {
string.save(io.joinpath(io._exedir,"out.xlsx"),$"\res\out.xlsx")
}
if(not io.exist(io.joinpath(io._exedir,"compare.py"),4)){
string.save(io.joinpath(io._exedir,"compare.py"),$"\res\compare.py")
}
io.open()
mainForm.show()
}
mainForm.button_in.oncommand = function(id,event){
process("explorer.exe",io.joinpath(io._exedir,"in.xlsx"))
}
open = function(){
process("explorer.exe",io.joinpath(io._exedir,"out.xlsx"))
}
mainForm.button_0.oncommand = function(id,event){
mainForm.button_0.disabled = true
thread.invoke(
function(mainForm,python_path){
io.open()
import process
import win
prcs = process(python_path,io.joinpath(io._exedir,"\compare.py"),"0")
while(prcs.wait() == true){
mainForm.button_0.disabled = false
if(win.msgbox("是否打开输出","Notice",4,mainForm.hwnd) == 6){
process("explorer.exe",io.joinpath(io._exedir,"out.xlsx"))
}
io.close()
break
}
},mainForm,python_path
)
}
mainForm.button_1.oncommand = function(id,event){
mainForm.button_1.disabled = true
thread.invoke(
function(mainForm,python_path){
io.open()
import process
import win
prcs = process(python_path,io.joinpath(io._exedir,"\compare.py"),"1")
while(prcs.wait() == true){
mainForm.button_1.disabled = false
if(win.msgbox("是否打开输出","Notice",4,mainForm.hwnd) == 6){
process("explorer.exe",io.joinpath(io._exedir,"out.xlsx"))
}
io.close()
break
}
},mainForm,python_path
)
}
mainForm.button_20.oncommand = function(id,event){
mainForm.button_20.disabled = true
thread.invoke(
function(mainForm,python_path){
io.open()
import process
import win
prcs = process(python_path,io.joinpath(io._exedir,"\compare.py"),"20")
while(prcs.wait() == true){
mainForm.button_20.disabled = false
if(win.msgbox("是否打开输出","Notice",4,mainForm.hwnd) == 6){
process("explorer.exe",io.joinpath(io._exedir,"out.xlsx"))
}
io.close()
break
}
},mainForm,python_path
)
}
mainForm.button_21.oncommand = function(id,event){
mainForm.button_21.disabled = true
thread.invoke(
function(mainForm,python_path){
io.open()
import process
import win
prcs = process(python_path,io.joinpath(io._exedir,"\compare.py"),"21")
while(prcs.wait() == true){
mainForm.button_21.disabled = false
if(win.msgbox("是否打开输出","Notice",4,mainForm.hwnd) == 6){
process("explorer.exe",io.joinpath(io._exedir,"out.xlsx"))
}
io.close()
break
}
},mainForm,python_path
)
}
mainForm.button_30.oncommand = function(id,event){
mainForm.button_30.disabled = true
thread.invoke(
function(mainForm,python_path){
io.open()
import process
import win
prcs = process(python_path,io.joinpath(io._exedir,"\compare.py"),"30")
while(prcs.wait() == true){
mainForm.button_30.disabled = false
if(win.msgbox("是否打开输出","Notice",4,mainForm.hwnd) == 6){
process("explorer.exe",io.joinpath(io._exedir,"out.xlsx"))
}
io.close()
break
}
},mainForm,python_path
)
}
mainForm.button_31.oncommand = function(id,event){
mainForm.button_31.disabled = true
thread.invoke(
function(mainForm,python_path){
io.open()
import process
import win
prcs = process(python_path,io.joinpath(io._exedir,"\compare.py"),"31")
while(prcs.wait() == true){
mainForm.button_31.disabled = false
if(win.msgbox("是否打开输出","Notice",4,mainForm.hwnd) == 6){
process("explorer.exe",io.joinpath(io._exedir,"out.xlsx"))
}
io.close()
break
}
},mainForm,python_path
)
}
mainForm.button_32.oncommand = function(id,event){
mainForm.button_32.disabled = true
thread.invoke(
function(mainForm,python_path){
io.open()
import process
import win
prcs = process(python_path,io.joinpath(io._exedir,"\compare.py"),"32")
while(prcs.wait() == true){
mainForm.button_32.disabled = false
if(win.msgbox("是否打开输出","Notice",4,mainForm.hwnd) == 6){
process("explorer.exe",io.joinpath(io._exedir,"out.xlsx"))
}
io.close()
break
}
},mainForm,python_path
)
}
mainForm.button_40.oncommand = function(id,event){
mainForm.button_40.disabled = true
io.open()
if(mainForm.edit.text == "" or tonumber(mainForm.edit.text) > 45){
win.msgboxErr("Num > 45 Or Num == Null")
mainForm.button_40.disabled = false
} else {
thread.invoke(
function(mainForm,python_path){
io.open()
import process
import win
prcs = process(python_path,io.joinpath(io._exedir,"\compare.py"),"40",mainForm.edit.text)
while(prcs.wait() == true){
mainForm.button_40.disabled = false
if(win.msgbox("是否打开输出","Notice",4,mainForm.hwnd) == 6){
process("explorer.exe",io.joinpath(io._exedir,"out.xlsx"))
}
io.close()
break
}
},mainForm,python_path
)
}
}
mainForm.button_41.oncommand = function(id,event){
mainForm.button_41.disabled = true
if(mainForm.edit.text == "" or tonumber(mainForm.edit.text) > 45){
win.msgboxErr("Num > 45 Or Num == Null")
mainForm.button_41.disabled = false
} else {
thread.invoke(
function(mainForm,python_path){
import process
import win
io.open()
prcs = process(python_path,io.joinpath(io._exedir,"\compare.py"),"41",mainForm.edit.text)
while(prcs.wait() == true){
mainForm.button_41.disabled = false
if(win.msgbox("是否打开输出","Notice",4,mainForm.hwnd) == 6){
process("explorer.exe",io.joinpath(io._exedir,"out.xlsx"))
}
io.close()
break
}
},mainForm,python_path
)
}
}
mainForm.button_42.oncommand = function(id,event){
mainForm.button_42.disabled = true
if(mainForm.edit.text == "" or tonumber(mainForm.edit.text) > 25){
win.msgboxErr("Num > 45 Or Num == Null")
mainForm.button_42.disabled = false
} else {
thread.invoke(
function(mainForm,python_path){
import process
import win
io.open()
prcs = process(python_path,io.joinpath(io._exedir,"\compare.py"),"42",mainForm.edit.text)
while(prcs.wait() == true){
mainForm.button_42.disabled = false
if(win.msgbox("是否打开输出","Notice",4,mainForm.hwnd) == 6){
process("explorer.exe",io.joinpath(io._exedir,"out.xlsx"))
}
io.close()
break
}
},mainForm,python_path
)
}
}
mainForm.button_43.oncommand = function(id,event){
mainForm.button_43.disabled = true
if(mainForm.edit.text == "" or tonumber(mainForm.edit.text) > 20){
win.msgboxErr("Num > 45 Or Num == Null")
mainForm.button_43.disabled = false
} else {
thread.invoke(
function(mainForm,python_path){
import process
import win
io.open()
prcs = process(python_path,io.joinpath(io._exedir,"\compare.py"),"43",mainForm.edit.text)
while(prcs.wait() == true){
mainForm.button_43.disabled = false
if(win.msgbox("是否打开输出","Notice",4,mainForm.hwnd) == 6){
process("explorer.exe",io.joinpath(io._exedir,"out.xlsx"))
}
io.close()
break
}
},mainForm,python_path
)
}
}
mainForm.static.oncommand = function(id,event){
var frmChild = mainForm.loadForm("\dlg\history.aardio")
frmChild.show()
}
return win.loopMessage()
下为history.aardio
import win.ui;
/*DSG{{*/
var winform = win.form(cls="H_FORM";text="History";right=315;bottom=433;border="dialog frame";exmode="toolwindow";max=false;min=false)
winform.add(
edit={cls="edit";left=8;top=14;right=306;bottom=420;edge=1;font=LOGFONT(h=-16;name='梦源黑体 CN W9';weight=420);multiline=1;readonly=1;vscroll=1;z=1}
)
/*}}*/
mainForm.show(false)
winform.edit.text = /*更新日志:
2022.06.03 第一版(0.0.0.32)
1.aardio初具雏形
2.完善python
2022.06.20 第二版(0.0.2.16)
更新内容:
1.修复while逻辑bug
2.修复tonumber()bug
3.增加判定逻辑
4.修改文件信息
5.增加更新日志
注:aardio闭源,python开源*/
winform.beforeDestroy = function(){
mainForm.show(true)
}
winform.show();
win.loopMessage();
return winform;
请自备ref.xlsx文件!!!
白嫖链接:(坚果云网盘)
https://www.jianguoyun.com/p/DVRCRUsQoKLBChiFq8gEIAA (访问密码:E5eyoA)
土豪链接:(空文件)
新建文本文档.txt
(76 Bytes, 下载次数: 20)
|
免费评分
-
查看全部评分
|