Skip to content

Commit

Permalink
fixed weighted calcuations and updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanrdsch committed Nov 3, 2023
1 parent b2070e9 commit b090c73
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 14 additions & 4 deletions frontend/src/DataProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const DATA = Map<number, Data2>([
[
1,
[
[0, 0],
[1, 1],
[2, 2],
[3, 3],
Expand All @@ -16,6 +17,7 @@ const DATA_2 = Map<number, Data2>([
[
2,
[
[0, 0],
[1, 100],
[2, 20],
[3, 30],
Expand All @@ -31,6 +33,7 @@ test('it returns a single dataset, not normalized', () => {
})
).toEqual(
Map([
[0, 0],
[1, 1],
[2, 2],
[3, 3],
Expand All @@ -47,7 +50,8 @@ test('it returns a single dataset, normalized', () => {
})
).toEqual(
Map([
[1, 0],
[0, 0],
[1, 0.25],
[2, 0.5],
[3, 1],
])
Expand All @@ -65,6 +69,7 @@ test('it returns two datasets, added, if they are both selected', () => {
})
).toEqual(
Map([
[0, 0],
[1, 101],
[2, 22],
[3, 33],
Expand All @@ -84,8 +89,9 @@ test('it returns two datasets, normalized then averaged, if they are both select
})
).toEqual(
Map([
[1, 0.5],
[2, 0.25],
[0, 0],
[1, 0.625],
[2, 0.375],
[3, 0.75],
])
)
Expand Down Expand Up @@ -137,6 +143,7 @@ test('it weights datasets when normalizing', () => {
})
).toEqual(
Map([
[0, 0],
[1, 0.75],
[2, 0.125],
[3, 0.625],
Expand All @@ -155,6 +162,7 @@ test("it doesn't weight datasets when not normalizing", () => {
})
).toEqual(
Map([
[0, 0],
[1, 101],
[2, 22],
[3, 33],
Expand All @@ -171,6 +179,7 @@ test('it filters geoIds', () => {
})
).toEqual(
Map([
[0, 0],
[1, 1],
[3, 3],
])
Expand All @@ -187,7 +196,8 @@ test('it filters by geoIds, then normalizes with respect to only those ids', ()
})
).toEqual(
Map([
[1, 0],
[0, 0],
[1, 0.33],
[2, 1],
])
)
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/DataProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@ const normalizeData = (params: Params, totalWeight: number, valueByGeoId: Map<nu
.sort((a, b) => a - b)

const weightedPercentileScale = (value: number) => {
const maxValue = Math.max(...valueListNonZero)
if (value === 0) {
return 0
}
if (value === maxValue) {
return 1
}
// eslint-disable-next-line no-plusplus
for (let i = 0, l = valueListNonZero.length; i < l; i++) {
if (value <= valueListNonZero[i]) {
Expand Down

0 comments on commit b090c73

Please sign in to comment.