Skip to content

Commit f46a7c3

Browse files
committed
-Polished/refactored code.
-Updated docs -Turned off animations for charts. -Fixed issue where Tasker will not render proper metadata for commitments with "Everyday" frequency. -Releasing 0.1.1 -TODO:Polish code -TODO:Start using temporary branches -TODO:Fix bugs(like chart rendering) that happen with "Everyday" commitments -TODO:Inspect workflows for deleting commitments
1 parent a4b5295 commit f46a7c3

File tree

104 files changed

+1283
-785
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+1283
-785
lines changed

Tasker/AudioMachine.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ using Engine::AudioDevice;
3535
using Engine::AudioMachine;
3636

3737
/**
38-
* @brief AudioMachine::AudioMachine
38+
* @brief AudioMachine::AudioMachine initializes the AudioDevice and all other
39+
* state(such as audio formats) to enable the AudioDevice to function properly.
3940
*/
4041
AudioMachine::AudioMachine() : audioDevice(nullptr), qAudioInput(nullptr) {
4142
QAudioFormat format;
@@ -117,7 +118,9 @@ void AudioMachine::stopRecording() {
117118
qAudioInput->stop();
118119
audioDevice->close();
119120
}
120-
bool AudioMachine::isAudioDeviceValid() {
121-
audioDevice->isOpen();
122-
return audioDevice->isOpen();
123-
}
121+
/**
122+
* @brief AudioMachine::isAudioDeviceValid if the AudioDevice is open, then this
123+
* function returns true. Otherwise, it returns false.
124+
* @return
125+
*/
126+
bool AudioMachine::isAudioDeviceValid() { return audioDevice->isOpen(); }

Tasker/AudioMachine.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ class AudioMachine;
1010
}
1111

1212
/**
13-
* @brief The Engine::AudioMachine class
13+
* @brief The Engine::AudioMachine class bundles and abstracts the details of
14+
* AudioDevice to make the audio device(such as built-in microphone) into a
15+
* stateful machine. It also makes it easier to interface with AudioDevice by
16+
* providing methods such as stopRecording().
1417
*/
1518
class Engine::AudioMachine : public QObject {
1619
Q_OBJECT

Tasker/CommStatsQWidget.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ CommStatsQWidget::CommStatsQWidget(QWidget *parent)
4949
commitmentMetaDataText.resize(100);
5050
beginDateText.resize(100);
5151
setSelectable(true);
52-
// this->ui->GoalQLabel->setAlignment(Qt::AlignCenter);
53-
// this->la
54-
// qDebug()<<""
55-
// snapshot.setMaximumSize(600, 600);
5652
qDebug() << "size of snapshot=" << snapshot.size();
5753
qDebug() << "size polocy of snapshot" << snapshot.sizePolicy();
5854
// snapshot.setMaximumHeight(400);
@@ -349,26 +345,26 @@ void CommStatsQWidget::saveCurrentSession() {
349345
void CommStatsQWidget::updateCommitmentInfoStatsQWidget() {
350346
commitmentMetaDataText.fill(' ');
351347
QString frequencyString{};
352-
// frequencyString.reserve(20);
353-
// frequencyString.resize(20);
354-
frequencyString.append(", ");
355-
frequencyString.append(QString::number(
356-
User::getInstance()->getCurrentCommitment().getFrequency().frequency));
357348
if (User::getInstance()->getCurrentCommitment().getType() ==
358349
udata::CommitmentType::WEEKLY) {
350+
351+
frequencyString.append(", ");
352+
frequencyString.append(QString::number(
353+
User::getInstance()->getCurrentCommitment().getFrequency().frequency));
359354
frequencyString.append(" time(s) a week.");
355+
356+
} else if (User::getInstance()->getCurrentCommitment().getType() ==
357+
udata::CommitmentType::EVERDAY) {
358+
frequencyString.append(", Everyday");
359+
360360
} else {
361361
// Not supported at the moment
362362
}
363-
qDebug() << "commitmentMetaDataText before format time-->"
364-
<< commitmentMetaDataText;
363+
365364
util::formatTime(
366365
commitmentMetaDataText,
367-
368366
User::getInstance()->getCurrentCommitment().getFrequency().goal,
369367
frequencyString, 0);
370-
qDebug() << "commitmentMetaDataText after format time-->"
371-
<< commitmentMetaDataText;
372368
this->ui->goalQLabel->setText(commitmentMetaDataText);
373369
}
374370
void CommStatsQWidget::updateBeginDateQLabel() {

Tasker/CommStatsQWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private slots:
121121
// QVBoxLayout layout{};
122122
CreateCommitmentQWidget createCommimentWindow;
123123
NewSessionQWidget newSessionQWidget;
124-
udata::CommitmentSnaphot snapshot;
124+
CommitmentSnaphot snapshot;
125125
void updateSnapshot();
126126
Perf::PerfTimer newPerfTimer{};
127127
};

Tasker/Commitment.cpp

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,28 @@ using namespace udata;
1111
* @brief Commitment::Commitment
1212
*/
1313
Commitment::Commitment() {}
14-
14+
/**
15+
* @brief Commitment::Commitment Creates a new commitment. This constructor
16+
* tries its best to solve any date conflicts such as dateStart being greater
17+
* than dateEnd, which should not happen. It also updates all the TimeWindow
18+
* objects in commitment so that the data is up to date with the current date of
19+
* the machine.
20+
* @param newName The name of this new commitment.
21+
* @param newStart The date this commitment started. If, for whatever reason,
22+
* this date happens to be earlier than the current date of the machine, then
23+
* the current date is fetched from the system and this parameter is
24+
* overwritten.
25+
* @param newEnd The date this commitment will end, if it has an end date.
26+
* @param newFrequency The object that describes the frequency of this
27+
* commitment(how many times a week the user will commit to this).
28+
* @param newType The type of commitment this is; WEEKLY, MONTHLY, etc.
29+
* @param newNoEndDate Decides whether or not this commitment has an enddate.
30+
*/
1531
Commitment::Commitment(QString newName, QDate newStart, QDate newEnd,
16-
udata::CommitmentFrequency newInterval,
32+
udata::CommitmentFrequency newFrequency,
1733
CommitmentType newType, bool newNoEndDate)
1834
: name{newName}, dateStart{newStart}, dateEnd{newEnd},
19-
frequency{newInterval},
35+
frequency{newFrequency},
2036
commitmentWindows{}, Type{newType}, noEndDate{newNoEndDate} {
2137
if (dateStart < QDate::currentDate()) {
2238
dateStart = QDate::currentDate();
@@ -35,15 +51,17 @@ void Commitment::setFrequency(long long newTime, int newFrequency,
3551
}
3652
void Commitment::setFrequency(CommitmentFrequency newFrequency) {
3753
frequency = newFrequency;
38-
}
54+
} /**
55+
* @brief Commitment::setCommitmentWindows
56+
* @param newCommitmentWindows
57+
* @note updates commitment windows if the date between this commitment and
58+
* the system are out of sync.
59+
*/
3960
void Commitment::setCommitmentWindows(
4061
QVector<TimeWindow> &newCommitmentWindows) {
4162
for (auto windows : newCommitmentWindows) {
4263
commitmentWindows.append(windows);
4364
}
44-
qDebug() << "setting windows on this commitment-->"
45-
<< commitmentWindows.length();
46-
// commitmentWindows = newCommitmentWindows;
4765
}
4866
void Commitment::setType(CommitmentType newType) { Type = newType; }
4967
CommitmentType &Commitment::getType() { return Type; }
@@ -88,12 +106,16 @@ void Commitment::updateCommitmentWindows(Session newSession) {
88106
*/
89107
void Commitment::updateCommitmentWindows() {
90108
QDate currentDate = QDate::currentDate();
109+
// If the user is done with this commitment, our work is done. There is no
110+
// update needed.
91111
if (isDone()) {
92-
if (name == "Test#100") {
93-
qDebug() << "Test#100 is done!";
94-
}
95112
return;
96-
} else if (commitmentWindows.isEmpty()) {
113+
114+
}
115+
// If there are no TimeWindow objects that are part of the commitment then we
116+
// are constructing this Commitment for the first time and only need a single
117+
// TimeWindow.
118+
else if (commitmentWindows.isEmpty()) {
97119
commitmentWindows.push_back(TimeWindow{});
98120
TimeWindow &newWindow = commitmentWindows.last();
99121
newWindow.startDate.setDate(currentDate.year(), currentDate.month(),
@@ -103,6 +125,8 @@ void Commitment::updateCommitmentWindows() {
103125
currentDate.day());
104126
newWindow.frequency = frequency.frequency;
105127
} else {
128+
// If our TimeWindow objects are up to date, then we don't need to update
129+
// them :)
106130
TimeWindow &lastWindow = commitmentWindows.last();
107131
int daysSinceLastCommitmentWindow =
108132
lastWindow.startDate.daysTo(QDate::currentDate());
@@ -112,7 +136,11 @@ void Commitment::updateCommitmentWindows() {
112136

113137
else if (daysSinceLastCommitmentWindow < frequency.timeWindowSize) {
114138
return;
115-
} else if (daysSinceLastCommitmentWindow >= frequency.timeWindowSize) {
139+
}
140+
// Imagine we had a weekly commitment
141+
// If it has been more than week since the last time we added a TimeWindow,
142+
// then we might need to add 1 or more TimeWindow objects to this commitment
143+
else if (daysSinceLastCommitmentWindow >= frequency.timeWindowSize) {
116144
int NumberOfTimeWindows =
117145
daysSinceLastCommitmentWindow / frequency.timeWindowSize;
118146
currentDate = lastWindow.endDate.addDays(1);
@@ -134,15 +162,10 @@ void Commitment::updateCommitmentWindows() {
134162
* updated by this function.
135163
*/
136164
void Commitment::update() {
137-
// updateCommitmentWindows();
138-
qDebug() << "upating-->" << name;
139165
if (noEndDate) {
140-
qDebug() << "update on Commitment#1";
141166
done = false;
142167
return;
143168
}
144-
qDebug() << "update on Commitment#2";
145-
// << commitmentWindows.last().endDate << "," << dateEnd;
146169
if (QDate::currentDate() > dateEnd) {
147170
done = true;
148171
}
@@ -165,12 +188,11 @@ void Commitment::setDone(bool newDone) { done = newDone; }
165188
* Meaning this function, in that case, will return true.
166189
*
167190
* @note Commitments that have noEndDate set to "true" are never considered
168-
* "done". In such case, this function will always return "false".
191+
* "done". In such case, this function will always return false.
169192
* @return true if this commitment is "done". Otherwise, it returns false.
170193
*/
171194
bool Commitment::isDone() {
172195
update();
173-
qDebug() << "isDone#1";
174196
return done;
175197
}
176198
QVector<TimeWindow> &Commitment::getCommitmentWindows() {
@@ -214,8 +236,6 @@ QDataStream &udata::operator>>(QDataStream &in,
214236
*/
215237
QDataStream &udata::operator<<(QDataStream &out,
216238
const udata::Commitment &newCommitment) {
217-
qDebug() << "QDataStream &udata::operator<<(QDataStream &out, const "
218-
"udata::Commitment &newCommitment)";
219239
out << newCommitment.name << newCommitment.dateStart << newCommitment.dateEnd
220240
<< newCommitment.frequency << newCommitment.Type
221241
<< newCommitment.noEndDate;
@@ -262,9 +282,6 @@ QDataStream &udata::operator>>(QDataStream &in,
262282
in >> newDone;
263283

264284
newCommitment.name = commitmentName;
265-
if (commitmentName == "Poetry") {
266-
qDebug() << "number of time windows:" << newTimeWindows.length();
267-
}
268285
newCommitment.dateStart = commitmentDateStart;
269286
newCommitment.dateEnd = commitmentDateEnd;
270287
newCommitment.noEndDate = newNoEndDate;
@@ -285,7 +302,6 @@ QDataStream &udata::operator<<(QDataStream &out,
285302
out << s;
286303
};
287304
out << newTimeWindow.frequency;
288-
qDebug() << "newTimeWindow startDate=*****************#2";
289305
return out;
290306
}
291307
QDataStream &udata::operator>>(QDataStream &in, TimeWindow &newTimeWindow) {
@@ -294,8 +310,6 @@ QDataStream &udata::operator>>(QDataStream &in, TimeWindow &newTimeWindow) {
294310
int TimeWindowFrequency = 0;
295311
in >> newStartDate >> newEndDate;
296312
newTimeWindow.startDate = newStartDate;
297-
qDebug()
298-
<< "newTimeWindow startDate=*****************#1"; //<<newTimeWindow.startDate;
299313
newTimeWindow.endDate = newEndDate;
300314
int sessionCount = 0;
301315
in >> sessionCount;
@@ -387,8 +401,3 @@ QString Commitment::summary() const {
387401
return summary;
388402
}
389403
CommitmentFrequency &Commitment::getFrequency() { return frequency; }
390-
/**
391-
* @brief Commitment::setSessions
392-
* @param value
393-
*/
394-
void Commitment::setSessions(QVector<Session> value) {}

Tasker/Commitment.h

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,33 @@
1515
#include <StatsUtility.h>
1616

1717
/**
18-
*@brief The udata namespace has anything related to
19-
* data that persistent for users such as Commitment, Task, Session etc.
18+
*@brief The udata namespace has any entities related to
19+
* data that is persistent for users such as Commitment, Task, Session etc. All
20+
*utilities such as UdataUtils are also part of this namespace.
2021
*/
2122
namespace udata {
22-
2323
class Commitment;
2424
enum class CommitmentType;
2525
struct CommitmentFrequency;
26+
/**
27+
* @brief The TimeWindow struct represents a span of time(such as a week) that
28+
* the user has a number of tasks(defined by frequency) to complete for this
29+
* partifuclar TimeWindow, whether that'd be a week or a month. startDate is the
30+
* beginning of the TimeWindow, while endDate is the end of that TimeWindow(the
31+
* seventh day in the case of a week.)
32+
*/
2633
struct TimeWindow {
2734
QDate startDate;
2835
QDate endDate;
2936
QVector<Session> sessions;
3037
/**
3138
* @brief frequency
32-
* The only times the client(Commitment) should to write to this field is
33-
* when creating the TimeWindow for the first time and when a TimeWindow is
39+
* The only times the client(Commitment) should be able to write to this field
40+
* is when creating the TimeWindow for the first time, when a TimeWindow is
3441
* opened (isOpen() returns true) and not done yet(isDone() returns false )
3542
* and the frequency changes as a result of the Commitment's frequency
36-
* changing. Otherwise, frequency should not be modified.
43+
* changing. This frequency may also be modified by the user when they edit a
44+
* commitment .Otherwise, frequency should not be modified.
3745
*/
3846
int frequency;
3947
/**
@@ -66,28 +74,29 @@ QDataStream &operator<<(QDataStream &out, const TimeWindow &);
6674
QDataStream &operator>>(QDataStream &in, TimeWindow &);
6775
QDataStream &operator<<(QDataStream &out, const CommitmentType &);
6876
QDataStream &operator>>(QDataStream &in, CommitmentType &);
77+
6978
} // namespace udata
7079

7180
/**
7281
* @brief The udata::Commitment class
7382
*/
74-
enum class udata::CommitmentType { WEEKLY, MONTHLY, Custom };
83+
enum class udata::CommitmentType { WEEKLY, MONTHLY, EVERDAY, Custom };
7584
/**
76-
* @brief The util::CommitmentFrequency struct represents \
77-
* the time the user aims to spend per session(time) on each commitment \
85+
* @brief The util::CommitmentFrequency struct represents
86+
* the time the user aims to spend per session(time) on each commitment
7887
* AND how often they intend to spend that amount of time on each specific
79-
*Task/Session of \ the commitment.
80-
*@note Beware that this struct DOES NOT strictly \
81-
* "define" whether the user has completed a "session" \
82-
* withtin a certain TimeWindow. \
88+
*Task/Session of the commitment.
89+
*@note Beware that this struct DOES NOT strictly
90+
* "define" whether the user has completed a "session"
91+
* withtin a certain TimeWindow.
8392
*For example; suppose Alice commits to write 30 minutes everyday.
8493
* In that case the struct would look like this
8594
* struct util:CommitmentFrequency
8695
* {
8796
* time = 1800 //30 minutes in seconds
8897
* frequency = 1;
8998
* timeWindowSize = 1;
90-
* //The frequency variable represents how many times and the timeWindowSize\
99+
* //The frequency variable represents how many times and the timeWindowSize
91100
* variable represents the size of the time
92101
* }
93102
* In the case of twice a week:
@@ -101,11 +110,11 @@ enum class udata::CommitmentType { WEEKLY, MONTHLY, Custom };
101110
*there will 7 sessions. It just means that was Alice's optimal goal, and this
102111
*can be displayed in the
103112
* viewer(UI) as one sees fit. There could very much be the case where Alice
104-
*decides \
113+
*decides
105114
* to do 14 sessions of 15 minutes(14x15=30x7). A TimeWindow(in the case of
106-
*Alice a week) is \
115+
*Alice a week) is
107116
* is only considered accomplished(or closed if you will) when the total amount
108-
*of \ time(in this case 210 minutes) is reached. Tasker should encourage the
117+
*of time(in this case 210 minutes) is reached. Tasker should encourage the
109118
*user to commit to Frequency number of sessions per week(TimeWindow), BUT the
110119
*user may choose to "split" that time during the week into as many sessions as
111120
*they see fit. Hopefully that makes sense. This struct, being a simple struct,
@@ -186,6 +195,7 @@ class udata::Commitment {
186195
CommitmentType Type;
187196
bool noEndDate;
188197
bool done = false;
198+
189199
void update(); // helper function for isDone()
190200

191201
public:
@@ -197,15 +207,13 @@ class udata::Commitment {
197207
QDate &getDateEnd();
198208
void setDateEnd(QDate value);
199209
QVector<Session> getAllSessions();
200-
void setSessions(QVector<udata::Session> value);
201210
void setName(QString);
202211
const QString &getName() const;
203212
void setType(CommitmentType);
204213
CommitmentType &getType();
205214
QString summary() const;
206215
void updateCommitmentWindows(Session);
207216
void updateCommitmentWindows();
208-
209217
bool isDone();
210218
void setDone(bool);
211219
void setFrequency(long long newTime, int newFrequency, int newTimeWinowSize);

0 commit comments

Comments
 (0)