c6p / logseq-habit-tracker

Habit tracker for Logseq
MIT License
95 stars 5 forks source link

Question about coloring behavior in UI #19

Closed mstine closed 1 year ago

mstine commented 2 years ago

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!

c6p commented 2 years ago

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

mstine commented 2 years ago

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 commented 2 years ago

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

c6p commented 2 years ago

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?

mstine commented 2 years ago

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).

c6p commented 2 years ago

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

Cheers.

mstine commented 2 years ago

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:

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.

c6p commented 2 years ago

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?

mstine commented 2 years ago

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

c6p commented 2 years ago

Curious.

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

mstine commented 1 year ago

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!

c6p commented 1 year ago

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.