read_db.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. header("content-type: application/json");
  3. ini_set('display_errors', 1);
  4. ini_set('display_startup_errors', 1);
  5. error_reporting(E_ALL);
  6. // connect to the mongo database
  7. $m = new MongoDB\Driver\Manager("mongodb://root:oebb@mongo:27017");
  8. //radsatznummer should be given as a search parameter
  9. //if wrong throw back an error
  10. #$radsatz = '023977AA#1';
  11. $radsatz = $_GET['radsatz'];
  12. $filter = ['overhauls.radsatznummer' => $radsatz];
  13. //retrieve stationsnummer and taetigkeiten if the exist
  14. $options_taetigkeiten = ['projection' => ['_id' => 0, 'overhauls.process.schadcodes' =>1, 'overhauls.final_state.ist_schrott' => 1, 'overhauls.radsatznummer' => 1, 'overhauls.final_state.station_path' => 1, 'overhauls.process.stationsname' => 1, 'overhauls.process.stationsnummer' => 1, 'overhauls.process.prediction' => 1, 'overhauls.process.taetigkeiten.name' => 1 ]];
  15. $query_taetigkeiten = new MongoDB\Driver\Query($filter,$options_taetigkeiten);
  16. $cursor_taetigkeiten = $m->executeQuery('oebb.process_instances',$query_taetigkeiten);
  17. $res = array();
  18. $codes = array();
  19. foreach ($cursor_taetigkeiten as $document) {
  20. foreach ($document as $overhauls) {
  21. foreach ($overhauls as $overhaul) {
  22. if($overhaul->radsatznummer == $radsatz){
  23. foreach($overhaul->process as $process) {
  24. array_push($res,$process->stationsname);
  25. $proc = $process->taetigkeiten[0];
  26. // retrieve schrott from process instance
  27. if (property_exists($process, 'prediction') && $process->stationsnummer == 110) {
  28. $schrott = $process->prediction;
  29. $result['schrott'] = array('station' => $process->stationsnummer, 'tatsächlicher Status' => $overhaul->final_state->ist_schrott,'schrott'=> $schrott->schrott_probability, 'Vorhersage' => $schrott->schrott, 'Wahrscheinlickeitsgrenze' => $schrott->probability_limit);
  30. foreach($process->schadcodes as $schadcode) {
  31. $code = $schadcode->code;
  32. array_push($codes, $code);
  33. }
  34. }
  35. if(!empty((array)$proc)){
  36. array_push($res,$process->taetigkeiten[0]->name);
  37. }
  38. }
  39. //retrieve the stations path of wheelset
  40. $result['path'] = json_encode($overhaul->final_state->station_path);
  41. }
  42. }
  43. }
  44. }
  45. $result['schadcodes'] = $codes;
  46. $result['taetigkeiten'] = $res;
  47. //retrieve components
  48. $radsatz = explode("#",$radsatz)[0];
  49. $filter = ['radsatznummer' => $radsatz];
  50. $tauschgruppe = array();
  51. //check for radbremsscheiben_vorhanden || bremsscheibe
  52. $options_components = ['projection' => ['_id' => 0, 'radbremsscheiben_vorhanden' => 1, 'bremsscheibe' => 1, 'lager.typ' => 1]];
  53. $query_components = new MongoDB\Driver\Query($filter,$options_components);
  54. $cursor_components = $m->executeQuery('oebb.components',$query_components);
  55. //check for bremsscheibe && Lagertyp
  56. foreach ($cursor_components as $document) {
  57. if(property_exists($document, 'radbremsscheiben_vorhanden') or property_exists($document, 'bremsscheibe')) {
  58. $result['tauschgruppe'] = array("bremsscheiben" => true);
  59. // array_push($tauschgruppe, array("bremsscheibe" => true));
  60. }
  61. else {
  62. $result['tauschgruppe'] = array("bremsscheiben" => false);
  63. // array_push($tauschgruppe, array("bremsscheibe" => false));
  64. }
  65. $result['lagerbauart'] = $document->lager->typ;
  66. }
  67. //check for innenring
  68. $filter_ir = ['radsatznummer' => $radsatz, 'innenring' => ['$exists' => true]];
  69. $query_ir = new MongoDB\Driver\Query($filter_ir);
  70. $cursor_ir = $m->executeQuery('oebb.components',$query_ir);
  71. if(iterator_to_array($cursor_ir)) {
  72. $result['innenring'] = true;
  73. }
  74. else {
  75. $result['innenring'] = false;
  76. }
  77. $options_wheelsets = ['projection' => ['_id' => 0, 'bearbeitungstyp' => 1, 'hochregallager_oder_massenlager' => 1, 'wellentyp' => 1]];
  78. $query_wheelsets = new MongoDB\Driver\Query($filter, $options_wheelsets);
  79. $cursor_wheelsets = $m->executeQuery('oebb.wheelsets', $query_wheelsets);
  80. //check whether it is a Gueter- or personenzug
  81. foreach($cursor_wheelsets as $document) {
  82. if($document->hochregallager_oder_massenlager == 'massenlager') {
  83. #array_push($tauschgruppe, 'gueterzug');
  84. $result['zug'] = 'gueterzug';
  85. } else {
  86. $result['zug'] = 'personenzug';
  87. #array_push($tauschgruppe, array('zug' => 'personenzug'));
  88. }
  89. $result['bearbeitungsstufe'] = $document->bearbeitungstyp;
  90. $result['wellentyp'] = $document->wellentyp;
  91. }
  92. #$result['tauschgruppe'] = $tauschgruppe;
  93. echo json_encode($result);