domain-watchdog/assets/pages/StatisticsPage.tsx

119 lines
4.3 KiB
TypeScript
Raw Normal View History

2024-08-22 19:26:34 +02:00
import React, {useEffect, useState} from "react";
import {getStatistics, Statistics} from "../utils/api";
import {Card, Col, Divider, Row, Statistic, Tooltip} from "antd";
import {t} from "ttag";
import {
AimOutlined,
CompassOutlined,
DatabaseOutlined,
FieldTimeOutlined,
NotificationOutlined
} from "@ant-design/icons";
export default function StatisticsPage() {
const [stats, setStats] = useState<Statistics>()
useEffect(() => {
getStatistics().then(setStats)
}, [])
2024-08-22 19:47:52 +02:00
const successRate = stats !== undefined ?
2024-08-22 19:26:34 +02:00
(stats.domainPurchaseFailed === 0 ? undefined : stats.domainPurchased / stats.domainPurchaseFailed)
: undefined
return <>
<Row gutter={16}>
<Col span={12}>
<Card bordered={false}>
<Statistic
loading={stats === undefined}
prefix={<CompassOutlined/>}
title={t`RDAP queries`}
value={stats?.rdapQueries}
/>
</Card>
</Col>
<Col span={12}>
<Card bordered={false}>
<Statistic
loading={stats === undefined}
2024-08-22 19:47:52 +02:00
title={t`Alerts sent`}
2024-08-22 19:26:34 +02:00
prefix={<NotificationOutlined/>}
value={stats?.alertSent}
valueStyle={{color: 'blueviolet'}}
/>
</Card>
</Col>
</Row>
<Divider/>
<Row gutter={16}>
<Col span={12}>
<Card bordered={false}>
<Statistic
loading={stats === undefined}
2024-08-22 19:47:52 +02:00
title={t`Domain names in database`}
2024-08-22 19:26:34 +02:00
prefix={<DatabaseOutlined/>}
2024-08-22 20:04:02 +02:00
value={stats?.domainCountTotal}
2024-08-22 19:26:34 +02:00
valueStyle={{color: 'darkblue'}}
/>
</Card>
</Col>
<Col span={12}>
<Card bordered={false}>
<Statistic
loading={stats === undefined}
2024-08-22 19:47:52 +02:00
title={t`Tracked domain names`}
2024-08-22 19:26:34 +02:00
prefix={<AimOutlined/>}
value={stats?.domainTracked}
valueStyle={{color: 'darkviolet'}}
/>
</Card>
</Col>
</Row>
<Divider/>
<Row gutter={16}>
<Col span={12}>
<Card bordered={false}>
<Statistic
loading={stats === undefined}
2024-08-22 19:47:52 +02:00
title={t`Purchased domain names`}
2024-08-22 19:26:34 +02:00
prefix={<FieldTimeOutlined/>}
value={stats?.domainPurchased}
valueStyle={{color: '#3f8600'}}
/>
</Card>
</Col>
<Col span={12}>
<Card bordered={false}>
<Tooltip
2024-08-22 19:47:52 +02:00
title={t`This value is based on the status code of the HTTP response from the providers following the domain order.`}>
2024-08-22 19:26:34 +02:00
<Statistic
loading={stats === undefined}
2024-08-22 19:47:52 +02:00
title={t`Success rate`}
value={successRate === undefined ? '-' : successRate * 100}
2024-08-22 19:26:34 +02:00
suffix='%'
precision={2}
2024-08-22 19:47:52 +02:00
valueStyle={{color: successRate === undefined ? 'grey' : successRate >= 0.5 ? 'darkgreen' : 'orange'}}
2024-08-22 19:26:34 +02:00
/>
</Tooltip>
</Card>
</Col>
</Row>
<Divider/>
2024-08-22 19:47:52 +02:00
<Row gutter={16} justify='center' align='middle'>
{stats?.domainCount
.sort((a, b) => b.domain - a.domain)
.map(({domain, tld}) => <Col span={4}>
<Card bordered={false}>
<Statistic
loading={stats === undefined}
title={`.${tld}`}
value={domain}
valueStyle={{color: 'darkblue'}}
/>
</Card>
</Col>)}
2024-08-22 19:26:34 +02:00
</Row>
</>
}