-
Notifications
You must be signed in to change notification settings - Fork 1
Add help documentation and docstrings #29
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
18a60c6
First pass help docs and docstring test
microbit-robert 341d104
Docstring tweak
microbit-robert 1eb3c4f
More docstrings
microbit-robert 840d30e
Tweak help docs
microbit-robert 63d787c
More help docs tweaks
microbit-robert 6b03f6a
Add percent range to getCertainty docstring
microbit-robert c54d903
Remove duration paramter from stop block help docs
microbit-robert 69336c5
Version package in extension help docs
microbit-robert 9f629a9
Try using helper stubs for example code
microbit-robert 8d21e61
Update example docs after switching to clapping event
microbit-robert b1e10db
s/when when/when/g
microbit-matt-hillsdon 4ccb8af
Try linking to related docs in extension
microbit-robert 98c09f0
Remove .md extensions, is "See also" special
microbit-robert 82076b8
Revert attempts to add relative links to extension docs
microbit-robert 8f5502e
Tweak language and fix small errors
microbit-robert 831fdd9
Fix docstring at source
microbit-robert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,15 @@ | ||
| {} | ||
| { | ||
| "ml.getCertainty": "Get the certainty of an ML event in percent (0 to 100).", | ||
| "ml.getCertainty|param|event": "one of the actions the machine learning model was trained on", | ||
| "ml.isDetected": "Tests if an ML event is currently detected.", | ||
| "ml.isDetected|param|event": "one of the actions the machine learning model was trained on", | ||
| "ml.onStart": "Do something when an ML event is detected.", | ||
| "ml.onStart|param|body": "code to execute", | ||
| "ml.onStart|param|event": "one of the actions the machine learning model was trained on", | ||
| "ml.onStop": "Do something when an ML event is no longer detected.", | ||
| "ml.onStopDetailed": "Do something when an ML event is no longer detected.", | ||
| "ml.onStopDetailed|param|body": "code to execute", | ||
| "ml.onStopDetailed|param|event": "one of the actions the machine learning model was trained on", | ||
| "ml.onStop|param|body": "code to execute", | ||
| "ml.onStop|param|event": "one of the actions the machine learning model was trained on" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # on ML start | ||
|
|
||
| Gets the latest certainty value for an ML action. | ||
|
|
||
| ```sig | ||
| ml.getCertainty(ml.event.Unknown) | ||
| ``` | ||
|
|
||
| The ML model runs several times a second and calculates a certainty value for each action. The estimated action is the action with the highest certainty. An action cannot be the estimated action when its certainty is below the recognition point. Some programs may need to use the certainty values directly, for example to display or log them. Most programs can use the estimated action instead of certainty values. | ||
|
|
||
| ## Parameters | ||
|
|
||
| - **event**: one of the actions the machine learning model was trained on. | ||
|
|
||
| ## Returns | ||
|
|
||
| - a percentage as a [number](/types/number) from 0 to 100, representing the ML model’s certainty that this is the action being performed. The certainty for `unknown` is always 0. | ||
|
|
||
| ## Example | ||
|
|
||
| This example displays the ML model's certainty, in percent, that the current action is `clapping` every second. | ||
|
|
||
| ```blocks | ||
| loops.everyInterval(1000, function () { | ||
| basic.showNumber(ml.getCertainty(ml.event.Clapping)) | ||
| }) | ||
| ``` | ||
|
|
||
| ```package | ||
| machine-learning-help-stubs=github:microbit-foundation/pxt-microbit-ml-help-stubs#v0.0.1 | ||
| machine-learning=github:microbit-foundation/pxt-microbit-ml#v1.0.2 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # is ML detected | ||
|
|
||
| Checks if an ML action is the estimated action. | ||
|
|
||
| ```sig | ||
| ml.isDetected(ml.event.Unknown) | ||
| ``` | ||
|
|
||
| The ML model updates its estimated action several times a second. This function returns `true` if the chosen action is currently estimated. Use the boolean value to make logical decisions in your program. | ||
|
|
||
| Some programs will be easier to write using the “on ML start” and “on ML stop” event handlers instead. | ||
|
|
||
| ## Parameters | ||
|
|
||
| - **event**: one of the actions the machine learning model was trained on. The special value `unknown` represents the case where no action has a certainty above the recognition point. | ||
|
|
||
| ## Returns | ||
|
|
||
| - a [boolean](/types/boolean) value that is `true` if the ML action is the estimated action, `false` if the ML action is not the estimated action. | ||
|
|
||
| ## Example | ||
|
|
||
| This example will show a tick icon on the LED display if the estimated action is `clapping` at the time the conditional statement is checked. | ||
|
|
||
| ```blocks | ||
| basic.forever(function () { | ||
| if (ml.isDetected(ml.event.Clapping)) { | ||
| basic.showIcon(IconNames.Yes) | ||
| } | ||
| }) | ||
| ``` | ||
|
|
||
| ```package | ||
| machine-learning-help-stubs=github:microbit-foundation/pxt-microbit-ml-help-stubs#v0.0.1 | ||
| machine-learning=github:microbit-foundation/pxt-microbit-ml#v1.0.2 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # on ML start | ||
|
|
||
| Start an [event handler](/reference/event-handler) (part of the program that will run when something happens). This handler works when the ML model’s estimated action changes to the action you select. | ||
|
|
||
| ```sig | ||
| ml.onStart(ml.event.Unknown, function () { | ||
| }) | ||
| ``` | ||
|
|
||
| The ML model updates its estimated action several times a second, but this event handler only runs when the estimated action changes. | ||
|
|
||
| ## Parameters | ||
|
|
||
| - **event**: one of the actions the machine learning model was trained on. The special value `unknown` represents the case where no action has a certainty above the recognition point. | ||
|
|
||
| ## Example | ||
|
|
||
| This example plays a musical melody in the background when the action `clapping` has a certainty above the recognition point. | ||
|
|
||
| ```blocks | ||
| ml.onStart(ml.event.Clapping, function () { | ||
| music._playDefaultBackground(music.builtInPlayableMelody(Melodies.Dadadadum), music.PlaybackMode.InBackground) | ||
| }) | ||
| ``` | ||
|
|
||
| ```package | ||
| machine-learning-help-stubs=github:microbit-foundation/pxt-microbit-ml-help-stubs#v0.0.1 | ||
| machine-learning=github:microbit-foundation/pxt-microbit-ml#v1.0.2 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # on ML stop | ||
|
|
||
| Start an [event handler](/reference/event-handler) (part of the program that will run when something happens). This handler works when the ML model’s estimated action changes from the action you select. | ||
|
|
||
| ```sig | ||
| ml.onStop(ml.event.Unknown, function () { | ||
| }) | ||
| ``` | ||
|
|
||
| When an action changes, the stop event handler for the previous action will run, followed by the start event handler for the next action. | ||
|
|
||
| For example, if your start event handler for an action starts music playing in the background, you could use a stop event handler to stop it. | ||
|
|
||
| ## Parameters | ||
|
|
||
| - **event**: one of the actions the machine learning model was trained on. The special value `unknown` represents the case where no action has a certainty above the recognition point. | ||
|
|
||
| ## Example | ||
|
|
||
| This example stops playing a musical melody when the estimated action changes from `clapping` to any other action. | ||
|
|
||
| ```blocks | ||
| ml.onStop(ml.event.Clapping, function () { | ||
| music.stopMelody(MelodyStopOptions.All) | ||
| }) | ||
| ``` | ||
|
|
||
| ```package | ||
| machine-learning-help-stubs=github:microbit-foundation/pxt-microbit-ml-help-stubs#v0.0.1 | ||
| machine-learning=github:microbit-foundation/pxt-microbit-ml#v1.0.2 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # on ML stop | ||
|
|
||
| Start an [event handler](/reference/event-handler) (part of the program that will run when something happens). This handler works when the ML model’s estimated action changes from the action you select. | ||
|
|
||
| ```sig | ||
| ml.onStopDetailed(ml.event.Unknown, function (duration) { | ||
| }) | ||
| ``` | ||
|
|
||
| When an action changes, the stop event handler for the previous action will run, followed by the start event handler for the next action. | ||
|
|
||
| For example, if your start event handler for an action starts music playing in the background, you could use a stop event handler to stop it. | ||
|
|
||
| The event handler is passed a `duration` parameter. The duration is the [number](/types/number) of milliseconds since this action became the estimated action. You can use the duration parameter in your code, for example displaying it or using a variable to keep a running total. | ||
|
|
||
| ## Parameters | ||
|
|
||
| - **event**: one of the actions the machine learning model was trained on. The special value `unknown` represents the case where no action has a certainty above the recognition point. | ||
|
|
||
| ## Example | ||
|
|
||
| This example shows on the LED display, in seconds, how long the estimated action was `clapping`, when the estimated action changes from `clapping` to any other action. | ||
|
|
||
| ```blocks | ||
| ml.onStopDetailed(ml.event.Clapping, function (duration) { | ||
| basic.showNumber(duration / 1000) | ||
| }) | ||
| ``` | ||
|
|
||
| ```package | ||
| machine-learning-help-stubs=github:microbit-foundation/pxt-microbit-ml-help-stubs#v0.0.1 | ||
| machine-learning=github:microbit-foundation/pxt-microbit-ml#v1.0.2 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.