Skip to content

Commit

Permalink
Add support for Deco and Events
Browse files Browse the repository at this point in the history
  • Loading branch information
blackshadev committed Aug 19, 2023
1 parent a29370f commit 1ec2a55
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dive-downloader",
"description": "Download dives from any divecomputer with an electron app",
"productName": "dive-downloader",
"version": "0.1.6",
"version": "0.2.0",
"main": ".webpack/main",
"scripts": {
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
Expand Down
4 changes: 2 additions & 2 deletions src/redux/dive/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export interface ISample {
Heartbeat?: number;
Gasmix?: number;
Pressure?: { Pressure: number; Tank: number }[];
Deco?: { depth: number; time: number; type: number };
Events?: { type: SampleEventType; flags: number; value: number }[];
Deco?: { Depth: number; Time: number; Type: number };
Events?: { Type: SampleEventType; Flags: number; Value: number }[];
}

export interface Dive {
Expand Down
7 changes: 4 additions & 3 deletions src/redux/divecomputer/descriptor/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { createSelector } from 'reselect';
import { compareDescriptor, descriptorId } from './helpers';
import { DescriptorState } from './types';

export const allDescriptorsSelector = (state: {
descriptors: DescriptorState;
}) => state.descriptors.all.slice().sort(compareDescriptor);
export const allDescriptorsSelector = createSelector(
(state: { descriptors: DescriptorState }) => state.descriptors.all,
(descriptors) => descriptors.slice().sort(compareDescriptor)
);

export const selectedDescriptorSelector = (state: {
descriptors: DescriptorState;
Expand Down
22 changes: 19 additions & 3 deletions src/services/parsing/diveSampleParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Sample, SampleType } from 'libdivecomputerjs';
import { Sample, SampleEventType, SampleType } from 'libdivecomputerjs';
import { ISample } from '../../redux/dive';

interface ISampleAggregates {
Expand Down Expand Up @@ -117,11 +117,18 @@ export default class DiveSampleParser {
this.addNumerical(sample.type, sample.value);
break;
case SampleType.Deco:
this.workingSample.Deco = sample.value;
this.workingSample.Deco = {
Depth: sample.value.depth,
Time: sample.value.time,
Type: sample.value.type
};
break;
case SampleType.Pressure:
this.addPressure(sample.value);
break;
case SampleType.Event:
this.addEvent(sample.value.type, sample.value.value, sample.value.flags);
break;
default:
}
}
Expand Down Expand Up @@ -177,11 +184,20 @@ export default class DiveSampleParser {
this.aggregates.tanks[pressureValue.tank] = tankValue;
}

private addNumerical(sampleType: NumericalSamplesTypes, value: number) {
private addNumerical(sampleType: NumericalSamplesTypes, value: number): void {
const fieldName = DiveSampleParser.SampleTypeToFieldName(sampleType);
this.workingSample[fieldName] = value;
}

private addEvent(type: SampleEventType, value: number, flags: number): void {
this.workingSample.Events = this.workingSample.Events ?? [];
this.workingSample.Events.push({
Type: type,
Value: value,
Flags: flags
})
}

public finalize(): void {
this.samples.push(this.workingSample);
this.isFinalized = true;
Expand Down

0 comments on commit 1ec2a55

Please sign in to comment.