Skip to content

Commit d6271a6

Browse files
Mutugiiidogi
andauthored
manager: smoother survey rating scale export (fixes #9083) (#9088)
Co-authored-by: dogi <[email protected]>
1 parent fbb131b commit d6271a6

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "planet",
33
"license": "AGPL-3.0",
4-
"version": "0.20.22",
4+
"version": "0.20.23",
55
"myplanet": {
66
"latest": "v0.31.27",
77
"min": "v0.30.27"

src/app/exams/exams-view.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
</div>
8080
<div *ngSwitchCase="'ratingScale'" class="rating-scale-keypad">
8181
<div class="rating-scale-grid">
82-
<button type="button" mat-raised-button class="rating-scale-button" *ngFor="let num of [1,2,3,4,5,6,7,8,9]" [class.selected]="answer.value === num.toString()" (click)="setRatingScaleAnswer(num)">
82+
<button type="button" mat-raised-button class="rating-scale-button" *ngFor="let num of [1,2,3,4,5,6,7,8,9]" [class.selected]="answer.value === num.toString()" [attr.data-rating]="num" (click)="setRatingScaleAnswer(num)">
8383
{{num}}
8484
</button>
8585
</div>

src/app/exams/exams-view.scss

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,29 @@
6060
.rating-scale-grid {
6161
display: grid;
6262
grid-template-columns: repeat(3, 1fr);
63-
gap: 10px;
64-
max-width: 100px;
63+
gap: 12px;
64+
max-width: 240px;
6565
width: 100%;
6666
}
6767

6868
.rating-scale-button {
69-
height: 50px;
70-
font-size: 24px;
69+
height: 60px;
70+
font-size: 28px;
7171
font-weight: 500;
7272
border: 2px solid #ddd;
7373
border-radius: 8px;
7474
transition: all 0.2s ease;
7575

76+
&[data-rating="1"] { background-color: #ffeaea; }
77+
&[data-rating="2"] { background-color: #ffeeea; }
78+
&[data-rating="3"] { background-color: #fff2ea; }
79+
&[data-rating="4"] { background-color: #fff6ea; }
80+
&[data-rating="5"] { background-color: #fffaea; }
81+
&[data-rating="6"] { background-color: #f6faea; }
82+
&[data-rating="7"] { background-color: #f2faea; }
83+
&[data-rating="8"] { background-color: #eefaea; }
84+
&[data-rating="9"] { background-color: #eafaea; }
85+
7686
&:hover {
7787
border-color: $primary;
7888
box-shadow: 0 4px 8px rgba(0,0,0,0.1);

src/app/submissions/submissions.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,12 @@ export class SubmissionsService {
382382
} else if (question.type === 'ratingScale') {
383383
const ratingScaleAgg = this.aggregateQuestionResponses(question, updatedSubmissions, 'count');
384384
const ratingScaleImg = await this.generateChartImage(ratingScaleAgg);
385+
const averageRating = this.calculateAverageRating(question, updatedSubmissions);
385386
docContent.push({
386387
stack: [
387388
{ image: ratingScaleImg, width: 300, alignment: 'center', margin: [ 0, 10, 0, 10 ] },
388-
{ text: `Total respondents: ${updatedSubmissions.length}`, alignment: 'center' }
389+
{ text: `Total respondents: ${updatedSubmissions.length}`, alignment: 'center' },
390+
{ text: `The Score: ${averageRating}`, alignment: 'center', margin: [ 0, 5, 0, 0 ] }
389391
],
390392
alignment: 'center'
391393
});
@@ -621,6 +623,12 @@ export class SubmissionsService {
621623
});
622624
}
623625

626+
calculateAverageRating(question, submissions): number {
627+
const validRatings = submissions.map(sub => parseInt(sub.answers[question.index].value, 10)).filter(rating => !isNaN(rating) && rating >= 1 && rating <= 9);
628+
const sum = validRatings.reduce((total, rating) => total + rating, 0);
629+
return parseFloat((sum / validRatings.length).toFixed(1));
630+
}
631+
624632
aggregateQuestionResponses(
625633
question, submissions, mode: 'percent' | 'count' = 'percent', calculationMode: 'users' | 'selections' = 'users'
626634
) {

0 commit comments

Comments
 (0)