示例#1
0
    def onExport(self, evt):
        dialog = wx.FileDialog(self, u"选择要导出的文件位置", os.getcwd(), style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
                               wildcard="*.csv")
        if dialog.ShowModal() == wx.ID_OK:
            filePath = dialog.GetPath()
            if filePath:
                try:
                    personalWorkDayDict = self.exportData[0]
                    dailyAttendenceList = self.exportData[1]
                    personalWorkDayLengthList = self.exportData[2]
                    startDate = self.exportData[3]

                    firstLine = u'员工名,班组名'
                    totalWeekNum = int(len(dailyAttendenceList) / 7)
                    for totalWeekNum in range(1, totalWeekNum + 1):
                        dateStr = u',"第 ' + str(totalWeekNum) + u' 周\n'
                        endDate = TimeUtil.getFormatedDate(startDate, 6)
                        dateStr += (startDate + ' -- ' + endDate + '"')
                        firstLine += dateStr
                        startDate = TimeUtil.getFormatedDate(endDate, 1)

                    lines = [firstLine]

                    for item in personalWorkDayDict:
                        wokerName = item[0]
                        groupName = item[1]
                        workDayList = item[2]
                        lines.append(wokerName + ',' + groupName + u',' + u','.join(
                            list(map(lambda week: ' '.join(list(map(str, week))), workDayList))))

                    lines.append('\n')
                    lines.append(u'员工名,班组名,总天数,总工时(小时)')
                    # 工时
                    for i in range(len(personalWorkDayLengthList)):
                        lines.append(','.join(personalWorkDayLengthList[i]))

                    lines.append('\n')
                    lines.append(u'日期,出勤员工')
                    groupInfo = ',' + ''.join(list(map(lambda x: x[1].groupName + ',' * int(x[1].workLoad), dailyAttendenceList[0][1])))

                    innerLines = list()
                    for dailyAttendence in dailyAttendenceList:
                        date = dailyAttendence[0]
                        groupAttendenceList = dailyAttendence[1]
                        attendenceStr = date
                        for groupAttendence in groupAttendenceList:
                            attendence = groupAttendence[0]
                            attendenceStr += ',' + attendence
                        innerLines.append(attendenceStr)
                    lines.append(groupInfo)
                    lines.extend(innerLines)

                    FileUtil.writeAll(filePath, lines)
                    wx.MessageBox(u'成功导出到文件', filePath)
                except Exception as e:
                    wx.MessageBox(u'导出失败,原因为: ' + str(e))
        dialog.Destroy()
 def onFileRead(self, filePath):
     if filePath:
         try:
             workerList = FileUtil.readAll(filePath)
             wx.MessageBox(u"导入数据成功", u"导入数据", style=wx.OK | wx.ICON_EXCLAMATION)
             return workerList
         except Exception as e:
             wx.MessageBox(u"导入数据失败,请检测数据格式,并保证文件为UTF-8格式", u"导入数据", style=wx.OK | wx.ICON_EXCLAMATION)
             wx.MessageBox(str(e))
             return list()
import jieba as  jb
from wordcloud import WordCloud
import matplotlib.pyplot as plt
from src.Util.FileUtil import FileUtil
import json


txt = FileUtil.readFileToTex("E:\\flaskProject\\static\\file\wordText.txt",'["岗位职责""工作描述""工作职责""工作职责1""要求"]')
print(txt)
jb.add_word("机器学习",4)
words = jb.cut(txt)  # 使用精确模式对文本进行分词
counts = {}  # 通过键值对的形式存储词语及其出现的次数

# 统计词频
for word in words:
    if len(word) == 1:  # 单个词语不计算在内
        continue
    else:
        counts[word] = counts.get(word, 0) + 1  # 遍历所有词语,每出现一次其对应的值加 1
# 注解:dict.get(word,0)当能查询到相匹配的字典时,就会显示相应key对应的value,如果不能的话,就会显示后面的这个参数

# 有些不重要的词语但出现次数较多,可以通过构建排除词库excludes来删除

items = list(counts.items())

items.sort(key=lambda x: x[1], reverse=True)  # 根据词语出现的次数进行从大到小排序
jsonData = json.dumps(items,ensure_ascii=False)
print(jsonData)
# 输出统计结果
for i in range(10):
    word, count = items[i]
示例#4
0
 def onFileRead(self, filePath):
     if filePath:
         # try:
         lines = FileUtil.readAll(filePath)
         self.updateGrid(lines)
         wx.MessageBox("导入数据成功" + ' '.join(lines), "导入数据", style=wx.OK | wx.ICON_EXCLAMATION)