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

Keep track of changes of documents (halfway there) #6

Closed
schollz opened this issue Feb 7, 2016 · 4 comments
Closed

Keep track of changes of documents (halfway there) #6

schollz opened this issue Feb 7, 2016 · 4 comments

Comments

@schollz
Copy link
Owner

schollz commented Feb 7, 2016

I guess this could be done by storing diffs, or by storing a git internally or something...

@schollz
Copy link
Owner Author

schollz commented Feb 7, 2016

Its actually easy:

package main

import (
    "fmt"

    "github.com/sergi/go-diff/diffmatchpatch"
)

func diffRebuildtexts(diffs []diffmatchpatch.Diff) []string {
    text := []string{"", ""}
    for _, myDiff := range diffs {
        if myDiff.Type != diffmatchpatch.DiffInsert {
            text[0] += myDiff.Text
        }
        if myDiff.Type != diffmatchpatch.DiffDelete {
            text[1] += myDiff.Text
        }
    }
    return text
}

func main() {
    dmp := diffmatchpatch.New()

    a := "tiger"
    b := "tigor"
    diffs := dmp.DiffMain(a, b, true)

    // Store as strings
    delta := dmp.DiffToDelta(diffs)
    fmt.Println(diffs)
    text1 := dmp.DiffText1(diffs)
    fmt.Println(text1, delta)

    // rebuild from strings
    seq1, _ := dmp.DiffFromDelta(text1, delta)
    fmt.Println(seq1)
    texts_linemode := diffRebuildtexts(seq1)
    latest := texts_linemode[len(texts_linemode)-1]

    fmt.Println(latest)

    // add something else
    newest := "tigre"
    diffs = dmp.DiffMain(latest, newest, true)
    // Store as strings
    delta = dmp.DiffToDelta(diffs)
    fmt.Println(diffs)
    text1 = dmp.DiffText1(diffs)
    fmt.Println(text1, delta)

    // rebuild from strings
    seq1, _ = dmp.DiffFromDelta(text1, delta)
    fmt.Println(seq1)
    texts_linemode = diffRebuildtexts(seq1)
    latest = texts_linemode[len(texts_linemode)-1]

    fmt.Println(latest)

}

@schollz schollz changed the title Keep track of changes of documents [need help] Keep track of changes of documents (halfway there) Feb 7, 2016
@schollz
Copy link
Owner Author

schollz commented Feb 7, 2016

Its halfway there...got the diffs in there. Just need to make a client side way of accessing them.

@schollz
Copy link
Owner Author

schollz commented Feb 8, 2016

A subset of the diff documents should be shown to the user. Maybe all the documents that have a time between diffs of > 10 minutes? Or maybe a dynamic time setting that will allow fine/coarse adjustments. Or maybe just return the top 10 links to documents that have the greatest diffs between them.

@schollz
Copy link
Owner Author

schollz commented Feb 10, 2016

Done

@schollz schollz closed this as completed Feb 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant