# 6th August Report ## Progress Time: **09:00** Event: Entering the lab --- ### Modify data in database and test to Repairman App Time: **10:33** - I have install Robo3T to grant access into the smart dispenser database which Mr. Johnny has created. - I also have been allowed to modify with note that I shouldn't modify anything (like attributes, IDs, etc.), beyond testing purpose. - Mr. Johnny order me if I want to modify the data then create a new problem so it will be using my email and he knows that this is the data which I created for testing purpose only. - My data in JSON object: ```json= { "MissionNumber": 55, "Device_ID": "MA_03_01", "Email": "muhamadaldy17@gmail.com", "ErrorType": 1, "Description": "Button does not respond", "Status": 7, "UploadTime": "2019-08-04 12:00:00", "NotifyTime": "2019-08-05 08:00:00", "ConfirmTIme": "2019-08-05 10:00:00", "RepairCallTime": "2019-08-05 16:00:00", "RepairDoneTime": "2019-08-06 10:00:00", "MaintenanceDoneTime": "2019-08-06 11:00:00", "CompleteTime": "2019-08-06 12:00:00", "Maintainer": "Mr. Thariq", "Maintainer_ID": "1", "Result": "Somebody set us up a prank.", "Index": 0, "Source": "", "Source2": "", "Source3": "", "ArriveTime": "2019-08-06 08:00:00", "Complete_Index": 0, "Complete_Source": "", "Complete_Source2": "", "Complete_Source3": "", "Archive": false, "Delete": false } ``` - In Repairman App on Done Mission fragment, changes back the code, where last report I change the time parameter, from `CompleteTime` back to `RepairDoneTime`: - Result in display: <center> <img src="https://raw.githubusercontent.com/aru1702/images/master/ntust-documentation/40-01.JPG" style="max-width:250px" /> </center> <br> - We can see in the data JSON object above that `RepairDoneTime` has value **2019-08-06 10:00:00** so it is **August 6th on 10:00 A.M**. - From image we have one item that shows the data from above. - With this result it can be inferred that now the data from API is success to be retrived by the Repairman App. - With using the Employee ID, it will filtering which only get the data with the same ID from database, and the rest of them will be not included. --- ### Use many data to test all Home Page feature Time: **13:44** - In here I will create some report and modify them for three fragments in Home Page. - Done mission: 5 reports. - Today mission: 2 reports. - Future mission: 3 reports. - Some of reports will be grouped with same day, except for Today mission which is must be, to get group item in Done and Future mission. - For Done mission I will add base64 picture to be displayed in Done Mission item, using the dummy picture of "typescript lifecycle" because only for testing purpose. - To parsing the data from API into proper format, the Dispenser API service which filter the data should be modified to adjust some changes. - Add class named **Unit Converter** to convert unit to unit (like from API format to Date object), basically this class will has all the `public static` type function which can be called anytime and anywhere in same project. - In **unit-converter.class.ts**: ```typescript= export class UnitConverter { public static convertApiTimeToJson (time: string) { let splitTime = time.split(" "); let resultDate = splitTime[0]; let splitDate = resultDate.split("-"); let resultYear = splitDate[0]; let resultMonth = splitDate[1]; let resultDateOfMonth = splitDate[2]; let resultHour = splitTime[1]; let splitHour = resultHour.split(":"); let resultHourC = splitHour[0]; let resultMinute = splitHour[1]; let resultSecond = splitHour[2]; let newDate = { 'Year': resultYear, 'Month': resultMonth, 'DateOfMonth': resultDateOfMonth, 'Hour': resultHourC, 'Minute': resultMinute, 'Second': resultSecond }; return newDate; } public static convertApiTimeToDate (time: any) { let splitTime = time.split(" "); let resultDate = splitTime[0]; let splitDate = resultDate.split("-"); let resultYear = splitDate[0]; let resultMonth = splitDate[1] - 1; let resultDateOfMonth = splitDate[2]; let resultHour = splitTime[1]; let splitHour = resultHour.split(":"); let resultHourC = splitHour[0]; let resultMinute = splitHour[1]; let resultSecond = splitHour[2]; let newDate = new Date( resultYear, resultMonth, resultDateOfMonth, resultHourC, resultMinute, resultSecond, 0 ); return newDate; } } ``` - In **dispenser-api.service.ts**: ```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; } async getAssignmentToday (device_id: string, employee_id: string, nowTime: 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 = 4 and repair call time if (data[i]['Status'] === 4 && data[i]['RepairCallTime'] !== "") { let missionTime = UnitConverter.convertApiTimeToJson(data[i]['RepairCallTime']); let currentTime = UnitConverter.convertApiTimeToJson(nowTime); // if data has same day as mission deadline if ( missionTime['Year'] === currentTime['Year'] && missionTime['Month'] === currentTime['Month'] && missionTime['DateOfMonth'] === currentTime['DateOfMonth'] ) { let dateCurrentTime = UnitConverter.convertApiTimeToDate(nowTime).getTime(); let dateMissionTime = UnitConverter.convertApiTimeToDate(data[i]['RepairCallTime']).getTime(); // if data is under the deadline time if (dateCurrentTime <= dateMissionTime) { // put into data will be returned returnArray.push(data[i]); } } } } } return returnArray; } async getAssignmentNext (device_id: string, employee_id: string, nowTime: 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 = 4 and repair call time if (data[i]['Status'] === 4 && data[i]['RepairCallTime'] !== "") { let missionTime = UnitConverter.convertApiTimeToJson(data[i]['RepairCallTime']); let currentTime = UnitConverter.convertApiTimeToJson(nowTime); if (missionTime['Year'] >= currentTime['Year']) { if (missionTime['Month'] >= currentTime['Month']) { if (missionTime['DateOfMonth'] > currentTime['DateOfMonth']) { returnArray.push(data[i]); } } } } } } return returnArray; } ``` - In line 39 and 40 we call **Unit Converter** class which `convertApiTimeToJson()` function is to convert from API time format to JSON object. - In line 49 and 50 we have convert the time into Date format, then call the `getTime()` to convert into number format. **FYI**: `getTime()` function is from Date class function, not defined in the Unit Converter class. - After we have both in number form we check if the `missionTime` still above than `currentTime`, means that the mission for today is still valid. - Different from in line 84 to 87, it filter the mission that not in today Date. - The concept: Today Mission and Future/Next Mission have the same way to check the data from API, the difference is Today Mission gets the data that only valid for today and below the `missionTime` and Future/Next Mission gets the data that above from `missionTime` but not today. --- Time: **16:53** - In Done Mission on Home page: - Code in **home.page.ts** ```typescript= async ngOnInit () { let currentTime = this.convertDateToApiTimeFormat(new Date()); let device_id = "MA_03_01"; let employee_id = "1"; let doneMissionRawData = await this.api.getAssignmentDone(this.device_id, this.employee_id); let processedDoneMission = await this.processDataDoneMission(doneMissionRawData); this.doneMissionList = processedDoneMission; } ``` - The `convertDateToApiTimeFormat()` function is to convert the Date object from Date class into API time format as string. - **Result in page** <center> <img src="https://raw.githubusercontent.com/aru1702/images/master/ntust-documentation/40-02.JPG" style="max-width:250px" /> </center> <br> - We can see that the "typescript lifecycle" image(s) can be seen on third item, this means that the report from repairman has pictures. - It still continue to bottom that consists of 5 data which is the data from API with parameters `Device_ID` equals to **MA_03_01** and `Maintainer_ID` equals to **1**. - In Today Mission on Home page: - Code in **home.page.ts** ```typescript= async ngOnInit () { let currentTime = this.convertDateToApiTimeFormat(new Date()); let device_id = "MA_03_01"; let employee_id = "1"; let todayMissionRawData = await this.api.getAssignmentToday(this.device_id, this.employee_id, this.currentTime); let processedTodayMission = await this.processDataTodayMission(todayMissionRawData); this.todayMissionList = processedTodayMission; } ``` - **Result in page** <center> <img src="https://raw.githubusercontent.com/aru1702/images/master/ntust-documentation/40-03.JPG" style="max-width:250px" /> </center> <br> - This picture was taken on the same time as the documentation has been created, around 16:50 to 17:10. - When we change one of the item data on `RepairCallTime` from 20:00 to 16:00, means that it is below that the `currentTime`, that item will be discarded from Today Mission. <br> <center> <img src="https://raw.githubusercontent.com/aru1702/images/master/ntust-documentation/40-04.JPG" /> </center> <br> <center> <img src="https://raw.githubusercontent.com/aru1702/images/master/ntust-documentation/40-05.JPG" style="max-width:250px" /> </center> <br> - In Future Mission on Home page: - Code in **home.page.ts** ```typescript= async ngOnInit () { let currentTime = this.convertDateToApiTimeFormat(new Date()); let device_id = "MA_03_01"; let employee_id = "1"; let futureMissionRawData = await this.api.getAssignmentNext(this.device_id, this.employee_id, this.currentTime); let processedFutureMission = await this.processDataFutureMission(futureMissionRawData); this.futureMissionList = processedFutureMission; } ``` - **Result in page** <center> <img src="https://raw.githubusercontent.com/aru1702/images/master/ntust-documentation/40-06.JPG" style="max-width:250px" /> </center> <br> - Future Mission has similar design to Done Mission fragment on Home page so it will look alike. - Based on the system which I have describe in Today Mission, the data on Future Mission have `missionTime` above than now time or `currentTime` but not "today" date. --- ## Conclusion - Use the Robo3T to access the database, do the testing Home Page by set some attributes which is the value hasn't set yet. - By adding the timestamp on some time uses attributes and Maintainer ID now the data will resemble as the real data in their status, for example the item with status equals to 7 must has all timestamp being set, value in result of repairment, and maintainer information. - To modify the database, I must create new data by add the report problem using the User/Student App and modify the value of parameter needed. - Result in three parts/fragments of Home Page is successful, three of them can display the data although using the dummy data with self-insert to the database. --- Time: **18:10** Event: Leaving the lab ###### tags: `on-intern`