Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pros/cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def make(project: c.Project, build_args):
@project_option()
@click.pass_context
def make_upload(ctx, project: c.Project, build_args: List[str], **upload_args):
analytics.send("make-upload")
analytics.send("make_upload")
ctx.invoke(make, project=project, build_args=build_args)
ctx.invoke(upload, project=project, **upload_args)

Expand All @@ -46,7 +46,7 @@ def make_upload(ctx, project: c.Project, build_args: List[str], **upload_args):
@project_option()
@click.pass_context
def make_upload_terminal(ctx, project: c.Project, build_args, **upload_args):
analytics.send("make-upload-terminal")
analytics.send("make_upload_terminal")
from .terminal import terminal
ctx.invoke(make, project=project, build_args=build_args)
ctx.invoke(upload, project=project, **upload_args)
Expand All @@ -67,7 +67,7 @@ def build_compile_commands(project: c.Project, suppress_output: bool, compile_co
Build a compile_commands.json compatible with cquery
:return:
"""
analytics.send("build-compile-commands")
analytics.send("build_compile_commands")
exit_code = project.make_scan_build(build_args, cdb_file=compile_commands, suppress_output=suppress_output,
sandbox=sandbox)
if exit_code != 0:
Expand Down
16 changes: 8 additions & 8 deletions pros/cli/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def fetch(query: c.BaseTemplate):

Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more
"""
analytics.send("fetch-template")
analytics.send("fetch_template")
template_file = None
if os.path.exists(query.identifier):
template_file = query.identifier
Expand Down Expand Up @@ -101,7 +101,7 @@ def apply(project: c.Project, query: c.BaseTemplate, **kwargs):

Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more
"""
analytics.send("apply-template")
analytics.send("apply_template")
return c.Conductor().apply_template(project, identifier=query, **kwargs)


Expand All @@ -128,7 +128,7 @@ def install(ctx: click.Context, **kwargs):

Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more
"""
analytics.send("install-template")
analytics.send("install_template")
return ctx.invoke(apply, install_ok=True, **kwargs)


Expand All @@ -155,7 +155,7 @@ def upgrade(ctx: click.Context, project: c.Project, query: c.BaseTemplate, **kwa

Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more
"""
analytics.send("upgrade-project")
analytics.send("upgrade_project")
if not query.name:
for template in project.templates.keys():
click.secho(f'Upgrading {template}', color='yellow')
Expand All @@ -181,7 +181,7 @@ def uninstall_template(project: c.Project, query: c.BaseTemplate, remove_user: b

Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more
"""
analytics.send("uninstall-template")
analytics.send("uninstall_template")
c.Conductor().remove_template(project, query, remove_user=remove_user,
remove_empty_directories=remove_empty_directories)
if no_make_clean:
Expand Down Expand Up @@ -217,7 +217,7 @@ def new_project(ctx: click.Context, path: str, target: str, version: str,

Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more
"""
analytics.send("new-project")
analytics.send("new_project")
if version.lower() == 'latest' or not version:
version = '>0'
if not force_system and c.Project.find_project(path) is not None:
Expand Down Expand Up @@ -267,7 +267,7 @@ def query_templates(ctx, query: c.BaseTemplate, allow_offline: bool, allow_onlin

Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more
"""
analytics.send("query-templates")
analytics.send("query_templates")
if limit < 0:
limit = 15
templates = c.Conductor().resolve_templates(query, allow_offline=allow_offline, allow_online=allow_online,
Expand Down Expand Up @@ -310,7 +310,7 @@ def info_project(project: c.Project, ls_upgrades):

Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more
"""
analytics.send("info-project")
analytics.send("info_project")
from pros.conductor.project import ProjectReport
report = ProjectReport(project)
_conductor = c.Conductor()
Expand Down
4 changes: 2 additions & 2 deletions pros/cli/conductor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def create_template(ctx, path: str, destination: str, do_zip: bool, **kwargs):

pros conduct create-template . libblrs 2.0.1 --system "firmware/*.a" --system "include/*.h"
"""
analytics.send("create-template")
analytics.send("create_template")
project = c.Project.find_project(path, recurse_times=1)
if project:
project = c.Project(project)
Expand Down Expand Up @@ -152,7 +152,7 @@ def filename_remap(file_path: str) -> str:
@template_query(required=False)
@default_options
def purge_template(query: c.BaseTemplate, force):
analytics.send("purge-template")
analytics.send("purge_template")
if not query:
force = click.confirm('Are you sure you want to remove all cached templates? This action is non-reversable!',
abort=True)
Expand Down
4 changes: 2 additions & 2 deletions pros/cli/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def ls_usb(target):
"""
List plugged in VEX Devices
"""
analytics.send("ls-usb")
analytics.send("ls_usb")
from pros.serial.devices.vex import find_v5_ports, find_cortex_ports

class PortReport(object):
Expand Down Expand Up @@ -202,7 +202,7 @@ def __str__(self):
@shadow_command(upload)
@click.pass_context
def make_upload_terminal(ctx, **upload_kwargs):
analytics.send("upload-terminal")
analytics.send("upload_terminal")
from .terminal import terminal
ctx.invoke(upload, **upload_kwargs)
ctx.invoke(terminal, request_banner=False)
2 changes: 1 addition & 1 deletion pros/cli/user_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def user_script(script_file):
"""
Run a script file with the PROS CLI package
"""
analytics.send("user-script")
analytics.send("user_script")
import os.path
import importlib.util
package_name = os.path.splitext(os.path.split(script_file)[0])[0]
Expand Down
16 changes: 10 additions & 6 deletions pros/cli/v5_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def ls_files(port: str, vid: int, options: int):
"""
List files on the flash filesystem
"""
analytics.send("ls-files")
analytics.send("ls_files")
from pros.serial.devices.vex import V5Device
from pros.serial.ports import DirectPort
port = resolve_v5_port(port, 'system')[0]
Expand All @@ -72,7 +72,7 @@ def read_file(file_name: str, port: str, vid: int, source: str):
"""
Read file on the flash filesystem to stdout
"""
analytics.send("read-file")
analytics.send("read_file")
from pros.serial.devices.vex import V5Device
from pros.serial.ports import DirectPort
port = resolve_v5_port(port, 'system')[0]
Expand All @@ -98,7 +98,7 @@ def write_file(file, port: str, remote_file: str, **kwargs):
"""
Write a file to the V5.
"""
analytics.send("write-file")
analytics.send("write_file")
from pros.serial.ports import DirectPort
from pros.serial.devices.vex import V5Device
port = resolve_v5_port(port, 'system')[0]
Expand All @@ -121,7 +121,7 @@ def rm_file(file_name: str, port: str, vid: int, erase_all: bool):
"""
Remove a file from the flash filesystem
"""
analytics.send("rm-file")
analytics.send("rm_file")
from pros.serial.devices.vex import V5Device
from pros.serial.ports import DirectPort
port = resolve_v5_port(port, 'system')[0]
Expand All @@ -142,7 +142,7 @@ def cat_metadata(file_name: str, port: str, vid: int):
"""
Print metadata for a file
"""
analytics.send("cat-metadata")
analytics.send("cat_metadata")
from pros.serial.devices.vex import V5Device
from pros.serial.ports import DirectPort
port = resolve_v5_port(port, 'system')[0]
Expand Down Expand Up @@ -182,7 +182,7 @@ def rm_all(port: str, vid: int):
"""
Remove all user programs from the V5
"""
analytics.send("rm-all")
analytics.send("rm_all")
from pros.serial.devices.vex import V5Device
from pros.serial.ports import DirectPort
port = resolve_v5_port(port, 'system')[0]
Expand Down Expand Up @@ -232,6 +232,7 @@ def stop(port: str):

If FILE is unspecified or is a directory, then attempts to find the correct filename based on the PROS project
"""
analytics.send("stop")
from pros.serial.devices.vex import V5Device
from pros.serial.ports import DirectPort
port = resolve_v5_port(port, 'system')[0]
Expand All @@ -251,6 +252,7 @@ def capture(file_name: str, port: str, force: bool = False):
"""
Take a screen capture of the display
"""
analytics.send("capture_screen")
from pros.serial.devices.vex import V5Device
from pros.serial.ports import DirectPort
import png
Expand Down Expand Up @@ -297,6 +299,7 @@ def capture(file_name: str, port: str, force: bool = False):
@click.argument('port', type=str, default=None, required=False)
@default_options
def set_variable(variable, value, port):
analytics.send("set_variable")
import pros.serial.devices.vex as vex
from pros.serial.ports import DirectPort

Expand All @@ -313,6 +316,7 @@ def set_variable(variable, value, port):
@click.argument('port', type=str, default=None, required=False)
@default_options
def read_variable(variable, port):
analytics.send("read_variable")
import pros.serial.devices.vex as vex
from pros.serial.ports import DirectPort

Expand Down
58 changes: 34 additions & 24 deletions pros/ga/analytics.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import json
from os import path
import uuid
import requests
import time
from requests_futures.sessions import FuturesSession
import random
from concurrent.futures import as_completed

url = 'https://www.google-analytics.com/collect'
agent = 'pros-cli'

"""
Expand All @@ -18,48 +16,61 @@ def __init__(self):
from pros.config.cli_config import cli_config as get_cli_config
self.cli_config = get_cli_config()
#If GA hasn't been setup yet (first time install/update)
if not self.cli_config.ga:
if not self.cli_config.ga or not self.cli_config.ga.get("api_secret", None) or not self.cli_config.ga.get("unix_timestamp", None):
#Default values for GA
print("helooooo2222222")
# generate a unix timestamp
self.cli_config.ga = {
"enabled": "True",
"ga_id": "UA-84548828-8",
"ga_id": "G-PXK9EBVY1Y",
"api_secret": "VkPGaoemRfygVAXiabM-jg",
"unix_timestamp": int(time.time()),
"u_id": str(uuid.uuid4())
}
self.cli_config.save()
self.sent = False
#Variables that the class will use
self.gaID = self.cli_config.ga['ga_id']
self.apiSecret = self.cli_config.ga['api_secret']
self.user_timestamp = self.cli_config.ga['unix_timestamp']
self.useAnalytics = self.cli_config.ga['enabled']
self.uID = self.cli_config.ga['u_id']
print(f'Analytics config: enabled={self.useAnalytics} | ga_id={self.gaID} | api_secret={self.apiSecret} | u_id={self.uID}')
self.pendingRequests = []

def send(self,action):
def send(self, action, kwargs = {}):
if not self.useAnalytics or self.sent:
#print("not sending")
return
#print("sending")
self.sent=True # Prevent Send from being called multiple times
try:
#Payload to be sent to GA, idk what some of them are but it works
kwargs["engagement_time_msec"] = 1

url = f'https://www.google-analytics.com/mp/collect?measurement_id=G-PXK9EBVY1Y&api_secret={self.apiSecret}'
payload = {
'v': 1,
'tid': self.gaID,
'aip': 1,
'z': random.random(),
'cid': self.uID,
't': 'event',
'ec': 'action',
'ea': action,
'el': 'CLI',
'ev': '1',
'ni': 0
"client_id": f'CLI.{self.user_timestamp}',
"user_id": self.uID,
"non_personalized_ads": True,
"events": [
{
"name": action,
"params": kwargs
}
]
}
#print(payload)
#print(url)

#r = requests.post(url,data=json.dumps(payload),verify=True)
#print(r.status_code)
session = FuturesSession()

#Send payload to GA servers
future = session.post(url=url,
data=payload,
headers={'User-Agent': agent},
timeout=5.0)
data=str(payload).replace("False","false").replace("True","true"),
timeout=5.0,
verify = True)
self.pendingRequests.append(future)

except Exception as e:
Expand All @@ -77,11 +88,10 @@ def process_requests(self):
for future in as_completed(self.pendingRequests):
try:
response = future.result()

if not response.status_code==200:
if not response.status_code==204:
print("Something went wrong while sending analytics!")
print(response)

print(vars(response))
responses.append(response)

except Exception:
Expand Down