Skip to content

Latest commit

 

History

History
704 lines (677 loc) · 17.6 KB

notes.md

File metadata and controls

704 lines (677 loc) · 17.6 KB

Useful URLs

Offical website for query bus information

http://test.zhbuswx.com/BusLine/BusQuery.html#/

Get all latest bus status by line# and head station

http://test.zhbuswx.com/RealTime/GetRealTime?id=K1&fromStation=%E5%9F%8E%E8%BD%A8%E7%8F%A0%E6%B5%B7%E5%8C%97%E7%AB%99

{
  "flag":1002,
  "data":[
    {
      "BusNumber":"粤C00983D",
      "CurrentStation":"唐家",
      "LastPosition":"5"  // 只是表示状态, 8 = 已经离开车站, 5 = 在车站中停留
    },
    {
      "BusNumber":"粤C01739D",
      "CurrentStation":"柠溪",
      "LastPosition":"5"
    }
  ]
}

Search Line and get its details by keyword

http://test.zhbuswx.com/Handlers/BusQuery.ashx?handlerName=GetLineListByLineName&key=K1

Note: 注意同一路车有正反两个方向的线路

{
  "flag":1002,
  "data":[
    {
      "Id":"62cb5f6c-a3eb-40da-828f-78f34af99b20", <
      "Name":"K1",
      "LineNumber":"K1", <
      "Direction":0,
      "FromStation":"城轨珠海北站", <
      "ToStation":"拱北口岸总站", <
      "BeginTime":"06:05",
      "EndTime":"21:15",
      "Price":"3",
      "Interval":"17",
      "Description":"",
      "StationCount":18
    },
    {
      "Id":"cd013090-b695-4501-8a27-f3365d37cfb9",
      "Name":"K1",
      "LineNumber":"K1",
      "Direction":1,
      "FromStation":"拱北口岸总站",
      "ToStation":"城轨珠海北站",
      "BeginTime":"7:10",
      "EndTime":"22:25",
      "Price":"3",
      "Interval":"17",
      "Description":"",
      "StationCount":17
    }
  ]
}

Get station list by LineId

http://test.zhbuswx.com/StationList/GetStationList?id=62cb5f6c-a3eb-40da-828f-78f34af99b20

注意参数是LineId而不是LineNumber

{
  "flag":1002,
  "data":[
    {
      "Id":"ee5dd05e933248d1bb21b2e05391c35f",  <
      "Name":"城轨珠海北站",  <
      "Lng":"113.546275",
      "Lat":"22.405286",
      "Description":""
    },
    {
      "Id":"e32d190b672c4ae39dd6f12be31906c5",
      "Name":"罗西尼",
      "Lng":"113.547563",
      "Lat":"22.393576",
      "Description":""
    },
    {
      "Id":"8891bd56e6164c5ca32061187827fba0",
      "Name":"官塘",
      "Lng":"113.548082",
      "Lat":"22.380580",
      "Description":""
    },
    {
      "Id":"878050c46df3443cb8285bed974256f0",
      "Name":"南方软件园",
      "Lng":"113.569040",
      "Lat":"22.376513",
      "Description":""
    },
    {
      "Id":"497dd86a03b84b3e98941f4e921e5014",
      "Name":"海怡湾畔",
      "Lng":"113.587213",
      "Lat":"22.371210",
      "Description":""
    },
    {
      "Id":"4e66098018dc46ce82f8b5bdcd8cdbf9",
      "Name":"唐家市场",
      "Lng":"113.594163",
      "Lat":"22.361467",
      "Description":""
    },
    {
      "Id":"c79b96ca324e4609a9222450070e4fdc",
      "Name":"唐家",
      "Lng":"113.592342",
      "Lat":"22.358032",
      "Description":""
    },
    {
      "Id":"3a36a475daf74127a2584ea4dd34c223",
      "Name":"中山大学",
      "Lng":"113.587692",
      "Lat":"22.350598",
      "Description":""
    },
    {
      "Id":"40f98714310c45f083ee5b392bf1e4cd",
      "Name":"中大五院",
      "Lng":"113.568775",
      "Lat":"22.299097",
      "Description":""
    },
    {
      "Id":"8638c455a424445d8b5122b4a0628d9c",
      "Name":"香洲总站",
      "Lng":"113.561088",
      "Lat":"22.281890",
      "Description":""
    },
    {
      "Id":"986531bc5af04121a7a5bbbf27854cfb",
      "Name":"南坑",
      "Lng":"113.560798",
      "Lat":"22.278653",
      "Description":""
    },
    {
      "Id":"a12c061f76a24150b1f5cfe77f61858b",
      "Name":"香宁花园",
      "Lng":"113.552978",
      "Lat":"22.269285",
      "Description":""
    },
    {
      "Id":"fcfcde50c07e440ab044dbfae7b880c3",
      "Name":"柠溪",
      "Lng":"113.546385",
      "Lat":"22.263207",
      "Description":""
    },
    {
      "Id":"0d3d1f8a30044b689b87694dc65c1e36",
      "Name":"隧道南",
      "Lng":"113.545200",
      "Lat":"22.243733",
      "Description":""
    },
    {
      "Id":"d7db6ef4ddcb45b69f166e10751a2d44",
      "Name":"摩尔广场",
      "Lng":"113.546222",
      "Lat":"22.237328",
      "Description":""
    },
    {
      "Id":"c7a1c6413c8b44219dd1a4d8d265ac62",
      "Name":"华侨宾馆",
      "Lng":"113.546868",
      "Lat":"22.233377",
      "Description":""
    },
    {
      "Id":"57c5d2808dc74ebbb70e26d85368405f",
      "Name":"拱北",
      "Lng":"113.547950",
      "Lat":"22.224850",
      "Description":""
    },
    {
      "Id":"8b30950285a24e929bbbab85ce56ccd1",
      "Name":"拱北口岸总站",
      "Lng":"113.550592",
      "Lat":"22.220958",
      "Description":""
    }
  ]
}

每次用户键入巴士线路号时, 会调用两个webservice分别获取Bus line basic info和station list, 数据拼装之后结构如下:

是一个两层的结构, 第一层是一个数组, 数组中每个元素就是一条线路的基本信息加上这条线路的所有站点, 所有站点作为第2层的数组赋值给stations属性. 这个数据结构会存入Options的DataCache中, key为lineNumber, value为相应路线的这个数据结构。

[
  {
    "uuid":"c72cd82b-be2f-4879-a4a2-f4c05ecf54fd",
    "lineNumber":"1",
    "fromStation":"香洲",
    "toStation":"城轨珠海站",
    "stations":[
      {
        "uuid":"09d3df05b61d4b57959762d9ed2f986c",
        "name":"香洲"
      },
      {
        "uuid":"986531bc5af04121a7a5bbbf27854cfb",
        "name":"南坑"
      },
      {
        "uuid":"583401abc31545abace9cd3f6c79b58c",
        "name":"拱北"
      },
      {
        "uuid":"83372752a25d4bbcbce138cfaf59bf31",
        "name":"城轨珠海站"
      }
    ]
  },
  {
    "uuid":"afec0bea-5532-4872-b06e-a1b5e97e4c3f",
    "lineNumber":"1",
    "fromStation":"城轨珠海站",
    "toStation":"香洲",
    "stations":[
      {
        "uuid":"83372752a25d4bbcbce138cfaf59bf31",
        "name":"城轨珠海站"
      },
      {
        "uuid":"3dd7a19e5f8c44ea8b69f84f508727bb",
        "name":"拱北口岸"
      },
      {
        "uuid":"d990386ef4bc457cb2c691512acce341",
        "name":"南坑"
      },
      {
        "uuid":"759cac0a7aed47aca0e7daf21e23c44e",
        "name":"香洲"
      }
    ]
  }
]

Local storage中的watchedLines的数据结构如下:

watchedLines就是一个数组, 其中每个元素就是用户的一条关注, key属性由line#、fromStation、notifyStation组成。

[  
  {  
    "fromStation":"城轨珠海站",
    "key":"10__城轨珠海站__城轨珠海站",
    "searchKey":"10__城轨珠海站",
    "lineNumber":"10",
    "lineUuid":"7e58c98a-89af-4293-8e01-4393ac5c9a09",
    "notifyStation":"城轨珠海站",
    "toStation":"下栅检查站"
  }
]

Background那边把watchedLines数组Reshape之后会变成如下一个k-v mapping, k为line# + fromStation:

{
  "12__九洲港":[
    {
      "fromStation":"九洲港",
      "key":"12__九洲港__石花东",
      "lineNumber":"12",
      "lineUuid":"4040c9b6-9fd3-498a-87a8-78363ccc9d2b",
      "notifyStation":"石花东",
      "searchKey":"12__九洲港",
      "toStation":"海虹总站"
    }
  ],
  "10__城轨珠海站":[
    {
      "fromStation":"城轨珠海站",
      "key":"10__城轨珠海站__华侨宾馆",
      "lineNumber":"10",
      "lineUuid":"7e58c98a-89af-4293-8e01-4393ac5c9a09",
      "notifyStation":"华侨宾馆",
      "searchKey":"10__城轨珠海站",
      "toStation":"下栅检查站"
    }
  ],
  "10__下栅检查站":[
    {
      "fromStation":"下栅检查站",
      "key":"10__下栅检查站__威士茂北门",
      "lineNumber":"10",
      "lineUuid":"cafdc508-74f1-4053-bdec-0975c45d91fd",
      "notifyStation":"威士茂北门",
      "searchKey":"10__下栅检查站",
      "toStation":"城轨珠海站"
    },
    {
      "fromStation":"下栅检查站",
      "key":"10__下栅检查站__北山村",
      "lineNumber":"10",
      "lineUuid":"cafdc508-74f1-4053-bdec-0975c45d91fd",
      "notifyStation":"北山村",
      "searchKey":"10__下栅检查站",
      "toStation":"城轨珠海站"
    }
  ]
}

bus-data-fetcher.js中fetchBusRealTimeData()函数返回的巴士实时数据如下

key为searchKey, value是保护这条线路上所有巴士实时数据的数组

{
   "1__香洲":[
      {
         "busNumber":"粤C28490",
         "currentStation":"中山亭",
         "status":"8"
      },
      {
         "busNumber":"粤C28348",
         "currentStation":"公交临时站",
         "status":"5"
      },
      {
         "busNumber":"粤C08697D",
         "currentStation":"前山",
         "status":"8"
      },
      {
         "busNumber":"粤C28448",
         "currentStation":"城轨珠海站",
         "status":"5"
      },
      {
         "busNumber":"粤C28428",
         "currentStation":"城轨珠海站",
         "status":"5"
      },
      {
         "busNumber":"粤C28438",
         "currentStation":"城轨珠海站",
         "status":"5"
      }
   ],
   "10__城轨珠海站":[

   ],
   "2__城轨珠海站":[
      {
         "busNumber":"粤C28307",
         "currentStation":"拱北口岸",
         "status":"8"
      },
      {
         "busNumber":"粤C28362",
         "currentStation":"华侨宾馆",
         "status":"8"
      },
      {
         "busNumber":"粤C28863",
         "currentStation":"望海楼",
         "status":"5"
      }
   ]
}

background-common.js中所有数据取完之后的结构

包含watchedLines、watchedLineKeys、相关线路上巴士的实时数据、相关线路的巴士站列表

{
   "watchedLines":{
      "1__香洲":[
         {
            "fromStation":"香洲",
            "key":"1__香洲__香洲",
            "lineNumber":"1",
            "lineUuid":"c72cd82b-be2f-4879-a4a2-f4c05ecf54fd",
            "notifyStation":"香洲",
            "searchKey":"1__香洲",
            "toStation":"城轨珠海站"
         }
      ],
      "2__城轨珠海站":[
         {
            "fromStation":"城轨珠海站",
            "key":"2__城轨珠海站__城轨珠海站",
            "lineNumber":"2",
            "lineUuid":"7c9dbdd8-0707-4a03-aa2e-3f516d8295c8",
            "notifyStation":"城轨珠海站",
            "searchKey":"2__城轨珠海站",
            "toStation":"香洲"
         }
      ],
      "3__金鼎工业园":[
         {
            "fromStation":"金鼎工业园",
            "key":"3__金鼎工业园__金鼎工业园",
            "lineNumber":"3",
            "lineUuid":"7cb4cfe6-fb21-43da-abe3-ba5ee9cfea5e",
            "notifyStation":"金鼎工业园",
            "searchKey":"3__金鼎工业园",
            "toStation":"九洲港"
         }
      ]
   },
   "watchedLineKeys":[
      {
         "lineNumber":"1",
         "fromStation":"香洲"
      },
      {
         "lineNumber":"2",
         "fromStation":"城轨珠海站"
      },
      {
         "lineNumber":"3",
         "fromStation":"金鼎工业园"
      }
   ],
   "busStatusList":{
      "1__香洲":[
         {
            "busNumber":"粤C28343",
            "currentStation":"桃园新村",
            "status":"8"
         },
         {
            "busNumber":"粤C02753D",
            "currentStation":"新香洲万家",
            "status":"8"
         },
         {
            "busNumber":"粤C28369",
            "currentStation":"城轨珠海站",
            "status":"8"
         }
      ],
      "2__城轨珠海站":[
         {
            "busNumber":"粤C28468",
            "currentStation":"拱北口岸",
            "status":"8"
         },
         {
            "busNumber":"粤C28859",
            "currentStation":"拱北口岸",
            "status":"8"
         },
         {
            "busNumber":"粤C28852",
            "currentStation":"香洲",
            "status":"5"
         }
      ],
      "3__金鼎工业园":[
         {
            "busNumber":"粤C17883",
            "currentStation":"宝莱特科技",
            "status":"5"
         },
         {
            "busNumber":"粤C17852",
            "currentStation":"唐家市场",
            "status":"8"
         },
         {
            "busNumber":"粤C18085",
            "currentStation":"九洲港",
            "status":"5"
         }
      ]
   },
   "allStationList":{
      "1__香洲":{
         "uuid":"c72cd82b-be2f-4879-a4a2-f4c05ecf54fd",
         "lineNumber":"1",
         "fromStation":"香洲",
         "toStation":"城轨珠海站",
         "stations":[
            {
               "uuid":"09d3df05b61d4b57959762d9ed2f986c",
               "idx":0,
               "name":"香洲"
            },
            {
               "uuid":"986531bc5af04121a7a5bbbf27854cfb",
               "idx":1,
               "name":"南坑"
            },
            {
               "uuid":"83372752a25d4bbcbce138cfaf59bf31",
               "idx":2,
               "name":"城轨珠海站"
            }
         ]
      },
      "1__城轨珠海站":{
         "uuid":"afec0bea-5532-4872-b06e-a1b5e97e4c3f",
         "lineNumber":"1",
         "fromStation":"城轨珠海站",
         "toStation":"香洲",
         "stations":[
            {
               "uuid":"83372752a25d4bbcbce138cfaf59bf31",
               "idx":0,
               "name":"城轨珠海站"
            },
            {
               "uuid":"3dd7a19e5f8c44ea8b69f84f508727bb",
               "idx":1,
               "name":"拱北口岸"
            },
            {
               "uuid":"759cac0a7aed47aca0e7daf21e23c44e",
               "idx":2,
               "name":"香洲"
            }
         ]
      },
      "2__城轨珠海站":{
         "uuid":"7c9dbdd8-0707-4a03-aa2e-3f516d8295c8",
         "lineNumber":"2",
         "fromStation":"城轨珠海站",
         "toStation":"香洲",
         "stations":[
            {
               "uuid":"83372752a25d4bbcbce138cfaf59bf31",
               "idx":0,
               "name":"城轨珠海站"
            },
            {
               "uuid":"3dd7a19e5f8c44ea8b69f84f508727bb",
               "idx":1,
               "name":"拱北口岸"
            },
            {
               "uuid":"759cac0a7aed47aca0e7daf21e23c44e",
               "idx":2,
               "name":"香洲"
            }
         ]
      },
      "2__香洲":{
         "uuid":"f61aa2db-3bee-4a5a-a48e-ebd445e57bf6",
         "lineNumber":"2",
         "fromStation":"香洲",
         "toStation":"城轨珠海站",
         "stations":[
            {
               "uuid":"09d3df05b61d4b57959762d9ed2f986c",
               "idx":0,
               "name":"香洲"
            },
            {
               "uuid":"37e0f37540d342cc8c37746c6fcd207a",
               "idx":1,
               "name":"为农市场"
            },
            {
               "uuid":"83372752a25d4bbcbce138cfaf59bf31",
               "idx":2,
               "name":"城轨珠海站"
            }
         ]
      },
      "3__金鼎工业园":{
         "uuid":"7cb4cfe6-fb21-43da-abe3-ba5ee9cfea5e",
         "lineNumber":"3",
         "fromStation":"金鼎工业园",
         "toStation":"九洲港",
         "stations":[
            {
               "uuid":"6443ef8c7b3b4b858d3397a33403d2b5",
               "idx":0,
               "name":"金鼎工业园"
            },
            {
               "uuid":"bea8d4ed60c644d0bfe9fd47a0793dd9",
               "idx":1,
               "name":"宏利药业"
            },
            {
               "uuid":"962ee8ffd4224cc3ba52a6721f82635d",
               "idx":2,
               "name":"九洲港"
            }
         ]
      },
      "3__九洲港":{
         "uuid":"de849bff-8d2b-4622-82a6-cd453145030b",
         "lineNumber":"3",
         "fromStation":"九洲港",
         "toStation":"金鼎工业园",
         "stations":[
            {
               "uuid":"d8b2dc9ad1964bc8801e62c56c620a21",
               "idx":0,
               "name":"九洲港"
            },
            {
               "uuid":"bcc09604537f4f3dbcf2ad45f55049b8",
               "idx":1,
               "name":"石花东"
            },
            {
               "uuid":"c0e111a3f0b34161a2a7238bee606013",
               "idx":2,
               "name":"金鼎工业园"
            }
         ]
      }
   }
}

结合三者信息计算出来的一条线路上的notify station的calculated result结构为

{
   "1__香洲__中山亭":{
      "fromStation":"香洲",
      "key":"1__香洲__中山亭",
      "lineNumber":"1",
      "lineUuid":"c72cd82b-be2f-4879-a4a2-f4c05ecf54fd",
      "notifyStation":"中山亭",
      "notifyStationIdx":15,
      "searchKey":"1__香洲",
      "toStation":"城轨珠海站",
      "buses":[
         {
            "busNumber":"粤C07890D",
            "currentStation":"桃园新村",
            "status":"5",
            "currentStationIdx":2,
            "diffToNotifyStation":13
         },
         {
            "busNumber":"粤C07889D",
            "currentStation":"安居园",
            "status":"8",
            "currentStationIdx":8,
            "diffToNotifyStation":7
         },
         {
            "busNumber":"粤C07882D",
            "currentStation":"招商花园城南",
            "status":"8",
            "currentStationIdx":13,
            "diffToNotifyStation":2
         },
         {
            "busNumber":"粤C07765D",
            "currentStation":"前山",
            "status":"8",
            "currentStationIdx":18,
            "diffToNotifyStation":-3
         },
         {
            "busNumber":"粤C28343",
            "currentStation":"前山",
            "status":"8",
            "currentStationIdx":18,
            "diffToNotifyStation":-3
         },
         {
            "busNumber":"粤C07725D",
            "currentStation":"拱北",
            "status":"8",
            "currentStationIdx":23,
            "diffToNotifyStation":-8
         }
      ]
   }
}