Skip to content

Instantly share code, notes, and snippets.

@ArrayIterator
Last active January 30, 2020 02:56
Show Gist options
  • Save ArrayIterator/ad75ab496e6508ccfc8df00bdee43554 to your computer and use it in GitHub Desktop.
Save ArrayIterator/ad75ab496e6508ccfc8df00bdee43554 to your computer and use it in GitHub Desktop.

UPDATE FLEET LOCATION HISTORY

Processing Call ke GPS API & Fleet Location Upate

FAIL

Apabila gagal maka update table fleet column last_gps_update_data dengan :

Affected Table

  • fleet

QUERY fleet

Parameters:

:fleet_id          => (int) fleet id

:string_error_data => (string) "Http-Code: (int) Error Code"

SQL :

UPDATE fleet
    SET
        `last_gps_update_data` = :string_error_data
    WHERE id=:fleet_id

Succeed

Apabila sukses maka update table fleet column last_gps_update_data dan fleet_location_history

fleet_location_history akan di update apabila latitude & longitude exists saja.

apabila kosong fleet_location_history tidak akan ada perubahan

Affected Table

  • fleet
  • fleet_location_history

QUERY fleet

Parameters :


:fleet_id   => (int) fleet id
:json_data  => (string) Hasil result dari response gps

SQL :

UPDATE fleet
    SET 
        last_gps_update_data = :json_data, 
        last_gps_update_success = now() -- current time
    WHERE id=:fleet_id

QUERY ms_city (di eksekusi apabila response city tidak kosong), apabila queried city

Parameters :

:city_name   => (string) data lower address city

SQL: (for city_id if found integer id otherwise null)

SELECT id, `name`
    FROM ms_city 
    WHERE lower(`name`) LIKE CONCAT('%', :city_name, '%')
    ORDER BY LENGTH(`name`) 
    DESC LIMIT 1

QUERY fleet_location_history

Parameters :


:fleet_id   => (int) fleet id
:latitude   => (float) Latitude
:longitude  => (float) Longitude
:address    => (string) Address (Even Empty Update)
:city_id    => (int|null) `ms_city`.`id` from city queried search by gps city address
:driver_name => (string|null) string from driver if exists, or null if empty null 
:gsm_number  => (string|null) string from gsm if exists, or null if empty null

SQL :

UPDATE fleet_location_history
    SET
        fleet_id  = :fleet_d,
        latitude  = :latitude,
        longitude = :longitude,
        address   = :address,
        city_id   = :city_id,
        driver_name = :driver_name,
        gsm_no = :gsm_number,
        source = 1,         -- 1 if is on truck
        created_at = now()  -- current time

NOTE

See file Sampe Response.md

{
    "data": {
        "cache": true,
        "gmt_time": 1580350927,
        "data": {
            "msisdn": "6908",
            "latitude": "-7.197496000",
            "longitude": "112.646805000",
            "gps_time": 1580309747,
            "gps_time_gmt7": 1580309747,
            "gps_time_gmt": 1580284547,
            "car_model": "",
            "car_plate": "",
            "info": {
                "params": [],
                "company_name": "",
                "company_id": null,
                "gsm_number": "",
                "route_length": null,
                "top_speed": "38",
                "avg_speed": "38",
                "fuel_consumption": "-1",
                "fuel_cost": null,
                "stops_duration": null,
                "status_duration": null,
                "drives_duration": null,
                "engine_work": null,
                "engine_idle": null,
                "city": "Surabaya",
                "province": "East Java",
                "address": "Masjid Romokalisari, Jalan Romokalisari Gang Kelurahan, Tenggulunan, Jawa Timur, 57378, Indonesia",
                "odometer": "22427.713",
                "address_detail": {
                    "place_id": 171398934,
                    "licence": "Data \u00a9 OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
                    "osm_type": "way",
                    "osm_id": 369677877,
                    "lat": "-7.197481566981432",
                    "lon": "112.6468201915721",
                    "display_name": "1, RW 02, Romokalisari, Benowo, Surabaya, East Java, 57378, Indonesia",
                    "address": {
                        "road": "1",
                        "city_district": "RW 02",
                        "village": "Romokalisari",
                        "county": "Romokalisari",
                        "city": "Surabaya",
                        "state": "East Java",
                        "postcode": "57378",
                        "country": "Indonesia",
                        "country_code": "id"
                    },
                    "boundingbox": [
                        "-7.1995653",
                        "-7.1969368",
                        "112.6463021",
                        "112.648448"
                    ]
                },
                "direction": null
            }
        }
    }
}

Definitions

Result is on sub value of data

  1. cache determine is in cache result or not
  2. gmt_time (Mandatory) determine the first API GPS called / succeed request on UTC integer time() - Generated By Engine
  3. data.latitude (Mandatory) latitude
  4. data.longitude (Mandatory) longitude
  5. data.gps_time_gmt7 (Mandatory) determine the gps response time from gps provider on UTC+7/GMT+7 integer time() - Generated By 3rd Party, this was device/gps timestamp response
  6. data.gps_time_gmt (Mandatory) determine the gps response time from gps provider on UTC/GMTinteger time() - Generated By 3rd Party, this was device/gps timestamp response
  7. data.info array informations that contains some info (this is not mandatory)
  8. data.info.address this is address from gps provider if exists, if not exists, engine use OSM Map data.info.address_detail.address.display_name

For great map getting data from map embed location that does not used lat-lng.

Better to use OSM map from data:

data.info.address_detail.address.display_name

Example Address is (this from GPS Provider Address):

Masjid Romokalisari, Jalan Romokalisari Gang Kelurahan, Tenggulunan, Jawa Timur, 57378, Indonesia

But On Map Queried, please use (address_detail.display_name) for better result:

1, RW 02, Romokalisari, Benowo, Surabaya, East Java, 57378, Indonesia

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment