Skip to content

Commit

Permalink
feat: display the number of page views
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Oct 19, 2022
1 parent 15777c4 commit 0506e97
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
17 changes: 13 additions & 4 deletions public/partials/home.htm
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,32 @@ <h2 class="featurette-heading">
<h2 id="about">Metrics</h2>
<div class="row pb-5">
<!--Grid column-->
<div class="col-md-6">
<div class="col-md-4">
<div
class="row no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative"
>
<div class="col p-4 d-flex flex-column position-static">
<h3 class="mb-auto text-center">{{stat.nbUsers|number}} Users</h3>
</div>
</div>
</div>
<div class="col-md-4">
<div
class="row no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative"
>
<div class="col p-4 d-flex flex-column position-static">
<h3 class="mb-auto text-center">
{{stat.nbRepositories|number}} Anonymized Repositories
{{stat.nbRepositories|number}} Repositories
</h3>
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-4">
<div
class="row no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative"
>
<div class="col p-4 d-flex flex-column position-static">
<h3 class="mb-auto text-center">{{stat.nbUsers|number}} Users</h3>
<h3 class="mb-auto text-center">{{stat.nbPageViews|number}} Page views</h3>
</div>
</div>
</div>
Expand Down
13 changes: 10 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default async function start() {
app.set("trust proxy", true);
app.set("etag", "strong");

app.get('/ip', (request, response) => response.send(request.ip))
app.get("/ip", (request, response) => response.send(request.ip));

// handle session and connection
app.use(connection.appSession);
Expand Down Expand Up @@ -80,7 +80,7 @@ export default async function start() {
app.use("/github", rate, speedLimiter, connection.router);

// api routes
const apiRouter = express.Router()
const apiRouter = express.Router();
app.use("/api", rate, apiRouter);

apiRouter.use("/admin", router.admin);
Expand All @@ -103,7 +103,14 @@ export default async function start() {
await AnonymizedRepositoryModel.estimatedDocumentCount();

const nbUsers = (await AnonymizedRepositoryModel.distinct("owner")).length;
res.json({ nbRepositories, nbUsers });
const nbPageViews = await AnonymizedRepositoryModel.collection
.aggregate([
{
$group: { _id: null, total: { $sum: "$pageView" } },
},
])
.toArray();
res.json({ nbRepositories, nbUsers, nbPageViews: nbPageViews[0].total });
});

// web view
Expand Down

0 comments on commit 0506e97

Please sign in to comment.