-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incorporating LANL changes to support the Geppetto UI
- Loading branch information
Juston Moore
committed
Apr 10, 2021
1 parent
6981036
commit a20e71d
Showing
34 changed files
with
11,901 additions
and
3,978 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
Dockerfile | ||
.dockerignore | ||
.git/ | ||
testfiles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,16 @@ | ||
This research was developed with funding from the Defense Advanced Research Projects Agency (DARPA). | ||
Distribution Statement "A" (Approved for Public Release, Distribution Unlimited). | ||
This tool was originally developed with funding from the Defense Advanced | ||
Research Projects Agency (DARPA). Distribution Statement "A" (Approved for | ||
Public Release, Distribution Unlimited). | ||
|
||
Modifications to support the Geppetto User Interface are Copyright (2020). Triad | ||
National Security, LLC. All rights reserved. | ||
|
||
This program was produced under U.S. Government contract 89233218CNA000001 for | ||
Los Alamos National Laboratory (LANL), which is operated by Triad National | ||
Security, LLC for the U.S. Department of Energy/National Nuclear Security | ||
Administration. All rights in the program are reserved by Triad National | ||
Security, LLC, and the U.S. Department of Energy/National Nuclear Security | ||
Administration. The Government is granted for itself and others acting on its | ||
behalf a nonexclusive, paid-up, irrevocable worldwide license in this material | ||
to reproduce, prepare derivative works, distribute copies to the public, perform | ||
publicly and display publicly, and to permit others to do so. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
sq "github.com/Masterminds/squirrel" | ||
"github.com/pkg/errors" | ||
|
||
pb "github.com/mediaforensics/medifor/pkg/mediforproto" | ||
) | ||
|
||
func (s *apiService) GetAnalyticsWithScores(ctx context.Context, req *pb.GetAnalyticsWithScoresRequest) (*pb.GetAnalyticsWithScoresResponse, error) { | ||
analyticIds, err := s.getAnalyticsWithScores(ctx, req) | ||
|
||
if err != nil { | ||
return nil, errors.Wrap(err, "analytics with scores") | ||
} | ||
|
||
fuserIds, err := s.getFusersWithScores(ctx, req) | ||
|
||
if err != nil { | ||
return nil, errors.Wrap(err, "analytics with scores") | ||
} | ||
|
||
resp := &pb.GetAnalyticsWithScoresResponse{ | ||
AnalyticIds: analyticIds, | ||
FuserIds: fuserIds, | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
func (s *apiService) getAnalyticsWithScores(ctx context.Context, req *pb.GetAnalyticsWithScoresRequest) ([]string, error) { | ||
analyticIds := []string{} | ||
|
||
query := sq.Select("analytic_id"). | ||
Distinct(). | ||
From("detection"). | ||
LeftJoin("detectionTag USING (detection_id)"). | ||
Where(sq.NotEq{"finished": nil}). | ||
Where("coalesce(detection->'status'->>'code', '0') = '0'"). | ||
Where(sq.Or{ | ||
sq.And{ | ||
sq.Expr("detection ?? 'imgManip'"), | ||
sq.Expr("coalesce(detection->'imgManip'->>'optOut', 'OPT_OUT_NONE') NOT IN ('OPT_OUT_ALL', 'OPT_OUT_DETECTION')"), | ||
}, | ||
sq.And{ | ||
sq.Expr("detection ?? 'vidManip'"), | ||
sq.Expr("NOT (coalesce(detection->'vidManip'->'optOut', '[]'::jsonb) ?? 'VIDEO_OPT_OUT_DETECTION')"), | ||
}, | ||
}) | ||
|
||
if req.Tags != nil { | ||
tags, err := json.Marshal(req.Tags) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
query = query.Where("(tags || user_tags) @> ?", tags) | ||
} | ||
|
||
if req.ExcludeTags != nil { | ||
excludeTags, err := json.Marshal(req.ExcludeTags) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
query = query.Where("NOT (user_tags ??| array(SELECT jsonb_object_keys(?)))", excludeTags) | ||
} | ||
|
||
rows, err := query.PlaceholderFormat(sq.Dollar). | ||
RunWith(s.pgdb). | ||
QueryContext(ctx) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer rows.Close() | ||
|
||
for rows.Next() { | ||
var analyticId string | ||
|
||
if err := rows.Scan(&analyticId); err != nil { | ||
return nil, err | ||
} | ||
|
||
analyticIds = append(analyticIds, analyticId) | ||
} | ||
|
||
if err := rows.Err(); err != nil { | ||
return nil, err | ||
} | ||
|
||
return analyticIds, nil | ||
} | ||
|
||
func (s *apiService) getFusersWithScores(ctx context.Context, req *pb.GetAnalyticsWithScoresRequest) ([]string, error) { | ||
fuserIds := []string{} | ||
|
||
query := sq.Select("fuser_id"). | ||
Distinct(). | ||
From("fusion"). | ||
LeftJoin("detectionTag USING (detection_id)"). | ||
Where(sq.NotEq{"finished": nil}). | ||
Where("coalesce(fusion->'status'->>'code', '0') = '0'"). | ||
Where(sq.Or{ | ||
sq.And{ | ||
sq.Expr("fusion ?? 'imgManip'"), | ||
sq.Expr("coalesce(fusion->'imgManip'->>'optOut', 'OPT_OUT_NONE') NOT IN ('OPT_OUT_ALL', 'OPT_OUT_DETECTION')"), | ||
}, | ||
sq.And{ | ||
sq.Expr("fusion ?? 'vidManip'"), | ||
sq.Expr("NOT (coalesce(fusion->'vidManip'->'optOut', '[]'::jsonb) ?? 'VIDEO_OPT_OUT_DETECTION')"), | ||
}, | ||
}) | ||
|
||
if req.Tags != nil { | ||
tags, err := json.Marshal(req.Tags) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
query = query.Where("(tags || user_tags) @> ?", tags) | ||
} | ||
|
||
if req.ExcludeTags != nil { | ||
excludeTags, err := json.Marshal(req.ExcludeTags) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
query = query.Where("NOT ((tags || user_tags) @> ?)", excludeTags) | ||
} | ||
|
||
rows, err := query.PlaceholderFormat(sq.Dollar). | ||
RunWith(s.pgdb). | ||
QueryContext(ctx) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer rows.Close() | ||
|
||
for rows.Next() { | ||
var fuserId string | ||
|
||
if err := rows.Scan(&fuserId); err != nil { | ||
return nil, err | ||
} | ||
|
||
fuserIds = append(fuserIds, fuserId) | ||
} | ||
|
||
if err := rows.Err(); err != nil { | ||
return nil, err | ||
} | ||
|
||
return fuserIds, nil | ||
} |
Oops, something went wrong.