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