Statistics

Provides a view of the number of active orders in a day.

🚧

Make sure to replace [TT LAN IP]!

[TT LAN IP] in the example code provided is what should be replaced by what the local area network (LAN) assigned address of the Table Tracker gateway. (e.g. 192.168.1.232, 10.0.1.13, 192.168.0.324)

Please note that the code examples provided are only meant to provide an idea of what making a HTTP request to the API looks like.

πŸ“˜

V2 Change in Statistic response

In v2, the body of the statistics has been moved into it's own enclosure "statistics" to keep consistent with other individual responses.

GET /api/v2/statistics/{?target_time} [SECURED]

Return the order statistics for the current day.

Query Parameters

NameDescriptionDetails
target_timeThe target delivery time for an order in seconds.number, optional
default: 300

Example Request

// get statistics (GET http://[TT LAN IP]:8000/api/v1/statistics)

$.ajax({
    url: "http://[TT LAN IP]:8000/api/v2/statistics",
    type: "GET",
    data:{
        "target_time":"300",
    },
    headers:{
        "Authorization":"Bearer 2f1f4339c7b77fa3474bf8ba8852349273e928bb8ad9d186",
        "Content-Type":"application/json",
    },
})
.done(function(data, textStatus, jqXHR) {
    console.log("HTTP Request Succeeded: " + jqXHR.status);
    console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown) {
    console.log("HTTP Request Failed");
})
.always(function() {
    /* ... */
});
import java.io.IOException;
import org.apache.http.client.fluent.*;

public class SendRequest
{
  public static void main(String[] args) {
    sendRequest();
  }
  
  private static void sendRequest() {
    
    // get statistics (GET )
    
    try {
      
      // Create request
      Content content = Request.Get("http://[TT LAN IP]:8000/api/v2/statistics?target_time=300")
      
      // Add headers
      .addHeader("Authorization", "Bearer 2f1f4339c7b77fa3474bf8ba8852349273e928bb8ad9d186")
      .addHeader("Content-Type", "application/json")
      
      // Fetch request and return content
      .execute().returnContent();
      
      // Print content
      System.out.println(content);
    }
    catch (IOException e) { System.out.println(e); }
  }
}
// get statistics (GET http://10.0.1.2:8000/api/v1/statistics)

NSURL* URL = [NSURL URLWithString:@"http://[TT LAN IP]:8000/api/v2/statistics"];
NSDictionary* URLParams = @{
    @"target_time": @"300",
};
URL = NSURLByAppendingQueryParameters(URL, URLParams);
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:URL];
request.HTTPMethod = @"GET";

// Headers

[request addValue:@"Bearer 2f1f4339c7b77fa3474bf8ba8852349273e928bb8ad9d186" forHTTPHeaderField:@"Authorization"];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

// Connection

NSURLConnection* connection = [NSURLConnection connectionWithRequest:request delegate:nil];
[connection start];

/*
 * Utils: Add this section before your class implementation
 */

/**
 This creates a new query parameters string from the given NSDictionary. For
 example, if the input is @{@"day":@"Tuesday", @"month":@"January"}, the output
 string will be @"day=Tuesday&month=January".
 @param queryParameters The input dictionary.
 @return The created parameters string.
*/
static NSString* NSStringFromQueryParameters(NSDictionary* queryParameters)
{
    NSMutableArray* parts = [NSMutableArray array];
    [queryParameters enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
        NSString *part = [NSString stringWithFormat: @"%@=%@",
            [key stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding],
            [value stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]
        ];
        [parts addObject:part];
    }];
    return [parts componentsJoinedByString: @"&"];
}

/**
 Creates a new URL by adding the given query parameters.
 @param URL The input URL.
 @param queryParameters The query parameter dictionary to add.
 @return A new NSURL.
*/
static NSURL* NSURLByAppendingQueryParameters(NSURL* URL, NSDictionary* queryParameters)
{
    NSString* URLString = [NSString stringWithFormat:@"%@?%@",
        [URL absoluteString],
        NSStringFromQueryParameters(queryParameters),
    ];
    return [NSURL URLWithString:URLString];
}
curl -X "GET" "http://[TT LAN IP]:8000/api/v2/statistics?target_time=300" \
	-H "Authorization: Bearer 2f1f4339c7b77fa3474bf8ba8852349273e928bb8ad9d186" \
	-H "Content-Type: application/json"
# Install the Python Requests library:
# `pip install requests`

import requests

def send_request():
    # get statistics (GET http://[TT LAN IP]:8000/api/v1/statistics)

    try:
        r = requests.get(
            url="http://[TT LAN IP]:8000/api/v2/statistics",
            params = {
                "target_time":"300",
            },
            headers = {
                "Authorization":"Bearer 2f1f4339c7b77fa3474bf8ba8852349273e928bb8ad9d186",
                "Content-Type":"application/json",
            },
        )
        print('Response HTTP Status Code : {status_code}'.format(status_code=r.status_code))
        print('Response HTTP Response Body : {content}'.format(content=r.content))
    except requests.exceptions.RequestException as e:
        print('HTTP Request failed')

Responses

200 OK

{
  "status": 200,
  "returnCode": 10,
  "statistics": {
    "averageSeconds": 1809.5,
    "exceededToday": 0,
    "ordersToday": 2.0,
    "targetTime": 200.0,
    "percentGoal": 50.0
  }
}

400 Bad Request

Returns if target_time is not an integer.

{
  "status": 400,
  "message": "Invalid number for target_time.",
  "returnCode": -22
}