Skip to content
Snippets Groups Projects
Commit 5e2be55c authored by Hans Kristian Hoel's avatar Hans Kristian Hoel
Browse files

tring to sett up list of languages to display the code that is most used

parent 4944ef82
No related branches found
No related tags found
No related merge requests found
......@@ -8,37 +8,26 @@ import (
"strconv"
)
// func Counter(S []map[string]float64) map[string]int {
// //List := strings.Fields(S)
// count := make(map[string]int)
// for _, Lang := range S {
// _, ok := count[Lang]
// if ok {
// count[Lang] += 1func Counter(S []map[string]float64) map[string]int {
// //List := strings.Fields(S)
// count := make(map[string]int)
// for _, Lang := range S {
// _, ok := count[Lang]
// if ok {
// count[Lang] += 1
// } else {
// count[Lang] = 1
// }
// }
// return count
// }
// } else {
// count[Lang] = 1
// }
// }
// return count
// }
func Counter(S []string) map[string]int {
//List := strings.Fields(S)
count := make(map[string]int)
for _, Lang := range S {
_, ok := count[Lang]
if ok {
count[Lang] += 1
} else {
count[Lang] = 1
}
}
return count
}
func HandlerLanguages(w http.ResponseWriter, r *http.Request) {
var I []IDLang
var L Language
var Code []map[string]float64
var Code []string
URL1 := "https://git.gvk.idi.ntnu.no/api/v4/projects" // main url
URL2 := "https://git.gvk.idi.ntnu.no/api/v4/projects?private_token=" // url for token
......@@ -89,9 +78,9 @@ func HandlerLanguages(w http.ResponseWriter, r *http.Request) {
URL = URL + "?private_token=" + auth // adds token to link
}
fmt.Println(URL) //****************************************************************
// fmt.Println(URL) //****************************************************************
var CodeTemp map[string]float64
var CodeTemp = make(map[string]interface{})
resp = DoRequest(Client, w, URL) // request link
......@@ -101,13 +90,18 @@ func HandlerLanguages(w http.ResponseWriter, r *http.Request) {
return
}
Code = append(Code, CodeTemp)
for j := range CodeTemp {
Code = append(Code, j)
}
}
for CodeLang, NumCount := range Counter(Code) {
fmt.Println(CodeLang, "=", NumCount)
}
// fmt.Println(Code)
// for CodeLang, NumCount := range Counter(Code) {
// fmt.Println(CodeLang, "=", NumCount)
// }
L.Languages = append(L.Languages, Code...)
limit := QueryGet("limit", "5", r) // gets limit for localhost link
......
......@@ -27,10 +27,6 @@ type IDLang struct {
ID int `json:"id"`
}
type CodeType struct {
CodeMap map[string]float64
}
type Language struct {
Languages []string `json:"lagnguages"`
Auth bool `json:"auth"`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment