added handling of parens in datastream values#17
Conversation
|
Thanks! I've verified this works great for Python tuples ( btw, some Micropython/CircuitPython code you can use to quickly try this out is: import time, math
while True:
t = time.monotonic() % 2*math.pi
vals = t, math.sin(t), math.cos(t)
print(vals) # prints python tuple ()
#print(list(vals)) # prints python list []
time.sleep(0.05) |
There was a problem hiding this comment.
Pull Request Overview
Adds support for handling parentheses in datastream values by stripping leading and trailing parentheses from both series names and data values during parsing.
- Modifies the
handleIncomingLinefunction to remove leading(and trailing)characters - Updates both series name parsing (lines starting with #) and data value parsing
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // Parse for chart (existing logic) | ||
| if (line.trim().startsWith('#')) { | ||
| const names = line.replace(/^\s*#+\s*/, '').split(/[\s,\t]+/).filter(Boolean) | ||
| const names = line.replace(/^\(/, '').replace(/\)$/, '').replace(/^\s*#+\s*/, '').split(/[\s,\t]+/).filter(Boolean) |
There was a problem hiding this comment.
The parentheses removal logic should be applied after the hash symbol removal, not before. The current order may incorrectly handle cases where parentheses are part of the hash prefix (e.g., '#(data)'). Consider reordering: line.replace(/^\s*#+\s*/, '').replace(/^\(/, '').replace(/\)$/, '')
| const names = line.replace(/^\(/, '').replace(/\)$/, '').replace(/^\s*#+\s*/, '').split(/[\s,\t]+/).filter(Boolean) | |
| const names = line.replace(/^\s*#+\s*/, '').replace(/^\(/, '').replace(/\)$/, '').split(/[\s,\t]+/).filter(Boolean) |
| // Parse for chart (existing logic) | ||
| if (line.trim().startsWith('#')) { | ||
| const names = line.replace(/^\s*#+\s*/, '').split(/[\s,\t]+/).filter(Boolean) | ||
| const names = line.replace(/^\(/, '').replace(/\)$/, '').replace(/^\s*#+\s*/, '').split(/[\s,\t]+/).filter(Boolean) |
There was a problem hiding this comment.
The parentheses removal logic is duplicated. Consider extracting this into a helper function to improve maintainability and ensure consistent behavior across both parsing paths.
| return | ||
| } | ||
| const parts = line.trim().split(/[\s,\t]+/).filter(Boolean) | ||
| const parts = line.trim().replace(/^\(/, '').replace(/\)$/, '').split(/[\s,\t]+/).filter(Boolean) |
There was a problem hiding this comment.
The parentheses removal logic is duplicated. Consider extracting this into a helper function to improve maintainability and ensure consistent behavior across both parsing paths.
Summary
This commit should add the feature requested in #12.
When parsing the values in 'handleIncomingLine' it replaces starting and ending parens.
Motivation & Context
Closes #12
Changes
How to Test
@todbot
Checklist
npm run lintand fixed any issuesnpm run typecheck(TypeScript) with no errorsnpm testand tests passnpm run test:coverageif code paths changed significantlyAdditional Notes