Add debug info for propagation log
This commit is contained in:
parent
8a8428975b
commit
db7f2791e2
26
page.go
26
page.go
|
@ -1,9 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/divan/graphx/graph"
|
"github.com/divan/graphx/formats"
|
||||||
"github.com/divan/graphx/layout"
|
"github.com/divan/graphx/layout"
|
||||||
"github.com/gopherjs/vecty"
|
"github.com/gopherjs/vecty"
|
||||||
"github.com/gopherjs/vecty/elem"
|
"github.com/gopherjs/vecty/elem"
|
||||||
|
@ -25,19 +26,17 @@ type Page struct {
|
||||||
forceEditor *widgets.ForceEditor
|
forceEditor *widgets.ForceEditor
|
||||||
network *NetworkSelector
|
network *NetworkSelector
|
||||||
simulationConf *widgets.Simulation
|
simulationConf *widgets.Simulation
|
||||||
|
|
||||||
data *graph.Graph
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPage creates and inits new app page.
|
// NewPage creates and inits new app page.
|
||||||
func NewPage() *Page {
|
func NewPage() *Page {
|
||||||
page := &Page{
|
page := &Page{
|
||||||
loader: widgets.NewLoader(),
|
loader: widgets.NewLoader(),
|
||||||
forceEditor: widgets.NewForceEditor(),
|
forceEditor: widgets.NewForceEditor(),
|
||||||
simulationConf: widgets.NewSimulation(""),
|
|
||||||
}
|
}
|
||||||
page.network = NewNetworkSelector(page.onNetworkChange)
|
page.network = NewNetworkSelector(page.onNetworkChange)
|
||||||
page.webgl = NewWebGLScene()
|
page.webgl = NewWebGLScene()
|
||||||
|
page.simulationConf = widgets.NewSimulation("localhost:8084", page.CurrentNetwork)
|
||||||
return page
|
return page
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,8 +118,19 @@ func (p *Page) onUpdateClick(e *vecty.Event) {
|
||||||
|
|
||||||
func (p *Page) onNetworkChange(network *Network) {
|
func (p *Page) onNetworkChange(network *Network) {
|
||||||
fmt.Println("Network changed:", network)
|
fmt.Println("Network changed:", network)
|
||||||
p.data = network.Data
|
|
||||||
config := p.forceEditor.Config()
|
config := p.forceEditor.Config()
|
||||||
p.layout = layout.NewFromConfig(p.data, config.Config)
|
p.layout = layout.NewFromConfig(network.Data, config.Config)
|
||||||
go p.UpdateGraph()
|
go p.UpdateGraph()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CurrentNetwork returns JSON encoded description of the current graph/network.
|
||||||
|
func (p *Page) CurrentNetwork() []byte {
|
||||||
|
net := p.network.current.Data
|
||||||
|
var buf bytes.Buffer
|
||||||
|
err := formats.NewD3JSON(&buf, true).ExportGraph(net)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("[ERROR] Can't export graph:", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return buf.Bytes()
|
||||||
|
}
|
||||||
|
|
90917
whispervis.js
90917
whispervis.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,29 +1,36 @@
|
||||||
package widgets
|
package widgets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gopherjs/vecty"
|
"github.com/gopherjs/vecty"
|
||||||
"github.com/gopherjs/vecty/elem"
|
"github.com/gopherjs/vecty/elem"
|
||||||
"github.com/gopherjs/vecty/event"
|
"github.com/gopherjs/vecty/event"
|
||||||
"github.com/gopherjs/vecty/prop"
|
"github.com/gopherjs/vecty/prop"
|
||||||
|
"github.com/status-im/simulation/propagation"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Simulation represents configuration panel for propagation simulation.
|
// Simulation represents configuration panel for propagation simulation.
|
||||||
type Simulation struct {
|
type Simulation struct {
|
||||||
vecty.Core
|
vecty.Core
|
||||||
|
networkFn func() []byte // function that returns current network JSON description
|
||||||
|
|
||||||
address string // backend host address
|
address string // backend host address
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSimulation creates new simulation configuration panel. If simulation
|
// NewSimulation creates new simulation configuration panel. If simulation
|
||||||
// backend host address is not specified, it'll use 'localhost:8084' as a default.
|
// backend host address is not specified, it'll use 'localhost:8084' as a default.
|
||||||
func NewSimulation(address string) *Simulation {
|
func NewSimulation(address string, networkFn func() []byte) *Simulation {
|
||||||
if address == "" {
|
if address == "" {
|
||||||
address = "http://localhost:8084"
|
address = "http://localhost:8084"
|
||||||
}
|
}
|
||||||
return &Simulation{
|
return &Simulation{
|
||||||
address: address,
|
address: address,
|
||||||
|
networkFn: networkFn,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +85,42 @@ func (s *Simulation) Address() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Simulation) onSimulateClick(e *vecty.Event) {
|
func (s *Simulation) onSimulateClick(e *vecty.Event) {
|
||||||
// TODO(divan): connect to backend and run simulation
|
if s.networkFn == nil {
|
||||||
fmt.Println("Start simulation")
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
go s.runSimulation()
|
||||||
|
}
|
||||||
|
|
||||||
|
// runSimulation starts whisper message propagation simulation,
|
||||||
|
// remotely talking to simulation backend.
|
||||||
|
func (s *Simulation) runSimulation() {
|
||||||
|
payload := s.networkFn()
|
||||||
|
buf := bytes.NewBuffer(payload)
|
||||||
|
url := "http://" + s.address + "/"
|
||||||
|
resp, err := http.Post(url, "application/json", buf)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("[ERROR] POST request to simulation backend:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var plog propagation.Log
|
||||||
|
err = json.NewDecoder(resp.Body).Decode(&plog)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("[ERROR] decoding response from simulation backend:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var max int
|
||||||
|
for _, ts := range plog.Timestamps {
|
||||||
|
if ts > max {
|
||||||
|
max = ts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
timespan := time.Duration(max) * time.Millisecond
|
||||||
|
fmt.Printf("Whoa! Got results! %d timestamps over %v\n", len(plog.Timestamps), timespan)
|
||||||
|
for i, ts := range plog.Timestamps {
|
||||||
|
fmt.Printf("[%dms] %d / %d links/nodes\n", ts, len(plog.Indices[i]), len(plog.Nodes[i]))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue