Skip to content

Commit

Permalink
chore: add csv header + fix user type + convert score to score with m…
Browse files Browse the repository at this point in the history
…ax_score 10 #400
  • Loading branch information
bsilkyn committed May 7, 2024
1 parent a5aac8c commit efbad5e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion frontend/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from 'cypress';

export default defineConfig({
e2e: {
baseUrl: 'http://nginx',
baseUrl: 'https://localhost',
specPattern: 'src/test/e2e/**/*.cy.{js,jsx,ts,tsx}',
},
});
15 changes: 9 additions & 6 deletions frontend/src/components/projects/DownloadCSV.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ import Button from 'primevue/button';
import { useI18n } from 'vue-i18n';
import { useGroup } from '@/composables/services/group.service.ts';
import { useStudents } from '@/composables/services/student.service.ts';
import { type Project } from '@/types/Project.ts';
/* Props */
const props = defineProps<{
projectId: string;
projectName: string;
project: Project;
}>();
/* Injections */
const { t } = useI18n();
const { groups, getGroupsByProject } = useGroup();
const { students, getStudentsByGroup } = useStudents();
/* Constants */
const header = 'OrgDefinedId,Last Name,First Name,Email,Grade,End-of-Line Indicator\n';
/* Functions */
/**
* generateCSVAndDownload generates a csv combining all the scores for all students in all groups associated
Expand All @@ -23,7 +26,7 @@ const { students, getStudentsByGroup } = useStudents();
*/
const generateCSVAndDownload = async (): Promise<void> => {
// retrieve all the groups associated with a given project
await getGroupsByProject(props.projectId);
await getGroupsByProject(props.project.id);
// construct for every group's student a csv line according to ufora grade csv standard
// and concatenate them all into one csv
const csvPromises =
Expand All @@ -33,14 +36,14 @@ const generateCSVAndDownload = async (): Promise<void> => {
students.value
?.map((student) => {
// single csv line
return `#${student.id},${student.last_name},${student.first_name},${student.email},${group.score},#`;
return `#${student.student_id},${student.last_name},${student.first_name},${student.email},${group.score * 10 / props.project.max_score},#`;
})
.join('\n') ?? ''
);
}) ?? [];
const csvList = await Promise.all(csvPromises);
const csvContent = csvList.join('\n');
const csvContent = header + csvList.join('\n');
// create a blob from the csv content
const blob = new Blob([csvContent], { type: 'text/plain' });
Expand All @@ -51,7 +54,7 @@ const generateCSVAndDownload = async (): Promise<void> => {
// create an anchor element for downloading the file
const a = document.createElement('a');
a.href = url;
a.download = props.projectName + '.csv';
a.download = props.project.name + '.csv';
// click anchor element
a.click();
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/types/users/Student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Student extends User {
public last_enrolled: number,
public create_time: Date,
public last_login: Date | null,
public studentId: string,
public student_id: string,
public roles: Role[] = [],
public courses: Course[] = [],
public groups: Group[] = [],
Expand Down Expand Up @@ -51,7 +51,7 @@ export class Student extends User {
student.last_enrolled,
new Date(student.create_time),
student.last_login !== null ? new Date(student.last_login) : null,
student.studentId,
student.student_id,
);
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/projects/roles/TeacherProjectView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ watch(
</div>
<div class="col-12">
<template v-if="project !== null">
<DownloadCSV :project-id="project.id" :project-name="project.name" />
<DownloadCSV :project="project" />
</template>
</div>
</div>
Expand Down

0 comments on commit efbad5e

Please sign in to comment.