diff --git a/db.go b/db.go index a1e5c41..4245057 100644 --- a/db.go +++ b/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 { diff --git a/main.go b/main.go index b048c8b..db39c7f 100644 --- a/main.go +++ b/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/*")) diff --git a/templates/index.tmpl b/templates/index.tmpl index 8636d52..0916f81 100644 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -21,7 +21,7 @@ textarea { width: 100%; margin: 5px 0; - padding: 20px; + padding: 10px; border: none; overflow: auto; outline: none; @@ -72,10 +72,7 @@
- +
diff --git a/utils.go b/utils.go index 3882400..ed02a0a 100644 --- a/utils.go +++ b/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) + } + } + } + }