Skip to content

Commit

Permalink
Merge pull request #87 from FYP-2024-IQMA/SCRUM-156-Do-up-charts-in-T…
Browse files Browse the repository at this point in the history
…ableau

Scrum 156 do up charts in tableau
  • Loading branch information
tanyipeng834 authored Oct 15, 2024
2 parents 3940632 + 5b51d24 commit 553b63d
Show file tree
Hide file tree
Showing 16 changed files with 580 additions and 470 deletions.
Binary file added analytics/FYP Data Pipeline.twbx
Binary file not shown.
2 changes: 2 additions & 0 deletions backend/src/models/clickstreamModel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export interface Clickstream {
userID: string;
age: string,
eventType: "timeTaken" | "attemptsTaken";
section: string,
event: string;
timestamp: Date;
}
Expand Down
6 changes: 5 additions & 1 deletion frontend/iQMA-Skills-Builder/app/Assessment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {router, useLocalSearchParams} from 'expo-router';

import AsyncStorage from '@react-native-async-storage/async-storage';
import {AuthContext} from '@/context/AuthContext';
import { useTimer } from '@/helpers/useTimer';
import {Colors} from '@/constants/Colors';
import {LoadingIndicator} from '@/components/LoadingIndicator';
import {OverviewCard} from '@/components/OverviewCard';
Expand Down Expand Up @@ -42,13 +43,15 @@ export default function Assessment() {
} = useLocalSearchParams();
const [finalScenario, setFinalScenario] = useState<string>('');
const [checkFinal, setCheckFinal] = useState<boolean>(false);

const { startTimer, stopTimer } = useTimer(`${sectionID} ${unitID} Assessment`);

// Hardcoded for now until routing confirmed
// const isFinal: boolean = false;
// const sectionID = 'SEC0001';
// const unitID = 'UNIT0001';

useEffect(() => {
startTimer();
if (isFinal === 'true') {
(async () => {
try {
Expand Down Expand Up @@ -155,6 +158,7 @@ export default function Assessment() {
},
});
}
stopTimer();
}
};

Expand Down
35 changes: 2 additions & 33 deletions frontend/iQMA-Skills-Builder/app/AssessmentIntroduction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import {LoadingIndicator} from '@/components/LoadingIndicator';
import {OverviewCard} from '@/components/OverviewCard';
import ProgressBar from '@/components/ProgressBar';
import SectionCard from '@/components/SectionCard';
import axios from 'axios';
import {formatSection} from '@/helpers/formatSectionID';
import {formatUnit} from '@/helpers/formatUnitID';
import {useNavigation} from '@react-navigation/native';
import { useTimer } from '@/helpers/useTimer';

export default function AssessmentIntroduction() {
const navigation = useNavigation();
Expand All @@ -42,22 +42,7 @@ export default function AssessmentIntroduction() {
const [introDetails, setIntroDetails] = useState<string[]>([]);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [checkFinal, setCheckFinal] = useState<boolean>(false);

const startTimer = () => {
if (timerRef.current) {
clearInterval(timerRef.current);
}
timerRef.current = setInterval(() => {
setSeconds((prevSeconds) => prevSeconds + 1);
}, 1000);
};

const stopTimer = () => {
if (timerRef.current) {
clearInterval(timerRef.current);
timerRef.current = null;
}
};
const { startTimer, stopTimer } = useTimer(`${sectionID} ${unitID} Assessment Introduction`);

useEffect(() => {
startTimer();
Expand Down Expand Up @@ -138,22 +123,6 @@ export default function AssessmentIntroduction() {
},
});
stopTimer();
const userID = await AsyncStorage.getItem('userID');
try {
const response = await axios.post(
`${process.env.EXPO_PUBLIC_LOCALHOST_URL}/clickstream/sendMessage`,
{
userID: userID,
eventType: 'timeTaken',
event: `unitID ${unitID}`,
timestamp: new Date().toISOString(),
time: `${seconds}`,
}
);
} catch (e) {
console.error(e);
}
setSeconds(0);
};

return (
Expand Down
4 changes: 4 additions & 0 deletions frontend/iQMA-Skills-Builder/app/CheatSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {router, useLocalSearchParams} from 'expo-router';
import {Colors} from '@/constants/Colors';
import {CustomButton} from '@/components/CustomButton';
import {LoadingIndicator} from '@/components/LoadingIndicator';
import { useTimer } from '@/helpers/useTimer';
import {OverviewCard} from '@/components/OverviewCard';
import ProgressBar from '@/components/ProgressBar';
import {formatUnit} from '@/helpers/formatUnitID';
Expand Down Expand Up @@ -60,6 +61,7 @@ export default function CheatSheet() {
const [lessons, setLessons] = useState<any[]>([]);
const [unitNumber, setUnitNumber] = useState<string>('');
const [isLoading, setIsLoading] = useState<boolean>(true);
const { startTimer, stopTimer } = useTimer(`${sectionID} Cheat Sheet`);

useLayoutEffect(() => {
const progress =
Expand All @@ -74,6 +76,7 @@ export default function CheatSheet() {
}, [navigation]);

useEffect(() => {
startTimer();
if (sectionID && unitID) {
(async () => {
try {
Expand Down Expand Up @@ -120,6 +123,7 @@ export default function CheatSheet() {
totalProgress,
},
});
stopTimer();
};

return (
Expand Down
4 changes: 4 additions & 0 deletions frontend/iQMA-Skills-Builder/app/KeyTakeaway.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import SectionCard from '@/components/SectionCard';
import {formatSection} from '@/helpers/formatSectionID';
import {formatUnit} from '@/helpers/formatUnitID';
import {useNavigation} from '@react-navigation/native';
import { useTimer } from '@/helpers/useTimer';

export default function KeyTakeaway() {
const navigation = useNavigation();
Expand Down Expand Up @@ -62,6 +63,7 @@ export default function KeyTakeaway() {
totalProgress,
},
});
stopTimer();
};

// const sectionID = 'SEC0001';
Expand All @@ -88,8 +90,10 @@ export default function KeyTakeaway() {
const [lessonName, setLessonName] = useState<string>('');
const [keyTakeaway, setKeyTakeaway] = useState<string[]>([]);
const [nextLessonID, setnextLessonID] = useState<string>('');
const { startTimer, stopTimer } = useTimer(`${sectionID} ${unitID} ${lessonID} Key Takeaway`);

useEffect(() => {
startTimer();
if (
sectionID &&
unitID &&
Expand Down
4 changes: 4 additions & 0 deletions frontend/iQMA-Skills-Builder/app/Lesson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import YoutubePlayer from 'react-native-youtube-iframe';
import {formatSection} from '@/helpers/formatSectionID';
import {formatUnit} from '@/helpers/formatUnitID';
import {useNavigation} from '@react-navigation/native';
import { useTimer } from '@/helpers/useTimer';

// where things show up
export default function Lesson() {
Expand All @@ -38,6 +39,7 @@ export default function Lesson() {
const [playing, setPlaying] = useState<boolean>(true);
const [lessonDescription, setLessonDescription] = useState<string | []>();
const [isLoading, setIsLoading] = useState<boolean>(true);
const { startTimer, stopTimer } = useTimer(`${sectionID} ${unitID} ${lessonID} Lesson`);

useLayoutEffect(() => {
const progress =
Expand Down Expand Up @@ -69,9 +71,11 @@ export default function Lesson() {
totalProgress,
},
});
stopTimer();
};

useEffect(() => {
startTimer();
if (sectionID && unitID && lessonID) {
(async () => {
try {
Expand Down
6 changes: 4 additions & 2 deletions frontend/iQMA-Skills-Builder/app/RealityCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import SectionCard from '@/components/SectionCard';
import {formatSection} from '@/helpers/formatSectionID';
import {formatUnit} from '@/helpers/formatUnitID';
import {useNavigation} from '@react-navigation/native';
import { useTimer } from '@/helpers/useTimer';

// where things show up
export default function RealityCheck() {
Expand All @@ -35,8 +36,7 @@ export default function RealityCheck() {
string[]
>([]);
const [isLoading, setIsLoading] = useState<boolean>(true);

useEffect(() => {}, []);
const { startTimer, stopTimer } = useTimer(`${sectionID} ${unitID} Reality Check`);

useLayoutEffect(() => {
const progress =
Expand All @@ -51,6 +51,7 @@ export default function RealityCheck() {
}, [navigation]);

useEffect(() => {
startTimer();
if (sectionID && unitID) {
(async () => {
try {
Expand Down Expand Up @@ -90,6 +91,7 @@ export default function RealityCheck() {
totalProgress,
},
});
stopTimer();
};

return (
Expand Down
8 changes: 7 additions & 1 deletion frontend/iQMA-Skills-Builder/app/SectionIntroduction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {router, useLocalSearchParams} from 'expo-router';
import {Colors} from '@/constants/Colors';
import {CustomButton} from '@/components/CustomButton';
import {LoadingIndicator} from '@/components/LoadingIndicator';
import { useTimer } from '@/helpers/useTimer';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {OverviewCard} from '@/components/OverviewCard';
import ProgressBar from '@/components/ProgressBar';
import SectionCard from '@/components/SectionCard';
Expand Down Expand Up @@ -35,6 +37,7 @@ export default function SectionIntroduction() {
const [videoId, setVideoId] = useState<string>('');
const [playing, setPlaying] = useState<boolean>(true);
const [isLoading, setIsLoading] = useState<boolean>(true);
const { startTimer, stopTimer } = useTimer(`${sectionID} Introduction`);

useLayoutEffect(() => {
const progress =
Expand All @@ -49,6 +52,7 @@ export default function SectionIntroduction() {
}, [navigation]);

useEffect(() => {
startTimer();
if (sectionID) {
(async () => {
try {
Expand All @@ -61,6 +65,7 @@ export default function SectionIntroduction() {
setSectionName(sectionDetails.sectionName);

setSectionNumber(formatSection(sectionID as string));
await AsyncStorage.setItem('section', sectionDetails.sectionName);
} catch (error) {
console.error('Error fetching Lesson details:', error);
} finally {
Expand All @@ -70,7 +75,7 @@ export default function SectionIntroduction() {
}
}, [sectionID]);

const handlePress = () => {
const handlePress = async () => {
setPlaying(false);
router.push({
pathname: 'UnitIntroduction',
Expand All @@ -88,6 +93,7 @@ export default function SectionIntroduction() {
totalProgress,
},
});
stopTimer();
};

const onStateChange = (state: string) => {
Expand Down
5 changes: 5 additions & 0 deletions frontend/iQMA-Skills-Builder/app/SelfReflection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import SectionCard from '@/components/SectionCard';
import {formatSection} from '@/helpers/formatSectionID';
import {formatUnit} from '@/helpers/formatUnitID';
import {useNavigation} from '@react-navigation/native';
import { useTimer } from '@/helpers/useTimer';

export default function SelfReflection() {
const navigation = useNavigation();
Expand All @@ -37,6 +38,8 @@ export default function SelfReflection() {
setChatHistoryLength(length);
};
const [isLoading, setIsLoading] = useState<boolean>(true);
const { startTimer, stopTimer } = useTimer(`${sectionID} ${unitID} Self Reflection`);

useLayoutEffect(() => {
const progress =
parseInt(currentProgress as string) /
Expand All @@ -50,6 +53,7 @@ export default function SelfReflection() {
}, [navigation]);

useEffect(() => {
startTimer();
if (sectionID && unitID) {
(async () => {
try {
Expand Down Expand Up @@ -117,6 +121,7 @@ export default function SelfReflection() {
// after self-reflection navigate back to home for next unit
router.replace('Home');
}
stopTimer();
};

return (
Expand Down
48 changes: 3 additions & 45 deletions frontend/iQMA-Skills-Builder/app/UnitIntroduction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import axios from 'axios';
import {formatSection} from '@/helpers/formatSectionID';
import {formatUnit} from '@/helpers/formatUnitID';
import {useNavigation} from '@react-navigation/native';
import { useTimer } from '@/helpers/useTimer';

// where things show up
export default function UnitIntroduction() {
Expand All @@ -35,35 +36,8 @@ export default function UnitIntroduction() {
const [unitNumber, setUnitNumber] = useState<string>('');
const [unitName, setUnitName] = useState<string>('');
const [unitDescription, setUnitDescription] = useState<string[]>([]);

const [seconds, setSeconds] = useState<number>(0);
const timerRef = useRef<NodeJS.Timeout | null>(null);
const [isLoading, setIsLoading] = useState<boolean>(true);

const startTimer = () => {
if (timerRef.current) {
clearInterval(timerRef.current);
}
timerRef.current = setInterval(() => {
setSeconds((prevSeconds) => prevSeconds + 1);
}, 1000);
};

const stopTimer = () => {
if (timerRef.current) {
clearInterval(timerRef.current);
timerRef.current = null;
}
};

useEffect(() => {
startTimer();
return () => {
if (timerRef.current) {
clearInterval(timerRef.current);
}
};
}, []);
const { startTimer, stopTimer } = useTimer(`${sectionID} ${unitID} Introduction`);

useLayoutEffect(() => {
const progress =
Expand All @@ -78,6 +52,7 @@ export default function UnitIntroduction() {
}, [navigation]);

useEffect(() => {
startTimer();
if (sectionID && unitID) {
(async () => {
try {
Expand Down Expand Up @@ -119,23 +94,6 @@ export default function UnitIntroduction() {
},
});
stopTimer();
const userID = await AsyncStorage.getItem('userID');
try {
const response = await axios.post(
`${process.env.EXPO_PUBLIC_LOCALHOST_URL}/clickstream/sendMessage`,
{
userID: userID,
eventType: 'timeTaken',
event: `unitID ${unitID}`,
timestamp: new Date().toISOString(),
time: `${seconds}`,
}
);
console.log(response.data);
} catch (e) {
console.error(e);
}
setSeconds(0);
};

return (
Expand Down
Loading

0 comments on commit 553b63d

Please sign in to comment.