sonic

package module
v0.0.0-...-e62d76c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 12 Imported by: 0

README

Sonic

Lookout analyzer that generates sound from PRs.

The analyzer part uses bblfsh to extract the UAST nodes from old and new code separating the nodes in deleted and added. It gets the type of node, token (name), size (characters) and hash (used for comparing).

Sound generation is compatible with any midi synthesizer which exposes midi device. Currently the data sent is:

  • Note
  • Duration (sustain time in seconds)

Two note sequences are generated per file, one for deleted and another one for added:

  • file 1
    • deleted sequence
    • added sequence
  • file 2
    • deleted sequence
    • added sequence
  • ...

Note generation is done using Markov chains. The idea was taken from a hackernoon post and even two of its midi files borrowed to generate the two chains used in the project:

The midi files are not used as is but converted first to JSON so they are easier to read in the project. This web application was used to convert them.

Even if it's not really noticeable delete sequences use song1.midi Markov chain and added use song2.midi. To pick one of the weighted notes we use the FNV hash of the token (name).

Duration is a direct conversion from the node size with a maximum of 250 milliseconds.

Getting Started

Here's the information on how to configure midi synthesizer and the development environment. The project as is cannot be used to send data to github as the sound is played where synthesizer is running.

Prerequisites
docker run -d --name bblfshd --privileged -p 9432:9432 -v /var/lib/bblfshd:/var/lib/bblfshd bblfsh/bblfshd:latest
apt-get install libportmidi-dev
# or
brew install portmidi

Running it

Sound tests

There's a sound test with hardcoded data that can be run with:

go run cmd/test/main.go
Run analyzer

Start analyzer:

go run cmd/sonic/main.go

Analyze a change (last commit of a repo)

  • Go to a directory with the commit we want to analyze
  • git checkout to the specific dir in case we are not in it
  • Execute lookout-sdk executable:
$PATH_TO_LOOKOUT_SDK_BINARY/lookout-sdk review ipv4://localhost:2001

Authors

  • Maxim Sukharev
  • Javi Fontán

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File1 = Changes{
	Old: []sonicNode{
		{"FuncDecl", "TestIntegration", 8427, empty},
		{"FuncDecl", "TestUastQueries", 1625, empty},
		{"FuncDecl", "TestSquashCorrectness ", 3295, empty},
		{"FuncDecl", "queryResults", 347, empty},
		{"FuncDecl", "TestMissingHeadRefs", 751, empty},
		{"FuncDecl", "BenchmarkQueries", 3601, empty},
		{"FuncDecl", "benchmarkQuery", 252, empty},
		{"FuncDecl", "TestIndexes", 3147, empty},
		{"FuncDecl", "col", 285, empty},
		{"FuncDecl", "createTestIndexes", 1488, empty},
		{"FuncDecl", "createIndex", 311, empty},
		{"FuncDecl", "deleteIndex", 175, empty},
		{"FuncDecl", "setup", 370, empty},
		{"FuncDecl", "newSquashEngine", 351, empty},
		{"FuncDecl", "newBaseEngine", 219, empty},
	},
	New: []sonicNode{
		{"FuncDecl", "TestIntegration", 8427, empty},
		{"FuncDecl", "TestUastQueries", 1625, empty},
		{"FuncDecl", "TestSquashCorrectness", 3295, empty},
		{"FuncDecl", "queryResults", 347, empty},
		{"FuncDecl", "TestMissingHeadRefs", 751, empty},
		{"FuncDecl", "BenchmarkQueries", 3601, empty},
		{"FuncDecl", "benchmarkQuery", 252, empty},
		{"FuncDecl", "TestIndexes", 3147, empty},
		{"FuncDecl", "col", 285, empty},
		{"FuncDecl", "createTestIndexes", 1488, empty},
		{"FuncDecl", "createIndex", 311, empty},
		{"FuncDecl", "deleteIndex", 175, empty},
		{"FuncDecl", "setup", 370, empty},
		{"FuncDecl", "newSquashEngine", 351, empty},
		{"FuncDecl", "newBaseEngine", 219, empty},
	},
}

Functions

func Convert

func Convert(scale sound.Scale, nodes []sonicNode) []sound.Note

func ConvertMarkov

func ConvertMarkov(m sound.Markov, nodes []sonicNode) []sound.Note

Types

type Analyzer

type Analyzer struct {
	DataClient *lookout.DataClient
	DeviceID   portmidi.DeviceID
}

func (*Analyzer) NotifyPushEvent

func (a *Analyzer) NotifyPushEvent(ctx context.Context, e *pb.PushEvent) (*pb.EventResponse, error)

func (*Analyzer) NotifyReviewEvent

func (a *Analyzer) NotifyReviewEvent(ctx context.Context, e *pb.ReviewEvent) (*pb.EventResponse, error)

type Changes

type Changes struct {
	Old []sonicNode
	New []sonicNode
}

Directories

Path Synopsis
cmd
src

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL