mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Can find the biggest diffs
Former-commit-id: 29c753d2460f8c816ff491214331a1eebd3b85dc [formerly 3656760f77b9b5254432788bccd45f49b19282c4] [formerly 850a9052f998d573e0adbbeba43436b6b6fee431 [formerly 594360fe7a
]]
Former-commit-id: c25cbf36f365ded85d14203daf6796ad854b4b5d [formerly cc9f04eb2aa6c93c474cc2f78c3aff2ce9ef6e55]
Former-commit-id: 500c60a54acf1e2501a5083ec13412af3f2b4f47
This commit is contained in:
parent
ae2ec1a113
commit
021dd6e9e7
2
db.go
2
db.go
@ -156,7 +156,7 @@ func (p *CowyoData) save(newText string) error {
|
||||
diffs := dmp.DiffMain(p.CurrentText, newText, true)
|
||||
delta := dmp.DiffToDelta(diffs)
|
||||
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)
|
||||
enc, err := p.encode()
|
||||
if err != nil {
|
||||
|
6
main.go
6
main.go
@ -62,9 +62,9 @@ Options:`)
|
||||
p := CowyoData{"about", about_page, []string{}, []string{}}
|
||||
p.save(about_page)
|
||||
|
||||
//var q CowyoData
|
||||
//q.load("SpikySeaSlug")
|
||||
//rebuildTexts(q)
|
||||
var q CowyoData
|
||||
q.load("SpikySeaSlug2")
|
||||
rebuildTexts(q)
|
||||
|
||||
r := gin.Default()
|
||||
r.LoadHTMLGlob(path.Join(RuntimeArgs.SourcePath, "templates/*"))
|
||||
|
@ -21,7 +21,7 @@
|
||||
textarea {
|
||||
width: 100%;
|
||||
margin: 5px 0;
|
||||
padding: 20px;
|
||||
padding: 10px;
|
||||
border: none;
|
||||
overflow: auto;
|
||||
outline: none;
|
||||
@ -72,10 +72,7 @@
|
||||
<form action='#' id="emit" method="post" name="emit">
|
||||
|
||||
<div>
|
||||
<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 this page.
|
||||
Do not post anything private.
|
||||
Anyone with the URL can access this note.">{{ .CurrentText }}</textarea>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
44
utils.go
44
utils.go
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -93,13 +94,48 @@ func diffRebuildtexts(diffs []diffmatchpatch.Diff) []string {
|
||||
}
|
||||
|
||||
func rebuildTexts(p CowyoData) {
|
||||
m := map[int]int{}
|
||||
dmp := diffmatchpatch.New()
|
||||
current := ""
|
||||
lastText := ""
|
||||
lastTime := time.Now().AddDate(0, -1, 0)
|
||||
for i, diff := range p.Diffs {
|
||||
seq1, _ := dmp.DiffFromDelta(current, diff)
|
||||
seq1, _ := dmp.DiffFromDelta(lastText, diff)
|
||||
texts_linemode := diffRebuildtexts(seq1)
|
||||
rebuilt := texts_linemode[len(texts_linemode)-1]
|
||||
fmt.Println(i, p.Timestamps[i], rebuilt)
|
||||
current = rebuilt
|
||||
parsedTime, _ := time.Parse(time.ANSIC, p.Timestamps[i])
|
||||
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