briggySmalls / late-train-mate

A lightweight website that provides stats on delayed or cancelled UK train services
MIT License
0 stars 0 forks source link

Metric/stat mismatch! reported #6

Open briggySmalls opened 7 years ago

briggySmalls commented 7 years ago

The trains.py source code is sometimes triggering the assertion:

File "/Users/sambriggs/Code/Python/late-train-mate/late_train_mate/trains/trains.py", line 247, in _delays_in_service
    "Metric/stat mismatch!")
AssertionError: Metric/stat mismatch!

This bug should be eliminated

briggySmalls commented 7 years ago

This appears to be contradictory behaviour in the HSP API. A request to the serviceMetrics endpoint with a body of:

{
    "from_loc": "FPK",
    "to_loc": "CBG",
    "from_time": "0551",
    "to_time": "0600",
    "from_date": "2016-12-04",
    "to_date": "2016-12-11",
    "days": "SATURDAY",
    "tolerance": [
        30
    ]
}

Returns

{
  "header": {
    "from_location": "FPK",
    "to_location": "CBG"
  },
  "Services": [
    {
      "serviceAttributesMetrics": {
        "origin_location": "KGX",
        "destination_location": "CBG",
        "gbtt_ptd": "0551",
        "gbtt_pta": "0655",
        "toc_code": "GN",
        "matched_services": "1",
        "rids": [
          "201612107170606"
        ]
      },
      "Metrics": [
        {
          "tolerance_value": "0",
          "num_not_tolerance": "1",
          "num_tolerance": "0",
          "percent_tolerance": "0",
          "global_tolerance": true
        },
        {
          "tolerance_value": "30",
          "num_not_tolerance": "1",
          "num_tolerance": "0",
          "percent_tolerance": "0",
          "global_tolerance": false
        }
      ]
    }
  ]
}

I.e. the single relevant service was outside of the 30 minute tolerance specified. However a request to the serviceDetails endpoint with the RID taken from the previous response returns:

{
  "serviceAttributesDetails": {
    "date_of_service": "2016-12-10",
    "toc_code": "GN",
    "rid": "201612107170606",
    "locations": [
      {
        "location": "KGX",
        "gbtt_ptd": "0545",
        "gbtt_pta": "",
        "actual_td": "0544",
        "actual_ta": "",
        "late_canc_reason": "525"
      },
      {
        "location": "FPK",
        "gbtt_ptd": "0551",
        "gbtt_pta": "0550",
        "actual_td": "0551",
        "actual_ta": "0549",
        "late_canc_reason": "525"
      },
      ...
      {
        "location": "CBG",
        "gbtt_ptd": "",
        "gbtt_pta": "0655",
        "actual_td": "",
        "actual_ta": "0659",
        "late_canc_reason": "525"
      }
    ]
  }
}

Which indicates the delay was only 4 minutes.

briggySmalls commented 7 years ago

Post on the Google group API can be found here: https://groups.google.com/forum/#!topic/openraildata-talk/lF85nF1bnGE