Skip to content

Commit

Permalink
Added minimum accumulated probability filter, fixed toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed Nov 28, 2023
1 parent 1b81a94 commit 12d1a63
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 98 deletions.
84 changes: 47 additions & 37 deletions modules/analyze/analyzeobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,44 @@ var EdgeMemberOfGroup = engine.NewEdge("MemberOfGroup") // Get rid of this

func NewAnalyzeObjectsOptions() AnalyzeObjectsOptions {
return AnalyzeObjectsOptions{
MethodsF: engine.AllEdgesBitmap,
MethodsM: engine.AllEdgesBitmap,
MethodsL: engine.AllEdgesBitmap,
Direction: engine.In,
MaxDepth: -1,
MaxOutgoingConnections: -1,
MinProbability: 0,
PruneIslands: false,
MethodsF: engine.AllEdgesBitmap,
MethodsM: engine.AllEdgesBitmap,
MethodsL: engine.AllEdgesBitmap,
Direction: engine.In,
MaxDepth: -1,
MaxOutgoingConnections: -1,
MinEdgeProbability: 0,
MinAccumulatedProbability: 0,
PruneIslands: false,
}
}

type AnalyzeObjectsOptions struct {
Objects *engine.Objects
StartFilter query.NodeFilter
MiddleFilter query.NodeFilter
EndFilter query.NodeFilter
ObjectTypesF []engine.ObjectType
ObjectTypesM []engine.ObjectType
ObjectTypesL []engine.ObjectType
MethodsL engine.EdgeBitmap
MethodsM engine.EdgeBitmap
MethodsF engine.EdgeBitmap
MaxDepth int
MaxOutgoingConnections int
Direction engine.EdgeDirection
Backlinks bool // Full backlinks
Fuzzlevel int // Backlink depth
MinProbability engine.Probability
PruneIslands bool
NodeLimit int
Objects *engine.Objects
StartFilter query.NodeFilter
MiddleFilter query.NodeFilter
EndFilter query.NodeFilter
ObjectTypesF []engine.ObjectType
ObjectTypesM []engine.ObjectType
ObjectTypesL []engine.ObjectType
MethodsL engine.EdgeBitmap
MethodsM engine.EdgeBitmap
MethodsF engine.EdgeBitmap
MaxDepth int
MaxOutgoingConnections int
Direction engine.EdgeDirection
Backlinks bool // Full backlinks
Fuzzlevel int // Backlink depth
MinEdgeProbability engine.Probability
MinAccumulatedProbability engine.Probability
PruneIslands bool
NodeLimit int
}

type GraphNode struct {
CanExpand int
roundadded int
CanExpand int
roundadded int
accumulatedprobability float32 // 0-1
}

type PostProcessorFunc func(pg graph.Graph[*engine.Object, engine.EdgeBitmap]) graph.Graph[*engine.Object, engine.EdgeBitmap]
Expand Down Expand Up @@ -92,7 +95,8 @@ func AnalyzeObjects(opts AnalyzeObjectsOptions) AnalysisResults {
for o := range pg.Nodes() {
if ei, found := extrainfo[o]; !found || ei.roundadded == 0 {
extrainfo[o] = (&GraphNode{
roundadded: processinground,
roundadded: processinground,
accumulatedprobability: 1,
})
}
}
Expand Down Expand Up @@ -157,13 +161,21 @@ func AnalyzeObjects(opts AnalyzeObjectsOptions) AnalysisResults {
}
}

// Edge probability
var maxprobability engine.Probability
if opts.Direction == engine.In {
maxprobability = detectededges.MaxProbability(nextobject, currentobject)
} else {
maxprobability = detectededges.MaxProbability(currentobject, nextobject)
}
if maxprobability < engine.Probability(opts.MinProbability) {
if maxprobability < engine.Probability(opts.MinEdgeProbability) {
// Too unlikeliy, so we skip it
return true // continue
}

// Accumulated node probability
accumulatedprobability := ei.accumulatedprobability * float32(maxprobability) / 100
if accumulatedprobability < float32(opts.MinAccumulatedProbability)/100 {
// Too unlikeliy, so we skip it
return true // continue
}
Expand Down Expand Up @@ -205,6 +217,11 @@ func AnalyzeObjects(opts AnalyzeObjectsOptions) AnalysisResults {
Target: nextobject}] = detectededges
}

extrainfo[nextobject] = &GraphNode{
roundadded: processinground + 1,
accumulatedprobability: ei.accumulatedprobability * float32(maxprobability) / 100,
}

return true
})

Expand Down Expand Up @@ -285,13 +302,6 @@ func AnalyzeObjects(opts AnalyzeObjectsOptions) AnalysisResults {
}

processinground++
for o := range pg.Nodes() {
if ei, found := extrainfo[o]; !found || ei.roundadded == 0 {
extrainfo[o] = (&GraphNode{
roundadded: processinground,
})
}
}
}
pb.Finish()

Expand Down
17 changes: 17 additions & 0 deletions modules/analyze/html/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,23 @@ function refreshStatus() {
setTimeout(refreshStatus, 1000);
}

function toast(title, contents) {
toastcontent = $(`<div id="live-toast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">`+title+`</strong>
<!--small>Just now</small-->
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
`+contents+`
</div>
</div>`);
$("#toasts").append(toastcontent);
const toast = bootstrap.Toast.getOrCreateInstance(toastcontent);
toast.show();
}

// When we´re ready ...
$(function () {
// Initial GUI setup
Expand Down
Loading

0 comments on commit 12d1a63

Please sign in to comment.