# 5th August Report
## Progress
Time: **13:00**
Event: Entering the lab
*Note*: All the intern students have midterm report with Professor Ray and Professor Riri from University of Indonesia.
---
### Midterm meeting with Prof. Riri
Start time: **08:30**
End time: **12:30**
#### Presentation
{%slideshare MuhamadAldyBintang/20190805pwa-ian-aldy-thariqmidterm %}
You can download **[here](https://drive.google.com/file/d/12vHWL8UeJ3DAZHeEvklArATQ4ceiel8W/view)**.
#### Comments
- From Prof. Ray, we need to know how to sort the the nearby dispensers from the nearest to the farest.
- From Fadli, he suggest that we can use IPS to know the position of devices for indoor.
- We should discuss the idea with Mr. Johnny and team about this.
---
### Testing the home page of Repairman App using the data from API
Time: **14:53**
- Lastly the back end code to convert the data from API format to JSON object has already successful, even though still using the dummy data.
- In Dispenser API service, we use two function to get data from API:
- one is to get the data from the API so it's still raw, and
- the other one is filter the data based on format needed (for example: data for Done Mission need the status is greater than or equal to 5).
- Function to get the data from the API as raw data:
```typescript=
async getDispenserRepairCondition (device_id: string) {
let url = this.urlGetDispenserRepairCondition + device_id;
let returnValue = [{}];
await this.http.get(url).toPromise()
.then((result) => {
returnValue = result['Data'];
}, () => {
console.error("Promise rejected: unable to get dispenser repair condition!");
})
.catch((e) => {
console.error("Function error: on getDispenserRepairCondition => " + e);
});
return returnValue;
}
```
- Function to filter the data
```typescript=
async getAssignmentDone (device_id: string, employee_id: string) {
// get data from RepairCondition
let data = await this.getDispenserRepairCondition(device_id);
let returnArray = [];
// for every data will be filtered to get what have been done
for (let i = 0 ; i < data.length ; i++) {
// if data contains the employee id we need
if (data[i]['Maintainer_ID'] === employee_id) {
// if data contains status above-equal to 5 and has repair time done
if (data[i]['Status'] >= 5 && data[i]['RepairDoneTime'] !== "") {
returnArray.push(data[i]);
}
}
}
return returnArray;
}
```
- The code above is to filter the raw data from API into the data just for Done Mission, see code line 4 that this function also call the `getDispenserRepairCondition` function.
- In line 14th we can see that the data will filtered by status and see if the `RepairDoneTime` is not empty.
- Because the data from the API are not complete so we discard the filter for condition of `RepairDoneTime` is present.
- It become like this:
```typescript
if (data[i]['Status'] >= 5) {
...
}
```
- For this, I still testing the data for Done Mission and if success then go forward for the other function.
- In **ngOnInit()** function:
```typescript=
async ngOnInit() {
// get raw data
let doneMissionRawData = await this.api.getAssignmentDone("MA_03_01", "");
// process the data
let processedDoneMission = await this.processDataDoneMission(doneMissionRawData);
// set data into array
this.doneMissionList = processedDoneMission;
}
```
- In **processDataDoneMission()** function:
```typescript=
async processDataDoneMission (dataJson: any) {
// add time stamp and machine details into json
let dataAddOn = [];
for (let i = 0 ; i < dataJson.length ; i++) {
let Data = dataJson[i];
let dateDetails = this.getDateDetail(Data['CompleteTime']);
let machineDetails = await this.api.getDispenserDetail(Data['Device_ID']);
let newJson = {
dateDetails,
Data,
machineDetails
};
dataAddOn.push(newJson);
}
// grouping by date
let dataGroupingDate = this.groupByDate(dataAddOn);
// processing data into new json form
let resultArray = [];
for (let i = 0 ; i < dataGroupingDate.length ; i++) {
let getObject = dataGroupingDate[i];
let Data = [];
for (let j = 0 ; j < getObject['Data'].length ; j++) {
let getData = getObject['Data'][j]['Data'];
let ReportImages = [];
if (getData['Complete_Index'] === 3) {
ReportImages.push({"ReportImage": this.convertBase64ToImage(getData['Complete_Source'])});
ReportImages.push({"ReportImage": this.convertBase64ToImage(getData['Complete_Source2'])});
ReportImages.push({"ReportImage": this.convertBase64ToImage(getData['Complete_Source3'])});
} else if (getData['Complete_Index'] === 2) {
ReportImages.push({"ReportImage": this.convertBase64ToImage(getData['Complete_Source'])});
ReportImages.push({"ReportImage": this.convertBase64ToImage(getData['Complete_Source2'])});
} else if (getData['Complete_Index'] === 1) {
ReportImages.push({"ReportImage": this.convertBase64ToImage(getData['Complete_Source'])});
}
let MissionTimeOnlyHour = this.getHourMinuteFromDateString(getData['CompleteTime']);
let newData = {
"ClientName": "..." ,
"ClientAddress": "..." ,
"MissionTime": getData['CompleteTime'] ,
"MissionTimeOnlyHour": MissionTimeOnlyHour ,
"ClientPhone": "..." ,
"ClientContactPerson": "..." ,
"MachineType": getObject['Data'][j]['machineDetails']['Type'] ,
"MachineNumber": "..." ,
"ErrorCode": getData['ErrorType'] ,
"ProblemOccured": getData['Description'] ,
"NotificationTime": getData['NotifyTime'] ,
"Repairman": getData['Maintainer'] ,
"ClientNumber": "..." ,
"MissionNumber": getData['MissionNumber'] ,
"ReportIndex": getData['Complete_Index'] ,
"ReportImages": ReportImages
}
Data.push(newData);
}
let newDate = this.convertApiTimeToDate(Data[0]['MissionTime']);
let newDayString = this.dayNameArray[newDate.getDay()];
let newMonthString = this.monthNameArray[newDate.getMonth()];
let DateString = newMonthString + " " + newDate.getDate();
let newData = {
"DateString": DateString ,
"DayString": newDayString ,
"Date": newDate ,
"Data": Data
};
resultArray.push(newData);
}
return resultArray;
}
```
- If you see from my last report on **[here](https://hackmd.io/@muhamadaldy/rkl1PUZQH)**, you can see in several line, like in line 7, parameter to determine time is changing from `RepairDoneTime` into `CompleteTime`.
- This changes is because the value inside the previous parameter is not set and can make the code broken, there is a function that parsing the date and if the value is wrong then it will stop working.
- This changes only occur before the data being corrected, once the data is corrected and values in all parameter needed is set then we can change it back into `RepairDoneTime` as we needed.
- Result in display
<center>
<img src="https://raw.githubusercontent.com/aru1702/images/master/ntust-documentation/39-01.JPG" style="max-width: 250px" />
</center>
<br>
- Result in log
<center>
<img src="https://raw.githubusercontent.com/aru1702/images/master/ntust-documentation/39-02.JPG" />
</center>
<br>
- As we can see in the log that the data was received from the API so there still missing parameter even the time for some parameter.
- The data is successfully converted into JSON format for Done Mission and displayed in front end code with HTML and SCSS.
- For next the data should be manipulate by adding value into parameter that should has timestamp.
- To do this, I have asked Mr. Johnny to help me installing the Robo3T to access the MongoDb from my computer.
- He already gives me the access and will test tomorrow.
---
## Conclusion
- Testing using the data from the API, change some parameter in the backend code (.ts) because the time component (RepairDoneTime) which is used for determine the timestamp doesn't has value, change using CompleteTime.
- Testing is done and the result can be displayed although some parameter still missing and Mr. Johnny, my mentor, said that he is on progress for creating the authentication database for repairman and the rest of API needed.
- Has installing Robo3T to access the MongoDB (database) of smart dispenser, guided by Mr. Johnny and Thariq because last week Thariq already use this tool to verify the data.
---
Time: **18:05**
Event: Leaving the lab
###### tags: `on-intern`