Skip to content

Commit

Permalink
refactor: unify stats (#633)
Browse files Browse the repository at this point in the history
* feat(db): create overall stats model

* refactor: use overall stats instead of blob, block or transaction overall stats

* feat(db): create daily stats model

* refactor: refactor: use daily stats instead of blob, block or transaction daily stats

* feat(db): drop block, tx and blob stats models

* fix: remove references to block, tx and blob daily stats

* chore: add changesets
  • Loading branch information
PJColombo authored Dec 2, 2024
1 parent d5ef1bc commit c88e11f
Show file tree
Hide file tree
Showing 67 changed files with 12,300 additions and 8,772 deletions.
5 changes: 5 additions & 0 deletions .changeset/healthy-pears-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blobscan/db": minor
---

Dropped blob, block and transaction overall and daily stats models
5 changes: 5 additions & 0 deletions .changeset/shaggy-knives-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blobscan/db": minor
---

Added overall and daily stats models
6 changes: 3 additions & 3 deletions apps/web/src/components/Charts/Blob/DailyBlobSizeChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import type { FC } from "react";
import type { EChartOption } from "echarts";

import { ChartCard } from "~/components/Cards/ChartCard";
import type { DailyBlobStats } from "~/types";
import type { DailyStats } from "~/types";
import { buildTimeSeriesOptions, formatBytes } from "~/utils";

export type DailyBlobsSizeProps = {
days: DailyBlobStats["days"];
blobSizes: DailyBlobStats["totalBlobSizes"];
days: DailyStats["day"][];
blobSizes: DailyStats["totalBlobSize"][];
compact: boolean;
};
export const DailyBlobSizeChart: FC<Partial<DailyBlobsSizeProps>> = function ({
Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/components/Charts/Blob/DailyBlobsChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import type { FC } from "react";
import type { EChartOption } from "echarts";

import { ChartCard } from "~/components/Cards/ChartCard";
import type { DailyBlobStats } from "~/types";
import type { DailyStats } from "~/types";
import { buildTimeSeriesOptions, formatNumber } from "~/utils";

export type DailyBlobsChartProps = {
days: DailyBlobStats["days"];
blobs: DailyBlobStats["totalBlobs"];
uniqueBlobs: DailyBlobStats["totalUniqueBlobs"];
days: DailyStats["day"][];
blobs: DailyStats["totalBlobs"][];
uniqueBlobs: DailyStats["totalUniqueBlobs"][];
};

export const DailyBlobsChart: FC<Partial<DailyBlobsChartProps>> = function ({
Expand Down
33 changes: 9 additions & 24 deletions apps/web/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
buildBlobsRoute,
buildBlocksRoute,
buildTransactionsRoute,
deserializeBlockOverallStats,
deserializeFullBlock,
deserializeOverallStats,
} from "~/utils";

const LATEST_ITEMS_LENGTH = 5;
Expand All @@ -45,7 +45,7 @@ const Home: NextPage = () => {
expand: "transaction,blob",
});
const { data: rawOverallStats, error: overallStatsErr } =
api.stats.getAllOverallStats.useQuery();
api.stats.getOverallStats.useQuery();
const { data: dailyTxStats, error: dailyTxStatsErr } =
api.stats.getTransactionDailyStats.useQuery({
timeFrame: DAILY_STATS_TIMEFRAME,
Expand Down Expand Up @@ -78,16 +78,7 @@ const Home: NextPage = () => {
blobs,
};
}, [rawBlocksData]);
const overallStats = useMemo(() => {
if (!rawOverallStats) {
return;
}

return {
...rawOverallStats,
block: deserializeBlockOverallStats(rawOverallStats.block),
};
}, [rawOverallStats]);
const overallStats = useMemo(() => rawOverallStats ? deserializeOverallStats(rawOverallStats) : undefined, [rawOverallStats]);

const error =
latestBlocksError ||
Expand All @@ -104,7 +95,6 @@ const Home: NextPage = () => {
);
}

const totalBlobSize = overallStats?.blob?.totalBlobSize;

return (
<div className="flex flex-col items-center justify-center gap-12 sm:gap-20">
Expand Down Expand Up @@ -137,13 +127,8 @@ const Home: NextPage = () => {
<MetricCard
name="Total Tx Fees Saved"
metric={{
value:
typeof overallStats?.block?.totalBlobAsCalldataFee !==
"undefined" &&
typeof overallStats?.block?.totalBlobFee !== "undefined"
? overallStats.block.totalBlobAsCalldataFee -
overallStats.block.totalBlobFee
: undefined,
value: overallStats ?
overallStats.totalBlobAsCalldataFee - overallStats.totalBlobFee : undefined,
type: "ethereum",
}}
compact
Expand All @@ -152,28 +137,28 @@ const Home: NextPage = () => {
<MetricCard
name="Total Blocks"
metric={{
value: overallStats?.block?.totalBlocks,
value: overallStats?.totalBlocks,
}}
compact
/>
<MetricCard
name="Total Txs"
metric={{
value: overallStats?.transaction?.totalTransactions,
value: overallStats?.totalTransactions,
}}
compact
/>
<MetricCard
name="Total Blobs"
metric={{
value: overallStats?.blob?.totalBlobs,
value: overallStats?.totalBlobs,
}}
compact
/>
<MetricCard
name="Total Blob Size"
metric={{
value: totalBlobSize ? BigInt(totalBlobSize) : undefined,
value: overallStats?.totalBlobSize,
type: "bytes",
}}
compact
Expand Down
Loading

0 comments on commit c88e11f

Please sign in to comment.