Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix find desc (#43, #91) #97

Merged
merged 5 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions src/DescriptorsCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,11 @@ int FindDescriptor::construct_protobuf(

// Query for the Descriptors related to user-defined link
// that match the user-defined constraints
// We will need to the the AND operation
// We will need to do the AND operation
// on the construct_response.

int desc_ref = get_value<int>(cmd, "_ref",
query.get_available_reference());
query.get_available_reference());

query.QueryNode(
desc_ref,
Expand Down Expand Up @@ -668,16 +668,31 @@ int FindDescriptor::construct_protobuf(
return 0;
}

void FindDescriptor::convert_properties(Json::Value& entities)
void FindDescriptor::convert_properties(Json::Value& entities,
Json::Value& list)
{
bool flag_label = false;
bool flag_id = false;

for (auto& prop : list) {
if (prop.asString() == "_label") {
flag_label = true;
}
if (prop.asString() == "_id") {
flag_id = true;
}
}

for (auto& element : entities) {

if (element.isMember(VDMS_DESC_LABEL_PROP)) {
element["_label"] = element[VDMS_DESC_LABEL_PROP];
if (flag_label)
element["_label"] = element[VDMS_DESC_LABEL_PROP];
element.removeMember(VDMS_DESC_LABEL_PROP);
}
if (element.isMember(VDMS_DESC_ID_PROP)) {
element["_id"] = element[VDMS_DESC_ID_PROP];
if (flag_id)
element["_id"] = element[VDMS_DESC_ID_PROP];
element.removeMember(VDMS_DESC_ID_PROP);
}
}
Expand Down Expand Up @@ -711,6 +726,7 @@ Json::Value FindDescriptor::construct_responses(
}

const Json::Value& results = cmd["results"];
Json::Value list = get_value<Json::Value>(results, "list");

// Case (1)
if (cmd.isMember("link")) {
Expand All @@ -719,6 +735,10 @@ Json::Value FindDescriptor::construct_responses(

findDesc = json_responses[0];

if (findDesc.isMember("entities")) {
convert_properties(findDesc["entities"], list);
}

if (findDesc["status"] != 0) {
Json::Value return_error;
return_error["status"] = RSCommand::Error;
Expand All @@ -734,7 +754,7 @@ Json::Value FindDescriptor::construct_responses(
findDesc = json_responses[1];

if (findDesc.isMember("entities")) {
convert_properties(findDesc["entities"]);
convert_properties(findDesc["entities"], list);
}

if (findDesc["status"] != 0) {
Expand Down Expand Up @@ -783,14 +803,13 @@ Json::Value FindDescriptor::construct_responses(
std::vector<float>* distances;

bool compute_distance = false;
if (results.isMember("list")) {

for (int i = 0; i < results["list"].size(); ++i) {
if (results["list"][i].asString() == "_distance") {
compute_distance = true;
break;
}
Json::Value list = get_value<Json::Value>(results, "list");

for (auto& prop : list) {
if (prop.asString() == "_distance") {
compute_distance = true;
break;
}
}

Expand All @@ -817,8 +836,6 @@ Json::Value FindDescriptor::construct_responses(
Json::Value entities = findDesc["entities"];
findDesc.removeMember("entities");

convert_properties(entities);

for (int i = 0; i < (*ids).size(); ++i) {

Json::Value desc_data;
Expand All @@ -827,7 +844,7 @@ Json::Value FindDescriptor::construct_responses(
bool pass_constraints = false;

for (auto ent : entities) {
if (ent["_id"].asInt64() == d_id) {
if (ent[VDMS_DESC_ID_PROP].asInt64() == d_id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like some cleanup mixed in with the actual changes. Just make sure they aren't numerous enough to warrant a separate commit. Otherwise its ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually needed here in this commit as the "convertproperties" function (that was doing this translation internally) was moved below.

desc_data = ent;
pass_constraints = true;
break;
Expand Down Expand Up @@ -867,12 +884,13 @@ Json::Value FindDescriptor::construct_responses(
findDesc["info"] = "VCL Exception";
return error(findDesc);
}

}

findDesc["entities"].append(desc_data);
}

convert_properties(findDesc["entities"], list);

if (cache.isMember("cache_obj_id")) {
// We remove the vectors associated with that entry to
// free memory, without removing the entry from _cache_map
Expand Down
2 changes: 1 addition & 1 deletion src/DescriptorsCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ namespace VDMS{
{

private:
void convert_properties(Json::Value& entities);
void convert_properties(Json::Value& entities, Json::Value& list);

public:
FindDescriptor();
Expand Down
1 change: 1 addition & 0 deletions utils/src/api_schema/api_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@
"_ref": { "$ref": "#/definitions/refInt" },
"k_neighbors": { "$ref": "#/definitions/positiveInt" },
"results": { "$ref": "#/definitions/blockResults" },
"link": { "$ref": "#/definitions/blockLink" },
"constraints": { "type": "object" },
"properties": { "type": "object" }
},
Expand Down