From 1233f50ea7b16cb3ba700a0c77765c782d44ba05 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Tue, 6 Aug 2019 15:50:39 -0700 Subject: [PATCH 01/28] adding new telemetry to track --- src/constants.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/constants.ts b/src/constants.ts index 29a996103..26b7e59d4 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -126,6 +126,16 @@ export enum TelemetryEventName { SIMULATOR_BUTTON_AB = "SIMULATOR.BUTTON.AB", SIMULATOR_SWITCH = "SIMULATOR.SWITCH", + //Sensors + TEMPERATURE_SENSOR = "TEMPERATURE_SENSOR", + LIGHT_SENSOR = " LIGHT_SENSOR", + MOTION_SENSOR = "MOTION_SENSOR", + SHAKE = "SHAKE", + PLAY_TONE = "PLAY_TONE", + START_TONE = "START_TONE", + STOP_TONE = "STOP_TONE", + CAPACITIVE_TOUCH = "CAPACITIVE_TOUCH", + // Pop-up dialog CLICK_DIALOG_DONT_SHOW = "CLICK.DIALOG.DONT.SHOW", CLICK_DIALOG_EXAMPLE_CODE = "CLICK.DIALOG.EXAMPLE.CODE", From 9d03efb2aff51b621dd6275343c462980496546e Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Tue, 6 Aug 2019 15:50:57 -0700 Subject: [PATCH 02/28] adding telemetry handling for sensor --- src/extension.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index bc238a3f7..e1e4a7ae1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -101,6 +101,7 @@ export function activate(context: vscode.ExtensionContext) { case WebviewMessages.SENSOR_CHANGED: console.log("sensor changed"); console.log(messageJson + "\n"); + handleSensorTelemetry(message.text); if (childProcess) { childProcess.stdin.write(messageJson + "\n"); } @@ -523,6 +524,24 @@ const handleButtonPressTelemetry = (buttonState: any) => { } }; +const handleSensorTelemetry = (sensorState: any) => { + if (sensorState["temperarture"]) { + telemetryAI.trackFeatureUsage(TelemetryEventName.TEMPERATURE_SENSOR); + } else if (sensorState["light"]) { + telemetryAI.trackFeatureUsage(TelemetryEventName.LIGHT_SENSOR); + } else if ( + sensorState["motion_x"] || + sensorState["motion_y"] || + sensorState["motion_z"] + ) { + telemetryAI.trackFeatureUsage(TelemetryEventName.MOTION_SENSOR); + } else if (sensorState["shake"]) { + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_SWITCH); + } else (sensorState["shake"]) { + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_SWITCH); + } +}; + const updatePythonExtraPaths = () => { const pathToLib: string = __dirname; const currentExtraPaths: string[] = From 08f6b2ac5c651af34793aa5db7f005fa017be1ad Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Mon, 12 Aug 2019 08:42:03 -0700 Subject: [PATCH 03/28] add telemetry for sensor calls --- src/constants.ts | 33 ++++++++++++++++++--------------- src/extension.ts | 23 ++++++++++++++--------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 152fbde90..4dcbaed39 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -11,9 +11,9 @@ const localize: nls.LocalizeFunc = nls.config({ export const CONSTANTS = { DEBUG_CONFIGURATION_NAME: "Pacifica Simulator Debugger", DEPENDENCY_CHECKER: { - PYTHON: 'python', - PYTHON3: 'python3', - PYTHON_LAUNCHER: 'py -3' + PYTHON: "python", + PYTHON3: "python3", + PYTHON_LAUNCHER: "py -3" }, ERROR: { INCORRECT_FILE_NAME_FOR_DEVICE: localize( @@ -40,7 +40,10 @@ export const CONSTANTS = { "error.noProgramFoundDebug", "Cannot find a program to debug." ), - NO_PYTHON_PATH: localize("error.noPythonPath", "We found that you don't have Python 3 installed on your computer, please install the latest version, add it to your PATH and try again."), + NO_PYTHON_PATH: localize( + "error.noPythonPath", + "We found that you don't have Python 3 installed on your computer, please install the latest version, add it to your PATH and try again." + ), STDERR: (data: string) => { return localize("error.stderr", `\n[ERROR] ${data} \n`); }, @@ -116,7 +119,10 @@ export const CONSTANTS = { }, NAME: localize("name", "Pacifica Simulator"), WARNING: { - ACCEPT_AND_RUN: localize("warning.agreeAndRun", "By selecting ‘Agree and Run’, you understand the extension executes Python code on your local computer, which may be a potential security risk."), + ACCEPT_AND_RUN: localize( + "warning.agreeAndRun", + "By selecting ‘Agree and Run’, you understand the extension executes Python code on your local computer, which may be a potential security risk." + ) } }; @@ -137,14 +143,11 @@ export enum TelemetryEventName { SIMULATOR_SWITCH = "SIMULATOR.SWITCH", //Sensors - TEMPERATURE_SENSOR = "TEMPERATURE_SENSOR", - LIGHT_SENSOR = " LIGHT_SENSOR", - MOTION_SENSOR = "MOTION_SENSOR", - SHAKE = "SHAKE", - PLAY_TONE = "PLAY_TONE", - START_TONE = "START_TONE", - STOP_TONE = "STOP_TONE", - CAPACITIVE_TOUCH = "CAPACITIVE_TOUCH", + SIMULATOR_TEMPERATURE_SENSOR = "SIMULATOR.TEMPERATURE", + SIMULATOR_LIGHT_SENSOR = " SIMULATOR.LIGHT_SENSOR", + SIMULATOR_MOTION_SENSOR = "SIMULATOR.MOTION_SENSOR", + SIMULATOR_SHAKE = "SIMULATOR.SHAKE", + SIMULATOR_CAPACITIVE_TOUCH = "SIMULATOR.CAPACITIVE_TOUCH", // Pop-up dialog CLICK_DIALOG_DONT_SHOW = "CLICK.DIALOG.DONT.SHOW", @@ -179,7 +182,7 @@ export namespace DialogResponses { }; export const CANCEL: MessageItem = { title: localize("dialogResponses.cancel", "Cancel") - } + }; export const HELP: MessageItem = { title: localize("dialogResponses.help", "I need help") }; @@ -200,7 +203,7 @@ export namespace DialogResponses { }; export const INSTALL_PYTHON: MessageItem = { title: localize("dialogResponses.installPython", "Install from python.org") - } + }; } export const USER_CODE_NAMES = { diff --git a/src/extension.ts b/src/extension.ts index 585ab1ce8..e577fbbd2 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -252,7 +252,9 @@ export async function activate(context: vscode.ExtensionContext) { return hasAccepted; }); // Don't run users code if they don't accept - if (shouldExitCommand) { return; } + if (shouldExitCommand) { + return; + } } openWebview(); @@ -502,7 +504,6 @@ export async function activate(context: vscode.ExtensionContext) { ); } - const getActivePythonFile = () => { const editors: vscode.TextEditor[] = vscode.window.visibleTextEditors; const activeEditor = editors.find( @@ -554,19 +555,23 @@ const handleButtonPressTelemetry = (buttonState: any) => { const handleSensorTelemetry = (sensorState: any) => { if (sensorState["temperarture"]) { - telemetryAI.trackFeatureUsage(TelemetryEventName.TEMPERATURE_SENSOR); + telemetryAI.trackFeatureUsage( + TelemetryEventName.SIMULATOR_TEMPERATURE_SENSOR + ); } else if (sensorState["light"]) { - telemetryAI.trackFeatureUsage(TelemetryEventName.LIGHT_SENSOR); + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_LIGHT_SENSOR); } else if ( sensorState["motion_x"] || sensorState["motion_y"] || sensorState["motion_z"] ) { - telemetryAI.trackFeatureUsage(TelemetryEventName.MOTION_SENSOR); + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_MOTION_SENSOR); } else if (sensorState["shake"]) { - telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_SWITCH); - } else (sensorState["shake"]) { - telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_SWITCH); + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_SHAKE); + } else if (sensorState["touch"]) { + telemetryAI.trackFeatureUsage( + TelemetryEventName.SIMULATOR_CAPACITIVE_TOUCH + ); } }; @@ -621,4 +626,4 @@ function getWebviewContent(context: vscode.ExtensionContext) { } // this method is called when your extension is deactivated -export function deactivate() { } +export function deactivate() {} From 77864db3fca6e3144f37a030bda28325abd38f7d Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Mon, 12 Aug 2019 15:56:14 -0700 Subject: [PATCH 04/28] adding telemetryu for python side --- src/adafruit_circuitplayground/express.py | 12 ++- src/adafruit_circuitplayground/pixel.py | 30 +++--- src/constants.ts | 20 ++++ src/extension.ts | 46 ++++++++- src/telemetry/telemetryAI.ts | 108 ++++++++++++++-------- src/view/components/Simulator.tsx | 10 +- 6 files changed, 169 insertions(+), 57 deletions(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index ad8bb4b63..e25453cbd 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -42,6 +42,7 @@ def __init__(self): 'detect_taps': 1, 'tapped': False, 'shake': False, + 'latest_call': 'None' } self.pixels = Pixel(self.__state) @@ -61,19 +62,20 @@ def button_b(self): @property def detect_taps(self): + self.__state['latest_call'] = 'detect_taps' return self.__state['detect_taps'] @detect_taps.setter def detect_taps(self, value): value_int = int(value) - self.__state['detect_taps'] = value_int if ( + self.__state['C'] = value_int if ( value_int == 1 or value_int == 2) else 1 @property def tapped(self): + self.__state['latest_call'] = 'tapped' """ Not Implemented! """ - raise NotImplementedError( "This method is not implemented by the simulator") @@ -136,6 +138,7 @@ def adjust_touch_threshold(self, adjustement): """Not implemented! The CPX Simulator doesn't use capacitive touch threshold. """ + self.__state['latest_call'] = 'adjust_touch_threshold' raise NotImplementedError( "this method is not supported by the simulator") @@ -143,6 +146,7 @@ def shake(self, shake_threshold=30): return self.__state['shake'] def play_file(self, file_name): + self.__state['latest_call'] = 'play_file' file_name = utils.remove_leading_slashes(file_name) abs_path_parent_dir = os.path.abspath( os.path.join(self.__abs_path_to_code_file, os.pardir)) @@ -165,19 +169,21 @@ def play_file(self, file_name): def play_tone(self, frequency, duration): """ Not Implemented! """ + self.__state['latest_call'] = 'play_tone' raise NotImplementedError( "This method is not implemented by the simulator") def start_tone(self, frequency): """ Not Implemented! """ + self.__state['latest_call'] = 'start_tone' raise NotImplementedError( "This method is not implemented by the simulator") def stop_tone(self): """ Not Implemented! """ - # Stop playing any tones. + self.__state['latest_call'] = 'stop_tone' raise NotImplementedError( "This method is not implemented by the simulator") diff --git a/src/adafruit_circuitplayground/pixel.py b/src/adafruit_circuitplayground/pixel.py index 5b2a20d15..713b1bd80 100644 --- a/src/adafruit_circuitplayground/pixel.py +++ b/src/adafruit_circuitplayground/pixel.py @@ -21,12 +21,15 @@ def __show_if_auto_write(self): def __getitem__(self, index): if not self.__valid_index(index): - raise IndexError('The index is not a valid number, you can access the Neopixels from 0 to 9.') + raise IndexError( + 'The index is not a valid number, you can access the Neopixels from 0 to 9.') return self.__state['pixels'][index] - + def __setitem__(self, index, val): if not self.__valid_index(index): - raise IndexError('The index is not a valid number, you can access the Neopixels from 0 to 9.') + raise IndexError( + 'The index is not a valid number, you can access the Neopixels from 0 to 9.') + self.__state['latest_call'] = 'pixels' self.__state['pixels'][index] = self.__extract_pixel_value(val) self.__show_if_auto_write() @@ -34,6 +37,7 @@ def __valid_index(self, index): return type(index) is int and index >= -len(self.__state['pixels']) and index < len(self.__state['pixels']) def fill(self, val): + self.__state['latest_call'] = 'pixels' for index in range(len(self.__state['pixels'])): self.__state['pixels'][index] = self.__extract_pixel_value(val) self.__show_if_auto_write() @@ -47,24 +51,27 @@ def __extract_pixel_value(self, val): elif type(val) is tuple: rgb_value = val else: - raise ValueError('The pixel color value type should be tuple, list or hexadecimal.') + raise ValueError( + 'The pixel color value type should be tuple, list or hexadecimal.') # Values validation if len(rgb_value) != 3 or any(not self.__valid_rgb_value(pix) for pix in rgb_value): - raise ValueError('The pixel color value should be a tuple with three values between 0 and 255 or an hexadecimal color between 0x000000 and 0xFFFFFF.') + raise ValueError( + 'The pixel color value should be a tuple with three values between 0 and 255 or an hexadecimal color between 0x000000 and 0xFFFFFF.') return rgb_value def __hex_to_rgb(self, hexValue): if hexValue[0:2] == '0x' and len(hexValue) <= 8: - hexToRgbValue = [0,0,0] + hexToRgbValue = [0, 0, 0] hexColor = hexValue[2:].zfill(6) - hexToRgbValue[0] = int(hexColor[0:2], 16) # R - hexToRgbValue[1] = int(hexColor[2:4], 16) # G - hexToRgbValue[2] = int(hexColor[4:6], 16) # B + hexToRgbValue[0] = int(hexColor[0:2], 16) # R + hexToRgbValue[1] = int(hexColor[2:4], 16) # G + hexToRgbValue[2] = int(hexColor[4:6], 16) # B return tuple(hexToRgbValue) else: - raise ValueError('The pixel hexadicimal color value should be in range #000000 and #FFFFFF.') + raise ValueError( + 'The pixel hexadicimal color value should be in range #000000 and #FFFFFF.') def __valid_rgb_value(self, pixValue): return type(pixValue) is int and pixValue >= 0 and pixValue <= 255 @@ -76,7 +83,8 @@ def brightness(self): @brightness.setter def brightness(self, brightness): if not self.__valid_brightness(brightness): - raise ValueError('The brightness value should be a number between 0 and 1.') + raise ValueError( + 'The brightness value should be a number between 0 and 1.') self.__state['brightness'] = brightness self.__show_if_auto_write() diff --git a/src/constants.ts b/src/constants.ts index 4dcbaed39..db5a4edaa 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -118,6 +118,16 @@ export const CONSTANTS = { "https://learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/circuit-playground-express-library" }, NAME: localize("name", "Pacifica Simulator"), + PYTHON_TRACKED_CALLS: { + ADJUST_THRESHOLD: "adjust_touch_threshold", + DETECT_TAPS: "detect_taps", + PLAY_FILE: "play_file", + PLAY_TONE: "play_tone", + START_TONE: "start_tone", + STOP_TONE: "stop_tone", + PIXELS: "pixels", + TAPPED: "tapped" + }, WARNING: { ACCEPT_AND_RUN: localize( "warning.agreeAndRun", @@ -149,6 +159,16 @@ export enum TelemetryEventName { SIMULATOR_SHAKE = "SIMULATOR.SHAKE", SIMULATOR_CAPACITIVE_TOUCH = "SIMULATOR.CAPACITIVE_TOUCH", + //Mock calls + SIMULATOR_ADJUST_THRESHOLD = "SIMULATOR.ADJUST_THRESHOLD", + SIMULATOR_DETECT_TAPS = "SIMULATOR.DETECT_TAPS", + SIMULATOR_PLAY_TONE = "SIMULATOR.PLAY_TONE ", + SIMULATOR_PLAY_FILE = "SIMULATOR.PLAY_FILE", + SIMULATOR_START_TONE = "SIMULATOR.START_TONE", + SIMULATOR_STOP_TONE = "SIMULATOR.STOP_TONE", + SIMULATOR_TAPPED = "SIMULATOR.TAPPED", + SIMULATOR_PIXELS = "SIMULATOR.PIXELS", + // Pop-up dialog CLICK_DIALOG_DONT_SHOW = "CLICK.DIALOG.DONT.SHOW", CLICK_DIALOG_EXAMPLE_CODE = "CLICK.DIALOG.EXAMPLE.CODE", diff --git a/src/extension.ts b/src/extension.ts index e577fbbd2..fcddee41f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -318,12 +318,25 @@ export async function activate(context: vscode.ExtensionContext) { if (currentPanel && message.length > 0 && message != oldMessage) { oldMessage = message; let messageToWebview; + let previousCall = ""; // Check the message is a JSON try { messageToWebview = JSON.parse(message); // Check the JSON is a state switch (messageToWebview.type) { case "state": + let state = JSON.parse(messageToWebview.data); + console.log( + `state has changed ${previousCall} ${ + state["latest_call"] + }` + ); + if ( + state["latest_call"] !== previousCall && + state["latest_call"] !== "None" + ) { + sendPythonTelemetry(state["latest_call"]); + } console.log( `Process state output = ${messageToWebview.data}` ); @@ -554,7 +567,7 @@ const handleButtonPressTelemetry = (buttonState: any) => { }; const handleSensorTelemetry = (sensorState: any) => { - if (sensorState["temperarture"]) { + if (sensorState["temperature"]) { telemetryAI.trackFeatureUsage( TelemetryEventName.SIMULATOR_TEMPERATURE_SENSOR ); @@ -605,6 +618,37 @@ const logToOutputChannel = ( } }; +const sendPythonTelemetry = (latestCall: string) => { + console.log(`in the latest call ${latestCall}`); + switch (latestCall) { + case CONSTANTS.PYTHON_TRACKED_CALLS.ADJUST_THRESHOLD: + telemetryAI.trackFeatureUsage( + TelemetryEventName.SIMULATOR_ADJUST_THRESHOLD + ); + break; + case CONSTANTS.PYTHON_TRACKED_CALLS.DETECT_TAPS: + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_DETECT_TAPS); + break; + case CONSTANTS.PYTHON_TRACKED_CALLS.PLAY_FILE: + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_PLAY_FILE); + break; + case CONSTANTS.PYTHON_TRACKED_CALLS.START_TONE: + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_START_TONE); + break; + case CONSTANTS.PYTHON_TRACKED_CALLS.STOP_TONE: + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_STOP_TONE); + break; + case CONSTANTS.PYTHON_TRACKED_CALLS.PLAY_TONE: + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_PLAY_TONE); + break; + case CONSTANTS.PYTHON_TRACKED_CALLS.TAPPED: + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_TAPPED); + break; + case CONSTANTS.PYTHON_TRACKED_CALLS.PIXELS: + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_PIXELS); + break; + } +}; function getWebviewContent(context: vscode.ExtensionContext) { return ` diff --git a/src/telemetry/telemetryAI.ts b/src/telemetry/telemetryAI.ts index 19702828c..addcabffa 100644 --- a/src/telemetry/telemetryAI.ts +++ b/src/telemetry/telemetryAI.ts @@ -4,52 +4,78 @@ import getPackageInfo from "./getPackageInfo"; // tslint:disable-next-line:export-name export default class TelemetryAI { - private static telemetryReporter: TelemetryReporter; - private static enableTelemetry: boolean | undefined; - - constructor(vscodeContext: vscode.ExtensionContext) { - TelemetryAI.telemetryReporter = this.createTelemetryReporter(vscodeContext); - TelemetryAI.enableTelemetry = vscode.workspace.getConfiguration().get("telemetry.enableTelemetry"); - if (TelemetryAI.enableTelemetry === undefined) { - TelemetryAI.enableTelemetry = true; - } - } + private static telemetryReporter: TelemetryReporter; + private static enableTelemetry: boolean | undefined; - public getExtensionName(context: vscode.ExtensionContext): string { - const { extensionName } = getPackageInfo(context); - return extensionName; + constructor(vscodeContext: vscode.ExtensionContext) { + TelemetryAI.telemetryReporter = this.createTelemetryReporter(vscodeContext); + TelemetryAI.enableTelemetry = vscode.workspace + .getConfiguration() + .get("telemetry.enableTelemetry"); + if (TelemetryAI.enableTelemetry === undefined) { + TelemetryAI.enableTelemetry = true; } + } - public getExtensionVersionNumber(context: vscode.ExtensionContext): string { - const { extensionVersion } = getPackageInfo(context); - return extensionVersion; - } + public getExtensionName(context: vscode.ExtensionContext): string { + const { extensionName } = getPackageInfo(context); + return extensionName; + } - public sendTelemetryIfEnabled(eventName: string, properties?: { [key: string]: string }, measurements?: { [key: string]: number }) { - if (TelemetryAI.enableTelemetry) { - TelemetryAI.telemetryReporter.sendTelemetryEvent(eventName, properties, measurements); - } - } + public getExtensionVersionNumber(context: vscode.ExtensionContext): string { + const { extensionVersion } = getPackageInfo(context); + return extensionVersion; + } - public trackFeatureUsage(eventName: string, eventProperties?: { [key: string]: string }) { - this.sendTelemetryIfEnabled(eventName, eventProperties) + public sendTelemetryIfEnabled( + eventName: string, + properties?: { [key: string]: string }, + measurements?: { [key: string]: number } + ) { + if (TelemetryAI.enableTelemetry) { + TelemetryAI.telemetryReporter.sendTelemetryEvent( + eventName, + properties, + measurements + ); } + } - public runWithLatencyMeasure(functionToRun: () => void, eventName: string): void { - const numberOfNanosecondsInSecond: number = 1000000000; - const startTime: number = Number(process.hrtime.bigint()); - functionToRun(); - const latency: number = Number(process.hrtime.bigint()) - startTime; - const measurement = { - duration: latency / numberOfNanosecondsInSecond - } - this.sendTelemetryIfEnabled(eventName, {}, measurement); - } + public trackFeatureUsage( + eventName: string, + eventProperties?: { [key: string]: string } + ) { + this.sendTelemetryIfEnabled(eventName, eventProperties); + } - private createTelemetryReporter(context: vscode.ExtensionContext): TelemetryReporter { - const { extensionName, extensionVersion, instrumentationKey } = getPackageInfo(context); - const reporter: TelemetryReporter = new TelemetryReporter(extensionName, extensionVersion, instrumentationKey); - context.subscriptions.push(reporter); - return reporter; - } -} \ No newline at end of file + public runWithLatencyMeasure( + functionToRun: () => void, + eventName: string + ): void { + const numberOfNanosecondsInSecond: number = 1000000000; + const startTime: number = Number(process.hrtime.bigint()); + functionToRun(); + const latency: number = Number(process.hrtime.bigint()) - startTime; + const measurement = { + duration: latency / numberOfNanosecondsInSecond + }; + this.sendTelemetryIfEnabled(eventName, {}, measurement); + } + + private createTelemetryReporter( + context: vscode.ExtensionContext + ): TelemetryReporter { + const { + extensionName, + extensionVersion, + instrumentationKey + } = getPackageInfo(context); + const reporter: TelemetryReporter = new TelemetryReporter( + extensionName, + extensionVersion, + instrumentationKey + ); + context.subscriptions.push(reporter); + return reporter; + } +} diff --git a/src/view/components/Simulator.tsx b/src/view/components/Simulator.tsx index ce4f6cda1..b4a86f6e4 100644 --- a/src/view/components/Simulator.tsx +++ b/src/view/components/Simulator.tsx @@ -20,6 +20,10 @@ interface ICpxState { button_b: boolean; switch: boolean; touch: boolean[]; + detect_taps: 1; + tapped: boolean; + shake: boolean; + latest_call: string; } interface IState { @@ -48,7 +52,11 @@ const DEFAULT_CPX_STATE: ICpxState = { ], red_led: false, switch: false, - touch: [false, false, false, false, false, false, false] + touch: [false, false, false, false, false, false, false], + detect_taps: 1, + tapped: false, + shake: false, + latest_call: "None" }; const SIMULATOR_BUTTON_WIDTH = 60; From ff8ba763aa3fa0970d024ed04d7ba9f5144ac4f7 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Mon, 12 Aug 2019 15:57:29 -0700 Subject: [PATCH 05/28] solved typo --- src/adafruit_circuitplayground/express.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index e25453cbd..b138582ca 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -68,7 +68,7 @@ def detect_taps(self): @detect_taps.setter def detect_taps(self, value): value_int = int(value) - self.__state['C'] = value_int if ( + self.__state['latest_call'] = value_int if ( value_int == 1 or value_int == 2) else 1 @property From abb8a432273b55a1c6c00f84c3edc25c9485024d Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Mon, 12 Aug 2019 16:06:24 -0700 Subject: [PATCH 06/28] renamed constants --- src/constants.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index db5a4edaa..711177f85 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -160,12 +160,12 @@ export enum TelemetryEventName { SIMULATOR_CAPACITIVE_TOUCH = "SIMULATOR.CAPACITIVE_TOUCH", //Mock calls - SIMULATOR_ADJUST_THRESHOLD = "SIMULATOR.ADJUST_THRESHOLD", - SIMULATOR_DETECT_TAPS = "SIMULATOR.DETECT_TAPS", - SIMULATOR_PLAY_TONE = "SIMULATOR.PLAY_TONE ", - SIMULATOR_PLAY_FILE = "SIMULATOR.PLAY_FILE", - SIMULATOR_START_TONE = "SIMULATOR.START_TONE", - SIMULATOR_STOP_TONE = "SIMULATOR.STOP_TONE", + SIMULATOR_ADJUST_THRESHOLD = "SIMULATOR.ADJUST.THRESHOLD", + SIMULATOR_DETECT_TAPS = "SIMULATOR.DETECT.TAPS", + SIMULATOR_PLAY_TONE = "SIMULATOR.PLAY.TONE ", + SIMULATOR_PLAY_FILE = "SIMULATOR.PLAY.FILE", + SIMULATOR_START_TONE = "SIMULATOR.START.TONE", + SIMULATOR_STOP_TONE = "SIMULATOR.STOP.TONE", SIMULATOR_TAPPED = "SIMULATOR.TAPPED", SIMULATOR_PIXELS = "SIMULATOR.PIXELS", From e7732e53506c7eefa02892141ebfb3f0355dc0e3 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Mon, 12 Aug 2019 16:40:23 -0700 Subject: [PATCH 07/28] rename constants --- src/constants.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 711177f85..e11bfc5bd 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -154,10 +154,10 @@ export enum TelemetryEventName { //Sensors SIMULATOR_TEMPERATURE_SENSOR = "SIMULATOR.TEMPERATURE", - SIMULATOR_LIGHT_SENSOR = " SIMULATOR.LIGHT_SENSOR", - SIMULATOR_MOTION_SENSOR = "SIMULATOR.MOTION_SENSOR", + SIMULATOR_LIGHT_SENSOR = " SIMULATOR.LIGHT", + SIMULATOR_MOTION_SENSOR = "SIMULATOR.MOTION", SIMULATOR_SHAKE = "SIMULATOR.SHAKE", - SIMULATOR_CAPACITIVE_TOUCH = "SIMULATOR.CAPACITIVE_TOUCH", + SIMULATOR_CAPACITIVE_TOUCH = "SIMULATOR.CAPACITIVE.TOUCH", //Mock calls SIMULATOR_ADJUST_THRESHOLD = "SIMULATOR.ADJUST.THRESHOLD", From f35cd9b03e139577a0e5ede45f0d5f442cba8a2d Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Tue, 13 Aug 2019 08:44:07 -0700 Subject: [PATCH 08/28] adding appinsight --- src/adafruit_circuitplayground/express.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index ad8bb4b63..08299d341 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -8,9 +8,12 @@ from .pixel import Pixel from . import utils from collections import namedtuple +from applicationinsights import TelemetryClient Acceleration = namedtuple('acceleration', ['x', 'y', 'z']) +tc = TelemetryClient('58c03a53-0506-46fc-afd0-c75f193bce2f') + class Express: def __init__(self): @@ -114,6 +117,8 @@ def touch_A2(self): @property def touch_A3(self): + tc.track_event("touch_A3") + tc.flush() return self.__touch(3) @property @@ -169,6 +174,8 @@ def play_tone(self, frequency, duration): "This method is not implemented by the simulator") def start_tone(self, frequency): + tc.track_event("start_tone") + tc.flush() """ Not Implemented! """ raise NotImplementedError( From 99c13ac66033e5813d41738477dc06b7b5dcc67e Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Tue, 13 Aug 2019 08:47:31 -0700 Subject: [PATCH 09/28] removed previous telemetry method --- src/adafruit_circuitplayground/express.py | 1 - src/extension.ts | 44 ----------------------- src/process_user_code.py | 1 - src/view/components/Simulator.tsx | 4 +-- 4 files changed, 1 insertion(+), 49 deletions(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index 0ed5a8e27..20c53fb70 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -45,7 +45,6 @@ def __init__(self): 'detect_taps': 1, 'tapped': False, 'shake': False, - 'latest_call': 'None' } self.pixels = Pixel(self.__state) diff --git a/src/extension.ts b/src/extension.ts index e3eb1c790..0af40311c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -318,7 +318,6 @@ export async function activate(context: vscode.ExtensionContext) { if (currentPanel && message.length > 0 && message != oldMessage) { oldMessage = message; let messageToWebview; - let previousCall = ""; // Check the message is a JSON try { messageToWebview = JSON.parse(message); @@ -326,17 +325,6 @@ export async function activate(context: vscode.ExtensionContext) { switch (messageToWebview.type) { case "state": let state = JSON.parse(messageToWebview.data); - console.log( - `state has changed ${previousCall} ${ - state["latest_call"] - }` - ); - if ( - state["latest_call"] !== previousCall && - state["latest_call"] !== "None" - ) { - sendPythonTelemetry(state["latest_call"]); - } console.log( `Process state output = ${messageToWebview.data}` ); @@ -629,38 +617,6 @@ const logToOutputChannel = ( outChannel.append(message); } }; - -const sendPythonTelemetry = (latestCall: string) => { - console.log(`in the latest call ${latestCall}`); - switch (latestCall) { - case CONSTANTS.PYTHON_TRACKED_CALLS.ADJUST_THRESHOLD: - telemetryAI.trackFeatureUsage( - TelemetryEventName.SIMULATOR_ADJUST_THRESHOLD - ); - break; - case CONSTANTS.PYTHON_TRACKED_CALLS.DETECT_TAPS: - telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_DETECT_TAPS); - break; - case CONSTANTS.PYTHON_TRACKED_CALLS.PLAY_FILE: - telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_PLAY_FILE); - break; - case CONSTANTS.PYTHON_TRACKED_CALLS.START_TONE: - telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_START_TONE); - break; - case CONSTANTS.PYTHON_TRACKED_CALLS.STOP_TONE: - telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_STOP_TONE); - break; - case CONSTANTS.PYTHON_TRACKED_CALLS.PLAY_TONE: - telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_PLAY_TONE); - break; - case CONSTANTS.PYTHON_TRACKED_CALLS.TAPPED: - telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_TAPPED); - break; - case CONSTANTS.PYTHON_TRACKED_CALLS.PIXELS: - telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_PIXELS); - break; - } -}; function getWebviewContent(context: vscode.ExtensionContext) { return ` diff --git a/src/process_user_code.py b/src/process_user_code.py index d22ccc716..ce54081e0 100644 --- a/src/process_user_code.py +++ b/src/process_user_code.py @@ -22,7 +22,6 @@ 'motion_y', 'motion_z', 'touch' - ] read_val = "" diff --git a/src/view/components/Simulator.tsx b/src/view/components/Simulator.tsx index b4a86f6e4..992324733 100644 --- a/src/view/components/Simulator.tsx +++ b/src/view/components/Simulator.tsx @@ -23,7 +23,6 @@ interface ICpxState { detect_taps: 1; tapped: boolean; shake: boolean; - latest_call: string; } interface IState { @@ -55,8 +54,7 @@ const DEFAULT_CPX_STATE: ICpxState = { touch: [false, false, false, false, false, false, false], detect_taps: 1, tapped: false, - shake: false, - latest_call: "None" + shake: false }; const SIMULATOR_BUTTON_WIDTH = 60; From b89051096b8db64e0ec7f40c7f7768a79d2309f3 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Tue, 13 Aug 2019 09:11:26 -0700 Subject: [PATCH 10/28] adding extension name constant --- src/adafruit_circuitplayground/express.py | 31 +++++++++++++---------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index 20c53fb70..17c2e8d31 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -12,7 +12,8 @@ Acceleration = namedtuple('acceleration', ['x', 'y', 'z']) -tc = TelemetryClient('58c03a53-0506-46fc-afd0-c75f193bce2f') +TELEMETRY_CLIENT = TelemetryClient('58c03a53-0506-46fc-afd0-c75f193bce2f') +EXTENSION_NAME = 'EXTENSION_NAME' class Express: @@ -64,20 +65,22 @@ def button_b(self): @property def detect_taps(self): - self.__state['latest_call'] = 'detect_taps' + TELEMETRY_CLIENT.track_event(f'{EXTENSION_NAME}/detect_taps') + TELEMETRY_CLIENT.flush() return self.__state['detect_taps'] @detect_taps.setter def detect_taps(self, value): value_int = int(value) - self.__state['latest_call'] = value_int if ( + self.__state['detect_taps'] = value_int if ( value_int == 1 or value_int == 2) else 1 @property def tapped(self): - self.__state['latest_call'] = 'tapped' """ Not Implemented! """ + TELEMETRY_CLIENT.track_event(f'{EXTENSION_NAME}/tapped') + TELEMETRY_CLIENT.flush() raise NotImplementedError( "This method is not implemented by the simulator") @@ -118,8 +121,6 @@ def touch_A2(self): @property def touch_A3(self): - tc.track_event("touch_A3") - tc.flush() return self.__touch(3) @property @@ -142,7 +143,9 @@ def adjust_touch_threshold(self, adjustement): """Not implemented! The CPX Simulator doesn't use capacitive touch threshold. """ - self.__state['latest_call'] = 'adjust_touch_threshold' + TELEMETRY_CLIENT.track_event( + f'{EXTENSION_NAME}/adjust_touch_threshold') + TELEMETRY_CLIENT.flush() raise NotImplementedError( "this method is not supported by the simulator") @@ -150,7 +153,8 @@ def shake(self, shake_threshold=30): return self.__state['shake'] def play_file(self, file_name): - self.__state['latest_call'] = 'play_file' + TELEMETRY_CLIENT.track_event(f'{EXTENSION_NAME}/file_name') + TELEMETRY_CLIENT.flush() file_name = utils.remove_leading_slashes(file_name) abs_path_parent_dir = os.path.abspath( os.path.join(self.__abs_path_to_code_file, os.pardir)) @@ -173,23 +177,24 @@ def play_file(self, file_name): def play_tone(self, frequency, duration): """ Not Implemented! """ - self.__state['latest_call'] = 'play_tone' + TELEMETRY_CLIENT.track_event(f'{EXTENSION_NAME}/play_tone') + TELEMETRY_CLIENT.flush() raise NotImplementedError( "This method is not implemented by the simulator") def start_tone(self, frequency): - tc.track_event("start_tone") - tc.flush() """ Not Implemented! """ - self.__state['latest_call'] = 'start_tone' + TELEMETRY_CLIENT.track_event(f'{EXTENSION_NAME}/start_tone') + TELEMETRY_CLIENT.flush() raise NotImplementedError( "This method is not implemented by the simulator") def stop_tone(self): """ Not Implemented! """ - self.__state['latest_call'] = 'stop_tone' + TELEMETRY_CLIENT.track_event(f'{EXTENSION_NAME}/stop_tone') + TELEMETRY_CLIENT.flush() raise NotImplementedError( "This method is not implemented by the simulator") From 11b1a3efa0fd48c1d84ee159cb17aee4e3401b64 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Tue, 13 Aug 2019 09:20:42 -0700 Subject: [PATCH 11/28] replacing activation key --- src/adafruit_circuitplayground/express.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index 17c2e8d31..6c0c9ced4 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -12,7 +12,7 @@ Acceleration = namedtuple('acceleration', ['x', 'y', 'z']) -TELEMETRY_CLIENT = TelemetryClient('58c03a53-0506-46fc-afd0-c75f193bce2f') +TELEMETRY_CLIENT = TelemetryClient('__AIKEY__') EXTENSION_NAME = 'EXTENSION_NAME' From ff924b1ba533ab473265ac7d6ebfe3f582753cc3 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Tue, 13 Aug 2019 09:26:31 -0700 Subject: [PATCH 12/28] replace extension name const --- src/adafruit_circuitplayground/express.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index 6c0c9ced4..50ec73eba 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -13,7 +13,7 @@ Acceleration = namedtuple('acceleration', ['x', 'y', 'z']) TELEMETRY_CLIENT = TelemetryClient('__AIKEY__') -EXTENSION_NAME = 'EXTENSION_NAME' +EXTENSION_NAME = '__EXTENSIONNAME__' class Express: From fcfb0420eb2e9802b050c821e49f75f568ab0a0a Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Wed, 14 Aug 2019 18:33:22 -0700 Subject: [PATCH 13/28] change according to review --- src/adafruit_circuitplayground/express.py | 31 +++++++++++------------ src/adafruit_circuitplayground/pixel.py | 1 - src/constants.ts | 12 +-------- src/extension.ts | 1 - 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index f69d97215..5f61981ae 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -13,7 +13,7 @@ Acceleration = namedtuple('acceleration', ['x', 'y', 'z']) -TELEMETRY_CLIENT = TelemetryClient('__AIKEY__') +telemetry_client = TelemetryClient('__AIKEY__') EXTENSION_NAME = '__EXTENSIONNAME__' @@ -66,9 +66,9 @@ def button_b(self): @property def detect_taps(self): - TELEMETRY_CLIENT.track_event( + telemetry_client.track_event( f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["DETECT.TAPS"]}') - TELEMETRY_CLIENT.flush() + telemetry_client.flush() return self.__state['detect_taps'] @detect_taps.setter @@ -81,10 +81,9 @@ def detect_taps(self, value): def tapped(self): """ Not Implemented! """ - print() - TELEMETRY_CLIENT.track_event( + telemetry_client.track_event( f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["TAPPED"]}') - TELEMETRY_CLIENT.flush() + telemetry_client.flush() raise NotImplementedError(CONSTANTS.NOT_IMPLEMENTED_ERROR) @property @@ -146,9 +145,9 @@ def adjust_touch_threshold(self, adjustement): """Not implemented! The CPX Simulator doesn't use capacitive touch threshold. """ - TELEMETRY_CLIENT.track_event( + telemetry_client.track_event( f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["ADJUST_THRESHOLD"]}') - TELEMETRY_CLIENT.flush() + telemetry_client.flush() raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) @@ -157,9 +156,9 @@ def shake(self, shake_threshold=30): return self.__state['shake'] def play_file(self, file_name): - TELEMETRY_CLIENT.track_event( + telemetry_client.track_event( f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["STOP_TONE"]}') - TELEMETRY_CLIENT.flush() + telemetry_client.flush() file_name = utils.remove_leading_slashes(file_name) abs_path_parent_dir = os.path.abspath( os.path.join(self.__abs_path_to_code_file, os.pardir)) @@ -181,27 +180,27 @@ def play_file(self, file_name): def play_tone(self, frequency, duration): """ Not Implemented! """ - TELEMETRY_CLIENT.track_event( + telemetry_client.track_event( f'{EXTENSION_NAME}${CONSTANTS.TELEMETRY_EVENT_NAMES["PLAY_TONE"]}') - TELEMETRY_CLIENT.flush() + telemetry_client.flush() raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) def start_tone(self, frequency): """ Not Implemented! """ - TELEMETRY_CLIENT.track_event( + telemetry_client.track_event( f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["START_TONE"]}') - TELEMETRY_CLIENT.flush() + telemetry_client.flush() raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) def stop_tone(self): """ Not Implemented! """ - TELEMETRY_CLIENT.track_event( + telemetry_client.track_event( f'{EXTENSION_NAME}/${CONSTANTS.TELEMETRY_EVENT_NAMES["STOP_TONE"]}') - TELEMETRY_CLIENT.flush() + telemetry_client.flush() raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) diff --git a/src/adafruit_circuitplayground/pixel.py b/src/adafruit_circuitplayground/pixel.py index e2ed9af20..d09539dde 100644 --- a/src/adafruit_circuitplayground/pixel.py +++ b/src/adafruit_circuitplayground/pixel.py @@ -35,7 +35,6 @@ def __valid_index(self, index): return type(index) is int and index >= -len(self.__state['pixels']) and index < len(self.__state['pixels']) def fill(self, val): - self.__state['latest_call'] = 'pixels' for index in range(len(self.__state['pixels'])): self.__state['pixels'][index] = self.__extract_pixel_value(val) self.__show_if_auto_write() diff --git a/src/constants.ts b/src/constants.ts index bb35574cf..40688faeb 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -97,7 +97,7 @@ export const CONSTANTS = { RUNNING_CODE: localize("info.runningCode", "Running user code"), THIRD_PARTY_WEBSITE: localize( "info.thirdPartyWebsite", - "By clicking \"Agree and Proceed\" you will be redirected to adafruit.com, a third party website not managed by Microsoft. Please note that your activity on adafruit.com is subject to Adafruit's privacy policy", + 'By clicking "Agree and Proceed" you will be redirected to adafruit.com, a third party website not managed by Microsoft. Please note that your activity on adafruit.com is subject to Adafruit\'s privacy policy' ), WELCOME_OUTPUT_TAB: localize( "info.welcomeOutputTab", @@ -118,16 +118,6 @@ export const CONSTANTS = { "https://learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/circuit-playground-express-library" }, NAME: localize("name", "Pacifica Simulator"), - PYTHON_TRACKED_CALLS: { - ADJUST_THRESHOLD: "adjust_touch_threshold", - DETECT_TAPS: "detect_taps", - PLAY_FILE: "play_file", - PLAY_TONE: "play_tone", - START_TONE: "start_tone", - STOP_TONE: "stop_tone", - PIXELS: "pixels", - TAPPED: "tapped" - }, WARNING: { ACCEPT_AND_RUN: localize( "warning.agreeAndRun", diff --git a/src/extension.ts b/src/extension.ts index 0af40311c..3ec159b58 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -324,7 +324,6 @@ export async function activate(context: vscode.ExtensionContext) { // Check the JSON is a state switch (messageToWebview.type) { case "state": - let state = JSON.parse(messageToWebview.data); console.log( `Process state output = ${messageToWebview.data}` ); From 4275a43c0f3ef61e45db9158c134648c2fb7dade Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Wed, 14 Aug 2019 18:35:32 -0700 Subject: [PATCH 14/28] change due to review --- src/adafruit_circuitplayground/express.py | 2 -- src/view/components/Simulator.tsx | 4 ---- 2 files changed, 6 deletions(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index 5f61981ae..9990972c1 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -44,8 +44,6 @@ def __init__(self): 'motion_y': 0, 'motion_z': 0, 'touch': [False]*7, - 'detect_taps': 1, - 'tapped': False, 'shake': False, } diff --git a/src/view/components/Simulator.tsx b/src/view/components/Simulator.tsx index 992324733..ac10f235d 100644 --- a/src/view/components/Simulator.tsx +++ b/src/view/components/Simulator.tsx @@ -20,8 +20,6 @@ interface ICpxState { button_b: boolean; switch: boolean; touch: boolean[]; - detect_taps: 1; - tapped: boolean; shake: boolean; } @@ -52,8 +50,6 @@ const DEFAULT_CPX_STATE: ICpxState = { red_led: false, switch: false, touch: [false, false, false, false, false, false, false], - detect_taps: 1, - tapped: false, shake: false }; From eaad18220e5d1ff6a68f04816d0433bc33522944 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Wed, 14 Aug 2019 18:38:24 -0700 Subject: [PATCH 15/28] solved typo --- src/adafruit_circuitplayground/express.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index 9990972c1..b8bc6eb79 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -155,7 +155,7 @@ def shake(self, shake_threshold=30): def play_file(self, file_name): telemetry_client.track_event( - f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["STOP_TONE"]}') + f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["PLAY.FILE"]}') telemetry_client.flush() file_name = utils.remove_leading_slashes(file_name) abs_path_parent_dir = os.path.abspath( From d9a934960a1e5790447ef1b653fafde9d5a5825c Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Wed, 14 Aug 2019 18:45:55 -0700 Subject: [PATCH 16/28] add more event --- src/adafruit_circuitplayground/constants.py | 4 +++- src/adafruit_circuitplayground/express.py | 3 +++ src/adafruit_circuitplayground/pixel.py | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/adafruit_circuitplayground/constants.py b/src/adafruit_circuitplayground/constants.py index 1d2cdefce..6df682189 100644 --- a/src/adafruit_circuitplayground/constants.py +++ b/src/adafruit_circuitplayground/constants.py @@ -23,5 +23,7 @@ 'START_TONE': "START.TONE", 'STOP_TONE': "STOP.TONE", 'DETECT_TAPS': "DETECT.TAPS", - 'ADJUST_THRESHOLD': "ADJUST_THRESHOLD" + 'ADJUST_THRESHOLD': "ADJUST_THRESHOLD", + 'RED_LED': "RED_LED", + 'PIXELS': "PIXELS" } diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index b8bc6eb79..1d2287611 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -86,6 +86,9 @@ def tapped(self): @property def red_led(self): + telemetry_client.track_event( + f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["RED_LED"]}') + telemetry_client.flush() return self.__state['red_led'] @red_led.setter diff --git a/src/adafruit_circuitplayground/pixel.py b/src/adafruit_circuitplayground/pixel.py index d09539dde..af07c02c6 100644 --- a/src/adafruit_circuitplayground/pixel.py +++ b/src/adafruit_circuitplayground/pixel.py @@ -5,6 +5,12 @@ import sys from . import constants as CONSTANTS from . import utils +from applicationinsights import TelemetryClient +from . import constants as CONSTANTS + + +telemetry_client = TelemetryClient('__AIKEY__') +EXTENSION_NAME = '__EXTENSIONNAME__' class Pixel: @@ -21,6 +27,9 @@ def __show_if_auto_write(self): self.show() def __getitem__(self, index): + telemetry_client.track_event( + f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["PIXELS"]}') + telemetry_client.flush() if not self.__valid_index(index): raise IndexError(CONSTANTS.INDEX_ERROR) return self.__state['pixels'][index] From 96bedfe0946379ded1d7a4d341b02d35140318d8 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Wed, 14 Aug 2019 18:54:38 -0700 Subject: [PATCH 17/28] replace key by value --- src/adafruit_circuitplayground/constants.py | 4 ++-- src/adafruit_circuitplayground/express.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/adafruit_circuitplayground/constants.py b/src/adafruit_circuitplayground/constants.py index 6df682189..9c873e75f 100644 --- a/src/adafruit_circuitplayground/constants.py +++ b/src/adafruit_circuitplayground/constants.py @@ -23,7 +23,7 @@ 'START_TONE': "START.TONE", 'STOP_TONE': "STOP.TONE", 'DETECT_TAPS': "DETECT.TAPS", - 'ADJUST_THRESHOLD': "ADJUST_THRESHOLD", - 'RED_LED': "RED_LED", + 'ADJUST_THRESHOLD': "ADJUST.THRESHOLD", + 'RED_LED': "RED.LED", 'PIXELS': "PIXELS" } diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index 1d2287611..52c35ccb8 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -65,7 +65,7 @@ def button_b(self): @property def detect_taps(self): telemetry_client.track_event( - f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["DETECT.TAPS"]}') + f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["DETECT_TAPS"]}') telemetry_client.flush() return self.__state['detect_taps'] @@ -158,7 +158,7 @@ def shake(self, shake_threshold=30): def play_file(self, file_name): telemetry_client.track_event( - f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["PLAY.FILE"]}') + f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["PLAY_FILE"]}') telemetry_client.flush() file_name = utils.remove_leading_slashes(file_name) abs_path_parent_dir = os.path.abspath( From 9c97f968ae112c8cd622cd85051ab0310e4a4b44 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Thu, 15 Aug 2019 09:49:02 -0700 Subject: [PATCH 18/28] replaced f strings --- src/adafruit_circuitplayground/express.py | 16 ++++++++-------- src/adafruit_circuitplayground/pixel.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index 52c35ccb8..11220adb1 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -65,7 +65,7 @@ def button_b(self): @property def detect_taps(self): telemetry_client.track_event( - f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["DETECT_TAPS"]}') + '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["DETECT_TAPS"])) telemetry_client.flush() return self.__state['detect_taps'] @@ -80,14 +80,14 @@ def tapped(self): """ Not Implemented! """ telemetry_client.track_event( - f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["TAPPED"]}') + '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["TAPPED"])) telemetry_client.flush() raise NotImplementedError(CONSTANTS.NOT_IMPLEMENTED_ERROR) @property def red_led(self): telemetry_client.track_event( - f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["RED_LED"]}') + '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["RED_LED"])) telemetry_client.flush() return self.__state['red_led'] @@ -147,7 +147,7 @@ def adjust_touch_threshold(self, adjustement): The CPX Simulator doesn't use capacitive touch threshold. """ telemetry_client.track_event( - f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["ADJUST_THRESHOLD"]}') + '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["ADJUST_THRESHOLD"])) telemetry_client.flush() raise NotImplementedError( @@ -158,7 +158,7 @@ def shake(self, shake_threshold=30): def play_file(self, file_name): telemetry_client.track_event( - f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["PLAY_FILE"]}') + '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["PLAY_FILE"])) telemetry_client.flush() file_name = utils.remove_leading_slashes(file_name) abs_path_parent_dir = os.path.abspath( @@ -182,7 +182,7 @@ def play_tone(self, frequency, duration): """ Not Implemented! """ telemetry_client.track_event( - f'{EXTENSION_NAME}${CONSTANTS.TELEMETRY_EVENT_NAMES["PLAY_TONE"]}') + "{}/{}".format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["PLAY_TONE"])) telemetry_client.flush() raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) @@ -191,7 +191,7 @@ def start_tone(self, frequency): """ Not Implemented! """ telemetry_client.track_event( - f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["START_TONE"]}') + '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["START_TONE"])) telemetry_client.flush() raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) @@ -200,7 +200,7 @@ def stop_tone(self): """ Not Implemented! """ telemetry_client.track_event( - f'{EXTENSION_NAME}/${CONSTANTS.TELEMETRY_EVENT_NAMES["STOP_TONE"]}') + '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["STOP_TONE"])) telemetry_client.flush() raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) diff --git a/src/adafruit_circuitplayground/pixel.py b/src/adafruit_circuitplayground/pixel.py index af07c02c6..5456964c5 100644 --- a/src/adafruit_circuitplayground/pixel.py +++ b/src/adafruit_circuitplayground/pixel.py @@ -28,7 +28,7 @@ def __show_if_auto_write(self): def __getitem__(self, index): telemetry_client.track_event( - f'{EXTENSION_NAME}/{CONSTANTS.TELEMETRY_EVENT_NAMES["PIXELS"]}') + '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["PIXELS"])) telemetry_client.flush() if not self.__valid_index(index): raise IndexError(CONSTANTS.INDEX_ERROR) From d9ab5d5cba4cd86a91bbb0fceda267f3415bf3d0 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Thu, 15 Aug 2019 10:36:13 -0700 Subject: [PATCH 19/28] adding license info --- src/view/components/toolbar/SensorButton.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/view/components/toolbar/SensorButton.tsx b/src/view/components/toolbar/SensorButton.tsx index 708e7e35d..8726cf1a4 100644 --- a/src/view/components/toolbar/SensorButton.tsx +++ b/src/view/components/toolbar/SensorButton.tsx @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import * as React from "react"; import { ISensorButtonProps } from "../../viewUtils"; import "../../styles/SensorButton.css"; From 6229cd5acfd952c7a51a4f7202a45eabef1071bb Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Thu, 15 Aug 2019 11:26:11 -0700 Subject: [PATCH 20/28] adding a prefix for telemetry --- src/adafruit_circuitplayground/constants.py | 18 +++++++++--------- src/adafruit_circuitplayground/pixel.py | 4 ++++ src/constants.ts | 10 ---------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/adafruit_circuitplayground/constants.py b/src/adafruit_circuitplayground/constants.py index 9c873e75f..0b1eff246 100644 --- a/src/adafruit_circuitplayground/constants.py +++ b/src/adafruit_circuitplayground/constants.py @@ -17,13 +17,13 @@ TELEMETRY_EVENT_NAMES = { - 'TAPPED': "TAPPED", - 'PLAY_FILE': "PLAY.FILE", - 'PLAY_TONE': "PLAY.TONE", - 'START_TONE': "START.TONE", - 'STOP_TONE': "STOP.TONE", - 'DETECT_TAPS': "DETECT.TAPS", - 'ADJUST_THRESHOLD': "ADJUST.THRESHOLD", - 'RED_LED': "RED.LED", - 'PIXELS': "PIXELS" + 'TAPPED': "API.TAPPED", + 'PLAY_FILE': "API.PLAY.FILE", + 'PLAY_TONE': "API.PLAY.TONE", + 'START_TONE': "API.START.TONE", + 'STOP_TONE': "API.STOP.TONE", + 'DETECT_TAPS': "API.DETECT.TAPS", + 'ADJUST_THRESHOLD': "API.ADJUST.THRESHOLD", + 'RED_LED': "API.RED.LED", + 'PIXELS': "API.PIXELS" } diff --git a/src/adafruit_circuitplayground/pixel.py b/src/adafruit_circuitplayground/pixel.py index fda9955f3..c0c063330 100644 --- a/src/adafruit_circuitplayground/pixel.py +++ b/src/adafruit_circuitplayground/pixel.py @@ -38,6 +38,10 @@ def __getitem__(self, index): return self.__state['pixels'][index] def __setitem__(self, index, val): + telemetry_client.track_event( + '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["PIXELS"])) + telemetry_client.flush() + is_slice = False if type(index) is slice: is_slice = True diff --git a/src/constants.ts b/src/constants.ts index 40688faeb..3212ada65 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -149,16 +149,6 @@ export enum TelemetryEventName { SIMULATOR_SHAKE = "SIMULATOR.SHAKE", SIMULATOR_CAPACITIVE_TOUCH = "SIMULATOR.CAPACITIVE.TOUCH", - //Mock calls - SIMULATOR_ADJUST_THRESHOLD = "SIMULATOR.ADJUST.THRESHOLD", - SIMULATOR_DETECT_TAPS = "SIMULATOR.DETECT.TAPS", - SIMULATOR_PLAY_TONE = "SIMULATOR.PLAY.TONE ", - SIMULATOR_PLAY_FILE = "SIMULATOR.PLAY.FILE", - SIMULATOR_START_TONE = "SIMULATOR.START.TONE", - SIMULATOR_STOP_TONE = "SIMULATOR.STOP.TONE", - SIMULATOR_TAPPED = "SIMULATOR.TAPPED", - SIMULATOR_PIXELS = "SIMULATOR.PIXELS", - // Pop-up dialog CLICK_DIALOG_DONT_SHOW = "CLICK.DIALOG.DONT.SHOW", CLICK_DIALOG_EXAMPLE_CODE = "CLICK.DIALOG.EXAMPLE.CODE", From 0687c64b54d2ff008d7ce1a16a4ac960821de719 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Thu, 15 Aug 2019 11:30:15 -0700 Subject: [PATCH 21/28] removing spaces --- src/adafruit_circuitplayground/pixel.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/adafruit_circuitplayground/pixel.py b/src/adafruit_circuitplayground/pixel.py index c0c063330..21f966534 100644 --- a/src/adafruit_circuitplayground/pixel.py +++ b/src/adafruit_circuitplayground/pixel.py @@ -91,7 +91,6 @@ def __extract_pixel_value(self, val, is_slice=False): if len(rgb_value) != 3 or any(not self.__valid_rgb_value(pix) for pix in rgb_value): raise ValueError(CONSTANTS.VALID_PIXEL_ASSIGN_ERROR) extracted_values.append(rgb_value) - return rgb_value if not is_slice else extracted_values def __hex_to_rgb(self, hexValue): @@ -101,7 +100,6 @@ def __hex_to_rgb(self, hexValue): hexToRgbValue[0] = int(hexColor[0:2], 16) # R hexToRgbValue[1] = int(hexColor[2:4], 16) # G hexToRgbValue[2] = int(hexColor[4:6], 16) # B - return tuple(hexToRgbValue) else: raise ValueError(CONSTANTS.PIXEL_RANGE_ERROR) @@ -116,7 +114,6 @@ def brightness(self): @brightness.setter def brightness(self, brightness): if not self.__valid_brightness(brightness): - raise ValueError(CONSTANTS.BRIGHTNESS_RANGE_ERROR) self.__state['brightness'] = brightness self.__show_if_auto_write() From 9ae3b40dd9229a6edece316176ff53bb81455b68 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Thu, 15 Aug 2019 14:42:19 -0700 Subject: [PATCH 22/28] adapt to dev chages --- src/extension.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/extension.ts b/src/extension.ts index 017523b88..e85a444cd 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -130,6 +130,7 @@ export async function activate(context: vscode.ExtensionContext) { } break; case WebviewMessages.SENSOR_CHANGED: + handleSensorTelemetry(message.text); console.log(`Sensor changed ${messageJson} \n`); if (inDebugMode) { debuggerCommunicationHandler.emitSensorChanged(messageJson); From 70412b30a49ed2a3d513368ee27461c42deba09b Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Thu, 15 Aug 2019 16:29:16 -0700 Subject: [PATCH 23/28] chnage way sliders send telemetry --- src/constants.ts | 14 ++--- src/extension.ts | 58 ++++++++++++++------- src/python_constants.py | 3 +- src/view/components/toolbar/InputSlider.tsx | 6 +++ 4 files changed, 55 insertions(+), 26 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 4f3d24a35..cfd060128 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -19,7 +19,8 @@ export const CONSTANTS = { PYTHON_LAUNCHER: "py -3" }, ERROR: { - COMPORT_UNKNOWN_ERROR: "Writing to COM port (GetOverlappedResult): Unknown error code 121", + COMPORT_UNKNOWN_ERROR: + "Writing to COM port (GetOverlappedResult): Unknown error code 121", CPX_FILE_ERROR: localize( "error.cpxFileFormat", "The cpx.json file format is not correct." @@ -32,13 +33,13 @@ export const CONSTANTS = { return localize( "error.failedToOpenSerialPort", `[ERROR] Failed to open serial port ${port}.` - ) + ); }, FAILED_TO_OPEN_SERIAL_PORT_DUE_TO: (port: string, error: any) => { return localize( "error.failedToOpenSerialPortDueTo", `[ERROR] Failed to open serial port ${port} due to error: ${error}. \n` - ) + ); }, INCORRECT_FILE_NAME_FOR_DEVICE: localize( "error.incorrectFileNameForDevice", @@ -198,7 +199,7 @@ export const CONSTANTS = { return localize( "warning.serialMonitorAlreadyOpened", `Serial monitor is already opened for ${port} \n` - ) + ); }, SERIAL_MONITOR_NOT_STARTED: localize( "warning.serialMonitorNotStarted", @@ -262,7 +263,8 @@ export enum WebviewMessages { BUTTON_PRESS = "button-press", PLAY_SIMULATOR = "play-simulator", SENSOR_CHANGED = "sensor-changed", - REFRESH_SIMULATOR = "refresh-simulator" + REFRESH_SIMULATOR = "refresh-simulator", + SLIDER_TELEMETRY = "slider-telemetry" } // tslint:disable-next-line: no-namespace @@ -315,7 +317,7 @@ export const USER_CODE_NAMES = { export const STATUS_BAR_PRIORITY = { PORT: 20, OPEN_PORT: 30, - BAUD_RATE: 40, + BAUD_RATE: 40 }; export default CONSTANTS; diff --git a/src/extension.ts b/src/extension.ts index e85a444cd..11e9e6010 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -130,7 +130,7 @@ export async function activate(context: vscode.ExtensionContext) { } break; case WebviewMessages.SENSOR_CHANGED: - handleSensorTelemetry(message.text); + checkForTelemetry(message.text); console.log(`Sensor changed ${messageJson} \n`); if (inDebugMode) { debuggerCommunicationHandler.emitSensorChanged(messageJson); @@ -142,6 +142,9 @@ export async function activate(context: vscode.ExtensionContext) { console.log("Refresh button"); runSimulatorCommand(); break; + case WebviewMessages.SLIDER_TELEMETRY: + handleSensorTelemetry(message.text); + break; default: vscode.window.showInformationMessage( CONSTANTS.ERROR.UNEXPECTED_MESSAGE @@ -718,25 +721,42 @@ const handleButtonPressTelemetry = (buttonState: any) => { } }; -const handleSensorTelemetry = (sensorState: any) => { - if (sensorState["temperature"]) { - telemetryAI.trackFeatureUsage( - TelemetryEventName.SIMULATOR_TEMPERATURE_SENSOR - ); - } else if (sensorState["light"]) { - telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_LIGHT_SENSOR); - } else if ( - sensorState["motion_x"] || - sensorState["motion_y"] || - sensorState["motion_z"] - ) { - telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_MOTION_SENSOR); - } else if (sensorState["shake"]) { - telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_SHAKE); +const handleSensorTelemetry = (sensor: string) => { + switch (sensor) { + case "temperature": + telemetryAI.trackFeatureUsage( + TelemetryEventName.SIMULATOR_TEMPERATURE_SENSOR + ); + break; + case "light": + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_LIGHT_SENSOR); + break; + case "motion_x": + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_MOTION_SENSOR); + break; + case "motion_y": + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_MOTION_SENSOR); + break; + case "motion_z": + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_MOTION_SENSOR); + break; + case "shake": + telemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_SHAKE); + break; + case "touch": + telemetryAI.trackFeatureUsage( + TelemetryEventName.SIMULATOR_CAPACITIVE_TOUCH + ); + break; + } +}; + +const checkForTelemetry = (sensorState: any) => { + if (sensorState["shake"]) { + console.log(`telemtry sending`); + handleSensorTelemetry("shake"); } else if (sensorState["touch"]) { - telemetryAI.trackFeatureUsage( - TelemetryEventName.SIMULATOR_CAPACITIVE_TOUCH - ); + handleSensorTelemetry("touch"); } }; diff --git a/src/python_constants.py b/src/python_constants.py index 8b131e786..df6393cc3 100644 --- a/src/python_constants.py +++ b/src/python_constants.py @@ -13,7 +13,8 @@ "shake", "motion_x", "motion_y", - "motion_z" + "motion_z", + "touch" ] EXEC_COMMAND = "exec" diff --git a/src/view/components/toolbar/InputSlider.tsx b/src/view/components/toolbar/InputSlider.tsx index 8aecc37ce..f5a398f8b 100644 --- a/src/view/components/toolbar/InputSlider.tsx +++ b/src/view/components/toolbar/InputSlider.tsx @@ -78,6 +78,8 @@ class InputSlider extends React.Component { min={this.props.minValue} max={this.props.maxValue} onChange={this.handleOnChange} + onKeyUp={this.sendTelemetry} + onMouseUp={this.sendTelemetry} aria-valuenow={this.state.value} value={this.state.value} aria-label={`${this.props.type} sensor slider`} @@ -114,6 +116,10 @@ class InputSlider extends React.Component { this.setState({ value: newValue }); } + private sendTelemetry = () => { + vscode.postMessage({ command: "slider-telemetry", text: this.props.type }); + }; + private validateRange() { if (this.state.value < this.props.minValue) { this.setState({ value: this.props.minValue }); From 271cd12d146d8320e538eac2c7e9bec34e66e99b Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Thu, 15 Aug 2019 16:31:07 -0700 Subject: [PATCH 24/28] change to override --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 373699ddf..53f20ac9b 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,7 @@ ], "colors": [ { - "id": "badgeForegroundOverwrite", + "id": "badgeForegroundOverride", "description": "Color that fixes the issue with midnight blue ", "defaults": { "dark": "#FFFFFF", @@ -309,4 +309,4 @@ "extensionDependencies": [ "ms-python.python" ] -} \ No newline at end of file +} From 4a2e20da83233b9438ee6befe710bae4893f2068 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Thu, 15 Aug 2019 16:40:35 -0700 Subject: [PATCH 25/28] change overwrite to override --- src/view/styles/Button.css | 2 +- src/view/styles/InputSlider.css | 2 +- src/view/styles/SensorButton.css | 2 +- src/view/styles/ToolBar.css | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/view/styles/Button.css b/src/view/styles/Button.css index 680e733b8..b8d4bae93 100644 --- a/src/view/styles/Button.css +++ b/src/view/styles/Button.css @@ -5,7 +5,7 @@ } .button-icon { - fill: var(--vscode-badgeForegroundOverwrite); + fill: var(--vscode-badgeForegroundOverride); } .play-button { diff --git a/src/view/styles/InputSlider.css b/src/view/styles/InputSlider.css index e06222636..7d04b1499 100644 --- a/src/view/styles/InputSlider.css +++ b/src/view/styles/InputSlider.css @@ -19,7 +19,7 @@ margin-top: auto; margin-bottom: auto; margin-left: 5px; - color: var(--badgeForegroundOverwrite); + color: var(--badgeForegroundOverride); border-radius: 2px; font-size: 16px; font-weight: bold; diff --git a/src/view/styles/SensorButton.css b/src/view/styles/SensorButton.css index a8d8da2bf..94db9536e 100644 --- a/src/view/styles/SensorButton.css +++ b/src/view/styles/SensorButton.css @@ -1,5 +1,5 @@ .sensor-button { - color: var(--vscode-badgeForegroundOverwrite); + color: var(--vscode-badgeForegroundOverride); text-align: center; background-color: var(--vscode-button-background); width: 320px; diff --git a/src/view/styles/ToolBar.css b/src/view/styles/ToolBar.css index 58ad4c1db..2ad6a5ee7 100644 --- a/src/view/styles/ToolBar.css +++ b/src/view/styles/ToolBar.css @@ -33,7 +33,7 @@ -webkit-appearance: none; font-size: 16px; font-weight: bolder; - color: var(--vscode-badgeForegroundOverwrite); + color: var(--vscode-badgeForegroundOverride); text-align: left; margin-right: 40px; position: absolute; From 774ee6e6b2f99818fa520a4f897e0cf9329df6e4 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Mon, 19 Aug 2019 15:38:01 -0700 Subject: [PATCH 26/28] change tracking method in API --- src/adafruit_circuitplayground/express.py | 62 +++++++++++++---------- src/adafruit_circuitplayground/pixel.py | 20 +++----- src/adafruit_circuitplayground/utils.py | 12 +++++ 3 files changed, 53 insertions(+), 41 deletions(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index 6de670f9c..4cfe62910 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -13,9 +13,6 @@ Acceleration = namedtuple('acceleration', ['x', 'y', 'z']) -telemetry_client = TelemetryClient('__AIKEY__') -EXTENSION_NAME = '__EXTENSIONNAME__' - class Express: def __init__(self): @@ -46,7 +43,16 @@ def __init__(self): 'touch': [False]*7, 'shake': False, } - + self.telemetry_state = { + "DETECT_TAPS": False, + "TAPPED": False, + "RED_LED": False, + "ADJUST_THRESHOLD": False, + "PLAY_FILE": False, + "PLAY_TONE": False, + "START_TONE": False, + "STOP_TONE": False, + } self.__debug_mode = False self.__abs_path_to_code_file = '' self.pixels = Pixel(self.__state, self.__debug_mode) @@ -65,9 +71,9 @@ def button_b(self): @property def detect_taps(self): - telemetry_client.track_event( - '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["DETECT_TAPS"])) - telemetry_client.flush() + if(not self.telemetry_state["DETECT_TAPS"]): + utils.send_telemetry("DETECT_TAPS") + self.telemetry_state["DETECT_TAPS"] = True return self.__state['detect_taps'] @detect_taps.setter @@ -80,16 +86,16 @@ def detect_taps(self, value): def tapped(self): """ Not Implemented! """ - telemetry_client.track_event( - '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["TAPPED"])) - telemetry_client.flush() + if(not self.telemetry_state["TAPPED"]): + utils.send_telemetry("TAPPED") + self.telemetry_state["TAPPED"] = True raise NotImplementedError(CONSTANTS.NOT_IMPLEMENTED_ERROR) @property def red_led(self): - telemetry_client.track_event( - '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["RED_LED"])) - telemetry_client.flush() + if(not self.telemetry_state["RED_LED"]): + utils.send_telemetry("RED_LED") + self.telemetry_state["RED_LED"] = True return self.__state['red_led'] @red_led.setter @@ -147,9 +153,9 @@ def adjust_touch_threshold(self, adjustement): """Not implemented! The CPX Simulator doesn't use capacitive touch threshold. """ - telemetry_client.track_event( - '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["ADJUST_THRESHOLD"])) - telemetry_client.flush() + if(not self.telemetry_state["ADJUST_THRESHOLD"]): + utils.send_telemetry("ADJUST_THRESHOLD") + self.telemetry_state["ADJUST_THRESHOLD"] = True raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) @@ -158,9 +164,9 @@ def shake(self, shake_threshold=30): return self.__state['shake'] def play_file(self, file_name): - telemetry_client.track_event( - '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["PLAY_FILE"])) - telemetry_client.flush() + if(not self.telemetry_state["PLAY_FILE"]): + utils.send_telemetry("PLAY_FILE") + self.telemetry_state["PLAY_FILE"] = True file_name = utils.remove_leading_slashes(file_name) abs_path_parent_dir = os.path.abspath( os.path.join(self.__abs_path_to_code_file, os.pardir)) @@ -182,27 +188,27 @@ def play_file(self, file_name): def play_tone(self, frequency, duration): """ Not Implemented! """ - telemetry_client.track_event( - "{}/{}".format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["PLAY_TONE"])) - telemetry_client.flush() + if(not self.telemetry_state["PLAY_TONE"]): + utils.send_telemetry("PLAY_TONE") + self.telemetry_state["PLAY_TONE"] = True raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) def start_tone(self, frequency): """ Not Implemented! """ - telemetry_client.track_event( - '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["START_TONE"])) - telemetry_client.flush() + if(not self.telemetry_state["START_TONE"]): + utils.send_telemetry("START_TONE") + self.telemetry_state["START_TONE"] = True raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) def stop_tone(self): """ Not Implemented! """ - telemetry_client.track_event( - '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["STOP_TONE"])) - telemetry_client.flush() + if(not self.telemetry_state["STOP_TONE"]): + utils.send_telemetry("STOP_TONE") + self.telemetry_state["STOP_TONE"] = True raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) diff --git a/src/adafruit_circuitplayground/pixel.py b/src/adafruit_circuitplayground/pixel.py index 11d768cf6..cc9044f9e 100644 --- a/src/adafruit_circuitplayground/pixel.py +++ b/src/adafruit_circuitplayground/pixel.py @@ -9,15 +9,12 @@ from . import constants as CONSTANTS -telemetry_client = TelemetryClient('__AIKEY__') -EXTENSION_NAME = '__EXTENSIONNAME__' - - class Pixel: def __init__(self, state, debug_mode=False): self.__state = state self.auto_write = True self.__debug_mode = debug_mode + self.telemetry_state = False def show(self): # Send the state to the extension so that React re-renders the Webview @@ -31,21 +28,18 @@ def __set_debug_mode(self, debug_mode): self.__debug_mode = debug_mode def __getitem__(self, index): - - telemetry_client.track_event( - '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["PIXELS"])) - telemetry_client.flush() - if type(index) is not slice: if not self.__valid_index(index): raise IndexError(CONSTANTS.INDEX_ERROR) + if(not self.telemetry_state): + utils.send_telemetry("PIXELS") + self.telemetry_state = True return self.__state['pixels'][index] def __setitem__(self, index, val): - telemetry_client.track_event( - '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES["PIXELS"])) - telemetry_client.flush() - + if(not self.telemetry_state): + utils.send_telemetry("PIXELS") + self.telemetry_state = True is_slice = False if type(index) is slice: is_slice = True diff --git a/src/adafruit_circuitplayground/utils.py b/src/adafruit_circuitplayground/utils.py index c03e6e15d..26f7d9cda 100644 --- a/src/adafruit_circuitplayground/utils.py +++ b/src/adafruit_circuitplayground/utils.py @@ -7,11 +7,16 @@ import time from . import constants as CONSTANTS from . import debugger_communication_client +from applicationinsights import TelemetryClient previous_state = {} +telemetry_client = TelemetryClient('aba8e4b2-8ed2-4c89-b0a1-1595fbf8e833') +EXTENSION_NAME = '__EXTENSIONNAMEtest__' + + def show(state, debug_mode=False): global previous_state if state != previous_state: @@ -28,3 +33,10 @@ def show(state, debug_mode=False): def remove_leading_slashes(string): string = string.lstrip('\\/') return string + + +def send_telemetry(event_name): + print(f"calling with tstate {event_name}", flush=True) + telemetry_client.track_event( + '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES[event_name])) + telemetry_client.flush() From 7e266e75c51b8f6cf9abaa9b735a20fef357535c Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Mon, 19 Aug 2019 15:51:58 -0700 Subject: [PATCH 27/28] putting back default variables --- src/adafruit_circuitplayground/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/adafruit_circuitplayground/utils.py b/src/adafruit_circuitplayground/utils.py index 26f7d9cda..7c48b5476 100644 --- a/src/adafruit_circuitplayground/utils.py +++ b/src/adafruit_circuitplayground/utils.py @@ -13,8 +13,8 @@ previous_state = {} -telemetry_client = TelemetryClient('aba8e4b2-8ed2-4c89-b0a1-1595fbf8e833') -EXTENSION_NAME = '__EXTENSIONNAMEtest__' +telemetry_client = TelemetryClient('__AIKEY__') +EXTENSION_NAME = '__EXTENSIONNAME__' def show(state, debug_mode=False): From c5a17369f4e2458b2cdd9aa53aebe214f7346884 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Mon, 19 Aug 2019 16:28:27 -0700 Subject: [PATCH 28/28] change according to reviews --- src/adafruit_circuitplayground/express.py | 3 +++ src/adafruit_circuitplayground/utils.py | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index 4cfe62910..7b1f93bfa 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -100,6 +100,9 @@ def red_led(self): @red_led.setter def red_led(self, value): + if(not self.telemetry_state["RED_LED"]): + utils.send_telemetry("RED_LED") + self.telemetry_state["RED_LED"] = True self.__state['red_led'] = bool(value) self.__show() diff --git a/src/adafruit_circuitplayground/utils.py b/src/adafruit_circuitplayground/utils.py index 7c48b5476..2eeadeae6 100644 --- a/src/adafruit_circuitplayground/utils.py +++ b/src/adafruit_circuitplayground/utils.py @@ -36,7 +36,6 @@ def remove_leading_slashes(string): def send_telemetry(event_name): - print(f"calling with tstate {event_name}", flush=True) telemetry_client.track_event( '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES[event_name])) telemetry_client.flush()