added search for skipped days. Or days with data.

This commit is contained in:
LoudSnorer 2023-02-27 20:45:58 -05:00
parent 22d466ba56
commit 093885d646
2 changed files with 43 additions and 80 deletions

View File

@ -8,7 +8,7 @@
* for more details. */ * for more details. */
#define TEST_MACROS_ENABLED #define TEST_MACROS_ENABLEDoff
#include <test_macros.h> #include <test_macros.h>
#include <QWidget> #include <QWidget>
@ -266,6 +266,7 @@ void DailySearchTab::delayedCreateUi() {
selectCommandCombo->addItem(tr("AHI "),ST_AHI); selectCommandCombo->addItem(tr("AHI "),ST_AHI);
selectCommandCombo->addItem(tr("Daily Duration"),ST_DAILY_USAGE); selectCommandCombo->addItem(tr("Daily Duration"),ST_DAILY_USAGE);
selectCommandCombo->addItem(tr("Session Duration" ),ST_SESSION_LENGTH); selectCommandCombo->addItem(tr("Session Duration" ),ST_SESSION_LENGTH);
selectCommandCombo->addItem(tr("Days Skipped"),ST_DAYS_SKIPPED);
selectCommandCombo->addItem(tr("Disabled Sessions"),ST_DISABLED_SESSIONS); selectCommandCombo->addItem(tr("Disabled Sessions"),ST_DISABLED_SESSIONS);
selectCommandCombo->addItem(tr("Number of Sessions"),ST_SESSIONS_QTY); selectCommandCombo->addItem(tr("Number of Sessions"),ST_SESSIONS_QTY);
selectCommandCombo->insertSeparator(selectCommandCombo->count()); // separate from events selectCommandCombo->insertSeparator(selectCommandCombo->count()); // separate from events
@ -521,6 +522,11 @@ void DailySearchTab::on_selectCommandCombo_activated(int index) {
nextTab = TW_NONE ; nextTab = TW_NONE ;
setSelectOperation( OP_INVALID ,notUsed); setSelectOperation( OP_INVALID ,notUsed);
break; break;
case ST_DAYS_SKIPPED :
horizontalHeader1->setText(tr("No Data\nJumps to Date's Details "));
nextTab = TW_DETAILED ;
setSelectOperation(OP_NO_PARMS,notUsed);
break;
case ST_DISABLED_SESSIONS : case ST_DISABLED_SESSIONS :
horizontalHeader1->setText(tr("Number Disabled Session\nJumps to Date's Details ")); horizontalHeader1->setText(tr("Number Disabled Session\nJumps to Date's Details "));
nextTab = TW_DETAILED ; nextTab = TW_DETAILED ;
@ -612,12 +618,16 @@ void DailySearchTab::updateValues(qint32 value) {
} }
bool DailySearchTab::find(QDate& date,Day* day) void DailySearchTab::find(QDate& date)
{ {
if (!day) return false;
bool found=false; bool found=false;
Qt::Alignment alignment=Qt::AlignCenter; Qt::Alignment alignment=Qt::AlignCenter;
Day* day = p_profile->GetDay(date);
if ( (!day) && (searchTopic != ST_DAYS_SKIPPED)) { daysSkipped++; return;};
switch (searchTopic) { switch (searchTopic) {
case ST_DAYS_SKIPPED :
found=!day;
break;
case ST_DISABLED_SESSIONS : case ST_DISABLED_SESSIONS :
{ {
qint32 numDisabled=0; qint32 numDisabled=0;
@ -629,11 +639,6 @@ bool DailySearchTab::find(QDate& date,Day* day)
} }
} }
updateValues(numDisabled); updateValues(numDisabled);
//if (found) {
//QString displayStr= QString("%1/%2").arg(numDisabled).arg(sessions.size());
//addItem(date , displayStr,alignment );
//return true;
//}
} }
break; break;
case ST_NOTES : case ST_NOTES :
@ -668,7 +673,6 @@ bool DailySearchTab::find(QDate& date,Day* day)
QStringList notes = journal->settings[Bookmark_Notes].toStringList(); QStringList notes = journal->settings[Bookmark_Notes].toStringList();
QString findStr = selectString->text(); QString findStr = selectString->text();
for ( const auto & note : notes) { for ( const auto & note : notes) {
//if (note.contains(findStr,Qt::CaseInsensitive) )
if (compare(findStr , note)) if (compare(findStr , note))
{ {
found=true; found=true;
@ -752,18 +756,22 @@ bool DailySearchTab::find(QDate& date,Day* day)
} }
break; break;
case ST_NONE : case ST_NONE :
return false;
break; break;
} }
if (found) { if (found) {
addItem(date , valueToString(foundValue,"------"),alignment ); addItem(date , valueToString(foundValue,"------"),alignment );
return true; passFound++;
daysFound++;
} }
return false; return ;
}; };
void DailySearchTab::search(QDate date) void DailySearchTab::search(QDate date)
{ {
if (!date.isValid()) {
qWarning() << "DailySearchTab::find invalid date." << date;
return;
}
guiProgressBar->show(); guiProgressBar->show();
statusProgress->show(); statusProgress->show();
guiDisplayTable->clearContents(); guiDisplayTable->clearContents();
@ -772,47 +780,16 @@ void DailySearchTab::search(QDate date)
} }
foundString.clear(); foundString.clear();
passFound=0; passFound=0;
int count = 0; while (date >= earliestDate) {
int no_data = 0;
Day*day;
while (true) {
count++;
nextDate = date; nextDate = date;
if (passFound >= passDisplayLimit) { if (passFound >= passDisplayLimit) break;
break;
} find(date);
if (date < firstDate) { guiProgressBar->setValue(++daysProcessed);
break;
}
if (date > lastDate) {
break;
}
daysSearched++;
guiProgressBar->setValue(daysSearched);
if (date.isValid()) {
// use date
// find and add
//daysSearched++;
day= p_profile->GetDay(date);
if (day) {
if (find(date, day) ) {
passFound++;
daysFound++;
}
} else {
no_data++;
daysSkipped++;
// Skip day. maybe no sleep or sdcard was no inserted.
}
} else {
qWarning() << "DailySearchTab::search invalid date." << date;
break;
}
date=date.addDays(-1); date=date.addDays(-1);
} }
endOfPass(); endOfPass();
return ; return ;
}; };
void DailySearchTab::addItem(QDate date, QString value,Qt::Alignment alignment) { void DailySearchTab::addItem(QDate date, QString value,Qt::Alignment alignment) {
@ -838,7 +815,7 @@ void DailySearchTab::addItem(QDate date, QString value,Qt::Alignment alignment)
void DailySearchTab::endOfPass() { void DailySearchTab::endOfPass() {
startButtonMode=false; // display Continue; startButtonMode=false; // display Continue;
QString display; QString display;
if ((passFound >= passDisplayLimit) && (daysSearched<daysTotal)) { if ((passFound >= passDisplayLimit) && (daysProcessed<daysTotal)) {
statusProgress->setText(centerLine(tr("More to Search"))); statusProgress->setText(centerLine(tr("More to Search")));
statusProgress->show(); statusProgress->show();
startButton->setEnabled(true); startButton->setEnabled(true);
@ -862,9 +839,6 @@ void DailySearchTab::endOfPass() {
void DailySearchTab::on_dateItemClicked(QTableWidgetItem *item) void DailySearchTab::on_dateItemClicked(QTableWidgetItem *item)
{ {
// a date is clicked
// load new date
// change tab
int row = item->row(); int row = item->row();
int col = item->column(); int col = item->column();
guiDisplayTable->setCurrentItem(item,QItemSelectionModel::Clear); guiDisplayTable->setCurrentItem(item,QItemSelectionModel::Clear);
@ -1021,36 +995,24 @@ void DailySearchTab::on_clearButton_clicked()
selectUnits->hide(); selectUnits->hide();
hideResults(); hideResults();
} }
void DailySearchTab::on_startButton_clicked() void DailySearchTab::on_startButton_clicked()
{ {
if (startButtonMode) { if (startButtonMode) {
// have start mode search (latestDate );
// must set up search from the latest date and go to the first date.
search (lastDate );
startButtonMode=false; startButtonMode=false;
} else { } else {
// have continue search mode;
search (nextDate ); search (nextDate );
} }
} }
void DailySearchTab::on_intValueChanged(int ) { void DailySearchTab::on_intValueChanged(int ) {
//Turn off highlighting by deslecting edit capabilities
selectInteger->findChild<QLineEdit*>()->deselect(); selectInteger->findChild<QLineEdit*>()->deselect();
criteriaChanged(); criteriaChanged();
} }
void DailySearchTab::on_doubleValueChanged(double ) { void DailySearchTab::on_doubleValueChanged(double ) {
//Turn off highlighting by deslecting edit capabilities
selectDouble->findChild<QLineEdit*>()->deselect(); selectDouble->findChild<QLineEdit*>()->deselect();
criteriaChanged(); criteriaChanged();
} }
@ -1060,7 +1022,7 @@ void DailySearchTab::on_textEdited(QString ) {
} }
void DailySearchTab::on_dailyTabWidgetCurrentChanged(int ) { void DailySearchTab::on_dailyTabWidgetCurrentChanged(int ) {
// Any time a tab is changed - then the day information should be valid. // Any time a tab (daily, events , notes, bookmarks, seatch) is changed
// so finish updating the ui display. // so finish updating the ui display.
delayedCreateUi(); delayedCreateUi();
} }
@ -1071,7 +1033,7 @@ void DailySearchTab::displayStatistics() {
// display days searched // display days searched
QString skip= daysSkipped==0?"":QString(tr(" Skip:%1")).arg(daysSkipped); QString skip= daysSkipped==0?"":QString(tr(" Skip:%1")).arg(daysSkipped);
summaryProgress->setText(centerLine(QString(tr("Searched %1/%2%3 days.")).arg(daysSearched).arg(daysTotal).arg(skip) )); summaryProgress->setText(centerLine(QString(tr("%1/%2%3 days.")).arg(daysProcessed).arg(daysTotal).arg(skip) ));
// display days found // display days found
summaryFound->setText(centerLine(QString(tr("Found %1.")).arg(daysFound) )); summaryFound->setText(centerLine(QString(tr("Found %1.")).arg(daysFound) ));
@ -1135,12 +1097,12 @@ void DailySearchTab::criteriaChanged() {
maxInteger = 0; maxInteger = 0;
minDouble = 0.0; minDouble = 0.0;
maxDouble = 0.0; maxDouble = 0.0;
firstDate = p_profile->FirstDay(MT_CPAP); earliestDate = p_profile->FirstDay(MT_CPAP);
lastDate = p_profile->LastDay(MT_CPAP); latestDate = p_profile->LastDay(MT_CPAP);
daysTotal= 1+firstDate.daysTo(lastDate); daysTotal= 1+earliestDate.daysTo(latestDate);
daysFound=0; daysFound=0;
daysSkipped=0; daysSkipped=0;
daysSearched=0; daysProcessed=0;
startButtonMode=true; startButtonMode=true;
//initialize progress bar. //initialize progress bar.
@ -1189,6 +1151,7 @@ QString DailySearchTab::formatTime (qint32 ms) {
qint32 minutes = ms / 60000; qint32 minutes = ms / 60000;
ms = ms % 60000; ms = ms % 60000;
qint32 seconds = ms /1000; qint32 seconds = ms /1000;
//return QString(tr("%1h %2m %3s")).arg(hours).arg(minutes).arg(seconds);
return QString("%1:%2:%3").arg(hours).arg(minutes,2,10,QLatin1Char('0')).arg(seconds,2,10,QLatin1Char('0')); return QString("%1:%2:%3").arg(hours).arg(minutes,2,10,QLatin1Char('0')).arg(seconds,2,10,QLatin1Char('0'));
} }

View File

@ -39,7 +39,7 @@ class DailySearchTab : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
DailySearchTab ( Daily* daily , QWidget* , QTabWidget* ) ; DailySearchTab ( Daily* daily , QWidget* , QTabWidget* ) ;
~DailySearchTab(); ~DailySearchTab();
private: private:
@ -58,9 +58,9 @@ private:
const int passDisplayLimit = 30; const int passDisplayLimit = 30;
const int stringDisplayLen = 80; const int stringDisplayLen = 80;
enum ValueMode { invalidValueMode, notUsed , minutesToMs ,hoursToMs, hundredths , opWhole , displayWhole , opString, displayString}; enum ValueMode { invalidValueMode , notUsed , minutesToMs , hoursToMs , hundredths , opWhole , displayWhole , opString , displayString};
enum SearchTopic { ST_NONE, ST_DISABLED_SESSIONS, ST_NOTES, ST_NOTES_STRING, ST_BOOKMARKS, ST_BOOKMARKS_STRING, ST_AHI, ST_SESSION_LENGTH, ST_SESSIONS_QTY, ST_DAILY_USAGE, ST_EVENT }; enum SearchTopic { ST_NONE = 0 , ST_DAYS_SKIPPED = 1 , ST_DISABLED_SESSIONS = 2 , ST_NOTES = 3 , ST_NOTES_STRING , ST_BOOKMARKS , ST_BOOKMARKS_STRING , ST_AHI , ST_SESSION_LENGTH , ST_SESSIONS_QTY , ST_DAILY_USAGE, ST_EVENT };
enum OpCode { enum OpCode {
//DO NOT CHANGE NUMERIC OP CODES because THESE VALUES impact compare operations. //DO NOT CHANGE NUMERIC OP CODES because THESE VALUES impact compare operations.
@ -125,7 +125,7 @@ enum OpCode {
void delayedCreateUi(); void delayedCreateUi();
void search(QDate date); void search(QDate date);
bool find(QDate& , Day* day); void find(QDate&);
void criteriaChanged(); void criteriaChanged();
void endOfPass(); void endOfPass();
void displayStatistics(); void displayStatistics();
@ -153,14 +153,14 @@ enum OpCode {
int nextTab; int nextTab;
int channelId; int channelId;
QDate firstDate ; QDate earliestDate ;
QDate lastDate ; QDate latestDate ;
QDate nextDate; QDate nextDate;
// //
int daysTotal; int daysTotal;
int daysSkipped; int daysSkipped;
int daysSearched; int daysProcessed;
int daysFound; int daysFound;
int passFound; int passFound;