mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Can find the biggest diffs
This commit is contained in:
parent
825139b9a1
commit
594360fe7a
2
db.go
2
db.go
@ -156,7 +156,7 @@ func (p *CowyoData) save(newText string) error {
|
|||||||
diffs := dmp.DiffMain(p.CurrentText, newText, true)
|
diffs := dmp.DiffMain(p.CurrentText, newText, true)
|
||||||
delta := dmp.DiffToDelta(diffs)
|
delta := dmp.DiffToDelta(diffs)
|
||||||
p.CurrentText = newText
|
p.CurrentText = newText
|
||||||
p.Timestamps = append(p.Timestamps, time.Now().String())
|
p.Timestamps = append(p.Timestamps, time.Now().Format(time.ANSIC))
|
||||||
p.Diffs = append(p.Diffs, delta)
|
p.Diffs = append(p.Diffs, delta)
|
||||||
enc, err := p.encode()
|
enc, err := p.encode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
6
main.go
6
main.go
@ -62,9 +62,9 @@ Options:`)
|
|||||||
p := CowyoData{"about", about_page, []string{}, []string{}}
|
p := CowyoData{"about", about_page, []string{}, []string{}}
|
||||||
p.save(about_page)
|
p.save(about_page)
|
||||||
|
|
||||||
//var q CowyoData
|
var q CowyoData
|
||||||
//q.load("SpikySeaSlug")
|
q.load("SpikySeaSlug2")
|
||||||
//rebuildTexts(q)
|
rebuildTexts(q)
|
||||||
|
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
r.LoadHTMLGlob(path.Join(RuntimeArgs.SourcePath, "templates/*"))
|
r.LoadHTMLGlob(path.Join(RuntimeArgs.SourcePath, "templates/*"))
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
textarea {
|
textarea {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin: 5px 0;
|
margin: 5px 0;
|
||||||
padding: 20px;
|
padding: 10px;
|
||||||
border: none;
|
border: none;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
outline: none;
|
outline: none;
|
||||||
@ -72,10 +72,7 @@
|
|||||||
<form action='#' id="emit" method="post" name="emit">
|
<form action='#' id="emit" method="post" name="emit">
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<textarea autofocus rows={{ .NumRows }} class='auto_submit_item' id="emit_data" name="emit_data" placeholder="Start typing, it will save automatically.
|
<textarea autofocus rows={{ .NumRows }} class='auto_submit_item' id="emit_data" name="emit_data" placeholder="Start typing, it will save automatically. Go to cowyo.com/{{ .Title }} to reload your note. Do not post anything private since anyone with the URL can access this note.">{{ .CurrentText }}</textarea>
|
||||||
Go to cowyo.com/{{ .Title }} to reload this page.
|
|
||||||
Do not post anything private.
|
|
||||||
Anyone with the URL can access this note.">{{ .CurrentText }}</textarea>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
44
utils.go
44
utils.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -93,13 +94,48 @@ func diffRebuildtexts(diffs []diffmatchpatch.Diff) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func rebuildTexts(p CowyoData) {
|
func rebuildTexts(p CowyoData) {
|
||||||
|
m := map[int]int{}
|
||||||
dmp := diffmatchpatch.New()
|
dmp := diffmatchpatch.New()
|
||||||
current := ""
|
lastText := ""
|
||||||
|
lastTime := time.Now().AddDate(0, -1, 0)
|
||||||
for i, diff := range p.Diffs {
|
for i, diff := range p.Diffs {
|
||||||
seq1, _ := dmp.DiffFromDelta(current, diff)
|
seq1, _ := dmp.DiffFromDelta(lastText, diff)
|
||||||
texts_linemode := diffRebuildtexts(seq1)
|
texts_linemode := diffRebuildtexts(seq1)
|
||||||
rebuilt := texts_linemode[len(texts_linemode)-1]
|
rebuilt := texts_linemode[len(texts_linemode)-1]
|
||||||
fmt.Println(i, p.Timestamps[i], rebuilt)
|
parsedTime, _ := time.Parse(time.ANSIC, p.Timestamps[i])
|
||||||
current = rebuilt
|
duration := parsedTime.Sub(lastTime)
|
||||||
|
// fmt.Println(duration.Hours())
|
||||||
|
// fmt.Println("---------------")
|
||||||
|
// fmt.Println(i, p.Timestamps[i])
|
||||||
|
// fmt.Println(i, parsedTime)
|
||||||
|
// fmt.Println(i, lastTime)
|
||||||
|
// fmt.Println(i, duration)
|
||||||
|
// fmt.Println(i, rebuilt)
|
||||||
|
// fmt.Println("---------------")
|
||||||
|
m[i] = int(duration.Seconds())
|
||||||
|
if i > 0 {
|
||||||
|
m[i-1] = m[i]
|
||||||
}
|
}
|
||||||
|
// On to the next one
|
||||||
|
lastText = rebuilt
|
||||||
|
lastTime = parsedTime
|
||||||
|
}
|
||||||
|
fmt.Println(m)
|
||||||
|
n := map[int][]int{}
|
||||||
|
var a []int
|
||||||
|
for k, v := range m {
|
||||||
|
n[v] = append(n[v], k)
|
||||||
|
}
|
||||||
|
for k := range n {
|
||||||
|
a = append(a, k)
|
||||||
|
}
|
||||||
|
sort.Sort(sort.Reverse(sort.IntSlice(a)))
|
||||||
|
for _, k := range a {
|
||||||
|
for _, s := range n[k] {
|
||||||
|
if s != 0 && s != len(n) {
|
||||||
|
fmt.Printf("%d, %d\n", s, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user