Skip to content

Commit

Permalink
Merge pull request #70 from cepdnaclk/main
Browse files Browse the repository at this point in the history
deploy
  • Loading branch information
KATTA-00 authored Jan 28, 2024
2 parents 584ca9d + 29a587e commit c9d6261
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 62 deletions.
4 changes: 2 additions & 2 deletions code/backend/src/controllers/login.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class LoginController {
}

const email = loginReq.userName;
const player = await PlayerModel.findOne({ email });
if (player?.isVerified == "pending" || player?.isVerified == "rejected") {
const manager = await ManagerModel.findOne({ email });
if (manager?.isVerified == "pending" || manager?.isVerified == "rejected") {
throw new Error(HttpMsg.MANAGER_NOT_VERIFIED);
}

Expand Down
4 changes: 4 additions & 0 deletions code/backend/src/controllers/player.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class PlayerController {
const teamInstance = await TeamModel.findOne({ teamId });
const teamName = teamInstance?.teamName; // Add null check using optional chaining operator


const playerInTeamResponse = await playersInTeamService.addPlayerToTeam(
newPlayerEmail,
teamId,
Expand All @@ -60,7 +61,9 @@ class PlayerController {
);

// Send the invitation email

await sendInvitationEmail(fullName, newPlayerEmail, invitationToken, teamName!);

return playerInTeamResponse
}

Expand Down Expand Up @@ -106,6 +109,7 @@ class PlayerController {
// password
// );


// Create a player with an invitation token
const invitationToken = generateInvitationToken();
const playerResponse = await playerService.createPlayer(email, password, invitationToken);
Expand Down
2 changes: 1 addition & 1 deletion code/backend/src/controllers/team.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TeamController {
}

async checkTeamEmailExist(
teamId: string,
teamId: string,
email: string
): Promise<TeamIdEmailExistsResponseWithIsVerified> {
// check team ID and email of the manager matchers
Expand Down
3 changes: 2 additions & 1 deletion code/backend/src/routes/player.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ router.post("/add", async (req: Request, res: Response) => {
}

// Validate email format
if (!validateEmail(newPlayerEmail)) {
if (newPlayerEmail !== "" && !validateEmail(newPlayerEmail)) {
console.log(HttpMsg.INVALID_EMAIL);
res.status(HttpCode.BAD_REQUEST).send({ message: HttpMsg.INVALID_EMAIL });
return;
Expand Down Expand Up @@ -286,6 +286,7 @@ router.get("/analytics-summary/:duration",async (req:Request, res: Response) =>
try {

const playerEmail = req.body.userName; // player email is retrieved from the request body
console.log(playerEmail);

// Check if player exists
const playerExists = await playerController.checkPlayerExists(playerEmail);
Expand Down
23 changes: 18 additions & 5 deletions code/backend/src/services/managers.in.team.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class ManagersInTeamService {
): Promise<boolean> {
try {
// check entry exists
const managerTeam = await ManagerModel.findOne({
const managerTeam = await ManagerModel.find({
email: managerEmail,
teamId: teamId,
});

console.log(managerTeam)
if (managerTeam) {
return true;
}else{
Expand Down Expand Up @@ -158,7 +158,7 @@ class ManagersInTeamService {
},
{
title: "Highest Contributor",
value: 0
value: '--'
}
],
tableData: []
Expand Down Expand Up @@ -192,6 +192,9 @@ class ManagersInTeamService {
};
});

console.log("analyticsSummary.tableData:");
console.log(analyticsSummary.tableData);

tableDataPrev = jerseyIds.map((jerseyId) => {
return {
jersey_number: jerseyId,
Expand Down Expand Up @@ -221,7 +224,8 @@ class ManagersInTeamService {
const createdAt = new Date(session.createdAt).getTime();
return createdAt >= previous && createdAt <= current;
});
// console.log(filteredSessionsPrevious);
console.log("filteredSessionsPrevious:");
console.log(filteredSessionsPrevious);
await this.calculationForSessions(filteredSessionsPrevious, tableDataPrev);

// Get the number of sessions
Expand All @@ -234,11 +238,19 @@ class ManagersInTeamService {
const createdAt = new Date(session.createdAt).getTime();
return createdAt >= current && createdAt <= now;
});
console.log("filteredSessionsCurrent:");
console.log(filteredSessionsCurrent)

// Get the number of sessions
const numberOfSessions = filteredSessionsCurrent.length
analyticsSummary.summaryData[0].value = numberOfSessions;
analyticsSummary.summaryData[0].trend = Math.round(((numberOfSessions - prevSessions)*100/prevSessions));

if (prevSessions > 0) {
analyticsSummary.summaryData[0].trend = Math.round(((numberOfSessions - prevSessions)*100/prevSessions));
}else{
analyticsSummary.summaryData[0].trend = '--';
}



// Fill up table data
Expand Down Expand Up @@ -312,6 +324,7 @@ class ManagersInTeamService {
}

playerData.average_impact = playerData.cumulative_impact / playerData.impacts_recorded;

directionCount[impact.direction as keyof typeof directionCount] += 1;

// console.log(playerData)
Expand Down
61 changes: 32 additions & 29 deletions code/backend/src/services/player.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class PlayerService {
})
.filter((teamWithJerseyId): teamWithJerseyId is TeamResponseWithJerseyId => teamWithJerseyId !== null);

// console.log(teamResponsesWithJerseyId);
console.log(teamResponsesWithJerseyId);

// Initialize To store Impact stats for previous and current duration
let impactStatsPrev: ImpactStats = {
Expand Down Expand Up @@ -271,7 +271,7 @@ class PlayerService {



// console.log(team.teamId, sessions );
console.log(team.teamId, sessions );

let filteredSessionsPrevious: Array<SessionResponse> = [];

Expand All @@ -284,16 +284,16 @@ class PlayerService {
impactStatsPrev = await calculationForSessionsPrev(filteredSessionsPrevious, impactStatsPrev, team.jerseyId, flagPrev);
// console.log("impactStatsPrev:", flagPrev);
}
// console.log("Previous" + team.teamId );
// console.log(filteredSessionsPrevious);
console.log("Previous" + team.teamId );
console.log(filteredSessionsPrevious);


const filteredSessionsCurrent = sessions.filter(session => {
const createdAt = new Date(session.createdAt).getTime();
return createdAt >= current && createdAt <= now;
});
// console.log("Current" + team.teamId );
// console.log(filteredSessionsCurrent);
console.log("Current" + team.teamId );
console.log(filteredSessionsCurrent);



Expand All @@ -306,10 +306,12 @@ class PlayerService {
analyticsSummary.criticalSessions,
flagCurrent);

// console.log("impactStatsCurr:", flagCurrent);
console.log("impactStatsCurr:", flagCurrent);


}

console.log("impactStatsPrev:", flagPrev);

if (flagPrev || flagCurrent){
// Fill up the analytics summary from impact stats ==> values
Expand Down Expand Up @@ -372,6 +374,7 @@ class PlayerService {
}else{
analyticsSummary.criticalSessions = [];
}
console.log("analyticsSummary:");


return analyticsSummary;
Expand Down Expand Up @@ -430,7 +433,7 @@ class PlayerService {
): Promise<ImpactStats> {
try{

// console.log("Curr#####");
console.log("Curr#####");
// For each session
for (const session of sessions) {
// console.log("Session: " + session.sessionId);
Expand All @@ -452,7 +455,7 @@ class PlayerService {
let impactCountForSession:number = 0;
for (const impactPlayer of session.impactHistory) {

// console.log(impactPlayer.jerseyId, jerseyId)
console.log(impactPlayer.jerseyId, jerseyId)
if (impactPlayer.jerseyId === jerseyId) {

// Player has at least one impact in the current duration
Expand All @@ -463,48 +466,48 @@ class PlayerService {

//Session Analytics
impactCountForSession += 1;
// console.log("impactCountForSession: " + impactCountForSession);
console.log("impactCountForSession: " + impactCountForSession);

sessionAnalyticsItem.cumulative += impact.magnitude;
// console.log("sessionAnalyticsItem.cumulative: " + sessionAnalyticsItem.cumulative);
console.log("sessionAnalyticsItem.cumulative: " + sessionAnalyticsItem.cumulative);

if (sessionAnalyticsItem.highest < impact.magnitude){
sessionAnalyticsItem.highest = impact.magnitude;
// console.log("sessionAnalyticsItem.highest: " + sessionAnalyticsItem.highest);
console.log("sessionAnalyticsItem.highest: " + sessionAnalyticsItem.highest);
}

sessionAnalyticsItem.average = sessionAnalyticsItem.cumulative/impactCountForSession;
// console.log("sessionAnalyticsItem.average: " + sessionAnalyticsItem.average);
console.log("sessionAnalyticsItem.average: " + sessionAnalyticsItem.average);

// console.log("sessionAnalyticsItem###########3:")
// console.log(sessionAnalyticsItem);
console.log("sessionAnalyticsItem###########3:")
console.log(sessionAnalyticsItem);

// Update the impact stats
stats.impactsCumulative += impact.magnitude;
// console.log("stats.impactsCumulative: " + stats.impactsCumulative);
console.log("stats.impactsCumulative: " + stats.impactsCumulative);

stats.impactsRecorded += 1;
// console.log("stats.impactsRecorded: " + stats.impactsRecorded);
console.log("stats.impactsRecorded: " + stats.impactsRecorded);
if (stats.highestImpact < impact.magnitude) {

stats.highestImpact = impact.magnitude;
// console.log("stats.highestImpact: " + stats.highestImpact);
console.log("stats.highestImpact: " + stats.highestImpact);
}
stats.directionCount[impact.direction as keyof typeof stats.directionCount] += 1;
// console.log("stats.directionCount: " + stats.directionCount);
console.log("stats.directionCount: " + stats.directionCount);

const index = Math.floor(impact.magnitude / 20);
// console.log("index: " + index);

console.log("index: " + index);
console.log(impact.direction as keyof typeof histogramData)
histogramData[impact.direction as keyof typeof histogramData][index] += 1;
// console.log("histogramData:");
// console.log(impact.magnitude, impact.direction);
// console.log(histogramData);
console.log("histogramData:");
console.log(impact.magnitude, impact.direction);
console.log(histogramData);


// console.log(stats)
console.log(stats)
}
// console.log("End of each impact in the impact Player Loop");
console.log("End of each impact in the impact Player Loop");

// Round off the average impact

Expand All @@ -514,9 +517,9 @@ class PlayerService {
}

sessionAnalyticsItem.average = Math.round(sessionAnalyticsItem.average);
// console.log("sessionAnalyticsItem.average: " + sessionAnalyticsItem.average);
console.log("sessionAnalyticsItem.average: " + sessionAnalyticsItem.average);

// console.log("End of each impactPlayer in the session Loop");
console.log("End of each impactPlayer in the session Loop");

// If length of crirtical sessions<3 => directly push to the critical sessions
// Else: sort by cumulative impact => remove the least one and push only if least<current cumulative
Expand All @@ -527,7 +530,7 @@ class PlayerService {
}else {
// Sort the critical sessions array by cumulative impact in descending order
criticalSessions.sort((a, b) => b.cumulative - a.cumulative);
//console.log(sessionAnalyticsItem);
console.log(sessionAnalyticsItem);

if (sessionAnalyticsItem.cumulative > criticalSessions[criticalSessions.length - 1].cumulative) {
criticalSessions.pop();
Expand Down
2 changes: 1 addition & 1 deletion code/backend/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type AnalyticsSummaryTeam = {
summaryData: Array<{
title: string;
value: string | number;
trend?: string | number | '--';
trend?: string | number | "--";
}>;
tableData: Array<{
jersey_number: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ String CombinedOutput::getDirection()
else if (std::abs(aY) >= std::abs(aX) && std::abs(aY) >= std::abs(aZ))
{
if (aY > 0)
return "Top";
return "Front"; // TOP
else
return "Bottom";
return "Back"; // BOTTOM
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const ImpactSummaryCard: React.FC<{ metric: Metric; timeSpan: TimeSpan }> = ({
<span className={cardStyles.metaUnits}>{metric.metaUnits}</span>
)}
</p>
{timeSpan != "All Time" && metric.trend && (
{timeSpan != "All Time" && metric.trend !== undefined && (
<p className={cardStyles.trend}>
{trendElement}
<span className={cardStyles.duration}>{timeSpan}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
// TeamAnalyticsColumns,
TimeSpan,
TeamAnalyticsSummary,
Metric,
} from "../../../types";
// import TeamAnalyticsTable from "./TeamAnalyticsTable";
import { useQuery } from "@tanstack/react-query";
Expand Down Expand Up @@ -51,7 +52,7 @@ const TeamAnalytics = () => {
const responseData = await response.json();
return responseData;
}

console.log(AnalyticsSummaryManager);
const isInternetAvailable = useAppState((state) => state.isInternetAvailable);
if (!isInternetAvailable) {
//show no internet connection component
Expand Down Expand Up @@ -115,7 +116,7 @@ const TeamAnalytics = () => {
) : (
<>
<div className={styles.impactSummaryContainer}>
{AnalyticsSummaryManager?.summaryData?.map((metric) => (
{AnalyticsSummaryManager?.summaryData?.map((metric: Metric) => (
<ImpactSummaryCard
metric={metric}
timeSpan={timeSpan}
Expand All @@ -124,13 +125,14 @@ const TeamAnalytics = () => {
))}
</div>
<div className={styles.tableContainer}>
{AnalyticsSummaryManager?.tableData ? (
{AnalyticsSummaryManager?.tableData &&
AnalyticsSummaryManager?.tableData.length > 0 ? (
<TeamAnalyticsTable
teamAnalyticsTableData={AnalyticsSummaryManager?.tableData}
key={Date.now()}
/>
) : (
<p>No Data</p>
<p>No Player Data Available</p>
)}
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ const PlayerManagement = () => {

return;
}
console.log(data);
const response = await fetch(`${BASE_URL}/player/add`, {
method: "POST",
body: JSON.stringify({
Expand Down Expand Up @@ -253,13 +254,13 @@ const PlayerManagement = () => {
placeholder="Johnathan Doe"
/>
<label htmlFor="email">
Player's Email (Optional)
Player's Email
<span className={styles.additionalInfo}>
Link Impax Account
</span>
</label>
<input
{...register("email", { required: false })}
{...register("email", { required: true })}
type="email"
name="email"
id="email"
Expand Down
Loading

0 comments on commit c9d6261

Please sign in to comment.