import copy
import time
from tkinter import END
import numpy as np
import re


def read_file(file_path):
    """
    :param file_path: 文件位置
    :return: 文件内容列表
    """
    file = open(file_path, 'r')
    all_lines = file.readlines()
    dataset = []
    for i in range(len(all_lines)):
        if not all_lines[i].isspace():
            for x in re.split(',', all_lines[i]):
                dataset.append(float(x))
    return dataset


def sort(src):
    src = np.array(src)
    src = src.argsort()
    src = src.argsort() + 1
    return src.tolist()


class OPRMiner:
    """
    OPR算法
    """
    rule_num = 0  # 规则数量
    rule_left = []  # 规则前件
    rule_right = []  # 规则后件
    rule_leftnum = 0  # 规则前件支持度
    rule_rightnum = 0  # 规则后件支持度
    frequent_num = 0  # 总的频繁模式数量
    cd_num = 2  # 候选模式数量
    allrulenum = 0
    Z = []  # 存放本次生成的末尾数组
    Z2 = []
    Cd = []  # 存放本次生成的模式
    Cd2 = []
    L = []  # 存放每次生成的频繁模式
    S = []  # 存放序列
    P = []  # 存放末位的数组

    fre_num = 0

    # 新增：统计不同长度频繁模式的数量
    pattern_length_stats = {}  # 存储每个长度对应的频繁模式数量

    output_filepath = ""
    output_filename = "OPR-Miner-Output.txt"
    file_path = ""
    minconf = 0.4
    minsup = 12

    def __init__(self, file_path, output_filepath='',
                 min_conf=0.4, min_sup=12):
        """
        :param file_path: 输入文件位置
        :param output_filepath: 输出文件夹位置
        :param min_conf: 最小置信度
        :param min_sup: 最小支持度
        """
        self.S = read_file(file_path)
        self.output_filepath = output_filepath
        self.minconf = min_conf
        self.minsup = min_sup
        self.Cd = []
        self.Cd2 = []
        self.Z = []
        self.Z2 = []
        # 初始化长度统计字典
        self.pattern_length_stats = {}
        output_file = open(self.output_filepath + "/" + self.output_filename, 'w')
        output_file.close()

    def grow_BaseP1(self, Ld, L):
        p, q = copy.deepcopy(L), copy.deepcopy(Ld)  # 深拷贝L和Ld
        i, j = 1, 1
        self.Z = []
        while True:
            if i < len(p) and j < len(q):
                if q[j] == p[i] + 1:
                    self.Z.append(copy.deepcopy(q[j]))
                    j = j + 1
                    i = i + 1
                elif p[i] < q[j]:
                    i = i + 1
                else:
                    j = j + 1
            else:
                break
        L[0] = L[0] - len(self.Z)
        Ld[0] = Ld[0] - len(self.Z)  # len(self.Z)是支持度
        self.judge_fre(len(self.Z), self.Cd, self.Z)

    def grow_BaseP2(self, slen, Ld, L):
        first, fri, i, j = 0, 0, 1, 1
        p, q = copy.deepcopy(L), copy.deepcopy(Ld)
        self.Z = []
        self.Z2 = []
        while True:
            if i < len(p) and j < len(q):
                if q[j] == p[i] + 1:
                    first = q[j]
                    fri = first - slen
                    if self.S[first] > self.S[fri]:
                        self.Z.append(copy.deepcopy(q[j]))
                    elif self.S[first] != self.S[fri]:
                        self.Z2.append(copy.deepcopy(q[j]))
                    j = j + 1
                    i = i + 1
                elif p[i] < q[j]:
                    i = i + 1
                else:
                    j = j + 1
            else:
                break
        L[0] = L[0] - len(self.Z) - len(self.Z2)
        Ld[0] = Ld[0] - len(self.Z) - len(self.Z2)
        self.judge_fre(len(self.Z), self.Cd, self.Z)
        self.judge_fre(len(self.Z2), self.Cd2, self.Z2)

    # 模式融合
    def generate_fre(self):
        Lb = []
        slen = len(self.L[0])  # 模式长度

        fre = copy.deepcopy(self.L)
        self.L = []
        fre_number = copy.deepcopy(self.fre_num)
        self.fre_num = 0

        pos = copy.deepcopy(self.P)

        self.P = []

        for x in range(fre_number):
            Lb.append([])

        self.Cd = []
        self.Cd2 = []
        for y in range(slen + 1):
            self.Cd.append(0)
            self.Cd2.append(0)

        for s in range(fre_number):
            Lb[s].append(len(pos[s]))
            for d in range(len(pos[s])):
                Lb[s].append(copy.deepcopy(pos[s][d]))

        for i in range(fre_number):
            Q = copy.deepcopy(fre[i])  # 求后缀
            Q = Q[1:]
            q = sort(Q)
            L = []
            size = len(pos[i])
            self.rule_left = fre[i]
            self.rule_leftnum = size
            L.append(size)
            for k in range(size):
                L.append(copy.deepcopy(pos[i][k]))

            for j in range(fre_number):
                if L[0] >= self.minsup and Lb[j][0] >= self.minsup:
                    R = copy.deepcopy(fre[j])
                    R.pop()  # 求前缀
                    r = sort(R)
                    if q == r:
                        if fre[i][0] == fre[j][slen - 1]:  # 最前最后位置相等，拼接成两个模式
                            self.Cd[0] = fre[i][0]
                            self.Cd2[0] = fre[i][0] + 1
                            self.Cd[slen] = fre[i][0] + 1
                            self.Cd2[slen] = fre[i][0]
                            for t in range(1, slen):
                                if fre[i][t] > fre[j][slen - 1]:  # 中间位置增长
                                    self.Cd[t] = fre[i][t] + 1
                                    self.Cd2[t] = fre[i][t] + 1
                                else:
                                    self.Cd[t] = fre[i][t]
                                    self.Cd2[t] = fre[i][t]
                            self.cd_num = self.cd_num + 2
                            self.grow_BaseP2(len(self.Cd) - 1, Lb[j], L)
                        elif fre[i][0] < fre[j][slen - 1]:  # 第一个位置比最后一个位置小
                            self.Cd[0] = fre[i][0]  # 小的不变
                            self.Cd[slen] = fre[j][slen - 1] + 1  # 大的加一
                            for t in range(1, slen):
                                if fre[i][t] > fre[j][slen - 1]:
                                    self.Cd[t] = fre[i][t] + 1  # 中间位置增长
                                else:
                                    self.Cd[t] = fre[i][t]
                            self.cd_num = self.cd_num + 1
                            self.grow_BaseP1(Lb[j], L)
                        else:
                            self.Cd[0] = fre[i][0] + 1  # 大的加一
                            self.Cd[slen] = fre[j][slen - 1]  # 小的不变
                            for t in range(slen - 1):
                                if fre[j][t] > fre[i][0]:
                                    self.Cd[t + 1] = fre[j][t] + 1  # 中间位置增长
                                else:
                                    self.Cd[t + 1] = fre[j][t]
                            self.cd_num = self.cd_num + 1
                            self.grow_BaseP1(Lb[j], L)
        Lb.clear()
        pos.clear()
        fre.clear()

    def recommend(self, sup_begin, sup_end, Cd_begin, Cd_end):
        # recommend 函数的作用是生成和输出满足最小置信度要求的模式规则，并将这些规则写入输出文件。
        # 函数的核心逻辑是判断给定的规则是否满足最小置信度要求，如果满足，则将规则写入文件并增加规则数量计数器。
        if sup_end >= sup_begin * self.minconf:
            output_file = open(self.output_filepath + "/" + self.output_filename, 'a')
            strArr = "模式"
            for i in Cd_begin:
                strArr = strArr + str(i) + ","
            strArr = strArr + "=>"
            for j in Cd_end:
                strArr = strArr + str(j) + ","
            strArr = strArr + "置信度为：" + str(sup_end / sup_begin)
            output_file.write(strArr + "\n")
            output_file.close()
            self.rule_num = self.rule_num + 1

    def judge_fre(self, sup_num, Cd, Z):  # 频繁模式挖掘
        if sup_num >= self.minsup:
            self.P.append(copy.deepcopy(Z))
            self.L.append(copy.deepcopy(Cd))

            # 新增：统计频繁模式长度
            pattern_length = len(Cd)
            if pattern_length in self.pattern_length_stats:
                self.pattern_length_stats[pattern_length] += 1
            else:
                self.pattern_length_stats[pattern_length] = 1

            output_file = open(self.output_filepath + "/" + self.output_filename, 'a')
            strArr = "频繁模式："
            for i in Cd:
                strArr = strArr + str(i) + ","
            strArr = strArr + " 支持度为：" + str(sup_num)
            output_file.write(strArr + "\n")
            output_file.close()

            self.rule_right = Cd
            self.rule_rightnum = sup_num
            self.recommend(self.rule_leftnum, self.rule_rightnum, self.rule_left, self.rule_right)

            self.allrulenum = self.allrulenum + 1

            self.frequent_num = self.frequent_num + 1
            self.fre_num = self.fre_num + 1

    def judge_fre2(self, sup_num, Cd, Z):
        if sup_num >= self.minsup:
            self.P.append(copy.deepcopy(Z))
            self.L.append(copy.deepcopy(Cd))

            # 新增：统计频繁模式长度
            pattern_length = len(Cd)
            if pattern_length in self.pattern_length_stats:
                self.pattern_length_stats[pattern_length] += 1
            else:
                self.pattern_length_stats[pattern_length] = 1

            output_file = open(self.output_filepath + "/" + self.output_filename, 'a')
            strArr = "频繁模式："
            for i in Cd:
                strArr = strArr + str(i) + ","
            strArr = strArr + " 支持度为：" + str(sup_num)
            output_file.write(strArr + "\n")
            output_file.close()

            self.frequent_num = self.frequent_num + 1
            self.fre_num = self.fre_num + 1

    def find(self):
        i, j = 0, 1
        self.Cd.append(1)
        self.Cd.append(2)
        self.Cd2.append(2)
        self.Cd2.append(1)
        while j < len(self.S):
            if self.S[j] > self.S[i]:
                self.Z.append(j)
            elif self.S[j] != self.S[i]:
                self.Z2.append(j)
            i = i + 1
            j = j + 1
        self.judge_fre2(len(self.Z), self.Cd, self.Z)
        self.Cd = []
        self.judge_fre2(len(self.Z2), self.Cd2, self.Z2)
        self.Cd2 = []

    def output_pattern_length_stats(self, text):
        """
        新增方法：输出不同长度频繁模式的统计信息
        """
        text.insert(END, "\n=== 频繁模式长度统计 ===\n")

        # 将统计信息写入输出文件
        output_file = open(self.output_filepath + "/" + self.output_filename, 'a')
        output_file.write("\n=== 频繁模式长度统计 ===\n")

        # 按长度排序输出
        sorted_lengths = sorted(self.pattern_length_stats.keys())
        for length in sorted_lengths:
            count = self.pattern_length_stats[length]
            stats_info = f"长度为{length}的频繁模式数量为：{count}\n"
            text.insert(END, stats_info)
            output_file.write(stats_info)

        output_file.write("========================\n")
        output_file.close()

    def solve(self, text):
        """
        :param text: 文本框控件，用于回调信息返回
        :return: None
        """
        text.insert(END, "OPR_Miner算法开始运行，请等待...\n")
        text.insert(END, "算法参数：\n")
        text.insert(END,
                    " minconf:" + str(self.minconf) + " minsup:" + str(self.minsup) + "\n")

        begin_time = time.time()

        self.find()
        while self.fre_num:
            self.generate_fre()

        end_time = time.time()
        time_consuming = end_time - begin_time
        text.insert(END, "OPR_Miner算法运行完毕。\n")
        text.insert(END, "The time-consuming:" + str(time_consuming * 1000) + "ms" + "\n")
        text.insert(END, "The number of frequent patterns:" + str(self.frequent_num) + "\n")
        text.insert(END, "The number of candidate patterns:" + str(self.cd_num) + "\n")
        text.insert(END, "The number of rule number:" + str(self.rule_num) + "\n")

        # 新增：输出频繁模式长度统计
        self.output_pattern_length_stats(text)

        text.insert(END, "挖掘结果已写入：" + self.output_filepath + "/" + self.output_filename + "\n")


class IOPR:
    def __init__(self):
        self.datasets = {}  # 存储数据集
        self.results = {}


import tkinter as tk

import os
import tkinter as tk


def main(file_path, output_filepath, min_conf=0.4, min_sup=12):
    # 确保输出目录存在
    if not os.path.exists(output_filepath):
        os.makedirs(output_filepath)

    # 创建主窗口
    root = tk.Tk()
    root.title("OPR Miner 算法")

    # 创建用于显示输出的文本控件
    text = tk.Text(root, wrap='word', width=100, height=30)
    text.pack(expand=True, fill='both')

    # 实例化并运行 OPRMiner
    miner = OPRMiner(file_path=file_path, output_filepath=output_filepath, min_conf=min_conf, min_sup=min_sup)
    miner.solve(text)

    # 启动 tkinter 主循环
    root.mainloop()


# 示例用法
if __name__ == "__main__":
    file_path = "./datasets_ETT_afterProcess.txt"  # 替换为你的输入文件路径
    output_filepath = "OPR-output-ETT-50"  # 替换为你的输出目录路径
    min_conf = 0.4
    min_sup = 50

    main(file_path, output_filepath, min_conf, min_sup)






# import copy
# import time
# from tkinter import END
# import numpy as np
# import re
#
#
#
# def read_file(file_path):
#     """
#     :param file_path: 文件位置
#     :return: 文件内容列表
#     """
#     file = open(file_path, 'r')
#     all_lines = file.readlines()
#     dataset = []
#     for i in range(len(all_lines)):
#         if not all_lines[i].isspace():
#             for x in re.split(',', all_lines[i]):
#                 dataset.append(float(x))
#     return dataset
#
#
# def sort(src):
#     src = np.array(src)
#     src = src.argsort()
#     src = src.argsort() + 1
#     return src.tolist()
#
#
# class OPRMiner:
#     """
#     OPR算法
#     """
#     rule_num = 0  # 规则数量
#     rule_left = []  # 规则前件
#     rule_right = []  # 规则后件
#     rule_leftnum = 0  # 规则前件支持度
#     rule_rightnum = 0  # 规则后件支持度
#     frequent_num = 0  # 总的频繁模式数量
#     cd_num = 2  # 候选模式数量
#     allrulenum = 0
#     Z = []  # 存放本次生成的末尾数组
#     Z2 = []
#     Cd = []  # 存放本次生成的模式
#     Cd2 = []
#     L = []  # 存放每次生成的频繁模式
#     S = []  # 存放序列
#     P = []  # 存放末位的数组
#
#     fre_num = 0
#
#     output_filepath = ""
#     output_filename = "OPR-Miner-Output.txt"
#     file_path = ""
#     minconf = 0.4
#     minsup = 12
#
#     def __init__(self, file_path, output_filepath='',
#                  min_conf=0.4, min_sup=12):
#         """
#         :param file_path: 输入文件位置
#         :param output_filepath: 输出文件夹位置
#         :param min_conf: 最小置信度
#         :param min_sup: 最小支持度
#         """
#         self.S = read_file(file_path)
#         self.output_filepath = output_filepath
#         self.minconf = min_conf
#         self.minsup = min_sup
#         self.Cd.clear()
#         self.Cd2.clear()
#         self.Z.clear()
#         self.Z2.clear()
#         output_file = open(self.output_filepath + "/" + self.output_filename, 'w')
#         output_file.close()
#
#     def grow_BaseP1(self, Ld, L):
#         p, q = copy.deepcopy(L), copy.deepcopy(Ld)#深拷贝L和Ld
#         i, j = 1, 1
#         self.Z.clear()
#         while True:
#             if i < len(p) and j < len(q):
#                 if q[j] == p[i] + 1:
#                     self.Z.append(copy.deepcopy(q[j]))
#                     j = j + 1
#                     i = i + 1
#                 elif p[i] < q[j]:
#                     i = i + 1
#                 else:
#                     j = j + 1
#             else:
#                 break
#         L[0] = L[0] - len(self.Z)
#         Ld[0] = Ld[0] - len(self.Z)#len(self.Z)是支持度
#         self.judge_fre(len(self.Z), self.Cd, self.Z)
#
#
#     def grow_BaseP2(self, slen, Ld, L):
#         first, fri, i, j = 0, 0, 1, 1
#         p, q = copy.deepcopy(L), copy.deepcopy(Ld)
#         self.Z.clear()
#         self.Z2.clear()
#         while True:
#             if i < len(p) and j < len(q):
#                 if q[j] == p[i] + 1:
#                     first = q[j]
#                     fri = first - slen
#                     if self.S[first] > self.S[fri]:
#                         self.Z.append(copy.deepcopy(q[j]))
#                     elif self.S[first] != self.S[fri]:
#                         self.Z2.append(copy.deepcopy(q[j]))
#                     j = j + 1
#                     i = i + 1
#                 elif p[i] < q[j]:
#                     i = i + 1
#                 else:
#                     j = j + 1
#             else:
#                 break
#         L[0] = L[0] - len(self.Z) - len(self.Z2)
#         Ld[0] = Ld[0] - len(self.Z) - len(self.Z2)
#         self.judge_fre(len(self.Z), self.Cd, self.Z)
#         self.judge_fre(len(self.Z2), self.Cd2, self.Z2)
#
#
#     # 模式融合
#     def generate_fre(self):
#         Lb = []
#         slen = len(self.L[0])  # 模式长度
#
#         fre = copy.deepcopy(self.L)
#         self.L.clear()
#         fre_number = copy.deepcopy(self.fre_num)
#         self.fre_num = 0
#
#         pos = copy.deepcopy(self.P)
#
#         self.P.clear()
#
#         for x in range(fre_number):
#             Lb.append([])
#
#         self.Cd.clear()
#         self.Cd2.clear()
#         for y in range(slen + 1):
#             self.Cd.append(0)
#             self.Cd2.append(0)
#
#         for s in range(fre_number):
#             Lb[s].append(len(pos[s]))
#             for d in range(len(pos[s])):
#                 Lb[s].append(copy.deepcopy(pos[s][d]))
#
#         for i in range(fre_number):
#             Q = copy.deepcopy(fre[i])  # 求后缀
#             Q = Q[1:]
#             q = sort(Q)
#             L = []
#             size = len(pos[i])
#             self.rule_left = fre[i]
#             self.rule_leftnum = size
#             L.append(size)
#             for k in range(size):
#                 L.append(copy.deepcopy(pos[i][k]))
#
#             for j in range(fre_number):
#                 if L[0] >= self.minsup and Lb[j][0] >= self.minsup:
#                     R = copy.deepcopy(fre[j])
#                     R.pop()  # 求前缀
#                     r = sort(R)
#                     if q == r:
#                         if fre[i][0] == fre[j][slen - 1]:  # 最前最后位置相等，拼接成两个模式
#                             self.Cd[0] = fre[i][0]
#                             self.Cd2[0] = fre[i][0] + 1
#                             self.Cd[slen] = fre[i][0] + 1
#                             self.Cd2[slen] = fre[i][0]
#                             for t in range(1, slen):
#                                 if fre[i][t] > fre[j][slen - 1]:  # 中间位置增长
#                                     self.Cd[t] = fre[i][t] + 1
#                                     self.Cd2[t] = fre[i][t] + 1
#                                 else:
#                                     self.Cd[t] = fre[i][t]
#                                     self.Cd2[t] = fre[i][t]
#                             self.cd_num = self.cd_num + 2
#                             self.grow_BaseP2(len(self.Cd) - 1, Lb[j], L)
#                         elif fre[i][0] < fre[j][slen - 1]:  # 第一个位置比最后一个位置小
#                             self.Cd[0] = fre[i][0]  # 小的不变
#                             self.Cd[slen] = fre[j][slen - 1] + 1  # 大的加一
#                             for t in range(1, slen):
#                                 if fre[i][t] > fre[j][slen - 1]:
#                                     self.Cd[t] = fre[i][t] + 1  # 中间位置增长
#                                 else:
#                                     self.Cd[t] = fre[i][t]
#                             self.cd_num = self.cd_num + 1
#                             self.grow_BaseP1(Lb[j], L)
#                         else:
#                             self.Cd[0] = fre[i][0] + 1  # 大的加一
#                             self.Cd[slen] = fre[j][slen - 1]  # 小的不变
#                             for t in range(slen - 1):
#                                 if fre[j][t] > fre[i][0]:
#                                     self.Cd[t + 1] = fre[j][t] + 1  # 中间位置增长
#                                 else:
#                                     self.Cd[t + 1] = fre[j][t]
#                             self.cd_num = self.cd_num + 1
#                             self.grow_BaseP1(Lb[j], L)
#         Lb.clear()
#         pos.clear()
#         fre.clear()
#
#     def recommend(self, sup_begin, sup_end, Cd_begin, Cd_end):
#         #recommend 函数的作用是生成和输出满足最小置信度要求的模式规则，并将这些规则写入输出文件。
#         # 函数的核心逻辑是判断给定的规则是否满足最小置信度要求，如果满足，则将规则写入文件并增加规则数量计数器。
#         if sup_end >= sup_begin * self.minconf:
#             output_file = open(self.output_filepath + "/" + self.output_filename, 'a')
#             strArr = "模式"
#             for i in Cd_begin:
#                 strArr = strArr + str(i) + ","
#             strArr = strArr + "=>"
#             for j in Cd_end:
#                 strArr = strArr + str(j) + ","
#             strArr = strArr + "置信度为：" + str(sup_end / sup_begin)
#             output_file.write(strArr + "\n")
#             output_file.close()
#             self.rule_num = self.rule_num + 1
#
#     def judge_fre(self, sup_num, Cd, Z):  #频繁模式挖掘
#         if sup_num >= self.minsup:
#             self.P.append(copy.deepcopy(Z))
#             self.L.append(copy.deepcopy(Cd))
#
#             output_file = open(self.output_filepath + "/" + self.output_filename, 'a')
#             strArr = "频繁模式："
#             for i in Cd:
#                 strArr = strArr + str(i) + ","
#             strArr = strArr + " 支持度为：" + str(sup_num)
#             output_file.write(strArr + "\n")
#             output_file.close()
#
#             self.rule_right = Cd
#             self.rule_rightnum = sup_num
#             self.recommend(self.rule_leftnum, self.rule_rightnum, self.rule_left, self.rule_right)
#
#             self.allrulenum = self.allrulenum + 1
#
#             self.frequent_num = self.frequent_num + 1
#             self.fre_num = self.fre_num + 1
#
#     def judge_fre2(self, sup_num, Cd, Z):
#         if sup_num >= self.minsup:
#             self.P.append(copy.deepcopy(Z))
#             self.L.append(copy.deepcopy(Cd))
#
#             output_file = open(self.output_filepath + "/" + self.output_filename, 'a')
#             strArr = "频繁模式："
#             for i in Cd:
#                 strArr = strArr + str(i) + ","
#             strArr = strArr + " 支持度为：" + str(sup_num)
#             output_file.write(strArr + "\n")
#             output_file.close()
#
#             self.frequent_num = self.frequent_num + 1
#             self.fre_num = self.fre_num + 1
#
#     def find(self):
#         i, j = 0, 1
#         self.Cd.append(1)
#         self.Cd.append(2)
#         self.Cd2.append(2)
#         self.Cd2.append(1)
#         while j < len(self.S):
#             if self.S[j] > self.S[i]:
#                 self.Z.append(j)
#             elif self.S[j] != self.S[i]:
#                 self.Z2.append(j)
#             i = i + 1
#             j = j + 1
#         self.judge_fre2(len(self.Z), self.Cd, self.Z)
#         self.Cd.clear()
#         self.judge_fre2(len(self.Z2), self.Cd2, self.Z2)
#         self.Cd2.clear()
#
#     def solve(self, text):
#         """
#         :param text: 文本框控件，用于回调信息返回
#         :return: None
#         """
#         text.insert(END, "OPR_Miner算法开始运行，请等待...\n")
#         text.insert(END, "算法参数：\n")
#         text.insert(END,
#                     " minconf:" + str(self.minconf) + " minsup:" + str(self.minsup) + "\n")
#
#         begin_time = time.time()
#
#         self.find()
#         while self.fre_num:
#             self.generate_fre()
#
#         end_time = time.time()
#         time_consuming = end_time - begin_time
#         text.insert(END, "OPR_Miner算法运行完毕。\n")
#         text.insert(END, "The time-consuming:" + str(time_consuming * 1000) + "ms" + "\n")
#         text.insert(END, "The number of frequent patterns:" + str(self.frequent_num) + "\n")
#         text.insert(END, "The number of candidate patterns:" + str(self.cd_num) + "\n")
#         text.insert(END, "The number of rule number:" + str(self.rule_num) + "\n")
#         text.insert(END, "挖掘结果已写入：" + self.output_filepath + "/" + self.output_filename + "\n")
#
# class IOPR:
#     def __init__(self):
#         self.datasets = {}  # 存储数据集
#         self.results = {}
#
# import tkinter as tk
#
#
# import os
# import tkinter as tk
#
#
# def main(file_path, output_filepath, min_conf=0.4, min_sup=12):
#     # 确保输出目录存在
#     if not os.path.exists(output_filepath):
#         os.makedirs(output_filepath)
#
#     # 创建主窗口
#     root = tk.Tk()
#     root.title("OPR Miner 算法")
#
#     # 创建用于显示输出的文本控件
#     text = tk.Text(root, wrap='word', width=100, height=30)
#     text.pack(expand=True, fill='both')
#
#     # 实例化并运行 OPRMiner
#     miner = OPRMiner(file_path=file_path, output_filepath=output_filepath, min_conf=min_conf, min_sup=min_sup)
#     miner.solve(text)
#
#     # 启动 tkinter 主循环
#     root.mainloop()
#
#
# # 示例用法
# if __name__ == "__main__":
#     file_path = "D:/python/pythonProject/op-Transformer/datasets_ETT_afterProcess.txt"  # 替换为你的输入文件路径
#     output_filepath = "OPR-output-ETT-50"  # 替换为你的输出目录路径
#     min_conf = 0.4
#     min_sup = 50
#
#     main(file_path, output_filepath, min_conf, min_sup)
