Hello! I'm encountering an issue with comparing two variables:
console.log(simulation.population == 40000000); //true
console.log(simulation.initialInfectedNumber == 5); //true
console.log(simulation.population < simulation.initialInfectedNumber); //true
Both variables are numbers:
export class Seirds {
...
population: number;
initialInfectedNumber: number;
...
}
I need clarification on how this works (since 40 million is not less than 5 :P). Maybe these variables contain strings even though they should be numbers.
EDIT:
Retrieve all simulation objects
Service:
public getAllSimulations(): Observable<Seirds[]> {
return this.httpClient.get<Seirds[]>(this.url + '/all');
}
Component method:
this.service.getAllSimulations().subscribe(
value => {
this.simulations = value;
}
API response:
[
{
"id": 1,
"name": "example name",
"population": 40000000,
"initialInfectedNumber": 5,
"daysOfSimulation": 2,
"reproductionRate": 3.0,
"immunityTime": 60.0,
"incubationTime": 4.0,
"naturalDeathRate": 0.0,
"quarantineRate": 0.5,
"birthRate": 0.0,
"diseaseDuration": 15.0,
"diseaseDeathRate": 0.1,
"reductionByRestrictions": 0.2,
"percentageOfPopulationWhenRestrictionsBegins": 1.0,
"daysOfRestrictions": 30.0,
"infectiousTime": 7.0,
"timeOfOnsetOfSymptoms": 5.0,
"timeOfDyingFromIncubation": 8.0,
"records": [
{
"susceptible": 39999995,
"exposed": 5,
"infected": 0,
"recovered": 0,
"deaths": 0,
"quarantined": 0
},
{
"susceptible": 39999993,
"exposed": 2,
"infected": 5,
"recovered": 0,
"deaths": 0,
"quarantined": 1
}
]
},
{
"id": 2,
"name": "example name",
"population": 40000000,
"initialInfectedNumber": 5,
"daysOfSimulation": 2,
"reproductionRate": 3.0,
"immunityTime": 60.0,
"incubationTime": 4.0,
"naturalDeathRate": 0.0,
"quarantineRate": 0.5,
"birthRate": 0.0,
"diseaseDuration": 15.0,
"diseaseDeathRate": 0.1,
"reductionByRestrictions": 0.2,
"percentageOfPopulationWhenRestrictionsBegins": 1.0,
"daysOfRestrictions": 30.0,
"infectiousTime": 7.0,
"timeOfOnsetOfSymptoms": 5.0,
"timeOfDyingFromIncubation": 8.0,
"records": [
{
"susceptible": 39999995,
"exposed": 5,
"infected": 0,
"recovered": 0,
"deaths": 0,
"quarantined": 0
},
{
"susceptible": 39999993,
"exposed": 2,
"infected": 5,
"recovered": 0,
"deaths": 0,
"quarantined": 1
}
]
}
]
Service component:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class SeirdsService {
private url = 'http://localhost:8080/api/seirds';
constructor(private httpClient: HttpClient) { }
public getAllSimulations(): Observable<Seirds[]> {
return this.httpClient.get<Seirds[]>(this.url + '/all');
}
public addSimulation(simulation: Seirds): Observable<Seirds> {
return this.httpClient.post<Seirds>(this.url, simulation);
}
public updateSimulation(simulation: Seirds): Observable<Seirds> {
return this.httpClient.put<Seirds>(this.url, simulation);
}
public deleteSimulation(id: number): void {
let endpoint = "/" + id;
this.httpClient.delete(this.url + endpoint).subscribe();
}
}
export class SeirdsRecord {
susceptible: number;
exposed: number;
infected: number;
recovered: number;
deaths: number;
quarantined: number;
}
export class Seirds {
id: number;
name: string;
population: number;
initialInfectedNumber: number;
daysOfSimulation: number;
reproductionRate: number;
immunityTime: number;
incubationTime: number;
naturalDeathRate: number;
quarantineRate: number;
birthRate: number;
diseaseDuration: number;
diseaseDeathRate: number;
reductionByRestrictions: number;
percentageOfPopulationWhenRestrictionsBegins: number;
daysOfRestrictions: number;
infectiousTime: number;
timeOfOnsetOfSymptoms: number;
timeOfDyingFromIncubation: number;
records: SeirdsRecord[];
}