Skip to content

Commit 6561b8f

Browse files
committed
compatibility-with-computer
1 parent ea23e72 commit 6561b8f

File tree

3 files changed

+154
-10
lines changed

3 files changed

+154
-10
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"type": "service_account",
3+
"project_id": "angelic-bee-411621",
4+
"private_key_id": "dd685fb9db8522658c4c0f07982a9439d5319115",
5+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCVsA1O+bllO6m7\nVWwYTVglXu0hIK27ihxhpsvgIV4eYeVkZj+YaDxeLDTR3mFCLCKDJ8Qjv3S2s1jz\nD/JvHT7nqWUF87VxXX4fgU10uMDIeeSM7KjhIeNPoIvFJm4kYN5PmufGtUK5+tSw\nSys8uDhjpb6cG+CVUeNwUnEFhJbAEgyProjZsW/snO+Y1o3OdN1G0CutPzmTpn+b\nLZ0/Mf/QXFcWZlfU0L9OwnJ8xiIO2aHFWS5S4vO98hzvSxsDh1vhMx4fVwyuld5P\n3NEJV8p/XmraCJFbrGVUZiaYhGv8VHhTYvlPZq3mhR+udBAoIDTzgHU+QjFL4ixa\njzmc3N3VAgMBAAECggEACZSPfX8BLSgA6IMCnJmSqy2kqqqfQ/IGd/+Ha+xmzDYC\nywa6SkRdnL9ikA4WFnihqthINuuBilH3PvNF1nO+O3B9jUB4W+2abWTGstJCUHJw\nvM5GzsXu+QEzAObBROXIRLsK245tW17g7vmYplW6EjKg/PfRy2zGzEESh8JhLaDA\n/pSUOFktaJp3GPAdvLx4Wa0kPRb4Y7+/ARiWH5KQGduEGiFl3gK1wHZhdKO6rPlE\njiwGlKKsHMowSZYltiebLv9e9+W/ACbToLWctXXASNzfYeke7Chp+JbbG5sjcHri\nPIxC2t30B1h9AlQh4O919LNKDxDoQjowCuZHicb9QQKBgQDQdGQWKQ61CJ7oZ3dZ\nBwgBJy3PDoFPnuE71Rcvzrs79CI4Dm1N02gXMvtkCC6Q4X2krGuJagWwK7OeIKDW\nqj5Y1gk/CICk0R8xVmR0Cvt1chlIGZtngs9kNyd78mSR6fdmWKQa9kH+gmeDXZ/0\nHv/T0eCGD82K9ogDsMGkDPjKoQKBgQC31EZ2atn6pve6wXyVIKRNa82T7odh/kiH\nnu4KjqneeacYzAIxrp0g4YOe6uwjfWBKJ4KT/mx93AOIjj/eluiPaV0UYnGGikGu\nvgKTbhUvJNGlzR718+FMnGqJa04FH29tgGgOV6ETSGAdOiV7wrxLBx8ru/3cbipD\nNP+DMBlatQKBgQCQvrEc3ieTN0g4clfiHsrFGjJp21WZNuaJCF9QWAmVCOGV8Rae\n+tQFf+YlwLSs75ax+PO2+EK44K+ZdmiYhqBCSWUkOsAxMfCp7qZUGaggFjlN4lIR\nnzhpCw9Etrx0wXSDwbs56ZNLqbs88Y73EWts5wgzrtd3zdYGUf8z7bn34QKBgDik\nBmX8PFe31ILNlTZZzWYxfjFDgKFX+T8YYB4OoRZ0g2DnkxF9zNpRwf1YQxQYUG/o\nxpoU/Za2ELyln9ZUxylQ/KYIQxSCSwStdRu6Anr5LEOa9RwxXcz+MPFQh8SaT/n8\nY5Nvuqi3Vy4KOXxtnxi7BAa0sN6XbxwwGz5vtpA1AoGATooJ3hY9ECgaq6yuK/YF\nl4R7hiTV6Yr7qx1DMbqBv2SpXy3pL4Onh1y2+rpvgH1B5LDLZ25euHRG3GHSuScE\nGcVN7PJ/7p1S/jUZ/Fx9ypKaG++yfU3KvRxW7trbE/8AS9CP5Uph/8UYQ016ilX4\nV/uSgS5MbZCWouIashyFIsc=\n-----END PRIVATE KEY-----\n",
6+
"client_email": "[email protected]",
7+
"client_id": "107655704552755133565",
8+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
9+
"token_uri": "https://oauth2.googleapis.com/token",
10+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/abr-432%40angelic-bee-411621.iam.gserviceaccount.com",
12+
"universe_domain": "googleapis.com"
13+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import gspread
2+
import socket
3+
import httplib2
4+
from oauth2client.service_account import ServiceAccountCredentials
5+
from typing import (Any, Dict, Iterator, List,
6+
Optional, Sequence, Set, Tuple, Union)
7+
import pprint
8+
9+
"""This module requires a creditials.json file before getting started.
10+
The following link provides a step by step tutorial on how to get startd.
11+
https://towardsdatascience.com/accessing-google-spreadsheet-data-using-python-90a5bc214fd2"""
12+
13+
class google_sheet:
14+
"""
15+
This module was designed for the testing team to automate tests by
16+
ultizing google sheets API to record data. The following attributes that this
17+
class needs is the file_name and the tab_number define.
18+
"""
19+
def __init__(self, creditals, file_name, tab_number):
20+
self.scope = ['https://spreadsheets.google.com/feeds',
21+
'https://www.googleapis.com/auth/drive']
22+
self.creditals = \
23+
ServiceAccountCredentials.from_json_keyfile_name(creditals, self.scope)
24+
self.gc = gspread.authorize(self.creditals)
25+
self.file_name = file_name
26+
self.tab_number = tab_number
27+
self.spread_sheet = self.open_google_sheet()
28+
self.worksheet = self.open_worksheet(self.tab_number)
29+
self.row_index = 1
30+
31+
def open_google_sheet(self):
32+
"""Open Google Spread Sheet"""
33+
sheet = self.gc.open(self.file_name)
34+
return sheet
35+
36+
def open_worksheet(self, tab_number: int )-> classmethod:
37+
"""Open individual worksheet within a googlesheet"""
38+
return self.spread_sheet.get_worksheet(tab_number)
39+
40+
def create_worksheet(self, tab_name: int):
41+
"""Create a worksheet with a title for a tab. This method need
42+
to have an existing spreadsheet for it to work."""
43+
try:
44+
self.spread_sheet.add_worksheet(tab_name, rows="1000", cols="26")
45+
except gspread.exceptions.APIError:
46+
print('Work Sheet already exists')
47+
48+
def write_header(self, header: List):
49+
"""Write Header to first row, this method as determines if the first row
50+
has a header that identical to the header the user is writing too."""
51+
header_list = self.worksheet.row_values(1)
52+
print(header_list)
53+
if header_list != header:
54+
self.worksheet.insert_row(header, self.row_index)
55+
56+
def write_to_row(self, data: List):
57+
"""Write data into a row in a List[] format, this method skips the first
58+
row of the worksheet due to headers. """
59+
try:
60+
self.row_index += 1
61+
self.worksheet.insert_row(data, index= self.row_index)
62+
except socket.gaierror:
63+
pass
64+
except httplib2.ServerNotFoundError:
65+
print('UNABLE TO CONNECT TO SERVER!!, CHECK CONNECTION')
66+
except Exception as error:
67+
print(error.traceback)
68+
69+
def delete_row(row_index: int):
70+
"""Delete Row from google sheet"""
71+
self.worksheet.delete_row(row_index)
72+
73+
def update_cell(self, row: int, column: int, single_data: any):
74+
"""Update an individual cell according to a row and column. Note that
75+
this function only updates one individual cell"""
76+
self.worksheet.update_cell(row, column, data)
77+
78+
def update_cells(self, cells, data):
79+
cell_list = self.worksheet.range(cells)
80+
self.worksheet.update_cells(data)
81+
82+
def get_all_data(self)-> Dict[str, any]:
83+
"""Get all the Data recorded from worksheet."""
84+
return self.worksheet.get_all_records()
85+
86+
def get_column(self, column_number: int)-> int:
87+
return self.worksheet.col_values(column_number)
88+
89+
def get_index_row(self):
90+
"""Check for the next available row to write too."""
91+
row_index = len(self.get_column(1))
92+
print("Row Index: ", row_index)
93+
return row_index
94+
95+
def update_row_index(self):
96+
"""Update self.row_index instance variable"""
97+
self.row_index = self.get_index_row()
98+
99+
100+
def get_all_sheets(self):
101+
"""List all tabs in the spreadsheets"""
102+
worksheets = self.spread_sheet.worksheets()
103+
return worksheets
104+
105+
def get_sheet_by_name(self, title: str):
106+
#worksheet = sh.worksheet("January")
107+
try:
108+
worksheet = self.spread_sheet.worksheet(title)
109+
return worksheet
110+
except gspread.exceptions.WorksheetNotFound:
111+
raise 'Worksheet does not exist!!, create a \
112+
worksheet first using the create_worksheet() function.'
113+
114+
def token_check():
115+
if self.creditals.access_token_expired:
116+
self.gc.login()

hardware-testing/hardware_testing/scripts/abr_asair_sensor.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@
66
import sys
77
import time as t
88
from typing import List
9+
import os
10+
911

1012

11-
try:
12-
sys.path.insert(0, "/var/lib/jupyter/notebooks")
13-
import google_sheets_tool # type: ignore[import]
14-
except ImportError:
15-
raise ImportError(
16-
"Run on robot. Make sure google_sheets_tool.py is in jupyter notebook."
17-
)
1813

1914

2015
def _get_user_input(lst: List[str], some_string: str) -> str:
@@ -29,10 +24,28 @@ def _get_user_input(lst: List[str], some_string: str) -> str:
2924

3025
class _ABRAsairSensor:
3126
def __init__(self, robot: str, duration: int, frequency: int) -> None:
27+
var = _get_user_input(["C", "R"], "Running on computer (C) or robot (R)? ")
28+
if var == "R":
29+
try:
30+
sys.path.insert(0, "/var/lib/jupyter/notebooks")
31+
import google_sheets_tool # type: ignore[import]
32+
credentials_path = "/var/lib/jupyter/notebooks/abr.json"
33+
except ImportError:
34+
from hardware_testing import google_sheets_tool
35+
raise ImportError(
36+
"Run on robot. Make sure google_sheets_tool.py is in jupyter notebook."
37+
)
38+
else:
39+
from hardware_testing import google_sheets_tool
40+
#credentials_path = "/hardware-testing/hardware_testing/abr.json"
41+
credentials_path = "C:/Users/Rhyann Clarke/opentrons/hardware-testing/hardware_testing/abr.json"
42+
43+
print(os.path.exists(credentials_path))
3244
test_name = "ABR-Environment-Monitoring"
3345
run_id = data.create_run_id()
3446
file_name = data.create_file_name(test_name, run_id, robot)
35-
sensor = asair_sensor.BuildAsairSensor(False, True)
47+
sensor = asair_sensor.BuildAsairSensor(False, False)
48+
print(sensor)
3649
env_data = sensor.get_reading()
3750
header = [
3851
"Robot",
@@ -45,7 +58,7 @@ def __init__(self, robot: str, duration: int, frequency: int) -> None:
4558
header_str = ",".join(header) + "\n"
4659
data.append_data_to_file(test_name, run_id, file_name, header_str)
4760
# Upload to google has passed
48-
credentials_path = "/var/lib/jupyter/notebooks/abr.json"
61+
4962
try:
5063
google_sheet = google_sheets_tool.google_sheet(
5164
credentials_path, "ABR Ambient Conditions", tab_number=0
@@ -119,8 +132,10 @@ def __init__(self, robot: str, duration: int, frequency: int) -> None:
119132
"PVT1ABR10",
120133
"PVT1ABR11",
121134
"PVT1ABR12",
135+
"ROOM_339",
136+
"Room_340",
122137
] # type: List
123-
robot = _get_user_input(robot_list, "Robot: ")
138+
robot = _get_user_input(robot_list, "Robot/Room: ")
124139
duration = int(input("Duration (min): "))
125140
frequency = int(input("Frequency (min): "))
126141
_ABRAsairSensor(robot, duration, frequency)

0 commit comments

Comments
 (0)