Rosetta Code/List authors of task descriptions: Difference between revisions

Content added Content deleted
(Added Go)
(→‎{{header|Go}}: Fixed bug, added some program comments and re-ran.)
Line 51: Line 51:
resp, _ := http.Get(url)
resp, _ := http.Get(url)
body, _ := ioutil.ReadAll(resp.Body)
body, _ := ioutil.ReadAll(resp.Body)
// find all tasks
matches := re1.FindAllStringSubmatch(string(body), -1)
matches := re1.FindAllStringSubmatch(string(body), -1)
resp.Body.Close()
resp.Body.Close()
for _, match := range matches {
for _, match := range matches {
tasks = append(tasks, match[1])
// exclude any 'category' references
if !strings.HasPrefix(match[1], "Category:") {
tasks = append(tasks, match[1])
}
}
}
}
}
authors := make(map[string]int)
authors := make(map[string]int)
for _, task := range tasks {
for _, task := range tasks {
// check the last or only history page for each task
page := fmt.Sprintf("http://rosettacode.org/mw/index.php?title=%s&dir=prev&action=history", task)
page := fmt.Sprintf("http://rosettacode.org/mw/index.php?title=%s&dir=prev&action=history", task)
resp, _ := http.Get(page)
resp, _ := http.Get(page)
body, _ := ioutil.ReadAll(resp.Body)
body, _ := ioutil.ReadAll(resp.Body)
// find all the users in that page
matches := re2.FindAllStringSubmatch(string(body), -1)
matches := re2.FindAllStringSubmatch(string(body), -1)
resp.Body.Close()
resp.Body.Close()
// the task author should be the final user on that page
author := matches[len(matches)-1][2]
author := matches[len(matches)-1][2]
author = strings.ReplaceAll(author, "_", " ")
author = strings.ReplaceAll(author, "_", " ")
// add this task to the author's count
authors[author]++
authors[author]++
}
}
// sort the authors in descending order by number of tasks created
authorNumbers := make([]authorNumber, 0, len(authors))
authorNumbers := make([]authorNumber, 0, len(authors))
for k, v := range authors {
for k, v := range authors {
Line 74: Line 83:
sort.Slice(authorNumbers, func(i, j int) bool {
sort.Slice(authorNumbers, func(i, j int) bool {
return authorNumbers[i].number > authorNumbers[j].number
return authorNumbers[i].number > authorNumbers[j].number
})
})
// print the top twenty say
fmt.Println("Total tasks :", len(tasks))
fmt.Println("Total tasks :", len(tasks))
fmt.Println("Total authors :", len(authors))
fmt.Println("Total authors :", len(authors))
Line 94: Line 104:


{{out}}
{{out}}
As of 10th January 2020:
As of 12th January 2020:
<pre>
<pre>
Total tasks : 1222
Total tasks : 1223
Total authors : 282
Total authors : 282


Line 105: Line 115:
1: 176 Paddy3118
1: 176 Paddy3118
2: 71 Markhobley
2: 71 Markhobley
3: 59 Gerard Schildberger
3: 60 Gerard Schildberger
4: 55 Mwn3d
4: 55 Mwn3d
5: 39 NevilleDNZ
5: 39 NevilleDNZ
6: 34 Short Circuit
6: 33 Short Circuit
7: 30 Nigel Galloway
7: 30 Nigel Galloway
8: 25 Thundergnat
8: 25 Thundergnat
Line 119: Line 129:
15: 17 ShinTakezou
15: 17 ShinTakezou
15: 17 Ledrug
15: 17 Ledrug
17: 16 Dmitry-kazakov
15: 17 Dmitry-kazakov
18: 13 Paulo Jorente
18: 13 Waldorf
18: 13 Abu
18: 13 Abu
18: 13 Waldorf
18: 13 Paulo Jorente
</pre>
</pre>