Skip to content

Commit

Permalink
fix rename, add utility function for debuggin (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshday authored Jul 18, 2023
1 parent 675f453 commit 62ee421
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/SimulationService.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ get_json(url::String) = JSON3.read(HTTP.get(url, json_header).body)

timestamp() = Dates.format(now(), "yyyy-mm-ddTHH:MM:SS")

# Dump all the info we can get about a simulation `id`
function debug_data(id::String)
@assert ENABLE_TDS[]
data_service_model = DataServiceModel(id::String)
request_json = data_service_model.execution_payload
amr = get_model(data_service_model.execution_payload.model_config_id)
route = String(Dict(v => k for (k,v) in operation_to_dsm_type)[data_service_model.type])
operation_request = OperationRequest(HTTP.Request("POST", "", [], JSON3.write(request_json)), route)
job_status = get_job_status(get_job(id))
return (; request_json, amr, data_service_model, operation_request, job_status)
end

#-----------------------------------------------------------------------------# job endpoints
get_job(id::String) = JobSchedulers.job_query(jobhash(id))

Expand Down Expand Up @@ -298,9 +310,11 @@ function get_dataset(obj::JSON3.Object)
tds_url = "$(TDS_URL[])/datasets/$(obj.id)/download-url?filename=$(obj.filename)"
s3_url = get_json(tds_url).url
df = CSV.read(download(s3_url), DataFrame)
return haskey(obj, :mappings) ?
rename!(df, Dict(string(k) => string(v) for (k,v) in obj.mappings)) :
df
for (k,v) in get(obj, :mappings, Dict())
@info "`get_dataset` (dataset id=$(repr(obj.id))) rename! $k => $v"
rename!(df, k => v)
end
return df
end


Expand Down
12 changes: 11 additions & 1 deletion test/tds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,21 @@ obj = get_model(model_config_id)
#-----------------------------------------------------------------------------# get_dataset ✓
datasets = get_json("$(TDS_URL[])/datasets")

# with mappings
data_obj = JSON3.read(JSON3.write((;
id = datasets[1].id,
name = datasets[1].name,
filename = datasets[1].file_names[1],
mappings = (; Ailing = "A")
mappings = (; Ailing ="A", Diagnosed="D", Healed="H")
)))

get_dataset(data_obj)

# without mappings
data_obj = JSON3.read(JSON3.write((;
id = datasets[1].id,
name = datasets[1].name,
filename = datasets[1].file_names[1]
)))

get_dataset(data_obj)
Expand Down

0 comments on commit 62ee421

Please sign in to comment.