void CLogAnalyzerView::UpdateUISetting() { if (!m_logger->GetActiveUISetting().isNull()) { tstring strSettingName = m_logger->GetActiveUISetting()->getName(); CLogAnalyzerApp* app = (CLogAnalyzerApp*)AfxGetApp(); if (app != NULL) { Poco::SharedPtr<CUISetting> currentSelSetting = app->GetUISetting(strSettingName); if (!currentSelSetting.isNull()) m_logger->SetActiveUISetting(currentSelSetting); } } }
void CLogAnalyzerView::ShowTraces(const CString& strComponent, BOOL bShowAll) { tstring strItemText = strComponent; const std::map<tstring, Poco::SharedPtr<CComponent>>& components = m_logger->GetComponents(); std::map<tstring, Poco::SharedPtr<CComponent>>::const_iterator ite = components.find(strItemText); if (ite != components.end()) { const std::vector<Poco::SharedPtr<CTraceLog>>& traceLogs = ite->second->GetTraceLogs(); if (bShowAll) { //Only show the traces you want in list control m_traceList.DeleteAllTraceLog(); for (int i = 0; i < traceLogs.size(); ++i) m_traceList.InsertTraceLog(traceLogs.at(i)); } //Show all traces and go to the first trace log that fits to you want else { Poco::SharedPtr<CUISetting> uiSetting = m_logger->GetActiveUISetting(); int nColumn = 0; int nCurSel = m_comboColumns.GetCurSel(); if (nCurSel == 0) nColumn = -1; //All else { CString strItem; m_comboColumns.GetLBText(nCurSel, strItem); tstring strItemValue = strItem.GetBuffer(strItem.GetLength()); if (!uiSetting.isNull()) { for (int i = 0; i < uiSetting->GetAllColumns().size(); ++i) { if (strItemValue == uiSetting->GetAllColumns().at(i)->m_strRealColumnName) { nColumn = i; break; } } } } m_traceList.SearchText(nColumn, m_strFindContent.GetBuffer(m_strFindContent.GetLength()), m_bMatchCase); } m_strCurrentPage.Format("%d", m_traceList.GetCurrentPage()); m_strTraceCount.Format("Total : %d", m_traceList.GetCount()); UpdateData(FALSE); } }
void NetPoco::httpRequest(string request, HTTPClientSession *session,string path, string headKey){ //Expires defaults to NOW. Will be reset if Expires or max-age headers are found! DateTime expires; cout << "DateTime now : " << DateTimeFormatter::format(expires.timestamp(), DateTimeFormat::RFC1123_FORMAT) << "\n"; HTTPRequest headReq(request, path, HTTPMessage::HTTP_1_1); Poco::SharedPtr<pair<map<string,string>, string > > dataFromCache = clientCache->get(headKey); if (!dataFromCache.isNull()) { map<string,string> cachedHeaders = dataFromCache->first; //cout << "HEADERS: \n"; //First check expires (HTTP 1.0): map<string,string>::iterator pos = cachedHeaders.find("Expires"); if (pos != cachedHeaders.end()) { cout << "Expires found" << pos->second << "\n"; DateTime dt; int tzd; DateTimeParser::parse(DateTimeFormat::RFC1123_FORMAT, pos->second , dt, tzd); expires = dt; } //Replace result with max-age if found (HTTP 1.1): pos = cachedHeaders.find("Cache-Control"); if (pos != cachedHeaders.end()) { StringTokenizer cacheControlPairs(pos->second, ",", StringTokenizer::TOK_TRIM); //cout << "Control pairs : " << cacheControlPairs.count() << "\n"; for(StringTokenizer::Iterator it = cacheControlPairs.begin(); it != cacheControlPairs.end(); ++it) { //cout << "Inspecting : "<< * it << "\n"; if(string::npos != it->find("max-age")){ StringTokenizer maxAgePair(pos->second, "=", StringTokenizer::TOK_TRIM); if (maxAgePair.count()==2) { unsigned int secondsMaxAge = atoi(maxAgePair[1].c_str()); cout << "Found max-age : " << secondsMaxAge << "\n"; //cout << DateTime().dayOfWeek() << "\n"; //Set expires to max-age: map<string,string>::iterator pos = cachedHeaders.find("Date"); if (pos != cachedHeaders.end()) { cout << "Date found : " << pos->second << "\n"; DateTime dt; int tzd; DateTimeParser::parse(DateTimeFormat::RFC1123_FORMAT, pos->second , dt, tzd); dt+=convertToMicro(secondsMaxAge); cout << "expires : " << DateTimeFormatter::format(dt.timestamp(), DateTimeFormat::RFC1123_FORMAT) << "\n"; expires = dt; } }else{ cout << "Error invalid max-age" << "\n"; } break; } } } DateTime now; //If not Expired use cache: if (now < expires ) { cout << "now < expires" << endl; this->usingCached = true; return; }else{ cout << "now > expires" << endl; this->usingCached = false; //Append Last-Modified and ETag to request headers: pos = cachedHeaders.find("Last-Modified"); if (pos != cachedHeaders.end()) { headReq.set("IF-MODIFIED-SINCE", pos->second); } pos = cachedHeaders.find("ETag"); if (pos != cachedHeaders.end()) { headReq.set("IF-NONE-MATCH", pos->second); } } } else{ //No data in cache: this->usingCached = false; cout << "Cache was empty" << "\n"; } cout << "send Request! \n"; session->sendRequest(headReq); }
void SeparationTask::exportComponents() const { debug_assert(&phaseMatrix() && &magnitudeSpectraMatrix(0) && &gainsMatrix()); logger().debug(nameAndTaskID() + " exporting the components."); Poco::Util::LayeredConfiguration& cfg = BasicApplication::instance().config(); // Determine whether to export components as WAV and/or as matrix files. bool exportAsMatrix = cfg.getBool("blissart.separation.export.matrix", false); if (exportAsMatrix) logger().debug("Exporting components as matrix file(s)."); bool exportAsWave = cfg.getBool("blissart.separation.export.wave", true); if (exportAsWave) logger().debug("Exporting components as waveform file(s)."); // Determine whether to use wiener reconstruction. bool wienerRec = cfg.getBool("blissart.separation.export.wienerrec", true); // Compute the reconstructed matrix (WH) in case of wiener reconstruction. Poco::SharedPtr<Matrix> reconst; if (wienerRec) { //reconst = new Matrix(phaseMatrix().rows(), phaseMatrix().cols()); reconst = new Matrix(magnitudeSpectraMatrix(0).rows(), gainsMatrix().cols()); if (_nrOfSpectra > 1) { reconst->zero(); Matrix hShifted = gainsMatrix(); for (unsigned int t = 0; t < _nrOfSpectra; ++t) { reconst->add(magnitudeSpectraMatrix(t) * hShifted); hShifted.shiftColumnsRight(); } } else { magnitudeSpectraMatrix(0).multWithMatrix(gainsMatrix(), reconst); } // revert transform to reconst reconst = revertTransforms(reconst); } // Retrieve desired component indices. vector<vector<int> > compIndices = _exportComponentIndices; if (compIndices.empty()) { vector<int> compIndicesSource; for (int i = 1; i <= _nrOfComponents; i++) { compIndicesSource.push_back(i); } compIndices.push_back(compIndicesSource); } // Reconstruct components and mix, if desired. int sourceIndex = 1; for (vector<vector<int> >::const_iterator sourceIt = compIndices.begin(); sourceIt != compIndices.end(); ++sourceIt, ++sourceIndex) { // Holds the mixed spectrogram if mixing is desired. Poco::SharedPtr<Matrix> mixedSpectrogram; logger().debug("Exporting components for source #" + Poco::NumberFormatter::format(sourceIndex)); for (vector<int>::const_iterator it = sourceIt->begin(); it != sourceIt->end(); ++it) { if (*it < 1 || *it > _nrOfComponents) { logger().error(nameAndTaskID() + ": invalid component index: " + Poco::NumberFormatter::format(*it)); continue; } int i = *it - 1; logger().debug(nameAndTaskID() + " exporting component #" + Poco::NumberFormatter::format(i)); // Compute the component's magnitude spectrum. Poco::SharedPtr<Matrix> magnitudeSpectrum = new Matrix( magnitudeSpectraMatrix(0).rows(), gainsMatrix().cols()); // NMD case if (_nrOfSpectra > 1) { magnitudeSpectrum->zero(); RowVector componentGains = gainsMatrix().nthRow(i); for (unsigned int t = 0; t < _nrOfSpectra; t++) { ColVector componentSpectrum = magnitudeSpectraMatrix(t).nthColumn(i); magnitudeSpectrum->add(componentSpectrum * componentGains); componentGains.shiftRight(); } } // "NMF" case (separated for efficiency) else { ColVector componentSpectrum = magnitudeSpectraMatrix(0).nthColumn(i); RowVector componentGains = gainsMatrix().nthRow(i); *magnitudeSpectrum = componentSpectrum * componentGains; } // revert transformation to component spectrogram magnitudeSpectrum = revertTransforms(magnitudeSpectrum); if (wienerRec) { // (Component/Whole) reconstruction reconst->floor(1e-6); magnitudeSpectrum->elementWiseDivision(*reconst, magnitudeSpectrum); // Use as filter for original spectrogram magnitudeSpectrum->elementWiseMultiplication(ftMagMatrix(), magnitudeSpectrum); } // Mix the components to a single spectrogram that is exported after // the loop. if (_mixExportedComponents) { if (mixedSpectrogram.isNull()) { mixedSpectrogram = new Matrix(magnitudeSpectrum->rows(), magnitudeSpectrum->cols()); mixedSpectrogram->zero(); } mixedSpectrogram->add(*magnitudeSpectrum); } // Export components individually. else { // Construct the filename. string prefix = getExportPrefix(); const int numDigits = (int)(1 + log10f((float)_nrOfComponents)); stringstream ss; ss << prefix; if (compIndices.size() > 1) { const int numDigitsS = (int)(1 + log10f((float)compIndices.size())); ss << '_' << setfill('0') << setw(numDigitsS) << sourceIndex; } ss << '_' << setfill('0') << setw(numDigits) << *it; if (exportAsMatrix) { magnitudeSpectrum->dump(ss.str() + ".dat"); } if (exportAsWave) { // Convert component spectrogram to time signal and save it as WAV. spectrogramToAudioFile(magnitudeSpectrum, ss.str() + ".wav"); } } } // Export the mixed source spectrogram to a single audio file. if (_mixExportedComponents) { // Construct the filename. stringstream ss; ss << getExportPrefix(); const int numDigitsS = (int)(1 + log10f((float)compIndices.size())); ss << "_source" << setfill('0') << setw(numDigitsS) << sourceIndex; // Convert component spectrogram to time signal and save it as WAV. string filename = ss.str(); logger().debug(nameAndTaskID() + ": creating mixed audio file " + filename); if (exportAsMatrix) { mixedSpectrogram->dump(filename + ".dat"); } if (exportAsWave) { spectrogramToAudioFile(mixedSpectrogram, filename + ".wav"); } } } }
void CLogAnalyzerView::OnBnClickedButtonOpen() { //Open File if (!m_logger.isNull() && !(m_logger->GetActiveUISetting().isNull())) { if (!m_logger->GetActiveUISetting()->IsAvailable()) if (AfxMessageBox("The UI setting is not available, Do you want to configurate it?", MB_OKCANCEL) == IDOK) { //OnAnalyseSetting(); return; } } CString strFile = _T(""); CFileDialog dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("Describe Files (*.log)|*.log|All Files (*.*)|*.*||"), NULL); if (dlgFile.DoModal() == IDOK) { strFile = dlgFile.GetPathName(); CString strItem; m_comboSettings.GetLBText(m_comboSettings.GetCurSel(), strItem); CLogAnalyzerApp* app = (CLogAnalyzerApp*)AfxGetApp(); if (app != NULL) { Poco::SharedPtr<CUISetting> currentSelSetting = app->GetUISetting(strItem.GetBuffer(strItem.GetLength())); if (!currentSelSetting.isNull()) { if (!m_logger.isNull() && !m_logger->GetFileName().empty()) { m_logger->ClearAllComponents(); //Open another log file, remove the previous one RemoveItem(); } m_logger->SetActiveUISetting(currentSelSetting); } //Update list control while(m_comboColumns.DeleteString(0)); while(m_traceList.DeleteColumn(0)); m_comboColumns.AddString("All"); //Init list control LV_COLUMN lv; lv.mask = LVCF_TEXT | LVCF_WIDTH; if (!currentSelSetting.isNull()) { int nIndex = 0; //Insert the first column of Line number lv.pszText = "Line"; lv.cx = 50; m_traceList.InsertColumn(nIndex++, &lv); const std::vector<Poco::SharedPtr<CColumnSetting>>& columns = currentSelSetting->GetAllColumns(); for (int i = 0; i < columns.size(); ++i) { if (columns.at(i)->m_bEnable) { lv.pszText = (LPSTR)columns.at(i)->m_strRealColumnName.c_str(); lv.cx = 100; m_traceList.InsertNewColumn(nIndex++, &lv, i); m_comboColumns.AddString(columns.at(i)->m_strRealColumnName.c_str()); } } m_traceList.SetColumnSetting(currentSelSetting->GetAllColumns()); } } m_comboColumns.SetCurSel(0); m_traceList.DeleteAllTraceLog(); m_logger->StartParse(tstring(strFile.GetBuffer(strFile.GetLength()))); CAnalyseProgressDlg dlg(m_logger); dlg.DoModal(); //Update tree view CClassView* pClassView = NULL; GET_CLASS_VIEW(pClassView); if (pClassView != NULL) { HTREEITEM hFile = pClassView->InsertLogFile(strFile); const std::map<tstring, Poco::SharedPtr<CComponent>>& components = m_logger->GetComponents(); std::map<tstring, Poco::SharedPtr<CComponent>>::const_iterator ite = components.begin(); while (ite != components.end()) { pClassView->InsertComponent(hFile, ite->second->GetComponentName().c_str()); ++ite; } pClassView->SetFocus(); } //Update log file information/UI Setting in property panel CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd(); if (pMainFrame != NULL) { Poco::SharedPtr<SLogFileProperty> logFilePro = new SLogFileProperty; logFilePro->m_strFileName = m_logger->GetFileName(); logFilePro->m_nFileSize = m_logger->GetFileSize(); pMainFrame->SetLogFileProperty(logFilePro); pMainFrame->SetCurrentUISettingProperty(m_logger->GetActiveUISetting()); } //Update tab title CLogAnalyzerDoc* pDoc = (CLogAnalyzerDoc*)GetDocument(); if (pDoc) { pDoc->SetTitle(dlgFile.GetFileName()); pDoc->SetDocIdentifier(strFile); } } }