Skip to content

Commit

Permalink
remove duplicates from lpc data, added graphing function in google_sh…
Browse files Browse the repository at this point in the history
…eets_tool
  • Loading branch information
rclarke0 committed May 16, 2024
1 parent 07c6b45 commit 98bba8c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 62 deletions.
84 changes: 56 additions & 28 deletions abr-testing/abr_testing/automation/google_sheets_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,33 @@ def delete_row(self, row_index: int) -> None:
"""Delete Row from google sheet."""
self.worksheet.delete_rows(row_index)

def batch_delete_rows(self, row_indices: List[int]) -> None:
"""Batch delete rows in list of indices."""
delete_body = {
"requests": [
{
"deleteDimension": {
"range": {
"sheetId": 0,
"dimension": "ROWS",
"startIndex": index,
"endIndex": index + 1,
}
}
}
for index in row_indices
]
}
self.spread_sheet.batch_update(body=delete_body)

def update_cell(
self, row: int, column: int, single_data: Any
) -> Tuple[int, int, Any]:
"""Update ONE individual cell according to a row and column."""
self.worksheet.update_cell(row, column, single_data)
return row, column, single_data

def get_all_data(self) -> Dict[str, Any]:
def get_all_data(self) -> List[Dict[str, Any]]:
"""Get all the Data recorded from worksheet."""
return self.worksheet.get_all_records()

Expand Down Expand Up @@ -141,36 +160,45 @@ def get_row_index_with_value(self, some_string: str, col_num: int) -> Any:
print("Row not found.")
return None
return row_index

def create__line_chart(self, titles: List[str], series: List[Dict[str, Any]], spreadsheet_id: str):

def create_line_chart(
self,
titles: List[str],
series: List[Dict[str, Any]],
domains: List[Dict[str, Any]],
) -> None:
"""Create chart of data on google sheet."""
chart_data = {
request_body = {
"requests": [
{
"addChart": {
"chart": {
"spec": {
"title": titles[0],
"basicChart": {
"chartType": "LINE",
"legendPosition": "BOTTOM_LEGEND",
"axis": [
{
"position": "BOTTOM_AXIS",
"title": titles[1]
"spec": {
"title": titles[0],
"basicChart": {
"chartType": "LINE",
"legendPosition": "RIGHT_LEGEND",
"axis": [
{"position": "BOTTOM_AXIS", "title": titles[1]},
{"position": "LEFT_AXIS", "title": titles[2]},
],
"domains": domains,
"series": series,
"headerCount": 1,
},
{
"position": "LEFT_AXIS",
"title": titles[2]
},
"position": {
"overlayPosition": {
"anchorCell": {
"sheetId": 0,
"rowIndex": 1,
"columnIndex": 1,
}
}
],
"ranges": [
series
],
"headerCount": 1
}
},
"position": {
"newSheet": True
}
},
}
}
body = {"requests": [{"addChart": {"chart": chart_data}}]}
self.batchUpdate(spreadsheet_id, body = body).execute()
}
]
}
self.spread_sheet.batch_update(body=request_body)
59 changes: 25 additions & 34 deletions abr-testing/abr_testing/data_collection/abr_lpc.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
"""Get Unique LPC Values from Run logs."""
import os
import argparse
from typing import Any, Dict, List
from abr_testing.automation import google_sheets_tool
import sys

# TODO: Remove duplicate rows
def identify_duplicate_data(all_data):

def remove_duplicate_data() -> None:
"""Determine unique sets of data."""
seen = set()
new_values = []
for row in all_data:
key = (row["Robot"], row["Errors"], row["Slot"], row["Module"], row["Adapter"], row["X"], row["Y"], row["Z"])
row_indices = []
sheet_data = google_sheet_lpc.get_all_data()
for i, row in enumerate(sheet_data):
key = (
row["Robot"],
row["Software Version"],
row["Errors"],
row["Slot"],
row["Module"],
row["Adapter"],
row["X"],
row["Y"],
row["Z"],
)

if key not in seen:
seen.add(key)
new_values.append(row)
return new_values

def update_sheet_with_new_values(new_values):
"""Update sheet with unique data sets only."""
google_sheet_lpc.clear()
headers = list(new_values[0].keys())
data = [headers] + [[row[col] for col in headers] for row in new_values]
google_sheet_lpc.update(data)
else:
row_indices.append(i)
if len(row_indices) > 0:
google_sheet_lpc.batch_delete_rows(row_indices)


if __name__ == "__main__":
Expand All @@ -42,24 +50,7 @@ def update_sheet_with_new_values(new_values):
print(f"Add credentials.json file to: {storage_directory}.")
sys.exit()
google_sheet_lpc = google_sheets_tool.google_sheet(credentials_path, "ABR-LPC", 0)
sheet_data = google_sheet_lpc.get_all_data()
print(len(sheet_data))
new_values = identify_duplicate_data(sheet_data)
print(len(new_values))
update_sheet_with_new_values(new_values)

num_of_rows = len(google_sheet_lpc.get_all_data())
# Create graph
graph_title = "ABR LPC"
x_axis_title = "X Offset (mm)"
y_axis_title = "Y Offset (mm)"
titles = [graph_title, x_axis_title, y_axis_title]
series = [
{"sheetId": 0,
"startRowIndex": 0,
"endRowIndex": num_of_rows,
"startColumnIndex": 29,
"endColumnIndex": 30}
]
spreadsheet_id = "1m9c3Ql2Uez4MC_aLayeUX6YO7WMkNA-4B5xk_w8zJc4"
google_sheet_lpc.create_line_chart(titles, series, spreadsheet_id)
print(len(google_sheet_lpc.get_all_data()))
remove_duplicate_data()
num_of_rows = print(len(google_sheet_lpc.get_all_data()))
# TODO: automate data analysis

0 comments on commit 98bba8c

Please sign in to comment.