import tkinter as tk
from tkinter import messagebox
import pandas as pd
import random
# 定义Kano模型的评分标准
kano_scores = {
'魅力型 (A)': {'positive': [5], 'negative': [1, 2, 3, 4]},
'期望型 (O)': {'positive': [4, 5], 'negative': [1, 2, 3]},
'必备型 (M)': {'positive': [3, 4, 5], 'negative': [1, 2]},
'无差异型 (I)': {'positive': [2, 3, 4, 5], 'negative': [1, 2, 3, 4, 5]},
'反向型 (R)': {'positive': [1, 2], 'negative': [3, 4, 5]},
'可疑型 (Q)': {'positive': [1, 2, 3, 4, 5], 'negative': [1, 2, 3, 4, 5]}
}
def generate_kano_data(num_records, num_questions, classifications):
data = {}
for i in range(1, num_questions + 1):
question_key_positive = f"问题 {i} 正向"
question_key_negative = f"问题 {i} 反向"
# 根据分类选择对应的评分
if i in classifications['魅力型 (A)']:
positive_scores = kano_scores['魅力型 (A)']['positive']
negative_scores = kano_scores['魅力型 (A)']['negative']
elif i in classifications['期望型 (O)']:
positive_scores = kano_scores['期望型 (O)']['positive']
negative_scores = kano_scores['期望型 (O)']['negative']
elif i in classifications['必备型 (M)']:
positive_scores = kano_scores['必备型 (M)']['positive']
negative_scores = kano_scores['必备型 (M)']['negative']
elif i in classifications['无差异型 (I)']:
positive_scores = kano_scores['无差异型 (I)']['positive']
negative_scores = kano_scores['无差异型 (I)']['negative']
elif i in classifications['反向型 (R)']:
positive_scores = kano_scores['反向型 (R)']['positive']
negative_scores = kano_scores['反向型 (R)']['negative']
else:
positive_scores = kano_scores['可疑型 (Q)']['positive']
negative_scores = kano_scores['可疑型 (Q)']['negative']
# 生成数据
data[question_key_positive] = [random.choice(positive_scores) for _ in range(num_records)]
data[question_key_negative] = [random.choice(negative_scores) for _ in range(num_records)]
return pd.DataFrame(data)
def save_to_excel(df):
try:
filename = "kano_model_data.xlsx"
df.to_excel(filename, index=False)
messagebox.showinfo("成功", f"数据已保存到 {filename}")
except Exception as e:
messagebox.showerror("错误", f"导出数据时发生错误: {str(e)}")
def on_generate_click():
try:
num_records = int(entry_num_records.get())
num_questions = int(entry_num_questions.get())
except ValueError:
messagebox.showerror("错误", "请输入有效的数字。")
return
# 初始化classifications字典,确保包含所有Kano分类的键
classifications = {
'魅力型 (A)': [],
'期望型 (O)': [],
'必备型 (M)': [],
'无差异型 (I)': [],
'反向型 (R)': [],
'可疑型 (Q)': []
}
for label, entry in kano_entries.items():
values = entry.get().strip()
if values:
classifications[label] = [int(v.strip()) for v in values.split(',')]
else:
classifications[label] = []
# 调试信息:打印classifications字典
print("Classifications:", classifications)
df = generate_kano_data(num_records, num_questions, classifications)
global generated_df
generated_df = df # 全局存储生成的数据
messagebox.showinfo("成功", "数据生成成功。")
def on_export_click():
if 'generated_df' in globals():
save_to_excel(generated_df)
else:
messagebox.showwarning("警告", "没有数据可以导出。请先生成数据。")
# 创建主窗口
root = tk.Tk()
root.title("Kano模型数据生成器")
# 输入框 - 生成多少条数据
label_num_records = tk.Label(root, text="生成数据条数:")
label_num_records.pack()
entry_num_records = tk.Entry(root)
entry_num_records.pack()
# 输入框 - 生成多少个题目
label_num_questions = tk.Label(root, text="生成题目数量:")
label_num_questions.pack()
entry_num_questions = tk.Entry(root)
entry_num_questions.pack()
# Kano分类输入框
kano_labels = ["魅力型 (A):", "期望型 (O):", "必备型 (M):", "无差异型 (I):", "反向型 (R):", "可疑型 (Q):"]
kano_entries = {}
for label in kano_labels:
kano_label = tk.Label(root, text=label)
kano_label.pack()
kano_entry = tk.Entry(root)
kano_entry.pack()
kano_entries[label] = kano_entry
# 生成按钮
generate_button = tk.Button(root, text="生成数据", command=on_generate_click)
generate_button.pack()
# 导出按钮
export_button = tk.Button(root, text="导出到Excel", command=on_export_click)
export_button.pack()
# 运行主循环
root.mainloop()
weixin_47089593
- 粉丝: 0
- 资源: 1
最新资源
- SEW Interface.xlsx 智能设备的相关参数及调试方法\SEW 变频器IO接口说明
- python实现的将 高德地图api内的省市区数据转换为指定表结构的sql语句
- 麒麟系统下Veyon远程控制软件的安装与配置指南
- 滚床SEW MOVIFIT- FC变频器配置手册.docx
- 免费的电脑时钟,副屏显示时间,可以设置字体大小和颜色
- C++语言实现的简单协程库.zip
- 升降机SEW MOVIDRIVE 变频器配置手册.docx
- 中文版infineon比例阀专用控制芯片TLE82453器件手册
- 移载机SEW MOVIDRIVE 变频器配置手册.docx
- C++11语言级别实现的简易数据库连接池.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈