Skip to content

Commit

Permalink
fix issue with overriding dates from spec
Browse files Browse the repository at this point in the history
  • Loading branch information
sterlingwes committed Jan 29, 2024
1 parent 6847304 commit 3cb803c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
- name: setup data fixture
run: mkdir -p site/src/generated && cp site/src/lib/server/__fixtures__/data.json site/src/generated/data.json
- name: run unit tests
run: TZ=America/New_York bun run test
run: bun run test
Binary file modified bun.lockb
Binary file not shown.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"start": "bun run dev",
"build": "cd site && bun run build",
"preview": "cd site && bun run preview",
"test": "vitest"
"test": "TZ=America/New_York vitest"
},
"devDependencies": {
"@types/bun": "latest"
Expand All @@ -22,7 +22,6 @@
"dependencies": {
"d3-node": "^3.0.0",
"date-fns": "^3.3.0",
"mockdate": "^3.0.5",
"point-at-length": "^1.1.0",
"reading-time": "^1.5.0",
"vitest": "^1.2.1"
Expand Down
94 changes: 47 additions & 47 deletions site/src/lib/server/__snapshots__/timeline.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`timeline datamodel integration 1`] = `
{
"clipPathTimes": "0;0.17444717444717445;0.18673218673218672;0.2457002457002457;0.257985257985258;0.32186732186732187;0.33415233415233414;0.40786240786240785;0.4201474201474201;0.5724815724815725;0.5847665847665847;0.6240786240786241;0.6363636363636364;0.7297297297297297;0.742014742014742;0.7764127764127764;0.7886977886977887;0.7985257985257985;0.8108108108108109;0.85995085995086;0.8722358722358723;0.9754299754299754;0.9877149877149877;1",
"clipPathValues": "7.265483521194563;7.265483521194563;7.461064832333399;7.461064832333399;11.438448228443644;11.438448228443644;17.9451889430103;17.9451889430103;21.47048171168563;21.47048171168563;54.04805022878668;54.04805022878668;87.25522154686861;87.25522154686861;98.99424525121678;98.99424525121678;99.15489557921396;99.15489557921396;112.77314983628851;112.77314983628851;248.1516359056855;248.1516359056855;400;400",
"clipPathValues": "9.714285715592453;9.714285715592453;9.975786926281383;9.975786926281383;15.293731505958267;15.293731505958267;23.9935431832114;23.9935431832114;28.70702179562914;28.70702179562914;72.26472963038266;72.26472963038266;116.66424537485395;116.66424537485395;132.35986012003764;132.35986012003764;132.5746569992702;132.5746569992702;150.78288944724008;150.78288944724008;331.7901533941068;331.7901533941068;400;400",
"dayTexts": [
{
"dayAnimId": "dayanim00",
Expand Down Expand Up @@ -714,16 +714,16 @@ exports[`timeline datamodel integration 1`] = `
"2023-10-08",
"2023-10-09",
],
"distance": 7.265483521194563,
"distance": 9.714285715592453,
"distanceBefore": 0,
"killedCounts": [
198,
256,
436,
],
"markerPoint": [
8.02081070783249,
230.32111889351592,
10.280012348794722,
228.45156922019999,
],
"markerTooltip": "October 9th 2023",
"postTime": 1696831740000,
Expand All @@ -734,12 +734,12 @@ exports[`timeline datamodel integration 1`] = `
},
{
"dates": [],
"distance": 0.1955813111388367,
"distanceBefore": 7.265483521194563,
"distance": 0.2615012106889294,
"distanceBefore": 9.714285715592453,
"killedCounts": [],
"markerPoint": [
8.201248972743082,
230.17180141202113,
10.521266610022343,
228.2519248781075,
],
"markerTooltip": "October 9th 2023",
"postTime": 1696836600000,
Expand All @@ -752,14 +752,14 @@ exports[`timeline datamodel integration 1`] = `
"dates": [
"2023-10-10",
],
"distance": 3.9773833961102443,
"distanceBefore": 7.461064832333399,
"distance": 5.317944579676882,
"distanceBefore": 9.975786926281383,
"killedCounts": [
765,
],
"markerPoint": [
11.936285096730685,
227.21964873848097,
15.927934376493553,
224.98591547475183,
],
"markerTooltip": "October 10th 2023",
"postTime": 1696935434000,
Expand All @@ -773,15 +773,15 @@ exports[`timeline datamodel integration 1`] = `
"2023-10-11",
"2023-10-12",
],
"distance": 6.506740714566657,
"distanceBefore": 11.438448228443644,
"distance": 8.699811677253136,
"distanceBefore": 15.293731505958267,
"killedCounts": [
1055,
1203,
],
"markerPoint": [
18.43804653833968,
223.24053780270765,
22.912860684430314,
217.5453029834417,
],
"markerTooltip": "October 12th 2023",
"postTime": 1697097120000,
Expand All @@ -794,14 +794,14 @@ exports[`timeline datamodel integration 1`] = `
"dates": [
"2023-10-13",
],
"distance": 3.525292768675328,
"distanceBefore": 17.9451889430103,
"distance": 4.71347861241774,
"distanceBefore": 23.9935431832114,
"killedCounts": [
1709,
],
"markerPoint": [
21.04619899170109,
219.92106124314708,
27.126907894039554,
213.9368230442184,
],
"markerTooltip": "October 13th 2023",
"postTime": 1697184720000,
Expand All @@ -822,8 +822,8 @@ exports[`timeline datamodel integration 1`] = `
"2023-10-21",
"2023-10-22",
],
"distance": 32.57756851710105,
"distanceBefore": 21.47048171168563,
"distance": 43.55770783475352,
"distanceBefore": 28.70702179562914,
"killedCounts": [
2215,
2450,
Expand All @@ -836,8 +836,8 @@ exports[`timeline datamodel integration 1`] = `
4651,
],
"markerPoint": [
50.708178983296904,
195.24142581204012,
62.97501855083281,
177.5525941442425,
],
"markerTooltip": "October 22nd 2023",
"postTime": 1697994240000,
Expand All @@ -859,8 +859,8 @@ exports[`timeline datamodel integration 1`] = `
"2023-10-31",
"2023-11-01",
],
"distance": 33.20717131808193,
"distanceBefore": 54.04805022878668,
"distance": 44.39951574447129,
"distanceBefore": 72.26472963038266,
"killedCounts": [
5087,
5791,
Expand All @@ -874,8 +874,8 @@ exports[`timeline datamodel integration 1`] = `
8805,
],
"markerPoint": [
75.94966045375378,
165.300391058581,
105.6632984895152,
146.53557344575486,
],
"markerTooltip": "November 1st 2023",
"postTime": 1698819405000,
Expand All @@ -890,16 +890,16 @@ exports[`timeline datamodel integration 1`] = `
"2023-11-03",
"2023-11-04",
],
"distance": 11.739023704348165,
"distanceBefore": 87.25522154686861,
"distance": 15.695614745183697,
"distanceBefore": 116.66424537485395,
"killedCounts": [
9061,
9257,
9488,
],
"markerPoint": [
87.55456264293207,
157.41296591929697,
121.5793210856571,
136.9869378796796,
],
"markerTooltip": "November 4th 2023",
"postTime": 1699111108000,
Expand All @@ -910,12 +910,12 @@ exports[`timeline datamodel integration 1`] = `
},
{
"dates": [],
"distance": 0.16065032799716794,
"distanceBefore": 98.99424525121678,
"distance": 0.21479687923255272,
"distanceBefore": 132.35986012003764,
"killedCounts": [],
"markerPoint": [
87.71254644975649,
157.30322852798625,
121.83444977154596,
136.95421017224908,
],
"markerTooltip": "November 4th 2023",
"postTime": 1699115100000,
Expand All @@ -931,17 +931,17 @@ exports[`timeline datamodel integration 1`] = `
"2023-11-07",
"2023-11-08",
],
"distance": 13.618254257074556,
"distanceBefore": 99.15489557921396,
"distance": 18.2082324479699,
"distanceBefore": 132.5746569992702,
"killedCounts": [
9770,
10000,
10328,
10569,
],
"markerPoint": [
101.63469419044512,
148.86451235354727,
141.02032101551592,
129.132222097083,
],
"markerTooltip": "November 8th 2023",
"postTime": 1699453500000,
Expand Down Expand Up @@ -992,8 +992,8 @@ exports[`timeline datamodel integration 1`] = `
"2023-12-16",
"2023-12-17",
],
"distance": 135.37848606939698,
"distanceBefore": 112.77314983628851,
"distance": 181.00726394686671,
"distanceBefore": 150.78288944724008,
"killedCounts": [
10818,
11078,
Expand Down Expand Up @@ -1036,8 +1036,8 @@ exports[`timeline datamodel integration 1`] = `
19235,
],
"markerPoint": [
233.940753364097,
71.42951814923794,
325.3320740188269,
31.97865096096632,
],
"markerTooltip": "December 17th 2023",
"postTime": 1702817520000,
Expand All @@ -1063,8 +1063,8 @@ exports[`timeline datamodel integration 1`] = `
"2023-12-30",
"2023-12-31",
],
"distance": 151.8483640943145,
"distanceBefore": 248.1516359056855,
"distance": 68.20984660589318,
"distanceBefore": 331.7901533941068,
"killedCounts": [
19453,
19667,
Expand All @@ -1088,7 +1088,7 @@ exports[`timeline datamodel integration 1`] = `
],
},
],
"totalDistance": 248.1516359056855,
"totalDistance": 331.7901533941068,
},
"postDelayLookup": {
"0": 40200,
Expand Down
9 changes: 1 addition & 8 deletions site/src/lib/server/timeline.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import MockDate from "mockdate";
import { afterAll, beforeAll, expect, test } from "vitest";
import { expect, test } from "vitest";
import { getTimeline } from "./timeline";
import { getSvgDomain } from "./svg";
import { getEnhancedPosts } from "./posts";
import dataFixture from "./__fixtures__/data.json";

test("timeline datamodel integration", () => {
beforeAll(() => {
MockDate.set(new Date(2023, 12, 31, 23, 0, 0, 0));
});

afterAll(() => MockDate.reset());

const posts = getEnhancedPosts(
require("../../content/enabler/talbroda.json").posts
);
Expand Down
17 changes: 5 additions & 12 deletions site/src/lib/server/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ const getData = () => {

const getTimelineBounds = (dataFetcher = getData) => {
const { dates } = dataFetcher();
const firstDate = startOfDay(parseISO(dates[0]));
const lastDate = endOfDay(parseISO(dates[dates.length - 1]));
const headDate = dates[0];
const tailDate = dates[dates.length - 1];
const firstDate = startOfDay(parseISO(headDate));
const lastDate = endOfDay(parseISO(tailDate));
const firstDateVal = firstDate.valueOf();
const lastDateVal = lastDate.valueOf();
const realTimeDuration = lastDateVal - firstDateVal;
Expand Down Expand Up @@ -47,7 +49,7 @@ export const getTimeline = ({
svgDomain: ReturnType<typeof getSvgDomain>;
dataFetcher?: typeof getData;
}) => {
const { firstDateVal, realTimeDuration } = getTimelineBounds();
const { firstDateVal, realTimeDuration } = getTimelineBounds(dataFetcher);
const { dates, killed } = dataFetcher ? dataFetcher() : getData();
const postDates = posts.map((post) => post.dateValue).sort();
const allDates = dates.map((date) => parseISO(date).valueOf());
Expand Down Expand Up @@ -104,8 +106,6 @@ export const getTimeline = ({
{}
);

console.log("svgDomain: ", svgDomain);

const graphConfig = sortedMarkerTimes.reduce(
(acc, postTime, postIndex) => {
const currentTimeInterval = acc.lastPostTime
Expand All @@ -114,13 +114,6 @@ export const getTimeline = ({

const distance =
(currentTimeInterval / realTimeDuration) * svgDomain.svgViewbox.width;
console.log({
postTime,
firstDateVal,
distance,
currentTimeInterval,
realTimeDuration,
});

const distanceBefore = acc.totalDistance;

Expand Down

0 comments on commit 3cb803c

Please sign in to comment.