Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change streak counts to terminate on falsey values rather than null #304

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/TestSummary.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ summary:
style: "font-size:20px;color:yellow;margin-left: 50px;margin-top:00px;"
```

``` tracker
searchType: frontmatter
searchTarget: sleptwell
folder: diary
summary:
template: "I once slept well for {{maxStreak()::i}} days in a row!"
```
## Using Expressions

Please check [expression examples](https://github.com/pyrochlore/obsidian-tracker/blob/master/examples/TestExpression.md) for more examples.
1 change: 1 addition & 0 deletions examples/diary/2021-01-21.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ deepValue:
very:
deep: 11.1
randchar: B
sleptwell: false
---

#weight:67.3kg
Expand Down
1 change: 1 addition & 0 deletions examples/diary/2021-01-22.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ deepValue:
very:
deep: 83.3
randchar: E
sleptwell: true
---

#weight:64.7kg
Expand Down
1 change: 1 addition & 0 deletions examples/diary/2021-01-23.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ deepValue:
very:
deep: 28.8
randchar: A
sleptwell: true
---

#weight:67.3kg
Expand Down
1 change: 1 addition & 0 deletions examples/diary/2021-01-24.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ deepValue:
very:
deep: 39.4
randchar: B
sleptwell: true
---

#weight:64.1kg
Expand Down
1 change: 1 addition & 0 deletions examples/diary/2021-01-25.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ deepValue:
very:
deep: 81.4
randchar: E
sleptwell: false
---

#weight:62.4kg
Expand Down
202 changes: 101 additions & 101 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions src/expr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const fnMapDatasetToValue: FnMapDatasetToValue = {
let streak = 0;
let maxStreak = 0;
for (let dataPoint of dataset) {
if (dataPoint.value !== null) {
if (dataPoint.value) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is why I "love" typescript (sarcasm). dataPoint.value is supposed to be a number field, however in reality Obsidian is passing in booleans as well.

streak++;
} else {
streak = 0;
Expand All @@ -186,7 +186,7 @@ const fnMapDatasetToValue: FnMapDatasetToValue = {
let maxStreakStart: Moment = null;
if (dataset) {
for (let dataPoint of dataset) {
if (dataPoint.value !== null) {
if (dataPoint.value) {
if (streak === 0) {
streakStart = dataPoint.date;
}
Expand Down Expand Up @@ -216,9 +216,9 @@ const fnMapDatasetToValue: FnMapDatasetToValue = {
if (ind < arrayDataset.length - 1) {
nextPoint = arrayDataset[ind + 1];
}
if (point.value !== null) {
if (point.value) {
streak++;
if (nextPoint?.value === null) {
if (!nextPoint?.value) {
streakEnd = point.date;
}
} else {
Expand All @@ -239,7 +239,7 @@ const fnMapDatasetToValue: FnMapDatasetToValue = {
let breaks = 0;
let maxBreaks = 0;
for (let dataPoint of dataset) {
if (dataPoint.value === null) {
if (!dataPoint.value) {
breaks++;
} else {
breaks = 0;
Expand All @@ -258,7 +258,7 @@ const fnMapDatasetToValue: FnMapDatasetToValue = {
let maxBreaksStart: Moment = null;
if (dataset) {
for (let dataPoint of dataset) {
if (dataPoint.value === null) {
if (!dataPoint.value) {
if (breaks === 0) {
breaksStart = dataPoint.date;
}
Expand Down Expand Up @@ -288,9 +288,9 @@ const fnMapDatasetToValue: FnMapDatasetToValue = {
if (ind < arrayDataset.length - 1) {
nextPoint = arrayDataset[ind + 1];
}
if (point.value === null) {
if (!point.value) {
breaks++;
if (nextPoint?.value !== null) {
if (nextPoint?.value) {
breaksEnd = point.date;
}
} else {
Expand All @@ -314,7 +314,7 @@ const fnMapDatasetToValue: FnMapDatasetToValue = {
let arrayDataset = Array.from(dataset);
for (let ind = arrayDataset.length - 1; ind >= 0; ind--) {
let point = arrayDataset[ind];
if (point.value === null) {
if (!point.value) {
break;
} else {
currentStreak++;
Expand All @@ -334,7 +334,7 @@ const fnMapDatasetToValue: FnMapDatasetToValue = {
if (ind < arrayDataset.length - 1) {
currentStreakStart = arrayDataset[ind + 1].date;
}
if (point.value === null) {
if (!point.value) {
break;
} else {
currentStreak++;
Expand All @@ -355,7 +355,7 @@ const fnMapDatasetToValue: FnMapDatasetToValue = {
let arrayDataset = Array.from(dataset);
for (let ind = arrayDataset.length - 1; ind >= 0; ind--) {
let point = arrayDataset[ind];
if (point.value === null) {
if (!point.value) {
break;
} else {
if (currentStreak === 0) {
Expand All @@ -378,7 +378,7 @@ const fnMapDatasetToValue: FnMapDatasetToValue = {
let arrayDataset = Array.from(dataset);
for (let ind = arrayDataset.length - 1; ind >= 0; ind--) {
let point = arrayDataset[ind];
if (point.value === null) {
if (!point.value) {
currentBreaks++;
} else {
break;
Expand All @@ -398,7 +398,7 @@ const fnMapDatasetToValue: FnMapDatasetToValue = {
if (ind < arrayDataset.length - 1) {
currentBreaksStart = arrayDataset[ind + 1].date;
}
if (point.value === null) {
if (!point.value) {
currentBreaks++;
} else {
break;
Expand All @@ -419,7 +419,7 @@ const fnMapDatasetToValue: FnMapDatasetToValue = {
let arrayDataset = Array.from(dataset);
for (let ind = arrayDataset.length - 1; ind >= 0; ind--) {
let point = arrayDataset[ind];
if (point.value === null) {
if (!point.value) {
if (currentBreaks === 0) {
currentBreaksEnd = point.date;
}
Expand Down