Avoid instanceof RangeIntensity checks
This commit is contained in:
parent
98f10971b3
commit
919996dd09
|
|
@ -1,7 +1,6 @@
|
|||
import { eqProps, flatten, zip } from "ramda";
|
||||
import { Interval, Comment } from "./ast";
|
||||
import { Duration } from "./Duration";
|
||||
import { RangeIntensity } from "./Intensity";
|
||||
|
||||
export type RepeatedInterval = {
|
||||
type: "repeat";
|
||||
|
|
@ -70,7 +69,7 @@ const extractRepeatedInterval = (intervals: Interval[], i: number): RepeatedInte
|
|||
};
|
||||
};
|
||||
|
||||
const isRangeInterval = (interval: Interval): boolean => interval.intensity instanceof RangeIntensity;
|
||||
const isRangeInterval = ({ intensity }: Interval): boolean => intensity.start !== intensity.end;
|
||||
|
||||
export const detectRepeats = (intervals: Interval[]): (Interval | RepeatedInterval)[] => {
|
||||
if (intervals.length < windowSize) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { Interval } from "../ast";
|
||||
import { Duration } from "../Duration";
|
||||
import { RangeIntensity } from "../Intensity";
|
||||
import { intensityValueToZoneType, ZoneType } from "../ZoneType";
|
||||
import { intervalsToIntensityNumbers } from "./intervalsToIntensityNumbers";
|
||||
|
||||
|
|
@ -21,12 +20,12 @@ export const zoneDistribution = (intervals: Interval[]): ZoneDuration[] => {
|
|||
const zones = emptyZones();
|
||||
|
||||
intervals.forEach((interval) => {
|
||||
if (interval.intensity instanceof RangeIntensity) {
|
||||
if (interval.intensity.start === interval.intensity.end) {
|
||||
zones[interval.intensity.zone].duration += interval.duration.seconds;
|
||||
} else {
|
||||
intervalsToIntensityNumbers([interval]).forEach((intensityValue) => {
|
||||
zones[intensityValueToZoneType(intensityValue)].duration++;
|
||||
});
|
||||
} else {
|
||||
zones[interval.intensity.zone].duration += interval.duration.seconds;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { chain, curry } from "ramda";
|
||||
import { Interval } from "../ast";
|
||||
import { Duration } from "../Duration";
|
||||
import { ConstantIntensity, Intensity, RangeIntensity } from "../Intensity";
|
||||
import { ConstantIntensity, Intensity } from "../Intensity";
|
||||
|
||||
const chunkDuration = (seconds: number, chunkSize: Duration, intervalDuration: Duration): Duration => {
|
||||
return seconds + chunkSize.seconds > intervalDuration.seconds
|
||||
|
|
@ -26,7 +26,7 @@ const chunkIntensity = (
|
|||
};
|
||||
|
||||
const chunkInterval = curry((chunkSize: Duration, interval: Interval): Interval[] => {
|
||||
if (!(interval.intensity instanceof RangeIntensity)) {
|
||||
if (interval.intensity.start === interval.intensity.end) {
|
||||
return [interval];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue