Last active
October 17, 2016 13:07
-
-
Save kaakaa/06f7c2d5d84bb03c492f81451570f08f to your computer and use it in GitHub Desktop.
SpeakerDeckは はてブアプリ で閲覧し辛いがために`後で読む`的に無言ブクマが多くなるのではないか
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"sort" | |
) | |
func analyze_median(bc []BukumaComments) { | |
var result []float64 | |
for _, v := range bc { | |
result = append(result, v.PercentageOfComments) | |
} | |
var s sort.Float64Slice = result | |
s.Sort() | |
fmt.Println(s[1 : len(s)-1]) | |
fmt.Println("Ave: ", average(s[1:len(s)-1]), "\n") | |
} | |
func analyze(bc []BukumaComments) { | |
var result []float64 | |
for _, v := range bc { | |
result = append(result, v.PercentageOfComments) | |
} | |
fmt.Println(result) | |
fmt.Println("Ave: ", average(result), "\n") | |
} | |
func average(f []float64) float64 { | |
sum := 0.0 | |
for _, v := range f { | |
sum += v | |
} | |
return sum / float64(len(f)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
type CountFunction func(*Response) BukumaComments | |
func (r *Response) count(f CountFunction) BukumaComments { | |
return f(r) | |
} | |
type Response struct { | |
Title string | |
Count int | |
Url string | |
Entry_url string | |
Screenshot string | |
Eid int | |
Bookmarks []Bookmark | |
} | |
type Bookmark struct { | |
User string | |
Tags []string | |
Timestamp string | |
Comment string | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"net/http" | |
"sync" | |
) | |
const QueryUrl = "https://b.hatena.ne.jp/entry/jsonlite/%s" | |
var SlideshareLinks = []string{ | |
"http://www.slideshare.net/yutamorishige50/ss-41321443", // 2909 | |
"http://www.slideshare.net/MoriharuOhzu/ss-14083300", // 2001 | |
"http://www.slideshare.net/livesense/web-49772012", // 1094 | |
"http://www.slideshare.net/matsunobu/ss-28303485", // 1049 | |
"http://www.slideshare.net/WinderJason/ss-14830238", // 1005 | |
"http://www.slideshare.net/masuda220/ss-14263541", // 914 | |
"http://www.slideshare.net/TakeharuIgari/htmlcss-34506501", // 906 | |
"http://www.slideshare.net/t_wada/exception-design-by-contract", // 905 | |
"http://www.slideshare.net/websig/websig32-teamlab", // 842 | |
"http://www.slideshare.net/yusukehirao/javascript-28744332", // 730 | |
} | |
var SpeakerDeckLinks = []string{ | |
"https://speakerdeck.com/ken_c_lo/zurui-design", // 2752 | |
"https://speakerdeck.com/naoya/kai-fa-zu-zhi-manezimentofalsekotu", // 1482 | |
"https://speakerdeck.com/naoya/webpuroguramatoshu-xue-falsejie-dian-sofalseru-rikou", // 1169 | |
"https://speakerdeck.com/mirakui/developer-productivity-in-cookpad", // 1093 | |
"https://speakerdeck.com/ykmc09/enziniagana-qi-woshou-reteinaitositara-sokonihaitutaihe-gaarufalsedarou-aruihaitutaihe-ganaifalsedarou", // 1005 | |
"https://speakerdeck.com/isaoshimizu/monsutowozhi-eruinhurafalsejin-tokorekara", // 974 | |
"https://speakerdeck.com/ken_c_lo/webenziniafalsetamefalsewebsabisudezainshi-jian-jiang-zuo", // 867 | |
"https://speakerdeck.com/kanny/miao-jian-shu-mo-falseroguwoiigan-zinisuruakitekutiya", // 829 | |
"https://speakerdeck.com/ken_c_lo/zuruidezaintekunituku2013-plus-semihuratuto-version", // 826 | |
"https://speakerdeck.com/shibayu36/hatenaburogutimufalsekai-fa-hurotogithub", // 814 | |
} | |
var HatenaLinks = []string{ | |
"http://www.find-job.net/startup/api-2013", // 4510 | |
"http://hatenanews.com/articles/201212/12134", // 3568 | |
"http://hatenanews.com/articles/201507/23596", // 2999 | |
"http://chronicle.g.hatena.ne.jp/rikuo/20070404", // 1487 | |
"http://d.hatena.ne.jp/ramyana/20081022/1224695284", // 1479 | |
"http://d.hatena.ne.jp/naoya/20131013/1381651545", // 1344 | |
"http://blog.hatenablog.com/entry/2015/12/29/153000", // 1275 | |
"http://hatenanews.com/articles/201106/4302", // 1019 | |
"http://d.hatena.ne.jp/naoya/20130205/1360062070", // 1019 | |
"http://www.itmedia.co.jp/news/articles/1303/01/news041.html", // 970 | |
} | |
func main() { | |
targets := [][]string{SlideshareLinks, SpeakerDeckLinks, HatenaLinks} | |
var num int | |
for _, v := range targets { | |
num += len(v) | |
} | |
var wg sync.WaitGroup | |
wg.Add(num) | |
var ss, sp, ht []BukumaComments | |
execute(SlideshareLinks, &ss, &wg) | |
execute(SpeakerDeckLinks, &sp, &wg) | |
execute(HatenaLinks, &ht, &wg) | |
wg.Wait() | |
for _, v := range ss { | |
if v.PercentageOfComments > 0.3 { | |
fmt.Println(v) | |
} | |
} | |
for _, v := range ht { | |
if v.PercentageOfComments > 0.3 { | |
fmt.Println(v) | |
} | |
} | |
fmt.Println("==== Slideshare Stats ====") | |
analyze(ss) | |
fmt.Println("==== SpeakerDeck Stats ====") | |
analyze(sp) | |
fmt.Println("==== 「はてな」 Stats ====") | |
analyze(ht) | |
fmt.Println("\n*****************************\n") | |
fmt.Println("==== Slideshare(Median) Stats ====") | |
analyze_median(ss) | |
fmt.Println("==== SpeakerDeck(Median) Stats ====") | |
analyze_median(sp) | |
fmt.Println("==== 「はてな」(Median) Stats ====") | |
analyze_median(ht) | |
} | |
func execute(t []string, bc *[]BukumaComments, wg *sync.WaitGroup) { | |
for _, v := range t { | |
go func(v string) { | |
*bc = append(*bc, count(v)) | |
wg.Done() | |
}(v) | |
} | |
} | |
func count(target string) BukumaComments { | |
url := fmt.Sprintf(QueryUrl, target) | |
resp, err := http.Get(url) | |
if err != nil { | |
panic(err) | |
} | |
defer resp.Body.Close() | |
var response Response | |
json.NewDecoder(resp.Body).Decode(&response) | |
result := response.count(countComments) | |
if err != nil { | |
panic(err) | |
} | |
return result | |
} | |
func countComments(r *Response) BukumaComments { | |
var c, nc int | |
for _, v := range r.Bookmarks { | |
if len(v.Comment) == 0 { | |
nc++ | |
} else { | |
c++ | |
} | |
} | |
return BukumaComments{ | |
Title: r.Title, | |
Count: r.Count, | |
NumOfComments: c, | |
NumOfNoComments: nc, | |
PercentageOfComments: float64(c) / float64(c+nc), | |
} | |
} | |
type BukumaComments struct { | |
Title string | |
Count int | |
NumOfComments int | |
NumOfNoComments int | |
PercentageOfComments float64 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment