-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor/2318/prepare migration of metric data services (#2514)
refactor: move calculation of metric data into selectors So that we can easily access them from Angular components to come during migration. The only "real" change is that on onAttributeTypesChanged nodeMetricData and edgeMetricData aren't recalculated anymore, as they are independent of attributeType. refs: #2318 Co-authored-by: Torsten Knauf <Torsten.Knauf@maibornwolff.de> Co-authored-by: Ruben Bridgewater <ruben@bridgewater.de>
- Loading branch information
1 parent
a09ebd1
commit d0b8567
Showing
52 changed files
with
369 additions
and
601 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...app/codeCharta/state/selectors/accumulatedData/metricData/edgeMetricData.selector.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { calculateEdgeMetricData, nodeEdgeMetricsMap } from "./edgeMetricData.selector" | ||
import { FILE_STATES, VALID_NODE_WITH_PATH } from "../../../../util/dataMocks" | ||
import { FileState } from "../../../../model/files/files" | ||
import { clone } from "../../../../util/clone" | ||
import { EdgeMetricDataService } from "../../../store/metricData/edgeMetricData/edgeMetricData.service" | ||
|
||
describe("edgeMetricDataSelector", () => { | ||
let fileStates: FileState[] | ||
|
||
beforeEach(() => { | ||
fileStates = clone(FILE_STATES) | ||
fileStates[0].file.map = clone(VALID_NODE_WITH_PATH) | ||
}) | ||
|
||
it("should create correct edge Metrics", () => { | ||
const result = calculateEdgeMetricData(fileStates, []) | ||
|
||
expect(result.map(x => x.name)).toContain("pairingRate") | ||
expect(result.map(x => x.name)).toContain("otherMetric") | ||
}) | ||
|
||
it("should calculate correct maximum value for edge Metrics", () => { | ||
const result = calculateEdgeMetricData(fileStates, []) | ||
|
||
expect(result.find(x => x.name === "pairingRate").maxValue).toEqual(2) | ||
expect(result.find(x => x.name === "otherMetric").maxValue).toEqual(1) | ||
}) | ||
|
||
it("should contain the None metric once", () => { | ||
const result = calculateEdgeMetricData(fileStates, []) | ||
|
||
expect(result.filter(x => x.name === EdgeMetricDataService.NONE_METRIC)).toHaveLength(1) | ||
}) | ||
|
||
it("should sort the metrics after calculating them", () => { | ||
const result = calculateEdgeMetricData(fileStates, []) | ||
|
||
expect(result).toHaveLength(4) | ||
expect(result[0].name).toBe("avgCommits") | ||
expect(result[1].name).toBe("None") | ||
expect(result[2].name).toBe("otherMetric") | ||
expect(result[3].name).toBe("pairingRate") | ||
}) | ||
|
||
it("metrics Map should contain correct entries", () => { | ||
calculateEdgeMetricData(fileStates, []) | ||
|
||
const pairingRateMapKeys = [...nodeEdgeMetricsMap.get("pairingRate").keys()] | ||
|
||
expect(pairingRateMapKeys[0]).toEqual("/root/big leaf") | ||
expect(pairingRateMapKeys[1]).toEqual("/root/Parent Leaf/small leaf") | ||
expect(pairingRateMapKeys[2]).toEqual("/root/Parent Leaf/other small leaf") | ||
}) | ||
}) |
33 changes: 12 additions & 21 deletions
33
.../edgeMetricData/edgeMetricData.reducer.ts → ...ata/metricData/edgeMetricData.selector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...lization/app/codeCharta/state/selectors/accumulatedData/metricData/metricData.selector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { createSelector } from "../../../angular-redux/createSelector" | ||
import { edgeMetricDataSelector } from "./edgeMetricData.selector" | ||
import { nodeMetricDataSelector } from "./nodeMetricData.selector" | ||
|
||
export const metricDataSelector = createSelector([nodeMetricDataSelector, edgeMetricDataSelector], (nodeMetricData, edgeMetricData) => ({ | ||
nodeMetricData, | ||
edgeMetricData | ||
})) |
16 changes: 16 additions & 0 deletions
16
...on/app/codeCharta/state/selectors/accumulatedData/metricData/metricNames.selector.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { CcState } from "../../../store/store" | ||
import { edgeMetricDataSelector } from "./edgeMetricData.selector" | ||
import { metricNamesSelector } from "./metricNames.selector" | ||
|
||
const mockedEdgeMetricDataSelector = edgeMetricDataSelector as unknown as jest.Mock | ||
jest.mock("./edgeMetricData.selector", () => ({ | ||
edgeMetricDataSelector: jest.fn() | ||
})) | ||
|
||
describe("metricNamesSelector", () => { | ||
it("should get the names of the metrics", () => { | ||
mockedEdgeMetricDataSelector.mockImplementationOnce(() => [{ name: "metricOfTruth" }, { name: "otherMetric" }]) | ||
|
||
expect(metricNamesSelector({} as unknown as CcState)).toEqual(["metricOfTruth", "otherMetric"]) | ||
}) | ||
}) |
4 changes: 4 additions & 0 deletions
4
...ization/app/codeCharta/state/selectors/accumulatedData/metricData/metricNames.selector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createSelector } from "../../../angular-redux/createSelector" | ||
import { edgeMetricDataSelector } from "./edgeMetricData.selector" | ||
|
||
export const metricNamesSelector = createSelector([edgeMetricDataSelector], edgeMetricData => edgeMetricData.map(x => x.name)) |
60 changes: 60 additions & 0 deletions
60
...app/codeCharta/state/selectors/accumulatedData/metricData/nodeMetricData.selector.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { TEST_DELTA_MAP_A, VALID_NODE_WITH_ROOT_UNARY } from "../../../../util/dataMocks" | ||
import { FileSelectionState, FileState } from "../../../../model/files/files" | ||
import { BlacklistType } from "../../../../codeCharta.model" | ||
import { NodeDecorator } from "../../../../util/nodeDecorator" | ||
import { clone } from "../../../../util/clone" | ||
import { NodeMetricDataService } from "../../../store/metricData/nodeMetricData/nodeMetricData.service" | ||
import { calculateNodeMetricData } from "./nodeMetricData.selector" | ||
|
||
describe("nodeMetricDataSelector", () => { | ||
let fileState: FileState | ||
|
||
beforeEach(() => { | ||
const file = clone(TEST_DELTA_MAP_A) | ||
NodeDecorator.decorateMapWithPathAttribute(file) | ||
fileState = { | ||
file, | ||
selectedAs: FileSelectionState.Single | ||
} | ||
}) | ||
|
||
it("should return a sorted array of metricData sorted by name calculated from visibleFileStates", () => { | ||
const expected = [ | ||
{ maxValue: 1000, minValue: 10, name: "functions" }, | ||
{ maxValue: 100, minValue: 1, name: "mcc" }, | ||
{ maxValue: 100, minValue: 30, name: "rloc" }, | ||
{ maxValue: 1, minValue: 1, name: NodeMetricDataService.UNARY_METRIC } | ||
] | ||
|
||
const result = calculateNodeMetricData([fileState], []) | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
|
||
it("should ignore blacklisted nodes", () => { | ||
const expected = [ | ||
{ maxValue: 1000, minValue: 100, name: "functions" }, | ||
{ maxValue: 100, minValue: 10, name: "mcc" }, | ||
{ maxValue: 70, minValue: 30, name: "rloc" }, | ||
{ maxValue: 1, minValue: 1, name: NodeMetricDataService.UNARY_METRIC } | ||
] | ||
|
||
const result = calculateNodeMetricData([fileState], [{ path: "root/big leaf", type: BlacklistType.exclude }]) | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
|
||
it("should always add unary metric if it's not included yet", () => { | ||
const result = calculateNodeMetricData([fileState], []) | ||
|
||
expect(result.filter(x => x.name === NodeMetricDataService.UNARY_METRIC)).toHaveLength(1) | ||
}) | ||
|
||
it("should not add unary metric a second time if the cc.json already contains unary", () => { | ||
fileState.file.map = VALID_NODE_WITH_ROOT_UNARY | ||
|
||
const result = calculateNodeMetricData([fileState], []) | ||
|
||
expect(result.filter(x => x.name === NodeMetricDataService.UNARY_METRIC).length).toBe(1) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
visualization/app/codeCharta/state/selectors/accumulatedData/metricData/sortByMetricName.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const sortByMetricName = (metricData: { name: string }[]) => { | ||
metricData.sort((a, b) => { | ||
const aLower = a.name.toLowerCase() | ||
const bLower = b.name.toLowerCase() | ||
return aLower > bLower ? 1 : bLower > aLower ? -1 : 0 | ||
}) | ||
} |
Oops, something went wrong.