Jump to content

RohanH

Members
  • Posts

    35
  • Joined

Everything posted by RohanH

  1. Thanks for the help, also the explanation for each step which cleared certain concepts for me! 🙂
  2. I want to display the column in the cli but I fail to do so! This is what I tried to print in cli. foreach($results_by_date as $name => $work) { foreach($work as $kdate => $date) { if($kdate == 'date'){ echo $date. "\n"; }else{ foreach($date as $kdata => $date_data){ foreach($date_data as $kdatakey => $data){ echo " " . $data. "\n"; } } } } }
  3. how we do so using assertions or it will be simple try and catch (I mean to ask is how to we realize that the test failed)? Another question is to run the test do we create the test function (using the foreach loops and print the column value?) and then call the file like ?
  4. And again, if we want to test this json?
  5. okay, and as per the random order of data in our table will it still work?
  6. No clue, they just skyped me the zip which had this broken html code.
  7. Will it still not be an issue to detect the data pattern and assign the field names?
  8. And just realized that. Also realized that no matter what we do because there is no identifiable pattern we cannot get the field names and data organized. They got the table so messed up! I am not sure how they want us to figure out which field belongs to which data, do you suggest me to submit the task without the field names? Because, from where I can see the data is ultimately going to be incorrect given the field names, also they want us to perform the test what test can we really perform in this json data model?
  9. So, the sequence was given as an example i am just using that as a reference. for ($i = 1; $i <= 4; $i++) { foreach ($results[$i] as $key => $sdata) { if (!empty($sdata[0]) && $sdata[0] != '&nbsp;') { if ($sdata[0] == 'N/A') { $res[$key]['student_details'] = $sdata[0]; } else { foreach ($sdata as $rkey => $rdata) { $replace_nbsp = str_replace("&nbsp;", "null", $rdata); if ($rkey == 0) { $new_arr['student_id'] = ($rdata != '&nbsp;') ? $rdata : $replace_nbsp; } else if ($rkey == 1) { $new_arr['report_time'] = ($rdata != '&nbsp;') ? $rdata : $replace_nbsp; } else if ($rkey == 2) { $new_arr['leaving_time'] = ($rdata != '&nbsp;') ? $rdata : $replace_nbsp; } else if ($rkey == 3) { $new_arr['office'] = ($rdata != '&nbsp;') ? $rdata : $replace_nbsp; } else if ($rkey == 4) { $new_arr['start_time'] = ($rdata != '&nbsp;') ? $rdata : $replace_nbsp; } else if ($rkey == 5) { $new_arr['destination'] = ($rdata != '&nbsp;') ? $rdata : $replace_nbsp; } } $res[$key]['student_details'][] = $new_arr; } } } }
  10. What can possibly be the criteria to test the json output in this case, can you suggest? so that I can be aware of them and maybe show an example too?
  11. {"0":{"date":"May29Tue","student_details":"N\/A"},"1":{"date":"May30Wed","student_details":[{"student_id":"AAVL","report_time":"06:00","leaving_time":"14:00","office":"null","start_time":"null","destination":"null"}]},"2":{"date":"May31Thu","student_details":[{"student_id":"8751","report_time":"03:55","leaving_time":"04:55","office":"WFH","start_time":"COMP AVL","destination":"08:00"},{"student_id":"8752","report_time":"08:35","leaving_time":"COMP AVL","office":"WFH","start_time":"11:55","destination":"12:25"}]},"3":{"date":"Jun01Fri","student_details":[{"student_id":"8462","report_time":"04:30","leaving_time":"05:30","office":"WFH","start_time":"COMP NOT AVL","destination":"07:10"},{"student_id":"8465","report_time":"07:45","leaving_time":"COMP NOT AVL","office":"WFH","start_time":"09:20","destination":"09:50"}]},"4":{"date":"Jun02Sat","student_details":[{"student_id":"CBSE","report_time":"02:00","leaving_time":"10:00","office":"null","start_time":"null","destination":"null"}]},"5":{"date":"Jun03Sun","student_details":"N\/A"},"6":{"date":"Jun04Mon","student_details":"N\/A"},"7":{"date":"Jun05Tue","student_details":"N\/A"},"8":{"date":"Jun06Wed","student_details":"N\/A"},"9":{"date":"Jun07Thu","student_details":"N\/A"},"10":{"date":"Jun08Fri","student_details":[{"student_id":"8113","report_time":"05:05","leaving_time":"06:05","office":"WFH","start_time":"ZRH","destination":"07:50"},{"student_id":"8114","report_time":"08:25","leaving_time":"ZRH","office":"WFH","start_time":"10:10","destination":"null"},{"student_id":"8277","report_time":"11:05","leaving_time":"WFH","office":"MAD","start_time":"13:40","destination":"14:10"}]},"11":{"date":"Jun09Sat","student_details":[{"student_id":"8274","report_time":"04:00","leaving_time":"05:00","office":"MAD","start_time":"WFH","destination":"07:25"},{"student_id":"8221","report_time":"08:10","leaving_time":"WFH","office":"VLC","start_time":"10:30","destination":"null"},{"student_id":"8222","report_time":"11:05","leaving_time":"VLC","office":"WFH","start_time":"14:00","destination":"14:30"}]},"12":{"date":"Jun10Sun","student_details":"N\/A"},"13":{"date":"Jun11Mon","student_details":"N\/A"},"14":{"date":"Jun12Tue","student_details":[{"student_id":"AAVL","report_time":"05:15","leaving_time":"13:15","office":"null","start_time":"null","destination":"null"}]},"15":{"date":"Jun13Wed","student_details":[{"student_id":"8973","report_time":"04:05","leaving_time":"05:05","office":"WFH","start_time":"SOF","destination":"08:05"},{"student_id":"8974","report_time":"08:50","leaving_time":"SOF","office":"WFH","start_time":"12:10","destination":"12:40"}]},"16":{"date":"Jun14Thu","student_details":[{"student_id":"ADTY","report_time":"09:30","leaving_time":"16:30","office":"null","start_time":"null","destination":"null"}]},"17":{"date":"Jun15Fri","student_details":[{"student_id":"8233","report_time":"12:25","leaving_time":"13:25","office":"WFH","start_time":"SSP","destination":"15:40"},{"student_id":"8237","report_time":"16:10","leaving_time":"SSP","office":"WFH","start_time":"18:25","destination":"18:55"}]},"18":{"date":"Jun16Sat","student_details":"N\/A"},"19":{"date":"Jun17Sun","student_details":"N\/A"},"20":{"date":"Jun18Mon","student_details":[{"student_id":"807","report_time":"11:35","leaving_time":"12:35","office":"WFH","start_time":"OMV","destination":"14:10"},{"student_id":"808","report_time":"14:35","leaving_time":"OMV","office":"WFH","start_time":"16:15","destination":"null"},{"student_id":"837","report_time":"16:50","leaving_time":"WFH","office":"BFS","start_time":"18:25","destination":"null"},{"student_id":"840","report_time":"18:55","leaving_time":"BFS","office":"WFH","start_time":"20:25","destination":"20:55"}]},"21":{"date":"Jun19Tue","student_details":[{"student_id":"8551","report_time":"10:50","leaving_time":"11:50","office":"WFH","start_time":"MJV","destination":"14:30"},{"student_id":"8552","report_time":"15:00","leaving_time":"null","office":"WFH","start_time":"17:40","destination":"null"},{"student_id":"8187","report_time":"18:55","leaving_time":"WFH","office":"LIN","start_time":"20:50","destination":"21:20"}]},"23":{"date":"N\/A","student_details":[{"student_id":"06:00","report_time":"14:00","leaving_time":"null","office":"null","start_time":"null","destination":"null"}]},"24":{"date":"AAVL","student_details":[{"student_id":"03:55","report_time":"04:55","leaving_time":"WFH","office":"COMP AVL","start_time":"08:00","destination":"null"},{"student_id":"08:35","report_time":"COMP AVL","leaving_time":"WFH","office":"11:55","start_time":"12:25","destination":"null"}]},"25":{"date":"8751","student_details":[{"student_id":"04:30","report_time":"05:30","leaving_time":"WFH","office":"COMP NOT AVL","start_time":"07:10","destination":"null"},{"student_id":"07:45","report_time":"COMP NOT AVL","leaving_time":"null","office":"09:20","start_time":"09:50","destination":"null"}]},"26":{"date":"8462","student_details":[{"student_id":"02:00","report_time":"10:00","leaving_time":"null","office":"null","start_time":"null","destination":"null"}]}} This here is the output, which I parsed to json that is the format they want for the output. And there is no such criteria for the test is defined, it simply says that the output must be validated by a test.
  12. Yes, that is what I intend to do basically but I am not sure how! Final task says I will need to validate the output with a test.
  13. But dont i need to write some script to perform the test on the output ?
  14. FINALLY !! Thank you ... It works... !!!😀 Now, one last doubt if I want to perform test in this(also get the output in command line) how can I do that?
  15. If they want me to add the N/A, No Record etc, in the same array along with the dates what do we change here? And when they talk about test here what can possibly be the test? it says : " Validates the output with a test, executable from command line along with the result."
  16. Okay, got that! But then now I am getting the dates seperately and not with the student data like previously I was getting the student data w.r.t the dates!
  17. Okay my bad it was the incorrect variable range it should be ranges
  18. This right here is not really giving me any output. This here needs any fix? $html = file_get_contents('modified.html'); // the table html $range = [ [ 'start' => ['r' => 5, 'c' => 0], // specify block of rows/cols 'end' => ['r' => 11, 'c' => 21] // ( top left is r=0 c=0 ) ], [ 'start' => ['r' => 13, 'c' => 0], 'end' => ['r' => 18, 'c' => 21] ], [ 'start' => ['r' => 19, 'c' => 0], 'end' => ['r' => 24, 'c' => 21] ], [ 'start' => ['r' => 25, 'c' => 0], 'end' => ['r' => 30, 'c' => 21] ] ]; function getColumns(&$html, $range) { $rows = []; $kr = 0; $p1 = 0; // find first row in out range for ($r = 0; $r <= $range['start']['r']; $r++) { $p1 = strpos($html, '<tr', $p1); ++$p1; } $p1--; for ($kr = $range['start']['r']; $kr <= $range['end']['r']; $kr++) { $rows[$kr] = getCells($html, $range, $p1); $p1 = strpos($html, '<tr', $p1 + 1); } $cols = []; for ($kc = $range['start']['c']; $kc <= $range['end']['c']; $kc++) { $cols[] = array_column($rows, $kc); } return $cols; } function getCells(&$html, $range, $p1) { $cells = []; for ($kc = $range['start']['c']; $kc <= $range['end']['c']; $kc++) { $p1 = strpos($html, '<td', $p1 + 1); $p1 = strpos($html, '>', $p1 + 1); $p2 = strpos($html, '<td', $p1); $cells[$kc] = trim(strip_tags(substr($html, $p1 + 1, $p2 - $p1 - 1))); } return $cells; } foreach ($ranges as $range) { $results[] = getColumns($html, $range); } echo '<pre>' . print_r($results, 1) . '</pre>';
  19. Okay, I guess we can put a check there to look for available data if student is found, then it inserts the data to the array. I am just presuming it, can I try doing that or it will be a foolish approach?
  20. THANKS AGAIN!! This here is another + for me in this task as the research task description says "Other information on the table may be ignored, but we appreciate it if you manage to fetch other information from the table, e.g. Not Available (N/A).". So basically apart from N/A, No Record etc, the array is supposed to contain 21 students.
  21. Well it works!!! Thank you 😄 but i just noticed that for a particular day only single record is getting fetched, is it possible to get all the students data for a particular day? Like here for june 09 we have 3 students, is it not possible to get record for all three students in the same array ?
  22. Probably the creator of the table must be awarded for creating such a table!! I have no clue how but the other who is also a fellow researcher (python) he somehow got the result !! And oh yes he wont show me how he did that! He claims that his result can take n number of rows and still produce the output.. He also got working unit tests for that! As we have already tried simple_html_dom and simplexml I am now trying with goutte I am not sure if it is even possible in php (only if the other fellow got some result in python). Also if there is any finding anyone comes across please share the same!!
  23. yes these are 3 students, so for the given table it should produce around 21 objects. So we have three student id here 8274, 8221, 8222
  24. I just tried adding some css. With a hope that someone can help me with some idea!!
  25. It is there, well it is not labelled though which makes it more confusing.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.