Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/simplify container #308

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion helfomat-web-ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ testem.log
.DS_Store
Thumbs.db

/docker/html
/docker/html

.angular
3 changes: 3 additions & 0 deletions helfomat-web-ui/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,8 @@
"@schematics/angular:directive": {
"prefix": "helfomat"
}
},
"cli": {
"analytics": false
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
import {Observable, of} from 'rxjs';
import {Answer} from '../../shared/answer.model';
import {GeoPoint} from '../../../_internal/geopoint';
import {HttpClient} from "@angular/common/http";
import {PictureId} from "./picture.service";
import organizations from "./organizations.json";
import {map} from "rxjs/operators";
import {environment} from "../../../environments/environment";

@Injectable({
providedIn: 'root'
Expand All @@ -26,7 +29,17 @@ export class OrganizationService {
}

findGlobalByQuestionAnswers(answers: UserAnswer[]): Observable<Organization[]> {
return this.httpClient.post<Organization[]>('api/organization/global/byQuestionAnswers', answers);
if (environment.kiosk) {
return of<Array<Organization>>(this.getScoredOrganizations(answers))
.pipe(map((organizations) => {
return organizations
.sort((a, b) => {
return b.scoreNorm - a.scoreNorm;
});
}));
} else {
return this.httpClient.post<Organization[]>('api/organization/global/byQuestionAnswers', answers);
}
}

findByPosition(position: GeoPoint, distance: number): Observable<Organization[]> {
Expand Down Expand Up @@ -59,7 +72,17 @@ export class OrganizationService {
}

getOrganization(urlName: string): Observable<Organization> {
return this.httpClient.get<Organization>('api/organization/' + urlName);
if (environment.kiosk) {
for (const organization of organizations) {
if (organization.urlName == urlName) {
return of(organization);
}
}

return of(null);
} else {
return this.httpClient.get<Organization>('api/organization/' + urlName);
}
}

getTravelDistances(id: string, location: GeoPoint): Observable<Array<TravelDistance>> {
Expand Down Expand Up @@ -91,6 +114,48 @@ export class OrganizationService {
websiteUrl
});
}

private getScoredOrganizations(answers: UserAnswer[]) {
const answerMap: { [key: string]: number } = {};

for (const answer of answers) {
answerMap[answer.id] = this.answerToNumber(answer.answer.toString());
}

const scoredOrganizations = [];
for (const organization of organizations) {
scoredOrganizations.push({
...organization,
scoreNorm: this.organizationScore(organization, answerMap)
})
}
return scoredOrganizations;
}

private answerToNumber(answer: string) {
switch (answer) {
case "NO":
return -1;
case "MAYBE":
return 0;
case "YES":
return 1;
}
};


private organizationScore(organization: Omit<Organization, "scoreNorm">, answerMap: { [key: string]: number }) {
let score = 0;
let numberOfQuestions = 0;
for (const question of organization.questions) {
const answerAsNumber = this.answerToNumber(question.answer);
const userAnswer = answerMap[question.questionId.value];
score += Math.abs(answerAsNumber - userAnswer);
numberOfQuestions++;
}
const RANGE_BETWEEN_ANSWERS = 2;
return Math.ceil(100 - (score / (numberOfQuestions * RANGE_BETWEEN_ANSWERS) * 100));
}
}

export class Organization {
Expand All @@ -100,7 +165,7 @@ export class Organization {
public organizationType: string;
public description: string;
public website: string;
public scoreNorm: number;
public scoreNorm?: number;
public pictures: PictureId[] = [];
public contactPersons: ContactPerson[] = [];
public defaultAddress: Address = null;
Expand Down Expand Up @@ -183,8 +248,8 @@ export class AnsweredQuestion {
public questionId: QuestionId;
public question: string;
public answer: string;
public description: string;
public position: number;
public description?: string;
public position?: number;
}

export interface QuestionId {
Expand Down
Loading