Skip to content

Commit

Permalink
Merge pull request #304 from souponaroom/bugfix-streaks-die-by-falsey
Browse files Browse the repository at this point in the history
Change streak counts to terminate on falsey values rather than null
  • Loading branch information
lazyguru authored Jan 19, 2024
2 parents bac8d81 + 0bd5005 commit 775f7ad
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 115 deletions.
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) {
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

0 comments on commit 775f7ad

Please sign in to comment.