Пример #1
0
 def loadLogAnalyticsFile(self):
     supportFiles = SupportFiles.files()
     if not supportFiles:
         print "not support one file !"
         return
     supportFileStr = ''
     for file in supportFiles:
         supportFileStr += "*." + file + " "
     supportFileStr = supportFileStr.strip()
     fileName = unicode(
         QtGui.QFileDialog.getOpenFileName(
             None, 'Open file', self.getLastOpenDir(),
             'log files(' + supportFileStr + ')'))
     if not fileName:
         return
     QSettingsUtil.setLastDir(
         FileUtil.getFileDir(str(_translate("", fileName.strip(), None))))
     file = QtCore.QFile(fileName)
     if not file.open(QtCore.QIODevice.ReadOnly):
         return
     stream = QtCore.QTextStream(file)
     stream.setCodec('UTF-8')
     data = stream.readAll()
     file.close()
     self.logAnalyticsEdit.setText(_translate('', data, None))
     # open logAnalyticsEdit show
     self.hSplitter.setSizes([1, 1])
Пример #2
0
 def dragEnterEvent(self, event):
     # http://www.iana.org/assignments/media-types/media-types.xhtml
     if event.mimeData().hasUrls() and event.mimeData().hasFormat(
             "text/uri-list"):
         for url in event.mimeData().urls():
             filePath = str(url.toLocalFile()).decode('utf-8')
             if SupportFiles.hasSupportFile(filePath):
                 event.acceptProposedAction()
             else:
                 print 'not accept this file!'
     else:
         print 'not accept this file too!'
Пример #3
0
 def doAnalyticsWithGroup(self):
     selectDir = str(self.selectDirectoryLineEdit.text())
     if not selectDir:
         logMsg = u'您尚未选择日志文件路径! 请先选择日志路径。'
         self.appendLog(logMsg)
         self.analyticsBtn.setEnabled(True)
         self.generateDocumentBtn.setEnabled(True)
         return
     allFilePaths = FileUtil.getAllFiles(selectDir)
     print 'len(allFilePaths): ', len(allFilePaths)
     supportFilePaths = []
     for filePath in allFilePaths:
         if SupportFiles.hasSupportFile(filePath) and \
                 not SupportFiles.hasContainsPath(filePath, *self.removeThePathKeys()):
             supportFilePaths.append(filePath)
     if not supportFilePaths:
         return
     # self.analyticsGroupTotalSize = len([supportFilePaths[i:i+10] for i in xrange(0, len(supportFilePaths), 10)])
     print 'len(supportFilePaths): ', len(supportFilePaths)
     # print 'len(analyticsGroupTotalSize): ', self.analyticsGroupTotalSize
     # 1. 数组分组,以10个一组
     # for i in xrange(0, len(supportFilePaths), 10):
     #     filePathList = supportFilePaths[i:i+10]
     #     # print 'filePathList: ', filePathList
     #     # 2,3 进行分组数据搜索
     #     # 无线程版
     #     # self.doSearchFile(filePathList)
     #     threadUtil = ThreadUtil(funcName=self.doSearchFile, filePaths=filePathList)
     #     threadUtil.setDaemon(True)
     #     threadUtil.start()
     # self.doSearchFile(supportFilePaths)
     # 去除多线程分组,默认采用多进程分析文件,避免同时使用多线程的情况下使用多进程,否则电脑会被冲爆
     threadUtil = ThreadUtil(funcName=self.doSearchFile,
                             filePaths=supportFilePaths)
     threadUtil.setDaemon(True)
     threadUtil.start()
Пример #4
0
 def newLocalSocketConnection(self):
     # print 'newLocalSocketConnection'
     # 处理新启动的程序(终端)发过来的参数
     serverSocket = self.localServer.nextPendingConnection()
     if not serverSocket:
         return
     serverSocket.waitForReadyRead(1000)
     stream = QtCore.QTextStream(serverSocket)
     stream.setCodec('UTF-8')
     pathData = str(_translate('', stream.readAll(), None))
     serverSocket.close()
     # 由于客户端在发送的时候,就已经处理只发送(传递) 打开的文件路径参数,故此处不做校验处理
     # print SupportFiles.hasSupportFile(pathData)
     if pathData and SupportFiles.hasSupportFile(pathData):
         self.setLogTxt(pathData)
Пример #5
0
import numpy as np
import SupportFiles

PianoRoll = np.genfromtxt(
    "C:/Users/Poori/Desktop/Parinama/MakePianoRoll/SmallDataSet/PianoRolls/piano_roll_set9.csv",
    delimiter=",")

#***************************************************************************************************************************************************************
#MAKE INPUT AND TARGET SEQUENCES
split = 0.7
timesteps_in_one_Batch = 1
Train, Test = SupportFiles.Splitdata(split, PianoRoll)
Input, Target, TestInput, TestTarget, Number_of_Batches_Train = SupportFiles.MakeInputTarget(
    timesteps_in_one_Batch, Train, Test)
import SupportFiles
import csv
import time
import numpy as np
import scipy
from scipy import sparse
from scipy.sparse import csr_matrix
shift                  =  5
split                  =  0.90
timesteps_in_one_Batch =  40   # 2 seconds of music training samples used per gradient-update predict the next  0.5 seconds


#***************************************************************************************************************************************************************
#INITIALIZATION
print("Opening BIG npz")
PianoRoll_sparse =scipy.sparse.load_npz("D:/EC2/Inputs/Three.npz")
PianoRoll=PianoRoll_sparse.tocsr()

#***************************************************************************************************************************************************************
#MAKE INPUT AND TARGET SEQUENCES
Train,Test=SupportFiles.Splitdata(split,PianoRoll)
print("Splitting into Train & Test is over")
SupportFiles.MakeInputTarget(timesteps_in_one_Batch,Train,shift)
SupportFiles.MakeTestInputTarget(timesteps_in_one_Batch,Test,shift)
Пример #7
0
    def setupUi(self, mainWindow, localServer, argv=None):
        self.mainwindow = mainWindow
        # 解决多终端问题 http://www.oschina.net/code/snippet_54100_629
        self.localServer = localServer
        # 保存所有 Tab 的 originalData
        self.originalDataList = []
        # 保存所有 Tab 的 filePath
        self.tabFilePathList = []
        # 获取当前脚本所在的目录
        self.sysArg0 = argv[0]
        self.filterConfigFilePath = os.path.join(
            os.path.dirname(os.path.realpath(self.sysArg0)),
            Constants.filterConfigFileName)
        mainWindow.setObjectName(_fromUtf8("MainWindow"))
        mainWindow.setWindowIcon(QtGui.QIcon(resource_path('img/log.png')))
        # MainWindow.resize(800, 600)
        self.centralwidget = QtGui.QWidget(mainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))

        self.statusBar = QtGui.QStatusBar(mainWindow)
        self.menubar = QtGui.QMenuBar(mainWindow)
        file = self.menubar.addMenu(' &File')
        openFileAction = QtGui.QAction('Open file', mainWindow)
        openFileAction.setStatusTip(_fromUtf8('选择日志文件'))
        openFileAction.setShortcut('Ctrl+O')
        openFileAction.connect(openFileAction, QtCore.SIGNAL('triggered()'),
                               self.openFile)

        saveLogAnalyticsAction = QtGui.QAction('Save Analytics', mainWindow)
        saveLogAnalyticsAction.setStatusTip(_fromUtf8('保存日志分析文件'))
        saveLogAnalyticsAction.setShortcut('Ctrl+Alt+S')
        saveLogAnalyticsAction.connect(saveLogAnalyticsAction,
                                       QtCore.SIGNAL('triggered()'),
                                       self.saveLogAnalyticsFile)

        loadLogAnalyticsAction = QtGui.QAction('Load Analytics', mainWindow)
        loadLogAnalyticsAction.setStatusTip(_fromUtf8('加载日志分析文件'))
        loadLogAnalyticsAction.setShortcut('Ctrl+Alt+O')
        loadLogAnalyticsAction.connect(loadLogAnalyticsAction,
                                       QtCore.SIGNAL('triggered()'),
                                       self.loadLogAnalyticsFile)

        file.addAction(openFileAction)
        file.addAction(loadLogAnalyticsAction)
        file.addAction(saveLogAnalyticsAction)

        setting = self.menubar.addMenu('&Setting')
        settingLogAnalyticsWinRightKeyAction = QtGui.QAction(
            'set log key', mainWindow)
        settingLogAnalyticsWinRightKeyAction.setStatusTip(
            _fromUtf8('注册LogAnalytics到右键'))
        settingLogAnalyticsWinRightKeyAction.connect(
            settingLogAnalyticsWinRightKeyAction, QtCore.SIGNAL('triggered()'),
            self.setLogAnalyticsWinRightKey)
        setting.addAction(settingLogAnalyticsWinRightKeyAction)

        settingCmdRightKeyAction = QtGui.QAction('set cmd key', mainWindow)
        settingCmdRightKeyAction.setStatusTip(_fromUtf8('注册cmdPrompt到右键'))
        settingCmdRightKeyAction.connect(settingCmdRightKeyAction,
                                         QtCore.SIGNAL('triggered()'),
                                         self.setCmdWinRightKey)
        setting.addAction(settingCmdRightKeyAction)
        setting.addSeparator()

        # 设置"copy log file" command path
        settingCopyLogCmdPathAction = QtGui.QAction('copy system cmd',
                                                    mainWindow)
        settingCopyLogCmdPathAction.setStatusTip(
            _fromUtf8('设置copy system log cmd 脚本路径'))
        settingCopyLogCmdPathAction.connect(settingCopyLogCmdPathAction,
                                            QtCore.SIGNAL('triggered()'),
                                            self.setCopySystemLogCmdPath)
        setting.addAction(settingCopyLogCmdPathAction)

        settingCopyLauncherLogCmdPathAction = QtGui.QAction(
            'copy launcher cmd', mainWindow)
        settingCopyLauncherLogCmdPathAction.setStatusTip(
            _fromUtf8('设置copy launcher log cmd 脚本路径'))
        settingCopyLauncherLogCmdPathAction.connect(
            settingCopyLauncherLogCmdPathAction, QtCore.SIGNAL('triggered()'),
            self.setCopyLauncherLogCmdPath)
        setting.addAction(settingCopyLauncherLogCmdPathAction)
        setting.addSeparator()

        # 设置文本换行
        self.settingTextWrapAction = QtGui.QAction('set text wrap', mainWindow)
        checkIconPixmap = QtGui.QPixmap(resource_path('img/check.png'))
        self.settingTextWrapAction.setIcon(QtGui.QIcon(checkIconPixmap))
        self.settingTextWrapAction.setStatusTip(_fromUtf8('自动换行'))
        self.setTextWrapIconVisible()
        self.settingTextWrapAction.connect(self.settingTextWrapAction,
                                           QtCore.SIGNAL('triggered()'),
                                           self.changeTextWrap)
        setting.addAction(self.settingTextWrapAction)

        # Auto Analytics分析, 可用于分析特定关键字,输出结果
        autoAnalytics = self.menubar.addMenu('&Auto')
        autoAnalyticsCallFailAction = QtGui.QAction('call fail analytics',
                                                    mainWindow)
        autoAnalyticsCallFailAction.setStatusTip(_fromUtf8('掉话分析'))
        autoAnalyticsCallFailAction.connect(
            autoAnalyticsCallFailAction, QtCore.SIGNAL('triggered()'),
            self.showAutoAnalyticsCallFailDialog)
        autoAnalyticsCallFailAction.setShortcut('Ctrl+Alt+F')
        autoAnalytics.addAction(autoAnalyticsCallFailAction)

        # Tools
        tools = self.menubar.addMenu('&Tools')
        # cmd tools: copy xtc system log to D:\xxFolder
        self.toolCopyXtcSystemLogAction = QtGui.QAction(
            'copy system log', mainWindow)
        self.toolCopyXtcSystemLogAction.setStatusTip(
            _fromUtf8('从SDCard拷贝System Log到D盘'))
        self.toolCopyXtcSystemLogAction.setShortcut('Ctrl+Alt+C')
        self.toolCopyXtcSystemLogAction.connect(
            self.toolCopyXtcSystemLogAction, QtCore.SIGNAL('triggered()'),
            self.copyXtcSystemLogThread)
        self.toolCopyXtcSystemLogAction.connect(
            self.toolCopyXtcSystemLogAction,
            QtCore.SIGNAL('copyLogTipSignal(QString)'), self.showCopyLogTips)
        tools.addAction(self.toolCopyXtcSystemLogAction)
        # cmd tools: copy xtc launcher log to D:\xxFolder
        self.toolCopyXtcLauncherLogAction = QtGui.QAction(
            'copy launcher log', mainWindow)
        self.toolCopyXtcLauncherLogAction.setStatusTip(
            _fromUtf8('从SDCard拷贝Launcher Log到D盘'))
        self.toolCopyXtcLauncherLogAction.setShortcut('Ctrl+Alt+L')
        self.toolCopyXtcLauncherLogAction.connect(
            self.toolCopyXtcLauncherLogAction, QtCore.SIGNAL('triggered()'),
            self.copyXtcLauncherLogThread)
        self.toolCopyXtcLauncherLogAction.connect(
            self.toolCopyXtcLauncherLogAction,
            QtCore.SIGNAL('copyLogTipSignal(QString)'), self.showCopyLogTips)
        tools.addAction(self.toolCopyXtcLauncherLogAction)
        tools.addSeparator()
        # split excel data tools.
        self.toolSplitExcelAction = QtGui.QAction('split excel data',
                                                  mainWindow)
        self.toolSplitExcelAction.setStatusTip(_fromUtf8('拆分Excel 数据'))
        self.toolSplitExcelAction.connect(self.toolSplitExcelAction,
                                          QtCore.SIGNAL('triggered()'),
                                          self.showSplitExcelDialog)
        tools.addAction(self.toolSplitExcelAction)
        tools.addSeparator()

        # 添加到 mainWindow
        mainWindow.setMenuBar(self.menubar)
        mainWindow.setStatusBar(self.statusBar)

        # vBoxLayout 和 hBoxLayout 的选择依据是:根据2个控件的排列方向,上下排(vBoxLayout)还是左右排(hBoxLayout)
        vBoxLayout = QtGui.QVBoxLayout()
        hBboxLayout = QtGui.QHBoxLayout()

        # 需要设置添加到 self.centralwidget
        self.logAnalyticsEdit = QtGui.QTextEdit()
        self.logAnalyticsEdit.setFont(self.getFont('Monospace'))

        self.filterLineEdit = QtGui.QLineEdit()
        self.filterLineEdit.setFont(self.getFont('Consolas'))
        self.filterBtn = QtGui.QPushButton()
        self.filterBtn.setText(u'Filter')
        self.saveKeyWordBtn = QtGui.QPushButton()
        self.saveKeyWordBtn.setText(u'Save')
        self.LoadKeyWorkBtn = QtGui.QPushButton()
        self.LoadKeyWorkBtn.setText(u'Load')
        self.filterBtn.setFixedWidth(60)
        self.saveKeyWordBtn.setFixedWidth(60)
        self.LoadKeyWorkBtn.setFixedWidth(60)

        self.filterBtn.setFont(self.getFont('Consolas'))
        self.saveKeyWordBtn.setFont(self.getFont('Consolas'))
        self.LoadKeyWorkBtn.setFont(self.getFont('Consolas'))

        self.filterBtn.setStatusTip(u'请输入过滤字符,多个字符间以 "|" 分割(Ctrl+F)')
        self.filterBtn.setShortcut('Ctrl+F')
        self.saveKeyWordBtn.setStatusTip(u'保存过滤条件(Ctrl+B)')
        self.saveKeyWordBtn.setShortcut('Ctrl+B')
        self.LoadKeyWorkBtn.setStatusTip(u'加载过滤条件(Ctrl+L)')
        self.LoadKeyWorkBtn.setShortcut('Ctrl+L')

        self.filterBtn.connect(self.filterBtn, QtCore.SIGNAL('clicked()'),
                               self.filter)
        self.saveKeyWordBtn.connect(self.saveKeyWordBtn,
                                    QtCore.SIGNAL('clicked()'),
                                    self.saveKeyWord)
        self.LoadKeyWorkBtn.connect(self.LoadKeyWorkBtn,
                                    QtCore.SIGNAL('clicked()'),
                                    self.loadKeyWord)

        self.tabWidget = QtGui.QTabWidget()
        self.tabWidget.setTabsClosable(True)
        self.tabWidget.setMovable(True)
        self.tabWidget.connect(self.tabWidget,
                               QtCore.SIGNAL('tabCloseRequested(int)'),
                               self.tabClose)
        self.tabWidget.connect(self.tabWidget,
                               QtCore.SIGNAL('currentChanged(int)'),
                               self.currentTabChange)
        self.tabWidget.connect(mainWindow,
                               QtCore.SIGNAL('closeCurrentTabSignal()'),
                               self.currentTabCloseSlot)
        self.tabWidget.connect(mainWindow,
                               QtCore.SIGNAL('dropOpenFileSignal(QString)'),
                               self.setLogTxt)

        self.filterLineEdit.setMaximumHeight(28)
        self.filterLineEdit.setMinimumHeight(28)
        hFilterSplitter = QtGui.QSplitter(QtCore.Qt.Horizontal)
        hFilterSplitter.addWidget(self.filterLineEdit)
        hFilterSplitter.addWidget(self.filterBtn)
        hFilterSplitter.addWidget(self.saveKeyWordBtn)
        hFilterSplitter.addWidget(self.LoadKeyWorkBtn)
        # 禁止鼠标拖动
        hHandler = hFilterSplitter.handle(1)
        if hHandler:
            hHandler.setDisabled(True)

        vSplitter = QtGui.QSplitter(QtCore.Qt.Vertical)
        vSplitter.addWidget(hFilterSplitter)
        vSplitter.addWidget(self.tabWidget)
        vHandler = vSplitter.handle(1)
        if vHandler:
            vHandler.setDisabled(True)

        self.hSplitter = QtGui.QSplitter(QtCore.Qt.Horizontal)
        self.hSplitter.addWidget(vSplitter)
        self.hSplitter.addWidget(self.logAnalyticsEdit)
        # 按比例分配 5:3
        self.hSplitter.setStretchFactor(0, 5)
        self.hSplitter.setStretchFactor(1, 3)
        # feature: arrow/collapse button to open/hidden logAnalyticsEdit
        # 设置LogAnalyticsEdit split 显示与隐藏
        hHandler = self.hSplitter.handle(1)
        toggleButton = QtGui.QPushButton(hHandler)
        toggleButton.setShortcut('Ctrl+T')
        toggleButton.move(0, 300)
        toggleButton.resize(10, 50)
        toggleButton.connect(toggleButton, QtCore.SIGNAL('clicked()'),
                             self.handleSplitterButton)
        # 设置 LogAnalyticsEdit 默认隐藏
        self.hSplitter.setSizes([1, 0])
        hBboxLayout.addWidget(self.hSplitter)
        vBoxLayout.addLayout(hBboxLayout)

        self.centralwidget.setLayout(vBoxLayout)

        # 处理右键打开,或者直接拖文件到桌面图标启动。
        # argv 参数大于1,说明有其他文件路径。第0位是当前应用程序,第1位则是我们需要处理的文件路径
        # 注意这里,是需要处理sys.argv 的编码问题的,方法是使用 WinCommandEnCoding.py 处理
        if len(argv) > 1:
            filePath = argv[1]
            if SupportFiles.hasSupportFile(filePath):
                self.setLogTxt(_translate('', filePath, None))
        # 监听新到来的连接(新的终端被打开)
        self.localServer.connect(localServer, QtCore.SIGNAL('newConnection()'),
                                 self.newLocalSocketConnection)

        mainWindow.setCentralWidget(self.centralwidget)