Skip to content

Commit

Permalink
Various feature additions
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Jan 2, 2022
1 parent bd06316 commit 1956cac
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 102 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
Fixed error when downloading a single log file.
* You can now export the opened log as a CSV file!
* A progress bar is now shown when downloading logs over SFTP.
* The field count shown in the side bar no longer includes individual array items.
* The name of ".rlog" files registered with the OS is now "Robot Logs" instead of "Robot logs" (to better match other formats).
27 changes: 20 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,9 @@ function setupMenu() {
label: "Export as CSV...",
accelerator: "CmdOrCtrl+E",
click() {
dialog.showMessageBox({
type: "info",
title: "Coming soon...",
message: "Coming soon...",
detail: "This feature is not available yet.",
icon: iconPath
})
var window = BrowserWindow.getFocusedWindow()
if (!window.webContents.getURL().endsWith("index.html")) return
window.webContents.send("export-csv")
}
},
{ type: "separator" },
Expand Down Expand Up @@ -821,4 +817,21 @@ ipcMain.on("update-odometry-popup", (_, id, command) => {
}
})
}
})

ipcMain.on("export-csv-dialog", (_, path) => {
var csvPath = path.substring(0, path.length - 4) + "csv"
var result = dialog.showSaveDialog(BrowserWindow.getFocusedWindow(), {
title: "Select export location for robot log",
defaultPath: csvPath,
properties: ["createDirectory", "showOverwriteConfirmation", "dontAddToRecent"],
filters: [
{ name: "Comma-separated values", extensions: ["csv"] }
]
})
result.then(response => {
if (!response.canceled) {
BrowserWindow.getFocusedWindow().send("export-csv-dialog-response", response.filePath)
}
})
})
100 changes: 33 additions & 67 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "advantage-scope",
"productName": "Advantage Scope",
"version": "1.9.8",
"version": "1.10.0",
"description": "Logging tool from FRC Team 6328.",
"main": "main.js",
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions preload/downloadPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,18 @@ ipcRenderer.on("download-save", (_, files, savePath) => {
if (error) {
sendError(error.message)
} else {
window.dispatchEvent(new CustomEvent("status-progress", { detail: null }))
if (files.length == 1) { // Single file
sftp.fastGet(fullRioPath + files[0], savePath, error => {
if (error) {
sendError(error.message)
} else {
window.dispatchEvent(new CustomEvent("status-progress", { detail: 1.0 }))
ipcRenderer.send("prompt-download-auto-open", savePath)
}
})

} else { // Multiple files
if (files.length > 10) {
window.dispatchEvent(new CustomEvent("status-alert", {
detail: "Downloading " + files.length.toString() + " logs..."
}))
}

var completeCount = 0
var skipCount = 0
files.forEach(file => {
Expand All @@ -128,6 +124,10 @@ ipcRenderer.on("download-save", (_, files, savePath) => {
sendError(error.message)
} else {
completeCount++
var progress = (completeCount - skipCount) / (files.length - skipCount)
window.dispatchEvent(new CustomEvent("status-progress", { detail: progress }))
console.log(progress)

if (completeCount >= files.length) {
if (skipCount > 0) {
var newCount = completeCount - skipCount
Expand Down
25 changes: 25 additions & 0 deletions preload/indexPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,29 @@ window.addEventListener("stop-live-socket", () => {
client.destroy()
client = null
}
})

// Manage exporting as CSV
ipcRenderer.on("export-csv", () => {
window.dispatchEvent(new Event("export-csv"))
})

window.addEventListener("export-csv-dialog", event => {
ipcRenderer.send("export-csv-dialog", event.detail)
})

ipcRenderer.on("export-csv-dialog-response", (_, path) => {
window.dispatchEvent(new CustomEvent("export-csv-dialog-response", {
detail: path
}))
})

window.addEventListener("save-csv-data", event => {
fs.writeFile(event.detail.path, event.detail.data, err => {
if (err)
throw err
else {
window.dispatchEvent(new Event("save-csv-data-response"))
}
})
})
46 changes: 46 additions & 0 deletions www/csvWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Log } from "./modules/log.mjs"

// Encodes the data from a Log to an array savable as a CSV.
onmessage = function (event) {
var log = new Log()
log.rawData = event.data

// Get list of fields
var fields = []
var processTree = data => {
Object.keys(data).sort().forEach(key => {
if (data[key].field != null) {
fields.push(data[key].field)
}
if (Object.keys(data[key].children).length > 0) {
processTree(data[key].children)
}
})
}
processTree(log.getFieldTree(false))

// Record timestamps
var data = [["Timestamp"]]
log.getTimestamps().forEach(timestamp => {
data.push([[timestamp]])
})

// Retrieve data
fields.forEach(id => {
data[0].push(log.getFieldInfo(id).displayKey)
var fieldData = log.getDataInRange(id, -Infinity, Infinity)
log.getTimestamps().forEach((_, index) => {
var nextIndex = fieldData.timestampIndexes.findIndex(value => value > index)
if (nextIndex == -1) nextIndex = fieldData.timestampIndexes.length
if (nextIndex == 0) {
var value = null
} else {
var value = fieldData.values[nextIndex - 1]
}
data[index + 1].push(JSON.stringify(value).replaceAll(",", "_"))
})
})

// Convert to string
this.postMessage(data.map(x => x.join(",")).join("\n"))
}
Loading

0 comments on commit 1956cac

Please sign in to comment.