Skip to content

Commit

Permalink
Merge pull request #13 from renanrms/export-format
Browse files Browse the repository at this point in the history
Export format
  • Loading branch information
renanrms authored Nov 8, 2023
2 parents 35f3736 + 72b68ec commit adc3be6
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ Todas as alterações notáveis neste projeto serão documentadas neste arquivo.
O formato é baseado em [Keep a Changelog](https://keepachangelog.com/pt-BR/1.0.0/),
e este projeto adere ao [Versionamento Semântico](https://semver.org/lang/pt-BR/spec/v2.0.0.html).

## [0.9.2] - 2023-11-08

### Melhorado

- Agora a exportação por padrão é um arquivo `.dat` no formato que o QtiPlot importa por padrão. Alterando a extensão para `.csv` os dados são exportados no formato CSV.

- Os dados são exportados com tempo inicial igual a zero, evitando os valores de tempo referenciados no instante de abertura do programa.

## [0.9.1] - 2023-11-06

### Adicionado
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ftrlab",
"productName": "FTRLab",
"version": "0.9.1",
"version": "0.9.2",
"description": "Sistema de aquisição de dados em tempo real para experimentos didáticos",
"main": "./out/main/index.js",
"author": {
Expand Down
51 changes: 38 additions & 13 deletions src/main/ipc/handlers/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,34 +177,59 @@ export function configureIpcHandlers(devicesController: DevicesController) {
},
order: [['timestamp', 'ASC']],
})
).map((measurementM) => transformToRelativeTime(measurementM.dataValues))

const fileHeader = `t, ${sensor.quantity}`

const fileBody = measurements
.map(
(measurement) =>
`${measurement.timestamp.toFixed(6)}, ${measurement.value}`,
)
.join('\n')

const fileContent = [fileHeader, fileBody].join('\n')
).map((measurementM, index, array) => ({
...measurementM.dataValues,
timestamp:
measurementM.dataValues.timestamp - array[0].dataValues.timestamp,
}))

dialog
.showSaveDialog(getMainWindow(), {
title: 'Exportar medições',
defaultPath: path.join(
app.getPath('documents'),
`${format(new Date(), 'yyyyMMdd_HHmmss')}_${sensor.quantity}.csv`,
`${format(new Date(), 'yyyyMMdd_HHmmss')}_${sensor.quantity}.dat`,
),

filters: [
{ name: 'Arquivos DAT', extensions: ['dat'] },
{ name: 'Arquivos CSV', extensions: ['csv'] },
{ name: 'Todos os Arquivos', extensions: ['*'] },
],
})
.then((result) => {
if (!result.canceled && result.filePath) {
let fileHeader
let fileBody

const extension = result.filePath.split('.').at(-1)

if (extension === 'csv') {
fileHeader = `t, ${sensor.quantity}`

fileBody = measurements
.map(
(measurement) =>
`${measurement.timestamp.toFixed(6)}, ${measurement.value}`,
)
.join('\n')
} else {
fileHeader = `t\t${sensor.quantity}`

fileBody = measurements
.map(
(measurement) =>
`${measurement.timestamp.toFixed(6).replace('.', ',')}\t${(
measurement.value as number
)
.toString()
.replace('.', ',')}`,
)
.join('\n')
}

const fileContent = [fileHeader, fileBody].join('\n')

fs.writeFile(result.filePath, fileContent, (err) => {
if (err) {
console.error('Erro ao salvar o arquivo:', err)
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import { ThemeProvider } from './components/providers/ThemeProvider'
import { Sidebar } from './components/Sidebar'
import { useDevices } from './features/devices/hooks/useDevices'
import { ChartsArea } from './features/measurements/components/ChartsArea'
import { maxDisplayedTimeRange } from './features/measurements/constants/maxDisplayedTimeRange'
import { useMeasurements } from './features/measurements/hooks/useMeasurements'

export function App() {
const [timeRange, setTimeRange] = useState<number>(maxDisplayedTimeRange)
const [timeRange, setTimeRange] = useState<number>(45)
const devices = useDevices()
const { sensorMeasurements, clearMeasurements } = useMeasurements(timeRange)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function ControlCard(props: ControlCardProps) {
<p className="mb-1">Janela de tempo: {formatTime(props.timeRange)}</p>
<Slider
defaultValue={maxDisplayedTimeRange}
step={0.1}
step={0.025}
min={1}
max={Math.log2(24 * 60 * 60)}
valueLabelFormat={(value) => `${value} s`}
Expand Down

0 comments on commit adc3be6

Please sign in to comment.