logseq-habit-tracker icon indicating copy to clipboard operation
logseq-habit-tracker copied to clipboard

Question about coloring behavior in UI

Open mstine opened this issue 2 years ago • 10 comments

Hi there,

I've dug a bit through existing issues and the source code, but I'm not finding the answer to my question very easily, so I thought I'd just ask.

I started using the plugin yesterday, and I've noticed some behavior that seems odd to me but is likely intended.

Here's a habit block:

- ## Habits  
	- DONE Meditate for 5 Minutes #[[Area: 🧠🧘🏻‍♂️Mental Health]] #habit  
	- LATER Complete a Workout #[[Area: Health]] #habit  
	- DONE Read Daily Stoic #[[Area: Character Development]] #habit  
	- LATER Publish an Atomic Essay #[[Area: Writing]] #habit  

image

Notice that the habits I've checked off for today (8-16) are colored red and do not contain a number, while the habits I checked off for yesterday do contain a number, and the 1/d habits are colored green.

I take this to mean that you don't apply the final coloring/numbering to a cell until the full 24-hour day has elapsed. Is this correct?

If so, this was surprising behavior to me. I would have expected any habit which has met it's frequency/period goal to immediately be colored green (producing the subsequent "dopamine hit" from accomplishing a goal).

Thoughts?

Thanks again for a marvelous plugin!

mstine avatar Aug 16 '22 14:08 mstine

Thanks, @mstine, for compliments.

I cannot exactly reproduce it. Could you share your configuration and habit blocks for both today and yesterday?

Numbering and colouring should be immediate, though I think sometimes Logseq returns stale results to queries, if after checking any habit, numbers are not reflected, you may refresh or re-index.

Not 24-hour day, but habits are checked and coloured using a rolling window period. So for any given day if the frequency in the last n-days (7 days for a [w]eek including that day) is greater than or equal to the target, it is green, else red.

So within your first period, the day will be coloured in red until the target 5 has been surpassed within a week. In my opinion, it is the correct behaviour, though I'm open to suggestions.

Cheers

c6p avatar Aug 16 '22 19:08 c6p

Sure! The below is after I reindexed a couple of times to ensure nothing was awry with my graph.

Your logic seems sound for the numbering and coloring, but it doesn't appear to work in my case.

Thanks again.

Config

{
  "disabled": false,
  "colors": [],
  "dateFormat": "MM-DD",
  "habits": {
    "Read Daily Stoic #[[Area: Character Development]]": {
      "period": "1/d",
      "order": 1
    },
    "Complete a Workout #[[Area: Health]]": {
      "period": "5/w",
      "order": 2
    },
    "Meditate for 5 Minutes #[[Area: 🧠🧘🏻‍♂️Mental Health]]": {
      "period": "1/d",
      "order": 0
    },
    "Publish an Atomic Essay #[[Area: Writing]]": {
      "period": "5/w",
      "order": 3
    },
    "Brand new habit #[[Area: Finances]]": {
      "period": "1/d"
    }
  },
  "habitPattern": "^(LATER|DONE)?\\s*(?<habit>.*?)(?:| - (?:(?<int>\\d*?) times|(?<count>.*?)))$",
  "ignorePattern": "LATER .*",
  "hideStreak": false
}

Yesterday (August 15)

- ## Habits  
	- DONE Meditate for 5 Minutes #[[Area: 🧠🧘🏻‍♂️Mental Health]] #habit  
	- DONE Complete a Workout #[[Area: Health]] #habit  
	- DONE Read Daily Stoic #[[Area: Character Development]] #habit  
	- DONE Publish an Atomic Essay #[[Area: Writing]] #habit  

Today (August 16)

- ## Habits  
	- DONE Meditate for 5 Minutes #[[Area: 🧠🧘🏻‍♂️Mental Health]] #habit  
	- DONE Complete a Workout #[[Area: Health]] #habit  
	- DONE Read Daily Stoic #[[Area: Character Development]] #habit  
	- DONE Publish an Atomic Essay #[[Area: Writing]] #habit  

Latest Screenshot

image

mstine avatar Aug 16 '22 21:08 mstine

Update just to show how things are progressing.

Today (August 17)

- ### Habits  
	- DONE Meditate for 5 Minutes #[[Area: 🧠🧘🏻‍♂️Mental Health]] #habit  
	- DONE Complete a Workout #[[Area: Health]] #habit  
	- DONE Read Daily Stoic #[[Area: Character Development]] #habit  
	- LATER Publish an Atomic Essay #[[Area: Writing]] #habit  

Latest Screenshot

image

mstine avatar Aug 17 '22 18:08 mstine

Sorry for the late answer. I can't reproduce it. Is Logseq and the plugin updated to the latest version?

image

Did you re-index the graph? Could you try with a clean directory?

c6p avatar Aug 18 '22 16:08 c6p

My apologies for the annoyance... when I checked for updates previously, nothing happened (network hiccup I guess), so I had assumed I was up to date. Apparently, I wasn't.

Updating to 0.8.1 fixed the problem (even without a reindex).

mstine avatar Aug 18 '22 16:08 mstine

No problem. Happy to see your problem has been resolved.

Cheers.

c6p avatar Aug 19 '22 06:08 c6p

Reopening this because the behavior keeps coming back (off and on), and I'm really not sure what to do.

I studied your source code to extract the query, and everything looks fine to me, but I haven't studied the coloring code enough to know what's happening to cause this:

image

The oddities here:

  • The two habits I checked off for today have gone back to the behavior where they are colored red with no number.
  • The habit (Complete a Workout) where I completed 5 days in a 7 day period (meeting the frequency/period goal) is red until the habit is completed on 8-19, and then green going forward until today where there is no color.
  • Also, for that same habit, there's a streak of 3? I do not understand that at all.

Let me know what data I can provide to help. Over the weekend, I did a lot of cleaning out of old cruft from when I moved from Obsidian to Logseq which I thought could corrupt the graph. I also disconnected, deleted the logseq folder, and reconnected. This briefly made things better, but then the confusing behavior returned within minutes.

mstine avatar Aug 22 '22 16:08 mstine

Thank you for reopening.

While investigating, I've found a presentational bug, when there are < 14 days of habits, numbers and coloring are off in slice. I'm not sure whether your issue is triggered by this, but I think so.

Though, streak of 3 is curious. It should be 1. It seems to be a similar slicing error for the same edge case in success handling.

If I cannot solve it as quick as I want (tomorrow?), the release should have to wait next week.

Cheers

Note: In the meantime, if you add a habit 14 days before (or to the beginning of the month), your problem may be resolved. Could you try?

c6p avatar Aug 23 '22 14:08 c6p

Apologies for the delayed response.

Since last commenting, I've continued tracking habits:

At present, even after reindexing the graph, the UI seems to be stuck in a strange state:

image

All habit tracking appears to stop on August 28th, even though I have continued tracking through today, September 2. (NOTE: I have changed my marker to #[[ATOMIC HABIT ⚛️]], but that has worked as expected).

If I go back to August 1 and add habits:

image

The view gets very interesting indeed:

image image

mstine avatar Sep 02 '22 12:09 mstine

Curious.

Sorry, I couldn't find time. I'll be away on my honeymoon for a few weeks.

c6p avatar Sep 05 '22 08:09 c6p

Hi there - I hope you had a nice honeymoon! I was wondering if you're going to find time to look at this one soon. If not, no worries. Just checking in. Thanks!

mstine avatar Dec 14 '22 16:12 mstine

Thanks for reaching out and best wishes, @mstine. Sorry for late answer. I'm currently occupied with other things. I will try to find some time to look all the issues.

c6p avatar Dec 21 '22 06:12 c6p