Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft/vil 339 #929

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion server/controllers/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ statisticsController.get({ path: '/student-accounts' }, async (_req, res) => {
);
});

//penser à ajouter une condition pour ne sélectionner que les durées supérieur à 60s pour le AVG
statisticsController.get({ path: '/connection-times' }, async (_req, res) => {
const durationThreshold = 60;

Expand All @@ -78,3 +77,23 @@ statisticsController.get({ path: '/connection-times' }, async (_req, res) => {
medianDuration: parseInt(medianConnectionTimesStats[0].duration),
});
});

statisticsController.get({ path: '/connection-counts' }, async (_req, res) => {
const baseConnectionCountsStats = await analyticSessionRepository
.createQueryBuilder('analytic_session')
.select('MIN(DISTINCT(duration)) AS minConnections')
.addSelect('MAX(DISTINCT(duration)) AS maxConnections')
.addSelect('ROUND(AVG(duration), 0) AS averageConnections')
.getRawOne();

const medianConnectionCountsStats = await AppDataSource.createQueryRunner().manager.query(
'SELECT connection_count AS connectionCount FROM (SELECT connection_count, ROW_NUMBER() OVER (ORDER BY connection_count) AS medianIdx FROM (SELECT COUNT(*) AS connection_count FROM analytic_session GROUP BY uniqueId) AS sub) AS d, (SELECT COUNT(*) AS cnt FROM (SELECT COUNT(*) AS connection_count FROM analytic_session GROUP BY uniqueId) AS sub_count) AS total_count WHERE d.medianIdx = (total_count.cnt DIV 2);',
);

res.sendJSON({
minConnections: baseConnectionCountsStats.minConnections,
maxConnections: baseConnectionCountsStats.maxConnections,
averageConnections: parseInt(baseConnectionCountsStats.averageConnections),
medianConnections: parseInt(medianConnectionCountsStats[0].connectionCount),
});
});
22 changes: 21 additions & 1 deletion src/api/statistics/statistics.get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { useQuery } from 'react-query';

import { axiosRequest } from 'src/utils/axiosRequest';
import type { ClassroomExchangesStats, ConnectionTimesStats, ContributionStats, StudentAccountsStats } from 'types/statistics.type';
import type {
ClassroomExchangesStats,
ConnectionCountsStats,
ConnectionTimesStats,
ContributionStats,
StudentAccountsStats,
} from 'types/statistics.type';

async function getContributions(): Promise<ContributionStats[]> {
return (
Expand Down Expand Up @@ -58,3 +64,17 @@ async function getConnectionTimes(): Promise<ConnectionTimesStats> {
export const useGetConnectionTimes = () => {
return useQuery(['analytic_sesssion'], () => getConnectionTimes());
};

async function getConnectionCounts(): Promise<ConnectionCountsStats> {
return (
await axiosRequest({
method: 'GET',
baseURL: '/api',
url: '/statistics/connection-counts',
})
).data;
}

export const useGetConnectionCounts = () => {
return useQuery(['analytic_sesssion'], () => getConnectionCounts());
};
7 changes: 7 additions & 0 deletions types/statistics.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ export interface ConnectionTimesStats {
averageDuration: number;
medianDuration: number;
}

export interface ConnectionCountsStats {
minConnections: number;
maxConnections: number;
averageConnections: number;
medianConnections: number;
}
Loading