diff --git a/backend/goserver/goserver b/backend/goserver/goserver index 90bd0d8..2ab198d 100755 Binary files a/backend/goserver/goserver and b/backend/goserver/goserver differ diff --git a/backend/goserver/list_tools.txt b/backend/goserver/list_tools.txt new file mode 100644 index 0000000..a87fe6e --- /dev/null +++ b/backend/goserver/list_tools.txt @@ -0,0 +1,37 @@ +KritaSelected/KisToolColorPicker +KritaFill/KisToolGradient +KritaShape/KisToolLazyBrush +KisToolTransform +KarbonCalligraphyTool +InteractionTool +KritaFill/KisToolFill +KritaShape/KisToolMultiBrush +KisToolSelectRectangular +ArtisticTextTool +VectorTool +KisToolPolygon +KisToolPencil +KisToolPath +KisToolSelectPolygonal +KritaShape/KisToolRectangle +KritaShape/KisToolEllipse +KritaTransform/KisToolMove +KritaShape/KisToolMeasure +TextTool +ZoomTool +KisRulerAssistantTool +KisToolPolyline +CreateShapesTool +KritaShape/KisToolBrush +KisToolSelectPath +KisToolSelectSimilar +KisToolSelectOutline +KritaShape/KisToolDyna +PathTool +KritaShape/KisToolText +KisToolCrop +KritaShape/KisToolLine +KritaShape/KisToolSmartPatch +PanTool +KisToolSelectElliptical +KisToolSelectContiguous diff --git a/backend/goserver/main.go b/backend/goserver/main.go index 4b00317..a416e1f 100644 --- a/backend/goserver/main.go +++ b/backend/goserver/main.go @@ -1,94 +1,99 @@ package main import ( "encoding/json" "fmt" "io/ioutil" sw "kritaServers/backend/goserver/server" "net/http" "time" ) type ColorGroup struct { ID int Name string Colors []string } func handlerInstall(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) fmt.Printf("REQUEST") bodyBuffer, _ := ioutil.ReadAll(r.Body) // fmt.Printf("after parse") //fmt.Println(string(bodyBuffer)) sw.InsertGeneralInfo(bodyBuffer) } func handlerTools(w http.ResponseWriter, r *http.Request) { bodyBuffer, _ := ioutil.ReadAll(r.Body) - // fmt.Println(string(bodyBuffer)) sw.InsertToolInfo(bodyBuffer) } func handlerImageProperties(w http.ResponseWriter, r *http.Request) { bodyBuffer, _ := ioutil.ReadAll(r.Body) //fmt.Println(string(bodyBuffer)) sw.InsertImageInfo(bodyBuffer) } func handlerAsserts(w http.ResponseWriter, r *http.Request) { // bodyBuffer, _ := ioutil.ReadAll(r.Body) fmt.Printf("Asserts") // fmt.Println(string(bodyBuffer)) // sw.InsertAssertInfo(bodyBuffer) } func handlerAgregatedData(w http.ResponseWriter, r *http.Request) { dataType := r.URL.Query().Get("datatype") result, err := json.Marshal(sw.GetAgregatedData(dataType)) sw.CheckErr(err) w.Write(result) } func handlerActions(w http.ResponseWriter, r *http.Request) { bodyBuffer, _ := ioutil.ReadAll(r.Body) fmt.Println(string(bodyBuffer)) sw.InsertActionInfo(bodyBuffer) } func handlerHello(w http.ResponseWriter, r *http.Request) { temp := sw.Agregated() fmt.Fprintf(w, temp) } func main() { fmt.Printf("hello") sw.InitDB() defer sw.Session.Close() http.HandleFunc("/install/receiver/submit/org.krita.krita/", handlerInstall) http.HandleFunc("/tools/receiver/submit/org.krita.krita/", handlerTools) http.HandleFunc("/imageProperties/receiver/submit/org.krita.krita/", handlerImageProperties) http.HandleFunc("/asserts/receiver/submit/org.krita.krita/", handlerAsserts) http.HandleFunc("/actions/receiver/submit/org.krita.krita/", handlerActions) http.HandleFunc("/agregatedData", handlerAgregatedData) http.HandleFunc("/GoogleLogin", sw.HandleGoogleLogin) http.HandleFunc("/GoogleCallback", sw.HandleGoogleCallback) http.HandleFunc("/", handlerHello) ticker := time.NewTicker(time.Minute * 2) - tickerActions := time.NewTicker(time.Second * 10) + tickerActions := time.NewTicker(time.Minute * 3) + tickerTools := time.NewTicker(time.Second * 10) go func() { for t := range ticker.C { sw.AgregateInstalInfo() fmt.Println("Tick at", t) } }() go func() { for t := range tickerActions.C { sw.AgregateActions() - sw.AgregateTools() fmt.Println("Tick actions at", t) } }() + go func() { + for t := range tickerTools.C { + sw.AgregateTools() + fmt.Println("Tick tools at", t) + } + }() http.ListenAndServe(":8080", nil) } diff --git a/backend/goserver/server/agregateInfo.go b/backend/goserver/server/agregateInfo.go index 7d1a74a..4bbc846 100644 --- a/backend/goserver/server/agregateInfo.go +++ b/backend/goserver/server/agregateInfo.go @@ -1,182 +1,191 @@ package server import ( "bufio" "encoding/json" "fmt" md "kritaServers/backend/goserver/server/models" "os" "gopkg.in/mgo.v2/bson" ) var agreagtedData md.CollectedData func getFloat64(n int, err error) float64 { CheckErr(err) return float64(n) } func checkOtherCount(count float64) float64 { if count < 0 { return 0 } return count } func countActionsUse(name string) float64 { results := []bson.M{} c := Session.DB("telemetry").C("actions") pipe := c.Pipe([]bson.M{{"$unwind": "$actions"}, {"$match": bson.M{"actions.actionname": name}}, {"$group": bson.M{"_id": "$actions.actionname", "total_count": bson.M{"$sum": "$actions.countuse"}}}}) //fmt.Println(pipe) resp := []bson.M{} err := pipe.All(&resp) CheckErr(err) //fmt.Println(resp) // simple print proving it's working err = pipe.All(&results) CheckErr(err) if len(results) > 0 { num, _ := results[0]["total_count"].(float64) return num } return 0 } -func countToolsUse(name string) float64 { - results := []bson.M{} +func countToolsUse(name string) (float64, float64) { + resultsCount := []bson.M{} + resultsAvg := []bson.M{} + + var countUse float64 + var averageTimeUse float64 c := Session.DB("telemetry").C("tools") pipe := c.Pipe([]bson.M{{"$unwind": "$tools"}, {"$match": bson.M{"tools.toolname": name}}, {"$group": bson.M{"_id": "$tools.toolname", "total_count": bson.M{"$sum": "$tools.countuse"}}}}) - //fmt.Println(pipe) + pipe2 := c.Pipe([]bson.M{{"$unwind": "$tools"}, {"$match": bson.M{"tools.toolname": name}}, {"$group": bson.M{"_id": "$tools.toolname", "total_count": bson.M{"$avg": "$tools.time"}}}}) + resp := []bson.M{} + resp2 := []bson.M{} err := pipe.All(&resp) + err = pipe2.All(&resp2) CheckErr(err) - //fmt.Println(resp) // simple print proving it's working - err = pipe.All(&results) + err = pipe.All(&resultsCount) + err = pipe2.All(&resultsAvg) CheckErr(err) - fmt.Println(len(results)) - if len(results) > 0 { - num, _ := results[0]["total_count"].(float64) - fmt.Println(name, num) - return num + if len(resultsCount) > 0 { + countUse, _ = resultsCount[0]["total_count"].(float64) + // fmt.Println(name, num) } - return 0 + if len(resultsAvg) > 0 { + averageTimeUse, _ = resultsAvg[0]["total_count"].(float64) + fmt.Println(name, averageTimeUse) + } + return countUse, averageTimeUse } func AgregateActions() { - // agreagtedData.Actions.Add_new_paint_layer = countActionsUse("add_new_paint_layer") - // agreagtedData.Actions.Clear = countActionsUse("clear") - // agreagtedData.Actions.Copy_layer_clipboard = countActionsUse("copy_layer_clipboard") - // agreagtedData.Actions.Cut_layer_clipboard = countActionsUse("сut_layer_clipboard") - // agreagtedData.Actions.Edit_cut = countActionsUse("edit_cut") - // agreagtedData.Actions.Edit_redo = countActionsUse("edit_redo") - // agreagtedData.Actions.Edit_undo = countActionsUse("edit_undo") - // agreagtedData.Actions.File_new = countActionsUse("file_new") - // agreagtedData.Actions.Fill_selection_background_color = countActionsUse("fill_selection_background_color") - // agreagtedData.Actions.Fill_selection_foreground_color = countActionsUse("fill_selection_foreground_color") - // agreagtedData.Actions.Fill_selection_pattern = countActionsUse("fill_selection_pattern") - // agreagtedData.Actions.Paste_at = countActionsUse("paste_at") - // agreagtedData.Actions.Stroke_selection = countActionsUse("stroke_selection") - // agreagtedData.Actions.View_show_canvas_only = countActionsUse("view_show_canvas_only") file, err := os.Open("list_actions.txt") CheckErr(err) defer file.Close() var action md.ActionCollected scanner := bufio.NewScanner(file) for scanner.Scan() { action.Name = scanner.Text() action.CountUse = countActionsUse(action.Name) agreagtedData.Actions = append(agreagtedData.Actions, action) } - - // check for errors err = scanner.Err() CheckErr(err) - } func AgregateTools() { - agreagtedData.Tools.KisToolBrush = countToolsUse("Tool/Activate/KritaShape/KisToolBrush") - agreagtedData.Tools.KisToolLine = countToolsUse("Tool/Activate/KritaShape/KisToolLine") + file, err := os.Open("list_tools.txt") + CheckErr(err) + defer file.Close() + + var ToolUse md.ToolsCollected + var ToolActivate md.ToolsCollected + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + ToolUse.Name = scanner.Text() + ToolUse.CountUse, _ = countToolsUse("/Use/" + ToolUse.Name) + agreagtedData.ToolsUse = append(agreagtedData.ToolsUse, ToolUse) + + ToolActivate.Name = ToolUse.Name + ToolActivate.CountUse, _ = countToolsUse("/Activate/" + ToolActivate.Name) + agreagtedData.ToolsActivate = append(agreagtedData.ToolsActivate, ToolUse) + } + err = scanner.Err() + CheckErr(err) } func AgregateInstalInfo() { c := Session.DB("telemetry").C("installInfo") //Some error takes place. We lose a little bit of data countRecords := getFloat64(c.Find(bson.M{}).Count()) //compiler agreagtedData.Compiler.Type.GCC = getFloat64(c.Find(bson.M{"compiler.type": "GCC"}).Count()) agreagtedData.Compiler.Type.Clang = getFloat64(c.Find(bson.M{"compiler.type": "Clang"}).Count()) agreagtedData.Compiler.Type.MSVC = getFloat64(c.Find(bson.M{"compiler.type": "MSVC"}).Count()) agreagtedData.Compiler.Type.Other = countRecords - agreagtedData.Compiler.Type.GCC - agreagtedData.Compiler.Type.Clang - agreagtedData.Compiler.Type.MSVC agreagtedData.Compiler.Type.Other = checkOtherCount(agreagtedData.Compiler.Type.Other) //os agreagtedData.Platform.Os.Linux = getFloat64(c.Find(bson.M{"platform.os": "linux"}).Count()) agreagtedData.Platform.Os.Windows = getFloat64(c.Find(bson.M{"platform.os": "windows"}).Count()) agreagtedData.Platform.Os.Mac = getFloat64(c.Find(bson.M{"platform.os": "mac"}).Count()) agreagtedData.Platform.Os.Other = countRecords - agreagtedData.Platform.Os.Linux - agreagtedData.Platform.Os.Windows - agreagtedData.Platform.Os.Mac agreagtedData.Platform.Os.Other = checkOtherCount(agreagtedData.Platform.Os.Other) fmt.Println("LINUX") fmt.Println(agreagtedData.Platform.Os.Linux) fmt.Println(agreagtedData.Platform.Os.Other) //version os windows agreagtedData.Platform.Version.Windows.V7 = getFloat64(c.Find(bson.M{"platform.version": "7"}).Count()) agreagtedData.Platform.Version.Windows.V8 = getFloat64(c.Find(bson.M{"platform.version": "8"}).Count()) agreagtedData.Platform.Version.Windows.V81 = getFloat64(c.Find(bson.M{"platform.version": "8.1"}).Count()) agreagtedData.Platform.Version.Windows.V10 = getFloat64(c.Find(bson.M{"platform.version": "10"}).Count()) agreagtedData.Platform.Version.Windows.Other = agreagtedData.Platform.Os.Windows - agreagtedData.Platform.Version.Windows.V7 - agreagtedData.Platform.Version.Windows.V8 - agreagtedData.Platform.Version.Windows.V81 - agreagtedData.Platform.Version.Windows.V10 agreagtedData.Platform.Version.Windows.Other = checkOtherCount(agreagtedData.Platform.Version.Windows.Other) //version os linux //не уверен, что именно так пишется нужные версии linux agreagtedData.Platform.Version.Linux.Ubuntu1404 = getFloat64(c.Find(bson.M{"platform.version": "ubuntu-14.04"}).Count()) agreagtedData.Platform.Version.Linux.Ubuntu1410 = getFloat64(c.Find(bson.M{"platform.version": "ubuntu-14.10"}).Count()) agreagtedData.Platform.Version.Linux.Ubuntu1504 = getFloat64(c.Find(bson.M{"platform.version": "ubuntu-15.04"}).Count()) agreagtedData.Platform.Version.Linux.Ubuntu1510 = getFloat64(c.Find(bson.M{"platform.version": "ubuntu-15.10"}).Count()) agreagtedData.Platform.Version.Linux.Ubuntu1604 = getFloat64(c.Find(bson.M{"platform.version": "ubuntu-16.04"}).Count()) agreagtedData.Platform.Version.Linux.Other = agreagtedData.Platform.Os.Linux - agreagtedData.Platform.Version.Linux.Ubuntu1404 - agreagtedData.Platform.Version.Linux.Ubuntu1410 - agreagtedData.Platform.Version.Linux.Ubuntu1504 - agreagtedData.Platform.Version.Linux.Ubuntu1510 - agreagtedData.Platform.Version.Linux.Ubuntu1604 - agreagtedData.Platform.Version.Linux.Ubuntu1610 - agreagtedData.Platform.Version.Linux.Ubuntu1704 agreagtedData.Platform.Version.Linux.Other = checkOtherCount(agreagtedData.Platform.Version.Linux.Other) agreagtedData.Platform.Version.Mac.V1012 = getFloat64(c.Find(bson.M{"platform.version": "10.12"}).Count()) agreagtedData.Platform.Version.Mac.Other = agreagtedData.Platform.Os.Mac - agreagtedData.Platform.Version.Mac.V1012 agreagtedData.Platform.Version.Mac.Other = checkOtherCount(agreagtedData.Platform.Version.Linux.Other) //cpu agreagtedData.CPU.Architecture.X86_64 = getFloat64(c.Find(bson.M{"cpu.architecture": "x86_64"}).Count()) agreagtedData.CPU.Architecture.X86 = getFloat64(c.Find(bson.M{"cpu.architecture": "i386"}).Count()) agreagtedData.CPU.Architecture.Other = countRecords - agreagtedData.CPU.Architecture.X86_64 - agreagtedData.CPU.Architecture.X86 agreagtedData.CPU.Architecture.Other = checkOtherCount(agreagtedData.CPU.Architecture.Other) agreagtedData.CPU.Cores.C1 = getFloat64(c.Find(bson.M{"cpu.count": "1"}).Count()) agreagtedData.CPU.Cores.C2 = getFloat64(c.Find(bson.M{"cpu.count": "2"}).Count()) agreagtedData.CPU.Cores.C3 = getFloat64(c.Find(bson.M{"cpu.count": "3"}).Count()) agreagtedData.CPU.Cores.C4 = getFloat64(c.Find(bson.M{"cpu.count": "4"}).Count()) agreagtedData.CPU.Cores.C6 = getFloat64(c.Find(bson.M{"cpu.count": "6"}).Count()) agreagtedData.CPU.Cores.C8 = getFloat64(c.Find(bson.M{"cpu.count": "8"}).Count()) agreagtedData.CPU.Cores.Other = countRecords - agreagtedData.CPU.Cores.C1 - agreagtedData.CPU.Cores.C2 - agreagtedData.CPU.Cores.C3 - agreagtedData.CPU.Cores.C4 - agreagtedData.CPU.Cores.C6 - agreagtedData.CPU.Cores.C8 agreagtedData.Locale.Language.English = getFloat64(c.Find(bson.M{"locale.language": "English"}).Count()) agreagtedData.Locale.Language.Russian = getFloat64(c.Find(bson.M{"locale.language": "Russian"}).Count()) agreagtedData.Locale.Language.Other = countRecords - agreagtedData.Locale.Language.English - agreagtedData.Locale.Language.Russian agreagtedData.Locale.Language.Other = checkOtherCount(agreagtedData.Locale.Language.Other) } func Agregated() string { out, _ := json.Marshal(agreagtedData) return string(out) } func AgregateToolsInfo() { } func GetAgregatedData(dataType string) md.CollectedData { switch dataType { case "install": return agreagtedData case "tools": default: var err md.CustomError err.Message = "Wrong request" } return agreagtedData } diff --git a/backend/goserver/server/models/collectModel.go b/backend/goserver/server/models/collectModel.go index c5450e5..3b3fe84 100644 --- a/backend/goserver/server/models/collectModel.go +++ b/backend/goserver/server/models/collectModel.go @@ -1,81 +1,87 @@ package models type ActionCollected struct { CountUse float64 Name string } +type ToolsCollected struct { + CountUse float64 + Name string +} type CollectedData struct { Platform struct { Os struct { Windows float64 Linux float64 Mac float64 Other float64 } Version struct { Windows struct { V7 float64 V8 float64 V81 float64 V10 float64 Other float64 } Linux struct { Ubuntu1404 float64 Ubuntu1410 float64 Ubuntu1504 float64 Ubuntu1510 float64 Ubuntu1604 float64 Ubuntu1610 float64 Ubuntu1704 float64 Other float64 } Mac struct { V1012 float64 Other float64 } } } CPU struct { Architecture struct { X86_64 float64 X86 float64 //на самом деле x86_64 c маленькой буквы Other float64 } Cores struct { C1 float64 C2 float64 C3 float64 C4 float64 C6 float64 C8 float64 Other float64 } } Compiler struct { Type struct { GCC float64 Clang float64 MSVC float64 Other float64 } // Version struct { //подумать что можно сделать // V5dot4 float64 // Other float64 // } } Locale struct { Language struct { English float64 Russian float64 Other float64 } } - Actions []ActionCollected + Actions []ActionCollected + ToolsUse []ToolsCollected + ToolsActivate []ToolsCollected Tools struct { KisToolBrush float64 KisToolLine float64 } }