From 021dd6e9e729412d6c514909bb8c9a3ea1a9c0b1 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 9 Feb 2016 17:52:52 -0500 Subject: [PATCH] Can find the biggest diffs Former-commit-id: 29c753d2460f8c816ff491214331a1eebd3b85dc [formerly 3656760f77b9b5254432788bccd45f49b19282c4] [formerly 850a9052f998d573e0adbbeba43436b6b6fee431 [formerly 594360fe7ab09489ae630f070b62fb52b0fabc32]] Former-commit-id: c25cbf36f365ded85d14203daf6796ad854b4b5d [formerly cc9f04eb2aa6c93c474cc2f78c3aff2ce9ef6e55] Former-commit-id: 500c60a54acf1e2501a5083ec13412af3f2b4f47 --- db.go | 2 +- main.go | 6 +++--- templates/index.tmpl | 7 ++----- utils.go | 44 ++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 46 insertions(+), 13 deletions(-) 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) + } + } + } + }