Debugging scripts
Last updated
library(httr)
library(jsonlite)
rest_url <- "https://<your senseforce backend platform url>/api/dataset/execute/<id>"
header_auth <- c("Authorization" = "Bearer <your API access token>")
header_type <- c("Content-Type" = "application/json")
headers <- add_headers(header_auth, header_type)
req <- POST(rest_url, body = "[]", headers)
stop_for_status(req)
res_df <- data.frame(fromJSON(content(req, "text", "application/json")))
script_variable_1 <- res_df$timestamp
script_variable_2 <- res_df$someColumnimport requests
import json
from pandas import DataFrame
url = "https://<your senseforce backend platform url>/api/dataset/execute/<id>"
headers = {"Content-Type": "application/json",
"Authorization": "Bearer <your API access token>"}
filters = []
response = requests.post(url, headers=headers, json=filters)
data = response.text
parsed_data = json.loads(data)
df = DataFrame(parsed_data)
script_variable_1 = df["timestamp"]
script_variable_2 = df["someColumn"]library(httr)
library(jsonlite)
rest_url <- "https://<your senseforce backend platform url>/api/dataset/execute/<id>"
header_auth <- c("Authorization" = "Bearer <your API access token>")
header_type <- c("Content-Type" = "application/json")
headers <- add_headers(header_auth, header_type)
req <- POST(rest_url, body = "[]", headers)
stop_for_status(req)
res_df <- data.frame(fromJSON(content(req, "text", "application/json")))
# variable setup
script_variable_1 <- res_df$timestamp
script_variable_2 <- res_df$someColumn
# start - interchangeable code
# ======================================================================
script_variable_2 <- script_variable_2 + 1000
result1 <- script_variable_1
result2 <- script_variable_2
# ======================================================================
# end - interchangeable code
print(result1)
print(result2)import requests
import json
from pandas import DataFrame
url = "https://<your senseforce backend platform url>/api/dataset/execute/<id>"
headers = {"Content-Type": "application/json",
"Authorization": "Bearer <your API access token>"}
filters = []
response = requests.post(url, headers=headers, json=filters)
data = response.text
parsed_data = json.loads(data)
df = DataFrame(parsed_data)
# variable setup
script_variable_1 = df["timestamp"]
script_variable_2 = df["someColumn"]
# start - interchangeable code
# ======================================================================
script_variable_2 = [x+1000 for x in script_variable_2]
result1 = script_variable_1
result1 = script_variable_2
# ======================================================================
# end - interchangeable code
print(x)
print(y)library(httr)
library(jsonlite)
url <- "https://<your senseforce backend platform url>/api/dataset/execute/"
auth <- "Bearer <your API access token>"
loadDataset <- function(id, filters, limit, offset) {
rest_url <- paste(url, id, sep = "")
rest_url <- paste(rest_url, "?limit=", limit, "&offset=", offset, sep = "")
header_auth <- c("Authorization" = auth)
header_type <- c("Content-Type" = "application/json")
headers <- add_headers(header_auth, header_type)
req <- POST(rest_url, body = filters, headers)
stop_for_status(req)
res_str <- content(req, "text", "application/json")
res_f_j <- fromJSON(res_str)
res_df <- data.frame(res_f_j)
return(res_df)
}
filters <- sprintf('[{
"clause": {
"type": "long",
"operator": 5,
"parameters": [{
"value": 5
}]
},
"columnName": "SomeColumn"
}]');
data1 <- loadDataset("<datasetId1>", filters, 100, 0)
data2 <- loadDataset("<datasetId2>", "[]", 100, 0)
# variable setup
script_variable_1 <- data1$someColumn
script_variable_2 <- data2$someColumn
# start - interchangeable code
script_variable_2 <- script_variable_2 + 1000
result1 <- script_variable_1
result2 <- script_variable_2
# end - interchangeable code
print(result1)
print(result2)import requests
import json
from pandas import DataFrame
url = "https://<your senseforce backend platform url>/api/dataset/execute/"
auth = "Bearer <your API access token>"
def load_dataset(id, filters, limit, offset):
rest_url = url + id + "?limit=" + str(limit) + "&offset=" + str(offset)
headers = {"Content-Type": "application/json", "Authorization": auth}
response = requests.post(rest_url, headers=headers, json=filters)
data = response.text
parsed_data = json.loads(data)
df = DataFrame(parsed_data)
return df
filters = [
{
"clause": {
"type": "long",
"operator": 5,
"parameters": [{
"value": 5
}
]
},
"columnName": "SomeColumn"
}]
data1 = load_dataset("<datasetId1>", filters, 100, 0)
data2 = load_dataset("<datasetId2>", [], 100, 0)
# variable setup
script_variable_1 = data1["someColumn"]
script_variable_2 = data2["someColumn"]
# start - interchangeable code
script_variable_2 = [x+1000 for x in script_variable_2]
result1 = script_variable_1
result2 = script_variable_2
# end - interchangeable code
print(result1)
print(result2)