src/app/features/home/home.component.
ts
1 import { Component } from '@angular/core';
2 import { MContainerComponent } from '../../m-framework/m-container/m-
container.component';
3 import { CommonModule } from '@angular/common';
4 import { FormsModule } from '@angular/forms';
5 import { Reading } from '../../data/Reading';
6 import { MTableComponent } from "../../m-framework/m-table/m-table.component";
7 import { MSearchButtonComponent } from "../../m-framework/m-search-button/m-
search-button.component";
8 import { MLocaldataService } from '../../services/m-localdata.service';
9
10 @Component({
11 selector: 'app-home',
12 standalone: true,
13 imports: [CommonModule, FormsModule, MContainerComponent, MTableComponent,
MSearchButtonComponent],
14 templateUrl: './home.component.html',
15 styleUrl: './home.component.css'
16 })
17
18 export class HomeComponent{
19 temperature: number;
20 highCount: number = 0;
21 elevatedCount: number = 0;
22 normalCount: number = 0;
23 inputTime: Date;
24 headers: string[] = ['reading', 'time'];
25
26 constructor(private mLocaldataService: MLocaldataService) {
27 this.temperature = 0;
28 this.inputTime = new Date();
29 }
30 public get ListOfReadings(){
31 return this.mLocaldataService.getList();
32 }
33
34 recordTimestamp() {
35 this.inputTime = new Date(); // current time
36 return this.inputTime
37 }
38 checkTime(){
39 const readings = this.mLocaldataService.getList();
40 for (const reading of readings) {
41 const existingTimestamp = new Date(reading.time);
42 const timeDiff = Math.abs(this.inputTime.getTime() -
existingTimestamp.getTime());
43 if (timeDiff < 60 * 60 * 1000) { // 1 hour in milliseconds
44 return false;
45 }
46 }
47 return true;
48 }
49
50
51 addReading(){
52 this.recordTimestamp()
53 if (this.checkTime()==true){
54 let reading = new Reading(
55 this.mLocaldataService.getNextID(),
56 this.inputTime,
57 this.temperature
58 );
59 this.mLocaldataService.add(reading);
60 this.temperature = 0 ;
61 this.recordTimestamp();
62 }
63 }
64
65 removeReading(carID: number){
66 this.mLocaldataService.remove(carID);
67 }
68 removeAll(){
69 this.mLocaldataService.removeAll();
70 }
71 navigateReading(){
72 console.log("Called");
73
74 }
75 countFever(){
76 const readings = this.mLocaldataService.getList();
77 readings.forEach(reading => {
78
79 if (reading.temperature >= 40) {
80 this.highCount++;
81 }
82 else if (reading.temperature >= 38 && reading.temperature <= 39.9) {
83 this.elevatedCount++;
84 } else {
85 this.normalCount++;
86 }
87 });
88 };
89 getMResultBoxLabel(){
90 if (this.temperature >= 40) {
91 return "Your temperature is high"
92 }
93 else if (this.temperature >= 38 && this.temperature <= 39.9) {
94
95 return "Your temperature is elevated"
96 }
97 else {
98 return "Your temperature is normal"
99 }
100
101 }
102 getMResultBoxClass(){
103 if (this.temperature >= 40) {
104 return "warning"
105 }
106 else if (this.temperature >= 38 && this.temperature <= 39.9) {
107 return "error"
108 }
109 else {
110 return "success"
111 }
112 }
113 }
114
115
116
117