Skip to content

Commit

Permalink
Minor rewording on generated blob view webpage.
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed Sep 4, 2024
1 parent 6fecacb commit 6b070b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
15 changes: 9 additions & 6 deletions backend/cache/dist/controllers/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ export const getView = async (req, res) => {
const today = new Date();
const last30Days = Array.from({ length: 30 }, (_, i) => format(subDays(today, i + 1), 'yyyy-MM-dd')).reverse();
// Calculate CDN Hits Percentage
const blobHits = [];
const blobViews = [];
const blobVisitors = [];
const blobCdnHitsPercentage = [];
last30Days.forEach(date => {
// If the date is not in the metrics, use a placeholder
const dayMetrics = (isValidMetrics && metrics.daily[date]?.blob) || { hits: 0, hitsEdge: 0, visitors: 0 };
blobHits.push(dayMetrics.hits);
blobViews.push(dayMetrics.hits);
blobVisitors.push(dayMetrics.visitors);
const cdnHitsPercentage = dayMetrics.hits === 0 ? 0 : (dayMetrics.hitsEdge / dayMetrics.hits) * 100;
blobCdnHitsPercentage.push(cdnHitsPercentage);
Expand Down Expand Up @@ -156,7 +156,7 @@ export const getView = async (req, res) => {
</style>
</head>
<body>
<h2>Dashboard for ${id}</h2>
<h2>Metrics for ${id}</h2>
<div class="chart-container">
<canvas id="hitsChart"></canvas>
</div>
Expand All @@ -168,7 +168,7 @@ export const getView = async (req, res) => {
</div>
<script>
const dates = ${JSON.stringify(last30Days)};
const blobHits = ${JSON.stringify(blobHits)};
const blobViews = ${JSON.stringify(blobViews)};
const blobVisitors = ${JSON.stringify(blobVisitors)};
const blobCdnHitsPercentage = ${JSON.stringify(blobCdnHitsPercentage)};
Expand All @@ -178,8 +178,8 @@ export const getView = async (req, res) => {
data: {
labels: dates,
datasets: [{
label: 'Hits',
data: blobHits,
label: 'Views',
data: blobViews,
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1
}]
Expand Down Expand Up @@ -235,6 +235,9 @@ export const getView = async (req, res) => {
}
});
</script>
<div style="text-align: center; margin-top: 20px;">
<a href="https://cdn.suiftly.io/metrics/${id}">JSON Metrics</a>
</div>
</body>
</html>
`;
Expand Down
15 changes: 9 additions & 6 deletions backend/cache/src/controllers/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ export const getView = async (req: Request, res: Response) => {
const last30Days = Array.from({ length: 30 }, (_, i) => format(subDays(today, i + 1), 'yyyy-MM-dd')).reverse();

// Calculate CDN Hits Percentage
const blobHits: number[] = [];
const blobViews: number[] = [];
const blobVisitors: number[] = [];
const blobCdnHitsPercentage: number[] = [];

last30Days.forEach(date => {
// If the date is not in the metrics, use a placeholder
const dayMetrics = (isValidMetrics && metrics.daily[date]?.blob) || { hits: 0, hitsEdge: 0, visitors: 0 };
blobHits.push(dayMetrics.hits);
blobViews.push(dayMetrics.hits);
blobVisitors.push(dayMetrics.visitors);
const cdnHitsPercentage = dayMetrics.hits === 0 ? 0 : (dayMetrics.hitsEdge / dayMetrics.hits) * 100;
blobCdnHitsPercentage.push(cdnHitsPercentage);
Expand Down Expand Up @@ -169,7 +169,7 @@ export const getView = async (req: Request, res: Response) => {
</style>
</head>
<body>
<h2>Dashboard for ${id}</h2>
<h2>Metrics for ${id}</h2>
<div class="chart-container">
<canvas id="hitsChart"></canvas>
</div>
Expand All @@ -181,7 +181,7 @@ export const getView = async (req: Request, res: Response) => {
</div>
<script>
const dates = ${JSON.stringify(last30Days)};
const blobHits = ${JSON.stringify(blobHits)};
const blobViews = ${JSON.stringify(blobViews)};
const blobVisitors = ${JSON.stringify(blobVisitors)};
const blobCdnHitsPercentage = ${JSON.stringify(blobCdnHitsPercentage)};
Expand All @@ -191,8 +191,8 @@ export const getView = async (req: Request, res: Response) => {
data: {
labels: dates,
datasets: [{
label: 'Hits',
data: blobHits,
label: 'Views',
data: blobViews,
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1
}]
Expand Down Expand Up @@ -248,6 +248,9 @@ export const getView = async (req: Request, res: Response) => {
}
});
</script>
<div style="text-align: center; margin-top: 20px;">
<a href="https://cdn.suiftly.io/metrics/${id}">JSON Metrics</a>
</div>
</body>
</html>
`;
Expand Down

0 comments on commit 6b070b7

Please sign in to comment.