Skip to content

Commit

Permalink
Fix result serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Englhardt committed Apr 30, 2019
1 parent b5b08f2 commit 82879b4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/OneClassActiveLearning.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using Random
using Reexport
using Statistics

import DataStructures
import Formatting
import JSON
import JuMP
Expand Down
4 changes: 2 additions & 2 deletions src/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ function JSON.json(res::Result)
jsonstring = "{"
jsonstring *= "\"id\":" * JSON.json(res.id) * ","
jsonstring *= "\"experiment\":" * JSON.json(res.experiment) * ","
jsonstring *= "\"al_history\":" * JSON.json(res.al_history) * ","
jsonstring *= "\"worker_info\":" * JSON.json(res.worker_info) * ","
jsonstring *= "\"data_stats\":" * JSON.json(res.data_stats) * ","
jsonstring *= "\"al_history\":" * JSON.json(res.al_history) * ","
jsonstring *= "\"al_summary\":" * JSON.json(res.al_summary) * ","
jsonstring *= "\"status\":" * JSON.json(res.status)
jsonstring *= "}"
Expand All @@ -91,7 +91,7 @@ end

function write_result_to_file(output_file, r::Result)
r_reparsed = JSON.parse(JSON.json(r))
d = OrderedDict()
d = DataStructures.OrderedDict()
for k in ["id", "experiment", "worker_info", "data_stats", "al_history", "al_summary", "status"]
d[k] = r_reparsed[k]
end
Expand Down
3 changes: 2 additions & 1 deletion test/serialize_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
worker_info = OneClassActiveLearning.get_worker_info()
expected = OneClassActiveLearning.Result(id, experiment, worker_info, DataStats(1, 1, 0.1, 0.1, [1,2,3,4], [5,6,7]), al_history, al_summary)

actual = Unmarshal.unmarshal(OneClassActiveLearning.Result, JSON.parse(JSON.json(expected)))
OneClassActiveLearning.write_result_to_file(TEST_OUTPUT_FILE, expected)
actual = Unmarshal.unmarshal(OneClassActiveLearning.Result, JSON.parsefile(TEST_OUTPUT_FILE))
@test actual.id == 42
@test length(actual.experiment[:param][:initial_pools]) == 123
@test haskey(actual.worker_info, :hostname)
Expand Down

0 comments on commit 82879b4

Please sign in to comment.