Skip to content

Commit

Permalink
v0.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jgclark committed Nov 10, 2023
1 parent 4717ed4 commit 58ac40c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 42 deletions.
7 changes: 6 additions & 1 deletion jgclark.Summaries/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
(And see the full [README](https://github.com/NotePlan/plugins/tree/main/jgclark.Summaries).)

<!-- - ??? make below work with all options -->

## [0.20.1] - 2023-11-10
- fix Refresh button not working after '/append progress update' command
- turns down logging against an API error

## [0.20.0] - 2023-10-12
### Added
- new **today progress** command that summarises tags or mentions _within today's note_. This could be useful for summarising `@calories(...)` noted from different meals, for example. This can also be invoked by an x-callback call, and through template calls. (For @seanokana)
Expand All @@ -10,7 +15,7 @@

## [0.19.4] - 2023-09-26 unreleased
### Added
- refresh button to output of **periodStats** command, where the time period is "<period> to date"
- Refresh button to output of **periodStats** command, where the time period is "<period> to date"
## [0.19.3] - 2023-08-06
### Fixed
- date logic on 'weeklyStatsToCSV' command output
Expand Down
24 changes: 12 additions & 12 deletions jgclark.Summaries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ The many **settings** for this command are set in the Plugin Prererence pane:
- Exclude today's entries? Whether to exclude today's entries in progress updates. Can be enabled if you tend to run the progress update as part of a start-of-day routine, and only add the updates later in the day.

### Calling from a Template
This command can be used in any Template, but is particularly designed to be used from a "Daily Note Template" by including a '**progressUpdate()**' command tag in a template such as:
This command can be used in any Template, but is particularly designed to be used from a "Daily Note Template" by including a '**progressUpdate(...)**' command tag in a template such as:
```
<%- progressUpdate({period: 'wtd', progressHeading: 'Habits', showSparklines: true}) %>
```
Expand All @@ -136,46 +136,46 @@ You can add many parameters, _which if present override all the main settings de
3. `showSparklines`: true (default) or false.
4. `excludeToday`: false (default) or true (applies when you set a date for period and you don't want to include today in the visualization -- e.g. if you use this template as part of your /dayStart routine and you haven't had time to do the habit yet!)

Each must be a`key:value` pair, with following pairs separated by commas, and all enclosed in curly brackets. The 'key' names of the other possible settings are found in the `plugin.json` file installed as part of the plugin.
Each must be a `key:"value"` pair, with following pairs separated by commas, and all enclosed in curly brackets (i.e. in [JSON5 format](https://json5.org)). The 'key' names of the other possible settings are found in the `plugin.json` file installed as part of the plugin.

Note: if you specifiy any of the settings that take hashtags or mentions, then _only those ones will be used_. E.g. `{... "progressYesNo":"#read,#pray,#exercise", ...}` will not use any of the usual '#hashtags or count' or '@mentions to count', but only show Yes/No for each of those 3 tags.
Note: if you specifiy any of the settings that take hashtags or mentions, then _only those ones will be used_. E.g. `{... progressYesNo:"#read,#pray,#exercise", ...}` will not use any of the usual '#hashtags or count' or '@mentions to count', but only show Yes/No for each of those 3 tags.

### Calling by x-callback
This is similar to the Template above: create a JSON version of "key":"value" pairs for parameters that are different from the normal saved settings, and then prefix with the string `noteplan://x-callback-url/runPlugin?pluginID=jgclark.Summaries&command=progressUpdate&arg0=`
This is similar to the Template above: create a JSON5 version of `key:"value"` pairs for parameters that are different from the normal saved settings, and then prefix with the string `noteplan://x-callback-url/runPlugin?pluginID=jgclark.Summaries&command=progressUpdate&arg0=`

For example:
```
noteplan://x-callback-url/runPlugin?pluginID=jgclark.Summaries&command=progressUpdate&arg0={"period": "2022-02-15", "excludeToday": true, "progressHeading": "Post-Birthday Habits", "showSparklines": true}
```

Note: The 'key' part and any string-based value part must be enclosed in **double quote marks** ("like this"), to make it valid JSON.
Note: Any string-based value part must be enclosed in **double quote marks** to make it valid JSON5.

Note: The JSON parts needs to be **urlencoded** before it can be used. (For help with this, see the **Get-X-Callback-URL command** from the "Link Creator" Plugin. Select RUN a Plugin command > progressUpdate ...)

## 'today progress' command (alias: 'tp')
Sometimes you want to have a summary of progress on something within a day -- for example `@carlories(...)` or `@exercise(...)`. To summarise these from today's daily note use **today progress**, which works in the same way as **appendProgressUpdate**.
Sometimes you want to have a summary of progress on something within a day -- for example `@carlories(...)` or `@exercise(...)`. To summarise these from today's daily note use **/today progress**, which works in the same way as **/append progress update**.

When run by the user as a **/command**, it inserts the output into the current note, and uses the following settings from the plugin pane:
When run by the user directly, it adds the output onto the current note, and uses the following settings from the plugin pane:
- #hashtags and @mentions to total: a comma separated list of the terms to total from today's note
- Today Progress heading: optional heading to insert before the results.

Or you can run it from an **x-callback** using the form `noteplan://x-callback-url/runPlugin?pluginID=jgclark.Summaries&command=today%20progress&arg0=?&arg1=?` where
Or you can run it from an **x-callback** using the form `noteplan://x-callback-url/runPlugin?pluginID=jgclark.Summaries&command=todayProgress&arg0=?&arg1=?` where
- `arg0` is the comma separated list of items to summarise
- `arg1` is the optional heading to use before the results

For example:
```
noteplan://x-callback-url/runPlugin?pluginID=jgclark.Summaries&command=today%20progress&arg0=@exercise,@calories&arg1=Post-Birthday%20Habits
noteplan://x-callback-url/runPlugin?pluginID=jgclark.Summaries&command=todayProgress&arg0=@exercise,@calories&arg1=Post-Birthday%20Habits
```

You can also run it as part of a **template**; for example use in a "Daily Note Template" by including a line like the following: `<%- todayProgressFromTemplate({todayProgressItems: '@calories, @exercise', todayProgressHeading: 'Progress Today'}) %>`. (Note the slightly different 'command name', and that this time the parameters need to be given as a JSON object of key:value pairs.)
You can also run it as part of a **template**; for example use in a "Daily Note Template" by including a line like the following: `<%- todayProgressFromTemplate({todayProgressItems: '@calories, @exercise', todayProgressHeading: 'Progress Today'}) %>`. (Note the slightly different 'command name', and that this time the parameters need to be given as a JSON5 object of key:'value' pairs.)

## 'periodStats' command (aliases: 'statsPeriod', 'stp')
This command generates some simple counts and other statistics of #hashtags or @mentions that you specify, and saves them into notes in a special 'Summaries' folder. For example:
- **count** every time you've noted you've visited family this month -- i.e. counts the number of times `#family` is mentioned in calendar notes this month
- **count** the times you've met with staff member Alice this year so far -- i.e. counts the number of times `@alice` is mentioned in calendar notes this year
- **sum** and **average** the length of your runs last quarter -- i.e. stats on all the mentions of `@run(N)` mentions (where, for example, `@run(7.5)` means a run of 7.5km/miles)
- automatically add your progress this week against your goal of getting an **average** 8 hours `@sleep()` when you log that each day.
- automatically add your progress this week against your goal of getting an **average** 8 hours `@sleep(N)` when you log that each day.

Here's an example of what it shows with sparklines:

Expand Down Expand Up @@ -204,7 +204,7 @@ It starts by asking for the time period you wish to operate over:

It asks where to save its output: to a specially-created note in the Summaries folder, or to the current note.

<img alt="Calendar Notes types" src="[email protected]" width=500px align="right"/>
<img alt="Calendar Notes types" src="[email protected]" width="220px" align="right" />
It also offers to write to the current Weekly / Monthly / Quarterly / Yearly notes if you have them enabled in the preferences.

It updates the previous note for that same time period, if it already exists.
Expand Down
9 changes: 5 additions & 4 deletions jgclark.Summaries/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"plugin.author": "Jonathan Clark",
"plugin.url": "https://github.com/NotePlan/plugins/tree/main/jgclark.Summaries/",
"plugin.changelog": "https://github.com/NotePlan/plugins/blob/main/jgclark.Summaries/CHANGELOG.md",
"plugin.version": "0.20.0",
"plugin.lastUpdateInfo": "0.20.0: add new '/today progress' and '/heatmap for tag' commands, and add refresh button to /periodStats output.\n0.19.3: bug fixes on 'weekly stats generation' commands.\n0.19.2: change date library.\n0.19.1: bug fix\n. 0.19.0: adds totals and averages for hashtags as well. Improve output of averages.\n0.18.0: offers full set of summary types in /periodStats as well as /progressUpdate. Bug fixes.\n0.17.3: fix edge case of malformed @mentions.\n0.17.2: fix edge cases in /periodStats\n0.17.1: worked around API bug when processing repeats like @repeats(1/7) in Summaries commands.",
"plugin.version": "0.20.1",
"plugin.lastUpdateInfo": "0.20.1: fix refresh after '/append progress update' command. Logging change.\n0.20.0: add new '/today progress' and '/heatmap for tag' commands, and add refresh button to /periodStats output.\n0.19.3: bug fixes on 'weekly stats generation' commands.\n0.19.2: change date library.\n0.19.1: bug fix\n. 0.19.0: adds totals and averages for hashtags as well. Improve output of averages.",
"plugin.dependencies": [],
"plugin.script": "script.js",
"plugin.isRemote": "false",
Expand All @@ -27,7 +27,7 @@
"description": "Append weekly/monthly habit and progress update",
"jsFunction": "makeProgressUpdate",
"arguments": [
"JSON-formatted parameter list"
"JSON5-formatted parameter list"
]
},
{
Expand All @@ -36,7 +36,8 @@
"description": "template entry point to appendProgressUpdate command",
"jsFunction": "progressUpdate",
"arguments": [
"JSON-formatted parameter list"
"JSON5-formatted parameter list",
"Source ('command' or 'template')"
]
},
{
Expand Down
1 change: 1 addition & 0 deletions jgclark.Summaries/src/forHeatmaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ export async function calcTagStatsMap(
} catch (err) {
logError(pluginJson, `calcTagStatsMap: ${err.name}: ${err.message}`)
return new Map()
}
}
Expand Down
28 changes: 16 additions & 12 deletions jgclark.Summaries/src/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//-----------------------------------------------------------------------------
// Progress update on some key goals to include in notes
// Jonathan Clark, @jgclark
// Last updated 3.3.2022 for v0.18.0, @jgclark
// Last updated 10.11.2023 for v0.20.1, @jgclark
//-----------------------------------------------------------------------------

import pluginJson from '../plugin.json'
Expand Down Expand Up @@ -34,14 +34,14 @@ import { showMessage } from "../../helpers/userInput";
* @param {?string} params as JSON string
* @returns {string} - returns string
*/
export async function progressUpdate(params: string = ''): Promise<string> {
export async function progressUpdate(params: string = '', source: string = 'template'): Promise<string> {
try {
logDebug(pluginJson, `progressUpdate (for template): Starting with params '${params}'`)
return await makeProgressUpdate(params, 'template') ?? '<error>'
logDebug(pluginJson, `progressUpdate (for template): Starting with params '${params}' (type: ${typeof params}) and source '${source}'`)
return await makeProgressUpdate(params, source) ?? '<error>'
}
catch (err) {
logError(pluginJson, 'progressUpdate (for template)' + err.message)
return '<error>' // for completeness
logError(pluginJson, `${err.message} in progressUpdate (for template)`)
return '❗️Error: please open Plugin Console and re-run.>' // for completeness
}
}

Expand All @@ -51,18 +51,20 @@ export async function progressUpdate(params: string = ''): Promise<string> {
* If it's week to date, then use the user's first day of week from NP setting.
* @author @jgclark
*
* @param {?string} params - can pass parameter string e.g. "{"period": 'mtd', "progressHeading": 'Progress'}"
* @param {?string} params - can pass parameter string (in JSON format) e.g. '{"period": "mtd", "progressHeading": "Progress"}'
* @param {?string} source of this call (command/xcb/template)
* @returns {?string} - either return string to Template, or void to plugin
*/
export async function makeProgressUpdate(params: string = '', source: string = 'command'): Promise<string | void> {
export async function makeProgressUpdate(paramsIn: string = '', source: string = 'command'): Promise<string | void> {
try {
// Get config setting
let config: SummariesConfig = await getSummariesSettings()
let settingsForGO: OccurrencesConfig

// If there are params passed, then we've been called by a template command (and so use those).
if (params) {
// First workaround situation where paramsIn can be a null Object when called from a template. If so, make an empty JSON string.
const params = (paramsIn && typeof paramsIn === 'object') ? paramsIn : "{}"
// If there are paramsIn passed, then we've been called by a template command (and so use those).
if (params !== '') {
// logDebug(pluginJson, `makeProgressUpdate: Starting from '${source}' with params '${params}'`)
config = overrideSettingsWithEncodedTypedArgs(config, params)
// clo(config, `config after overriding with params '${params}'`)
Expand All @@ -82,7 +84,7 @@ export async function makeProgressUpdate(params: string = '', source: string = '
if (periodParam !== '') {
period = periodParam
}
logDebug('makeProgressUpdate', `Starting for period '${period}' with title '${config.progressHeading}' and params '${params}'`)
logDebug('makeProgressUpdate', `Starting for period '${period}' with title '${config.progressHeading}' / params '${params}' / source '${source}'`)

// Now deal with any parameters passed that are mentions/hashtags to work on
const paramProgressYesNo = await getTagParamsFromString(params, 'progressYesNo', '')
Expand Down Expand Up @@ -165,7 +167,9 @@ export async function makeProgressUpdate(params: string = '', source: string = '
if (source === 'template') {
// this was a template command call, so simply return the output text
logDebug('makeProgressUpdate', `-> returning text to template for '${thisHeading}' (${periodAndPartStr} for ${periodString})`)
return ((config.progressHeading !== '') ? `${'#'.repeat(config.headingLevel)} ${headingAndXCBStr}\n` : '') + output
return (config.progressHeading !== '')
? `${'#'.repeat(config.headingLevel)} ${headingAndXCBStr}\n${output}`
: output
}

if (source === 'todayProgressUpdate') {
Expand Down
3 changes: 1 addition & 2 deletions jgclark.Summaries/src/summaryHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,8 @@ export function gatherOccurrences(periodString: string, fromDateStr: string, toD
const seenMentions = n.mentions.slice().reverse()
let lastMention = ''
for (const mention of seenMentions) {
// First need to add a check for a bug: '@repeat(1/7)' is returned as [@repeat(1/7), @repeat(1]. Skip the incomplete one.
// First need to add a check for an API bug: '@repeat(1/7)' is returned as [@repeat(1/7), @repeat(1]. Skip the incomplete one.
if (mention.match(/\([^\)]+$/)) { // opening bracket not followed by closing bracket
logInfo('gatherOccurrences', `- Skipping ill-formed '${mention}'`)
continue // skip this mention
}

Expand Down
17 changes: 6 additions & 11 deletions jgclark.Summaries/src/todayProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//-----------------------------------------------------------------------------
// Progress update for Today only
// Jonathan Clark, @jgclark
// Last updated 12.10.2022 for v0.20.0, @jgclark
// Last updated 10.11.2023 for v0.20.1, @jgclark
//-----------------------------------------------------------------------------

import pluginJson from '../plugin.json'
Expand Down Expand Up @@ -42,12 +42,7 @@ import { replaceSection } from '@helpers/note'
*/
export async function todayProgressFromTemplate(params: string = ''): Promise<string> {
try {

// Testing other func
// console.log(await getTagParamsFromString(`{todayProgressItems: '@calories,@exercise,#test'}`, 'todayProgressHeading', 'def'))
// console.log(await getTagParamsFromString(`{todayProgressItems: '@calories,@exercise,#test', todayProgressHeading: ''}`, 'todayProgressHeading', 'def'))

logDebug(pluginJson, `todayProgressFromTemplate() starting with params '${params}'`)
logDebug(pluginJson, `todayProgressFromTemplate() starting with params '${params}' (type: ${typeof params})`)

// let configFromParams = JSON.parse(params)
const config = await getSummariesSettings()
Expand All @@ -63,8 +58,8 @@ export async function todayProgressFromTemplate(params: string = ''): Promise<st
return summaryStr
}
catch (err) {
logError(pluginJson, 'todayProgressFromTemplate()' + err.message)
return '<error>' // for completeness
logError(pluginJson, `${err.message} in todayProgressFromTemplate()`)
return '❗️Error: please open Plugin Console and re-run.>' // for completeness
}
}

Expand Down Expand Up @@ -158,13 +153,13 @@ export async function makeTodayProgress(itemsToShowArr: Array<string> = [], sour
logDebug('makeTodayProgress', `- created progress update in ${timer(startTime)}`)

// If we have a heading specified, make heading, using periodAndPartStr or '{{PERIOD}}' if it exists. Add a refresh button.
// Create x-callback of form `noteplan://x-callback-url/runPlugin?pluginID=jgclark.Summaries&command=progressUpdate&arg0=...` with 'Refresh' pseudo-button
// Create x-callback of form `noteplan://x-callback-url/runPlugin?pluginID=jgclark.Summaries&command=todayProgress&arg0=...` with 'Refresh' pseudo-button
let thisHeading = ''
let thisHeadingLine = ''
let headingAndXCBStr = ''
if (heading !== '') {
const xCallbackParams = [itemsToShow.join(','), heading] // need to be strings in order
const xCallbackMD = createPrettyRunPluginLink('🔄 Refresh', 'jgclark.Summaries', 'today progress', xCallbackParams)
const xCallbackMD = createPrettyRunPluginLink('🔄 Refresh', 'jgclark.Summaries', 'todayProgress', xCallbackParams)
thisHeading = formatWithFields(heading, { PERIOD: periodString })
headingAndXCBStr = `${thisHeading} ${xCallbackMD}`
thisHeadingLine = `${'#'.repeat(config.headingLevel)} ${headingAndXCBStr}`
Expand Down

0 comments on commit 58ac40c

Please sign in to comment.