Skip to content

Commit e1630a7

Browse files
committed
use normalizedGender && new ratings system
1 parent a183392 commit e1630a7

5 files changed

Lines changed: 70 additions & 35 deletions

File tree

src/app/health/health.service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { StateService } from '../shared/state.service';
66
import { UsersService } from '../users/users.service';
77
import { stringToHex, ageFromBirthDate } from '../shared/utils';
88
import { findDocuments } from '../shared/mangoQueries';
9+
import { normalizeGender } from '../shared/gender.constants';
910

1011
@Injectable({
1112
providedIn: 'root'
@@ -109,7 +110,13 @@ export class HealthService {
109110
const eventData = this.newEventDoc(oldEvent, newEvent, time);
110111
return forkJoin([
111112
this.postHealthDoc(healthDoc, { userKey, lastExamination: time }, keyDoc),
112-
this.postHealthDoc({}, { ...eventData, profileId: userKey, creatorId: creatorKey, gender: user.gender, age }, keyDoc),
113+
this.postHealthDoc({}, {
114+
...eventData,
115+
profileId: userKey,
116+
creatorId: creatorKey,
117+
gender: normalizeGender(user.gender),
118+
age
119+
}, keyDoc),
113120
creatorHealthDoc.userKey || newEvent.selfExamination ?
114121
of({}) :
115122
this.postHealthDoc(creatorHealthDoc, { userKey: creatorKey }, creatorKeyDoc)

src/app/shared/forms/planet-rating.component.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ interface PopupFormModel {
4747
imports: [NgClass, MatIcon, PlanetStackedBarComponent, NgIf, FormsModule, ReactiveFormsModule, PlanetRatingStarsComponent]
4848
})
4949
export class PlanetRatingComponent implements OnChanges {
50-
5150
@Input() rating: any = { userRating: {} };
5251
@Input() item: any;
5352
@Input() parent;
@@ -83,15 +82,21 @@ export class PlanetRatingComponent implements OnChanges {
8382

8483
ngOnChanges() {
8584
// After any changes to ratings ensures all properties are set
86-
this.rating = Object.assign({ rateSum: 0, totalRating: 0, maleRating: 0, femaleRating: 0, userRating: {} }, this.rating);
85+
this.rating = Object.assign({
86+
rateSum: 0,
87+
totalRating: 0,
88+
maleRating: 0,
89+
femaleRating: 0,
90+
otherRating: 0,
91+
preferNotToSayRating: 0,
92+
didNotSpecifyRating: 0,
93+
userRating: {}
94+
}, this.rating);
8795
this.stackedBarData = [
8896
{ class: 'primary-color', amount: this.rating.maleRating },
89-
{ class: 'primary-light-color',
90-
amount: this.rating.totalRating === 0 ?
91-
1 :
92-
this.rating.totalRating - this.rating.maleRating - this.rating.femaleRating,
93-
noLabel: true
94-
},
97+
{ class: 'primary-light-color', amount: this.rating.otherRating, noLabel: true },
98+
{ class: 'bg-light-grey', amount: this.rating.didNotSpecifyRating, noLabel: true },
99+
{ class: 'bg-grey', amount: this.rating.preferNotToSayRating, noLabel: true },
95100
{ class: 'accent-color', amount: this.rating.femaleRating, align: 'right' }
96101
];
97102
this.rateForm.setValue({

src/app/shared/forms/rating.service.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
import { Injectable } from '@angular/core';
22
import { CouchService } from '../couchdb.service';
33
import { findDocuments } from '../mangoQueries';
4-
import { UserService } from '../user.service';
5-
import { of, Subject } from 'rxjs';
6-
import { catchError } from 'rxjs/operators';
7-
import { StateService } from '../state.service';
8-
9-
const startingRating = { rateSum: 0, totalRating: 0, maleRating: 0, femaleRating: 0, userRating: {}, allRatings: [] };
4+
import { UserService } from '../user.service';
5+
import { of, Subject } from 'rxjs';
6+
import { catchError } from 'rxjs/operators';
7+
import { StateService } from '../state.service';
8+
import { normalizeGender } from '../gender.constants';
9+
10+
const startingRating = {
11+
rateSum: 0,
12+
totalRating: 0,
13+
maleRating: 0,
14+
femaleRating: 0,
15+
otherRating: 0,
16+
preferNotToSayRating: 0,
17+
didNotSpecifyRating: 0,
18+
userRating: {},
19+
allRatings: []
20+
};
1021

1122
@Injectable({
1223
providedIn: 'root'
@@ -67,14 +78,23 @@ export class RatingService {
6778
// If totalRating is undefined, will start count at 1
6879
ratingInfo.totalRating = ratingInfo.totalRating + 1;
6980
ratingInfo.rateSum = ratingInfo.rateSum + rating.rate;
70-
switch (rating.user.gender) {
71-
case 'male':
72-
ratingInfo.maleRating = ratingInfo.maleRating + 1;
73-
break;
74-
case 'female':
75-
ratingInfo.femaleRating = ratingInfo.femaleRating + 1;
76-
break;
77-
}
81+
switch (normalizeGender(rating.user.gender)) {
82+
case 'male':
83+
ratingInfo.maleRating = ratingInfo.maleRating + 1;
84+
break;
85+
case 'female':
86+
ratingInfo.femaleRating = ratingInfo.femaleRating + 1;
87+
break;
88+
case 'other':
89+
ratingInfo.otherRating = ratingInfo.otherRating + 1;
90+
break;
91+
case 'preferNotToSay':
92+
ratingInfo.preferNotToSayRating = ratingInfo.preferNotToSayRating + 1;
93+
break;
94+
default:
95+
ratingInfo.didNotSpecifyRating = ratingInfo.didNotSpecifyRating + 1;
96+
break;
97+
}
7898
ratingInfo.userRating = rating.user.name === this.userService.get().name ? rating : ratingInfo.userRating;
7999
ratingInfo.allRatings = [ ...ratingInfo.allRatings, rating ];
80100
if (ratings.length > index + 1 && ratings[index + 1].item === id) {

src/app/shared/user.service.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { Injectable } from '@angular/core';
22
import { CouchService } from './couchdb.service';
33
import { catchError, switchMap, map, tap } from 'rxjs/operators';
44
import { of, Observable, Subject, BehaviorSubject, forkJoin } from 'rxjs';
5-
import { findDocuments } from '../shared/mangoQueries';
6-
import { environment } from '../../environments/environment';
7-
import { addToArray, removeFromArray, dedupeShelfReduce } from './utils';
8-
import { StateService } from './state.service';
5+
import { findDocuments } from '../shared/mangoQueries';
6+
import { environment } from '../../environments/environment';
7+
import { addToArray, removeFromArray, dedupeShelfReduce } from './utils';
8+
import { StateService } from './state.service';
9+
import { normalizeGender } from './gender.constants';
910

1011
// Holds the currently logged in user information
1112
// If available full profile from _users db, if not object in userCtx property of response from a GET _session
@@ -305,10 +306,10 @@ export class UserService {
305306
})));
306307
}
307308

308-
isProfileComplete() {
309-
const isComplete = !!(this.user.firstName && this.user.lastName && this.user.email && this.user.birthDate &&
310-
this.user.gender && this.user.language && this.user.phoneNumber && this.user.level);
311-
this.profileComplete.next(isComplete);
312-
}
309+
isProfileComplete() {
310+
const isComplete = !!(this.user.firstName && this.user.lastName && this.user.email && this.user.birthDate &&
311+
normalizeGender(this.user.gender) !== 'didNotSpecify' && this.user.language && this.user.phoneNumber && this.user.level);
312+
this.profileComplete.next(isComplete);
313+
}
313314

314315
}

src/app/submissions/submissions.service.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { TeamsService } from '../teams/teams.service';
1818
import { ChatService } from '../shared/chat.service';
1919
import { surveyAnalysisPrompt } from '../shared/ai-prompts.constants';
2020
import { loadChart, createChartCanvas, renderNoDataPlaceholder, CHART_COLORS } from '../shared/chart-utils';
21+
import { getGenderLabel, normalizeGender } from '../shared/gender.constants';
2122
import pdfMake from 'pdfmake/build/pdfmake';
2223
import pdfFonts from 'pdfmake/build/vfs_fonts';
2324

@@ -318,8 +319,9 @@ export class SubmissionsService {
318319
const title = `${toProperCase($localize`${type}`)} - ${$localize`${exam.name}`} (${updatedSubmissions.length})`;
319320
const data = updatedSubmissions.map(submission => {
320321
const answerIndexes = this.answerIndexes(questionTexts, submission);
322+
const genderLabel = getGenderLabel(submission.user.gender);
321323
return {
322-
[$localize`Gender`]: submission.user.gender || 'N/A',
324+
[$localize`Gender`]: genderLabel,
323325
[$localize`Age (years)`]: submission.user.birthDate ?
324326
ageFromBirthDate(time, submission.user.birthDate) :
325327
submission.user.age || 'N/A',
@@ -553,7 +555,7 @@ export class SubmissionsService {
553555
const userAge = submission.user.birthDate ?
554556
ageFromBirthDate(submission.lastUpdateTime, submission.user.birthDate) :
555557
submission.user.age;
556-
const userGender = submission.user.gender;
558+
const userGender = getGenderLabel(submission.user.gender, { fallback: '' });
557559
const communityOrNation = submission.planetName;
558560
const planetSource = submission.androidId !== undefined ? 'myPlanet' : 'Planet';
559561
const teamType = submission.teamInfo?.type ? toProperCase(submission.teamInfo.type) : '';
@@ -775,7 +777,7 @@ export class SubmissionsService {
775777
const userSubmissions = submissions.map(submission => ({
776778
userInfo: {
777779
age: submission.user.age || ageFromBirthDate(submission.lastUpdateTime, submission.user.birthDate),
778-
gender: submission.user.gender
780+
gender: normalizeGender(submission.user.gender)
779781
},
780782
answers: submission.answers
781783
}));

0 commit comments

Comments
 (0)