1
0
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:
Zack Scholl 2016-02-09 17:52:52 -05:00
parent 825139b9a1
commit 594360fe7a
4 changed files with 46 additions and 13 deletions

2
db.go
View File

@ -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 {

View File

@ -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/*"))

View File

@ -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>

View File

@ -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)
}
}
}
}