From 499b232624ad54c49f80f566ca432d350c91c750 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Wed, 21 Aug 2019 13:50:55 -0700 Subject: [PATCH 01/16] adding .po file --- .../locale/en/LC_MESSAGES/express.po | 26 +++++++++++++++++++ .../locale/express.pot | 26 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/adafruit_circuitplayground/locale/en/LC_MESSAGES/express.po create mode 100644 src/adafruit_circuitplayground/locale/express.pot diff --git a/src/adafruit_circuitplayground/locale/en/LC_MESSAGES/express.po b/src/adafruit_circuitplayground/locale/en/LC_MESSAGES/express.po new file mode 100644 index 000000000..50579af3a --- /dev/null +++ b/src/adafruit_circuitplayground/locale/en/LC_MESSAGES/express.po @@ -0,0 +1,26 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-08-21 13:35-0700\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: express.py:190 +msgid " is not a path to a .wav file." +msgstr "" + +#: express.py:192 +msgid "Please use Python 3 or higher." +msgstr "" diff --git a/src/adafruit_circuitplayground/locale/express.pot b/src/adafruit_circuitplayground/locale/express.pot new file mode 100644 index 000000000..50579af3a --- /dev/null +++ b/src/adafruit_circuitplayground/locale/express.pot @@ -0,0 +1,26 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-08-21 13:35-0700\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: express.py:190 +msgid " is not a path to a .wav file." +msgstr "" + +#: express.py:192 +msgid "Please use Python 3 or higher." +msgstr "" From d2664a055b4fcfcb13f0124d50a46bd233458a24 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Thu, 22 Aug 2019 16:58:08 -0700 Subject: [PATCH 02/16] adding a telemetry message --- src/adafruit_circuitplayground/express.py | 1 + src/extension.ts | 30 +++++++++++++++-------- src/python_constants.py | 4 +-- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index 6077a68bf..8eeb60056 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -43,6 +43,7 @@ def __init__(self): 'touch': [False]*7, 'shake': False, } + self.enable_telemetry = True self.telemetry_state = { "DETECT_TAPS": False, "TAPPED": False, diff --git a/src/extension.ts b/src/extension.ts index 37a6a3365..62cf59005 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -66,7 +66,7 @@ export async function activate(context: vscode.ExtensionContext) { // Add our library path to settings.json for autocomplete functionality updatePythonExtraPaths(); - await utils.checkPythonDependencies(context) + await utils.checkPythonDependencies(context); // Generate cpx.json try { @@ -412,6 +412,11 @@ export async function activate(context: vscode.ExtensionContext) { currentFileAbsPath ]); + if (childProcess) { + const message = { enable_telemtry: getTelemetryState() }; + childProcess.stdin.write(message + "\n"); + } + let dataFromTheProcess = ""; let oldMessage = ""; @@ -442,7 +447,7 @@ export async function activate(context: vscode.ExtensionContext) { case "print": console.log( `Process print statement output = ${ - messageToWebview.data + messageToWebview.data }` ); utils.logToOutputChannel( @@ -644,10 +649,9 @@ export async function activate(context: vscode.ExtensionContext) { "pacifica.selectSerialPort", () => { if (serialMonitor) { - telemetryAI.runWithLatencyMeasure( - () => { serialMonitor.selectSerialPort(null, null); }, - TelemetryEventName.COMMAND_SERIAL_MONITOR_CHOOSE_PORT - ); + telemetryAI.runWithLatencyMeasure(() => { + serialMonitor.selectSerialPort(null, null); + }, TelemetryEventName.COMMAND_SERIAL_MONITOR_CHOOSE_PORT); } else { vscode.window.showErrorMessage(CONSTANTS.ERROR.NO_FOLDER_OPENED); console.info("Serial monitor is not defined."); @@ -689,10 +693,9 @@ export async function activate(context: vscode.ExtensionContext) { "pacifica.closeSerialMonitor", (port, showWarning = true) => { if (serialMonitor) { - telemetryAI.runWithLatencyMeasure( - () => { serialMonitor.closeSerialMonitor(port, showWarning); }, - TelemetryEventName.COMMAND_SERIAL_MONITOR_CLOSE - ) + telemetryAI.runWithLatencyMeasure(() => { + serialMonitor.closeSerialMonitor(port, showWarning); + }, TelemetryEventName.COMMAND_SERIAL_MONITOR_CLOSE); } else { vscode.window.showErrorMessage(CONSTANTS.ERROR.NO_FOLDER_OPENED); console.info("Serial monitor is not defined."); @@ -868,6 +871,13 @@ const handleSensorTelemetry = (sensor: string) => { } }; +const getTelemetryState = () => { + const isEnabled = vscode.workspace + .getConfiguration() + .get("telemetry.enableTelemetry"); + return isEnabled === undefined ? true : false; +}; + const checkForTelemetry = (sensorState: any) => { if (sensorState["shake"]) { console.log(`telemtry sending`); diff --git a/src/python_constants.py b/src/python_constants.py index 2a1020278..a5bc0808c 100644 --- a/src/python_constants.py +++ b/src/python_constants.py @@ -3,7 +3,7 @@ CPX_DRIVE_NAME = "CIRCUITPY" - +ENABLE_TELEMERY = 'enable_telemetry' EXPECTED_INPUT_EVENTS = [ "button_a", "button_b", @@ -14,7 +14,7 @@ "motion_x", "motion_y", "motion_z", - "touch" + "touch", ] EXEC_COMMAND = "exec" From d246354c2279dfa5dacdf8a2bbafdcde4e7e70e2 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Thu, 22 Aug 2019 20:11:40 -0700 Subject: [PATCH 03/16] modifying telemetry in python --- src/adafruit_circuitplayground/express.py | 50 +++++---------------- src/adafruit_circuitplayground/telemetry.py | 36 +++++++++++++++ src/adafruit_circuitplayground/utils.py | 11 +---- src/extension.ts | 10 ++--- src/process_user_code.py | 4 ++ src/python_constants.py | 2 +- 6 files changed, 58 insertions(+), 55 deletions(-) create mode 100644 src/adafruit_circuitplayground/telemetry.py diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index 8eeb60056..d1e828166 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -10,6 +10,7 @@ from . import constants as CONSTANTS from collections import namedtuple from applicationinsights import TelemetryClient +from .telemetry import telemetry_py Acceleration = namedtuple('acceleration', ['x', 'y', 'z']) @@ -43,21 +44,11 @@ def __init__(self): 'touch': [False]*7, 'shake': False, } - self.enable_telemetry = True - 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) + @property def acceleration(self): return Acceleration(self.__state['motion_x'], self.__state['motion_y'], self.__state['motion_z']) @@ -72,9 +63,7 @@ def button_b(self): @property def detect_taps(self): - if(utils.telemetry_available() and not self.telemetry_state["DETECT_TAPS"]): - utils.send_telemetry("DETECT_TAPS") - self.telemetry_state["DETECT_TAPS"] = True + telemetry_py.send_telemetry("DETECT_TAPS") return self.__state['detect_taps'] @detect_taps.setter @@ -87,23 +76,17 @@ def detect_taps(self, value): def tapped(self): """ Not Implemented! """ - if(utils.telemetry_available() and not self.telemetry_state["TAPPED"]): - utils.send_telemetry("TAPPED") - self.telemetry_state["TAPPED"] = True + telemetry_py.send_telemetry("TAPPED") raise NotImplementedError(CONSTANTS.NOT_IMPLEMENTED_ERROR) @property def red_led(self): - if(utils.telemetry_available() and not self.telemetry_state["RED_LED"]): - utils.send_telemetry("RED_LED") - self.telemetry_state["RED_LED"] = True + telemetry_py.send_telemetry("RED_LED") return self.__state['red_led'] @red_led.setter def red_led(self, value): - if(utils.telemetry_available() and not self.telemetry_state["RED_LED"]): - utils.send_telemetry("RED_LED") - self.telemetry_state["RED_LED"] = True + telemetry_py.send_telemetry("RED_LED") self.__state['red_led'] = bool(value) self.__show() @@ -157,10 +140,7 @@ def adjust_touch_threshold(self, adjustement): """Not implemented! The CPX Simulator doesn't use capacitive touch threshold. """ - if(utils.telemetry_available() and not self.telemetry_state["ADJUST_THRESHOLD"]): - utils.send_telemetry("ADJUST_THRESHOLD") - self.telemetry_state["ADJUST_THRESHOLD"] = True - + telemetry_py.send_telemetry("ADJUST_THRESHOLD") raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) @@ -168,9 +148,7 @@ def shake(self, shake_threshold=30): return self.__state['shake'] def play_file(self, file_name): - if(utils.telemetry_available() and not self.telemetry_state["PLAY_FILE"]): - utils.send_telemetry("PLAY_FILE") - self.telemetry_state["PLAY_FILE"] = True + telemetry_py.send_telemetry("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)) @@ -193,27 +171,21 @@ def play_file(self, file_name): def play_tone(self, frequency, duration): """ Not Implemented! """ - if(utils.telemetry_available() and not self.telemetry_state["PLAY_TONE"]): - utils.send_telemetry("PLAY_TONE") - self.telemetry_state["PLAY_TONE"] = True + telemetry_py.send_telemetry("PLAY_TONE") raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) def start_tone(self, frequency): """ Not Implemented! """ - if(utils.telemetry_available() and not self.telemetry_state["START_TONE"]): - utils.send_telemetry("START_TONE") - self.telemetry_state["START_TONE"] = True + telemetry_py.send_telemetry("START_TONE") raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) def stop_tone(self): """ Not Implemented! """ - if(utils.telemetry_available() and not self.telemetry_state["STOP_TONE"]): - utils.send_telemetry("STOP_TONE") - self.telemetry_state["STOP_TONE"] = True + telemetry_py.send_telemetry("STOP_TONE") raise NotImplementedError( CONSTANTS.NOT_IMPLEMENTED_ERROR) diff --git a/src/adafruit_circuitplayground/telemetry.py b/src/adafruit_circuitplayground/telemetry.py new file mode 100644 index 000000000..ffc963484 --- /dev/null +++ b/src/adafruit_circuitplayground/telemetry.py @@ -0,0 +1,36 @@ +from . import constants as CONSTANTS +from applicationinsights import TelemetryClient + + +class Telemetry: + def __init__(self): + # State of the telemetry + self.__enable_telemetry = True + 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.telemetry_client = TelemetryClient('__AIKEY__') + self.extension_name = '__EXTENSIONNAME__' + + def send_telemetry(self, event_name): + print('entred telem sending {} with {}'.format( + event_name, self.__enable_telemetry), flush=True) + if self.telemetry_available() and not self.telemetry_state[event_name] and self.__enable_telemetry: + print('both true {}'.format(event_name), flush=True) + self.telemetry_client.track_event( + '{}/{}'.format(self.extension_name, CONSTANTS.TELEMETRY_EVENT_NAMES[event_name])) + self.telemetry_client.flush() + self.telemetry_state[event_name] = True + + def telemetry_available(self): + return self.telemetry_client.context.instrumentation_key != '__AIKEY__' + + +telemetry_py = Telemetry() diff --git a/src/adafruit_circuitplayground/utils.py b/src/adafruit_circuitplayground/utils.py index c36e344d9..4c6db595c 100644 --- a/src/adafruit_circuitplayground/utils.py +++ b/src/adafruit_circuitplayground/utils.py @@ -10,8 +10,6 @@ from applicationinsights import TelemetryClient previous_state = {} -telemetry_client = TelemetryClient('__AIKEY__') -EXTENSION_NAME = '__EXTENSIONNAME__' def show(state, debug_mode=False): global previous_state @@ -30,15 +28,8 @@ def remove_leading_slashes(string): string = string.lstrip('\\/') return string + def escape_if_OSX(file_name): if sys.platform.startswith(CONSTANTS.MAC_OS): file_name = file_name.replace(" ", "%20") return file_name - -def send_telemetry(event_name): - telemetry_client.track_event( - '{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES[event_name])) - telemetry_client.flush() - -def telemetry_available(): - return telemetry_client.context.instrumentation_key != '__AIKEY__' \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index 62cf59005..b29dee310 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -412,9 +412,10 @@ export async function activate(context: vscode.ExtensionContext) { currentFileAbsPath ]); + const enableTelemetry = getTelemetryState(); if (childProcess) { - const message = { enable_telemtry: getTelemetryState() }; - childProcess.stdin.write(message + "\n"); + const message = { enable_telemetry: enableTelemetry }; + childProcess.stdin.write(JSON.stringify(message) + "\n"); } let dataFromTheProcess = ""; @@ -874,13 +875,12 @@ const handleSensorTelemetry = (sensor: string) => { const getTelemetryState = () => { const isEnabled = vscode.workspace .getConfiguration() - .get("telemetry.enableTelemetry"); - return isEnabled === undefined ? true : false; + .get("telemetry.enableTelemetry", true); + return isEnabled; }; const checkForTelemetry = (sensorState: any) => { if (sensorState["shake"]) { - console.log(`telemtry sending`); handleSensorTelemetry("shake"); } else if (sensorState["touch"]) { handleSensorTelemetry("touch"); diff --git a/src/process_user_code.py b/src/process_user_code.py index 28bf37482..e795e8976 100644 --- a/src/process_user_code.py +++ b/src/process_user_code.py @@ -11,6 +11,7 @@ import python_constants as CONSTANTS from pathlib import Path from adafruit_circuitplayground.express import cpx +from adafruit_circuitplayground.telemetry import telemetry_py read_val = "" threads = [] @@ -41,6 +42,9 @@ def run(self): cpx._Express__state[event] = new_state.get( event, cpx._Express__state[event]) + telemetry_py._Telemetry__enable_telemetry = new_state.get( + CONSTANTS.ENABLE_TELEMETRY, True) + except Exception as e: print(CONSTANTS.ERROR_SENDING_EVENT, e, file=sys.stderr, flush=True) diff --git a/src/python_constants.py b/src/python_constants.py index a5bc0808c..d6d6e7b5b 100644 --- a/src/python_constants.py +++ b/src/python_constants.py @@ -3,7 +3,7 @@ CPX_DRIVE_NAME = "CIRCUITPY" -ENABLE_TELEMERY = 'enable_telemetry' +ENABLE_TELEMETRY = 'enable_telemetry' EXPECTED_INPUT_EVENTS = [ "button_a", "button_b", From ecf41f1e742effab43d1c5207eb52fb57ede1ae8 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Thu, 22 Aug 2019 20:13:31 -0700 Subject: [PATCH 04/16] impact pixelpy --- .../locale/en/LC_MESSAGES/express.po | 26 ------------------- .../locale/express.pot | 26 ------------------- src/adafruit_circuitplayground/pixel.py | 8 ++---- 3 files changed, 2 insertions(+), 58 deletions(-) delete mode 100644 src/adafruit_circuitplayground/locale/en/LC_MESSAGES/express.po delete mode 100644 src/adafruit_circuitplayground/locale/express.pot diff --git a/src/adafruit_circuitplayground/locale/en/LC_MESSAGES/express.po b/src/adafruit_circuitplayground/locale/en/LC_MESSAGES/express.po deleted file mode 100644 index 50579af3a..000000000 --- a/src/adafruit_circuitplayground/locale/en/LC_MESSAGES/express.po +++ /dev/null @@ -1,26 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-08-21 13:35-0700\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=CHARSET\n" -"Content-Transfer-Encoding: 8bit\n" - -#: express.py:190 -msgid " is not a path to a .wav file." -msgstr "" - -#: express.py:192 -msgid "Please use Python 3 or higher." -msgstr "" diff --git a/src/adafruit_circuitplayground/locale/express.pot b/src/adafruit_circuitplayground/locale/express.pot deleted file mode 100644 index 50579af3a..000000000 --- a/src/adafruit_circuitplayground/locale/express.pot +++ /dev/null @@ -1,26 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-08-21 13:35-0700\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=CHARSET\n" -"Content-Transfer-Encoding: 8bit\n" - -#: express.py:190 -msgid " is not a path to a .wav file." -msgstr "" - -#: express.py:192 -msgid "Please use Python 3 or higher." -msgstr "" diff --git a/src/adafruit_circuitplayground/pixel.py b/src/adafruit_circuitplayground/pixel.py index aee29e2b2..bffca6971 100644 --- a/src/adafruit_circuitplayground/pixel.py +++ b/src/adafruit_circuitplayground/pixel.py @@ -31,15 +31,11 @@ def __getitem__(self, index): if type(index) is not slice: if not self.__valid_index(index): raise IndexError(CONSTANTS.INDEX_ERROR) - if(utils.telemetry_available() and not self.telemetry_state): - utils.send_telemetry("PIXELS") - self.telemetry_state = True + utils.send_telemetry("PIXELS") return self.__state['pixels'][index] def __setitem__(self, index, val): - if(utils.telemetry_available() and not self.telemetry_state): - utils.send_telemetry("PIXELS") - self.telemetry_state = True + utils.send_telemetry("PIXELS") is_slice = False if type(index) is slice: is_slice = True From 636d8497c607061a77ccd698936049d4562366ad Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Thu, 22 Aug 2019 20:37:25 -0700 Subject: [PATCH 05/16] changing telemetry in pixels --- src/adafruit_circuitplayground/pixel.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/adafruit_circuitplayground/pixel.py b/src/adafruit_circuitplayground/pixel.py index bffca6971..530dbd48b 100644 --- a/src/adafruit_circuitplayground/pixel.py +++ b/src/adafruit_circuitplayground/pixel.py @@ -7,6 +7,7 @@ from . import utils from applicationinsights import TelemetryClient from . import constants as CONSTANTS +from .telemetry import telemetry_py class Pixel: @@ -31,11 +32,11 @@ def __getitem__(self, index): if type(index) is not slice: if not self.__valid_index(index): raise IndexError(CONSTANTS.INDEX_ERROR) - utils.send_telemetry("PIXELS") + telemetry_py.send_telemetry("PIXELS") return self.__state['pixels'][index] def __setitem__(self, index, val): - utils.send_telemetry("PIXELS") + telemetry_py.send_telemetry("PIXELS") is_slice = False if type(index) is slice: is_slice = True From 5a249d1fe384ecbd3d1c873978610036bc7bdf47 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Fri, 23 Aug 2019 10:49:28 -0700 Subject: [PATCH 06/16] removed print statement --- src/adafruit_circuitplayground/telemetry.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/adafruit_circuitplayground/telemetry.py b/src/adafruit_circuitplayground/telemetry.py index ffc963484..5272891f6 100644 --- a/src/adafruit_circuitplayground/telemetry.py +++ b/src/adafruit_circuitplayground/telemetry.py @@ -20,10 +20,7 @@ def __init__(self): self.extension_name = '__EXTENSIONNAME__' def send_telemetry(self, event_name): - print('entred telem sending {} with {}'.format( - event_name, self.__enable_telemetry), flush=True) if self.telemetry_available() and not self.telemetry_state[event_name] and self.__enable_telemetry: - print('both true {}'.format(event_name), flush=True) self.telemetry_client.track_event( '{}/{}'.format(self.extension_name, CONSTANTS.TELEMETRY_EVENT_NAMES[event_name])) self.telemetry_client.flush() From c8ca169bdb62beeac5ed41e57f2a2e23e7add8c4 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Fri, 23 Aug 2019 11:08:49 -0700 Subject: [PATCH 07/16] moving condition --- src/adafruit_circuitplayground/telemetry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adafruit_circuitplayground/telemetry.py b/src/adafruit_circuitplayground/telemetry.py index 5272891f6..36dfe61c3 100644 --- a/src/adafruit_circuitplayground/telemetry.py +++ b/src/adafruit_circuitplayground/telemetry.py @@ -20,7 +20,7 @@ def __init__(self): self.extension_name = '__EXTENSIONNAME__' def send_telemetry(self, event_name): - if self.telemetry_available() and not self.telemetry_state[event_name] and self.__enable_telemetry: + if self.__enable_telemetry and self.telemetry_available() and not self.telemetry_state[event_name]: self.telemetry_client.track_event( '{}/{}'.format(self.extension_name, CONSTANTS.TELEMETRY_EVENT_NAMES[event_name])) self.telemetry_client.flush() From 436cbe75f9ea0b754f8b70baac9fd6f4c4553e59 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Fri, 23 Aug 2019 12:14:35 -0700 Subject: [PATCH 08/16] moved telemetry to spwan --- src/adafruit_circuitplayground/express.py | 1 - src/adafruit_circuitplayground/telemetry.py | 3 ++- src/extension.ts | 9 ++------- src/process_user_code.py | 7 +++++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index d1e828166..ad40be2ec 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -48,7 +48,6 @@ def __init__(self): self.__abs_path_to_code_file = '' self.pixels = Pixel(self.__state, self.__debug_mode) - @property def acceleration(self): return Acceleration(self.__state['motion_x'], self.__state['motion_y'], self.__state['motion_z']) diff --git a/src/adafruit_circuitplayground/telemetry.py b/src/adafruit_circuitplayground/telemetry.py index 36dfe61c3..d5c98e18c 100644 --- a/src/adafruit_circuitplayground/telemetry.py +++ b/src/adafruit_circuitplayground/telemetry.py @@ -16,7 +16,8 @@ def __init__(self): "START_TONE": False, "STOP_TONE": False, } - self.telemetry_client = TelemetryClient('__AIKEY__') + self.telemetry_client = TelemetryClient( + 'aba8e4b2-8ed2-4c89-b0a1-1595fbf8e833') self.extension_name = '__EXTENSIONNAME__' def send_telemetry(self, event_name): diff --git a/src/extension.ts b/src/extension.ts index b29dee310..1db8ab371 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -409,15 +409,10 @@ export async function activate(context: vscode.ExtensionContext) { childProcess = cp.spawn(pythonExecutableName, [ utils.getPathToScript(context, "out", "process_user_code.py"), - currentFileAbsPath + currentFileAbsPath, + JSON.stringify({ enable_telemetry: getTelemetryState() }) ]); - const enableTelemetry = getTelemetryState(); - if (childProcess) { - const message = { enable_telemetry: enableTelemetry }; - childProcess.stdin.write(JSON.stringify(message) + "\n"); - } - let dataFromTheProcess = ""; let oldMessage = ""; diff --git a/src/process_user_code.py b/src/process_user_code.py index e795e8976..f1bd4a5d2 100644 --- a/src/process_user_code.py +++ b/src/process_user_code.py @@ -42,8 +42,8 @@ def run(self): cpx._Express__state[event] = new_state.get( event, cpx._Express__state[event]) - telemetry_py._Telemetry__enable_telemetry = new_state.get( - CONSTANTS.ENABLE_TELEMETRY, True) + # telemetry_py._Telemetry__enable_telemetry = new_state.get( + # CONSTANTS.ENABLE_TELEMETRY, True) except Exception as e: print(CONSTANTS.ERROR_SENDING_EVENT, @@ -94,6 +94,9 @@ def execute_user_code(abs_path_to_code_file): user_code = threading.Thread(args=(sys.argv[1],), target=execute_user_code) +telemetry_state = json.loads(sys.argv[2]) +telemetry_py.Telemetry__enable_telemetry = telemetry_state.get( + CONSTANTS.ENABLE_TELEMETRY, True) threads.append(user_code) user_code.start() From 982f149cedc20a2219297994916714ee7b5cd81e Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Fri, 23 Aug 2019 12:20:00 -0700 Subject: [PATCH 09/16] moved function to utils --- src/extension.ts | 9 +- src/extension_utils/utils.ts | 157 ++++++++++++++++++++++------------- 2 files changed, 100 insertions(+), 66 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 1db8ab371..ed8b0000f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -410,7 +410,7 @@ export async function activate(context: vscode.ExtensionContext) { childProcess = cp.spawn(pythonExecutableName, [ utils.getPathToScript(context, "out", "process_user_code.py"), currentFileAbsPath, - JSON.stringify({ enable_telemetry: getTelemetryState() }) + JSON.stringify({ enable_telemetry: utils.getTelemetryState() }) ]); let dataFromTheProcess = ""; @@ -867,13 +867,6 @@ const handleSensorTelemetry = (sensor: string) => { } }; -const getTelemetryState = () => { - const isEnabled = vscode.workspace - .getConfiguration() - .get("telemetry.enableTelemetry", true); - return isEnabled; -}; - const checkForTelemetry = (sensorState: any) => { if (sensorState["shake"]) { handleSensorTelemetry("shake"); diff --git a/src/extension_utils/utils.ts b/src/extension_utils/utils.ts index c8800dbbf..1c66cb6c0 100644 --- a/src/extension_utils/utils.ts +++ b/src/extension_utils/utils.ts @@ -40,11 +40,12 @@ export const validCodeFileName = (filePath: string) => { }; export const showPrivacyModal = (okAction: () => void) => { - vscode.window.showInformationMessage( - `${CONSTANTS.INFO.THIRD_PARTY_WEBSITE}: ${CONSTANTS.LINKS.PRIVACY}`, - DialogResponses.AGREE_AND_PROCEED, - DialogResponses.CANCEL, - ) + vscode.window + .showInformationMessage( + `${CONSTANTS.INFO.THIRD_PARTY_WEBSITE}: ${CONSTANTS.LINKS.PRIVACY}`, + DialogResponses.AGREE_AND_PROCEED, + DialogResponses.CANCEL + ) .then((privacySelection: vscode.MessageItem | undefined) => { if (privacySelection === DialogResponses.AGREE_AND_PROCEED) { okAction(); @@ -73,10 +74,10 @@ export function tryParseJSON(jsonString: string): any | boolean { if (jsonObj && typeof jsonObj === "object") { return jsonObj; } - } catch (exception) { } + } catch (exception) {} return false; -}; +} export function fileExistsSync(filePath: string): boolean { try { @@ -84,7 +85,7 @@ export function fileExistsSync(filePath: string): boolean { } catch (error) { return false; } -}; +} export function mkdirRecursivelySync(dirPath: string): void { if (directoryExistsSync(dirPath)) { @@ -99,7 +100,7 @@ export function mkdirRecursivelySync(dirPath: string): void { mkdirRecursivelySync(dirname); fs.mkdirSync(dirPath); } -}; +} export function directoryExistsSync(dirPath: string): boolean { try { @@ -107,7 +108,7 @@ export function directoryExistsSync(dirPath: string): boolean { } catch (e) { return false; } -}; +} /** * This method pads the current string with another string (repeated, if needed) @@ -138,11 +139,11 @@ export function padStart( } else { return (sourceString as any).padStart(targetLength, padString); } -}; +} export function convertToHex(num: number, width = 0): string { return padStart(num.toString(16), width, "0"); -}; +} export function generateCPXConfig(): void { const deviceContext: DeviceContext = DeviceContext.getInstance(); @@ -155,7 +156,7 @@ export function generateCPXConfig(): void { ); mkdirRecursivelySync(path.dirname(cpxConfigFilePath)); fs.writeFileSync(cpxConfigFilePath, JSON.stringify(cpxJson, null, 4)); -}; +} export const checkPythonDependency = async () => { const dependencyChecker: DependencyChecker = new DependencyChecker(); const result = await dependencyChecker.checkDependency( @@ -170,7 +171,7 @@ export const checkPipDependency = async () => { CONSTANTS.DEPENDENCY_CHECKER.PIP3 ); return result.payload; -} +}; export const setPythonExectuableName = async () => { // Find our what command is the PATH for python @@ -179,8 +180,11 @@ export const setPythonExectuableName = async () => { if (dependencyCheck.installed) { executableName = dependencyCheck.dependency; } else { - vscode.window.showErrorMessage(CONSTANTS.ERROR.NO_PYTHON_PATH, - DialogResponses.INSTALL_PYTHON) + vscode.window + .showErrorMessage( + CONSTANTS.ERROR.NO_PYTHON_PATH, + DialogResponses.INSTALL_PYTHON + ) .then((selection: vscode.MessageItem | undefined) => { if (selection === DialogResponses.INSTALL_PYTHON) { const okAction = () => { @@ -194,35 +198,52 @@ export const setPythonExectuableName = async () => { return executableName; }; -export const addVisibleTextEditorCallback = (currentPanel: vscode.WebviewPanel, context: vscode.ExtensionContext): vscode.Disposable => { - const initialPythonEditors = filterForPythonFiles(vscode.window.visibleTextEditors); +export const addVisibleTextEditorCallback = ( + currentPanel: vscode.WebviewPanel, + context: vscode.ExtensionContext +): vscode.Disposable => { + const initialPythonEditors = filterForPythonFiles( + vscode.window.visibleTextEditors + ); currentPanel.webview.postMessage({ command: "visible-editors", state: { activePythonEditors: initialPythonEditors } }); - return vscode.window.onDidChangeVisibleTextEditors((textEditors: vscode.TextEditor[]) => { - const activePythonEditors = filterForPythonFiles(textEditors); - currentPanel.webview.postMessage({ - command: "visible-editors", - state: { activePythonEditors } - }); - }, {}, context.subscriptions) + return vscode.window.onDidChangeVisibleTextEditors( + (textEditors: vscode.TextEditor[]) => { + const activePythonEditors = filterForPythonFiles(textEditors); + currentPanel.webview.postMessage({ + command: "visible-editors", + state: { activePythonEditors } + }); + }, + {}, + context.subscriptions + ); }; export const filterForPythonFiles = (textEditors: vscode.TextEditor[]) => { - return textEditors.filter( - editor => editor.document.languageId === "python" - ).map(editor => editor.document.fileName); + return textEditors + .filter(editor => editor.document.languageId === "python") + .map(editor => editor.document.fileName); }; -export const getActiveEditorFromPath = (filePath: string): vscode.TextDocument => { - const activeEditor = vscode.window.visibleTextEditors.find((editor: vscode.TextEditor) => editor.document.fileName === filePath); +export const getActiveEditorFromPath = ( + filePath: string +): vscode.TextDocument => { + const activeEditor = vscode.window.visibleTextEditors.find( + (editor: vscode.TextEditor) => editor.document.fileName === filePath + ); return activeEditor ? activeEditor.document : undefined; }; export const getServerPortConfig = (): number => { // tslint:disable: no-backbone-get-set-outside-model prefer-type-cast - if (vscode.workspace.getConfiguration().has(SERVER_INFO.SERVER_PORT_CONFIGURATION)) { + if ( + vscode.workspace + .getConfiguration() + .has(SERVER_INFO.SERVER_PORT_CONFIGURATION) + ) { return vscode.workspace .getConfiguration() .get(SERVER_INFO.SERVER_PORT_CONFIGURATION) as number; @@ -232,58 +253,78 @@ export const getServerPortConfig = (): number => { export const checkConfig = (configName: string): boolean => { return vscode.workspace.getConfiguration().get(configName) === true; -} +}; -export const checkPythonDependencies = async (context: vscode.ExtensionContext) => { +export const checkPythonDependencies = async ( + context: vscode.ExtensionContext +) => { let hasInstalledDependencies: boolean = false; if (checkPipDependency() && checkPythonDependency()) { if (checkConfig(CONFIG.SHOW_DEPENDENCY_INSTALL)) { hasInstalledDependencies = await promptInstallPythonDependencies(context); if (hasInstalledDependencies) { - await vscode.workspace.getConfiguration().update(CONFIG.SHOW_DEPENDENCY_INSTALL, false); + await vscode.workspace + .getConfiguration() + .update(CONFIG.SHOW_DEPENDENCY_INSTALL, false); } } } else { hasInstalledDependencies = false; } return hasInstalledDependencies; -} - +}; -export const promptInstallPythonDependencies = (context: vscode.ExtensionContext) => { - return vscode.window.showInformationMessage( - CONSTANTS.INFO.INSTALL_PYTHON_DEPENDENCIES, - DialogResponses.YES, - DialogResponses.NO) +export const promptInstallPythonDependencies = ( + context: vscode.ExtensionContext +) => { + return vscode.window + .showInformationMessage( + CONSTANTS.INFO.INSTALL_PYTHON_DEPENDENCIES, + DialogResponses.YES, + DialogResponses.NO + ) .then((selection: vscode.MessageItem | undefined) => { if (selection === DialogResponses.YES) { return installPythonDependencies(context); } else if (selection === DialogResponses.NO) { - return vscode.window.showInformationMessage( - CONSTANTS.INFO.ARE_YOU_SURE, - DialogResponses.INSTALL_NOW, - DialogResponses.DONT_INSTALL - ).then((installChoice: vscode.MessageItem | undefined) => { - if (installChoice === DialogResponses.INSTALL_NOW) { - return installPythonDependencies(context); - } else { - return false; - } - }) + return vscode.window + .showInformationMessage( + CONSTANTS.INFO.ARE_YOU_SURE, + DialogResponses.INSTALL_NOW, + DialogResponses.DONT_INSTALL + ) + .then((installChoice: vscode.MessageItem | undefined) => { + if (installChoice === DialogResponses.INSTALL_NOW) { + return installPythonDependencies(context); + } else { + return false; + } + }); } }); -} +}; +export const getTelemetryState = () => { + return vscode.workspace + .getConfiguration() + .get("telemetry.enableTelemetry", true); +}; -export const installPythonDependencies = async (context: vscode.ExtensionContext) => { +export const installPythonDependencies = async ( + context: vscode.ExtensionContext +) => { let installed: boolean = false; try { - const requirementsPath: string = getPathToScript(context, "out", "requirements.txt"); + const requirementsPath: string = getPathToScript( + context, + "out", + "requirements.txt" + ); const { stdout } = await exec(`pip3 install -r ${requirementsPath}`); installed = true; - vscode.window.showInformationMessage(CONSTANTS.INFO.SUCCESSFUL_INSTALL) + vscode.window.showInformationMessage(CONSTANTS.INFO.SUCCESSFUL_INSTALL); } catch (err) { console.error(err); installed = false; } - return installed -} \ No newline at end of file + return installed; +}; From 957bcd6e623b028027dd44eb9d472f6c30d9ecbe Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Fri, 23 Aug 2019 13:30:20 -0700 Subject: [PATCH 10/16] excalate changed to telemetry class --- src/adafruit_circuitplayground/telemetry.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/adafruit_circuitplayground/telemetry.py b/src/adafruit_circuitplayground/telemetry.py index d5c98e18c..d28fc4d87 100644 --- a/src/adafruit_circuitplayground/telemetry.py +++ b/src/adafruit_circuitplayground/telemetry.py @@ -15,6 +15,7 @@ def __init__(self): "PLAY_TONE": False, "START_TONE": False, "STOP_TONE": False, + "PIXELS": False } self.telemetry_client = TelemetryClient( 'aba8e4b2-8ed2-4c89-b0a1-1595fbf8e833') From d93ffb0b8afc3e673cb3d3ac18ac725aa94eddf2 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Fri, 23 Aug 2019 13:40:17 -0700 Subject: [PATCH 11/16] removed aikey --- src/adafruit_circuitplayground/telemetry.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/adafruit_circuitplayground/telemetry.py b/src/adafruit_circuitplayground/telemetry.py index d28fc4d87..98156469c 100644 --- a/src/adafruit_circuitplayground/telemetry.py +++ b/src/adafruit_circuitplayground/telemetry.py @@ -17,8 +17,7 @@ def __init__(self): "STOP_TONE": False, "PIXELS": False } - self.telemetry_client = TelemetryClient( - 'aba8e4b2-8ed2-4c89-b0a1-1595fbf8e833') + self.telemetry_client = TelemetryClient('__AIKEY__') self.extension_name = '__EXTENSIONNAME__' def send_telemetry(self, event_name): From 70a67839b7d9554693b508f36adf9342791d8136 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Fri, 23 Aug 2019 13:41:53 -0700 Subject: [PATCH 12/16] removed coma --- src/python_constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_constants.py b/src/python_constants.py index d6d6e7b5b..514af379c 100644 --- a/src/python_constants.py +++ b/src/python_constants.py @@ -14,7 +14,7 @@ "motion_x", "motion_y", "motion_z", - "touch", + "touch" ] EXEC_COMMAND = "exec" From f401b8720e5cc7ebe3dd383c39d4cf749a927a2b Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Fri, 23 Aug 2019 13:45:05 -0700 Subject: [PATCH 13/16] removed comment --- src/process_user_code.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/process_user_code.py b/src/process_user_code.py index f1bd4a5d2..6d42a6330 100644 --- a/src/process_user_code.py +++ b/src/process_user_code.py @@ -42,9 +42,6 @@ def run(self): cpx._Express__state[event] = new_state.get( event, cpx._Express__state[event]) - # telemetry_py._Telemetry__enable_telemetry = new_state.get( - # CONSTANTS.ENABLE_TELEMETRY, True) - except Exception as e: print(CONSTANTS.ERROR_SENDING_EVENT, e, file=sys.stderr, flush=True) From b88b250879579492112e1c2cb86259453600e2ef Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Fri, 23 Aug 2019 16:02:48 -0700 Subject: [PATCH 14/16] solved typo issue --- src/process_user_code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/process_user_code.py b/src/process_user_code.py index 6d42a6330..7dbe174c7 100644 --- a/src/process_user_code.py +++ b/src/process_user_code.py @@ -92,7 +92,7 @@ def execute_user_code(abs_path_to_code_file): user_code = threading.Thread(args=(sys.argv[1],), target=execute_user_code) telemetry_state = json.loads(sys.argv[2]) -telemetry_py.Telemetry__enable_telemetry = telemetry_state.get( +telemetry_py._Telemetry__enable_telemetry = telemetry_state.get( CONSTANTS.ENABLE_TELEMETRY, True) threads.append(user_code) user_code.start() From f388cb537a3e7fc5c5069286607f8c44b28bbe78 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Fri, 23 Aug 2019 16:08:28 -0700 Subject: [PATCH 15/16] solved typo issue --- src/process_user_code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/process_user_code.py b/src/process_user_code.py index 6d42a6330..7dbe174c7 100644 --- a/src/process_user_code.py +++ b/src/process_user_code.py @@ -92,7 +92,7 @@ def execute_user_code(abs_path_to_code_file): user_code = threading.Thread(args=(sys.argv[1],), target=execute_user_code) telemetry_state = json.loads(sys.argv[2]) -telemetry_py.Telemetry__enable_telemetry = telemetry_state.get( +telemetry_py._Telemetry__enable_telemetry = telemetry_state.get( CONSTANTS.ENABLE_TELEMETRY, True) threads.append(user_code) user_code.start() From 4747563b1d5164f9cf4c94f85410fd98b675ada5 Mon Sep 17 00:00:00 2001 From: Fatou Mounzeo Date: Fri, 23 Aug 2019 16:37:27 -0700 Subject: [PATCH 16/16] HOPEFULLY THE LAST one --- src/view/components/toolbar/InputSlider.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/view/components/toolbar/InputSlider.tsx b/src/view/components/toolbar/InputSlider.tsx index cee2a278b..56eaba400 100644 --- a/src/view/components/toolbar/InputSlider.tsx +++ b/src/view/components/toolbar/InputSlider.tsx @@ -96,7 +96,6 @@ class InputSlider extends React.Component { private handleOnChange = (event: any) => { const validatedValue = this.validateRange(this.updateValue(event)); - const newSensorState = this.writeMessage(validatedValue); if (newSensorState) { sendMessage(newSensorState); @@ -109,7 +108,7 @@ class InputSlider extends React.Component { value = parseInt(this.state.value, 10); } - return this.props.type && this.state.value + return this.props.type && this.state.value !== undefined ? { [this.props.type]: value } : undefined; };