add some metrics
This commit is contained in:
parent
5f6100b0bb
commit
730030f6f1
@ -6,20 +6,24 @@ import getMetrics from "../queries/get-metrics";
|
||||
import Layout from "../components/layout";
|
||||
|
||||
const initialData = {
|
||||
users: 0,
|
||||
phoneNumbers: 0,
|
||||
smsExchanged: 0,
|
||||
minutesCalled: 0,
|
||||
averageMinutesCalled: 0,
|
||||
};
|
||||
|
||||
const OpenMetrics: BlitzPage = () => {
|
||||
const [metrics] = useQuery(getMetrics, {}, { suspense: false, initialData });
|
||||
const { phoneNumbers, smsExchanged, minutesCalled } = metrics ?? initialData;
|
||||
const { users, phoneNumbers, smsExchanged, minutesCalled, averageMinutesCalled } = metrics ?? initialData;
|
||||
|
||||
return (
|
||||
<dl className="mt-5 grid grid-cols-1 gap-5 sm:grid-cols-3">
|
||||
<Card title="Users" value={users} />
|
||||
<Card title="Phone Numbers Registered" value={phoneNumbers} />
|
||||
<Card title="SMS Exchanged" value={smsExchanged} />
|
||||
<Card title="Minutes on Call" value={minutesCalled} />
|
||||
<Card title="Avg Call Length in Minutes" value={averageMinutesCalled} />
|
||||
</dl>
|
||||
);
|
||||
};
|
||||
|
@ -3,7 +3,8 @@ import { resolver } from "blitz";
|
||||
import db from "../../../db";
|
||||
|
||||
export default resolver.pipe(async () => {
|
||||
const [phoneNumbers, smsExchanged, allPhoneCalls] = await Promise.all([
|
||||
const [users, phoneNumbers, smsExchanged, allPhoneCalls] = await Promise.all([
|
||||
db.user.count(),
|
||||
db.phoneNumber.count(),
|
||||
db.message.count(),
|
||||
db.phoneCall.findMany(),
|
||||
@ -16,10 +17,13 @@ export default resolver.pipe(async () => {
|
||||
return seconds + Number.parseInt(phoneCall.duration);
|
||||
}, 0);
|
||||
const minutesCalled = Math.round(secondsCalled / 60);
|
||||
const averageMinutesCalled = (minutesCalled / allPhoneCalls.length).toFixed(2);
|
||||
|
||||
return {
|
||||
users,
|
||||
phoneNumbers,
|
||||
smsExchanged,
|
||||
minutesCalled,
|
||||
averageMinutesCalled,
|
||||
};
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user