diff --git a/backend/goserver/goserver b/backend/goserver/goserver index 2f54f2d..de3c24c 100755 Binary files a/backend/goserver/goserver and b/backend/goserver/goserver differ diff --git a/backend/goserver/main.go b/backend/goserver/main.go index 41f9fd2..6b1e335 100644 --- a/backend/goserver/main.go +++ b/backend/goserver/main.go @@ -1,115 +1,114 @@ package main import ( "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)) + fmt.Println(string(bodyBuffer)) sw.InsertGeneralInfo(bodyBuffer) } func handlerTools(w http.ResponseWriter, r *http.Request) { bodyBuffer, _ := ioutil.ReadAll(r.Body) - //fmt.Println(string(bodyBuffer)) - + fmt.Println(string(bodyBuffer)) sw.InsertToolInfo(bodyBuffer) } func handlerImageProperties(w http.ResponseWriter, r *http.Request) { bodyBuffer, _ := ioutil.ReadAll(r.Body) - //fmt.Println(string(bodyBuffer)) + 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 handlerActions(w http.ResponseWriter, r *http.Request) { bodyBuffer, _ := ioutil.ReadAll(r.Body) - //fmt.Println(string(bodyBuffer)) + fmt.Println(string(bodyBuffer)) sw.InsertActionInfo(bodyBuffer) } func handlerGetTools(w http.ResponseWriter, r *http.Request) { temp := sw.Agregated("tools") fmt.Fprintf(w, temp) } func handlerGetActions(w http.ResponseWriter, r *http.Request) { temp := sw.Agregated("actions") fmt.Fprintf(w, temp) } func handlerGetInstallInfo(w http.ResponseWriter, r *http.Request) { temp := sw.Agregated("install") fmt.Println("HANDLE INSTALL GET") fmt.Fprintf(w, temp) } func handlerGetImageInfo(w http.ResponseWriter, r *http.Request) { temp := sw.Agregated("images") 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("/GoogleLogin", sw.HandleGoogleLogin) http.HandleFunc("/GoogleCallback", sw.HandleGoogleCallback) http.HandleFunc("/get/tools", handlerGetTools) http.HandleFunc("/get/actions", handlerGetActions) http.HandleFunc("/get/install", handlerGetInstallInfo) http.HandleFunc("/get/images", handlerGetImageInfo) ticker := time.NewTicker(time.Minute * 2) tickerActions := time.NewTicker(time.Minute * 3) tickerTools := time.NewTicker(time.Minute * 3) tickerImages := time.NewTicker(time.Minute * 4) go func() { for t := range ticker.C { sw.AgregateInstalInfo() fmt.Println("Tick at", t) } }() go func() { for t := range tickerActions.C { sw.AgregateActions() fmt.Println("Tick actions at", t) } }() go func() { for t := range tickerTools.C { sw.AgregateTools() fmt.Println("Tick tools at", t) } }() go func() { for t := range tickerImages.C { sw.AgregateImageProps() fmt.Println("Tick image at", t) } }() http.ListenAndServe(":8080", nil) } diff --git a/backend/goserver/server/agregateInfo.go b/backend/goserver/server/agregateInfo.go index 8a3386e..dc8a0ef 100644 --- a/backend/goserver/server/agregateInfo.go +++ b/backend/goserver/server/agregateInfo.go @@ -1,270 +1,284 @@ package server import ( "bufio" "encoding/json" "fmt" md "kritaServers/backend/goserver/server/models" "os" + "strconv" mgo "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" ) var agreagtedData md.CollectedInstallData var agregatedTools md.ToolsCollectedData var agregatedActions []md.ActionCollected var agregatedImageInfo md.ImageCollected 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 getProportion(specificCount float64, totalCount float64) string { + result := strconv.FormatFloat(specificCount/totalCount, 'f', -1, 32) + return result } + 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, 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"}}}}) 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) err = pipe.All(&resultsCount) err = pipe2.All(&resultsAvg) CheckErr(err) if len(resultsCount) > 0 { countUse, _ = resultsCount[0]["total_count"].(float64) // fmt.Println(name, num) } if len(resultsAvg) > 0 { averageTimeUse, _ = resultsAvg[0]["total_count"].(float64) fmt.Println(name, averageTimeUse) } return countUse, averageTimeUse } func getWidth(high int, low int, session *mgo.Collection) float64 { count := getFloat64(session.Find(bson.M{"images.width": bson.M{"$gt": high, "$lte": low}}).Count()) return count } func getHeight(high int, low int, session *mgo.Collection) float64 { count := getFloat64(session.Find(bson.M{"images.height": bson.M{"$gt": high, "$lte": low}}).Count()) return count } func getLayer(high int, low int, session *mgo.Collection) float64 { count := getFloat64(session.Find(bson.M{"images.numlayers": bson.M{"$gt": high, "$lte": low}}).Count()) return count } func getFileSize(high int, low int, session *mgo.Collection) float64 { count := getFloat64(session.Find(bson.M{"images.size": bson.M{"$gt": high, "$lte": low}}).Count()) return count } func AgregateImageProps() { c := Session.DB("telemetry").C("images") var ic md.ImageCollected - ic.WD.L500 = getWidth(0, 500, c) - ic.WD.L1000 = getWidth(500, 1000, c) - ic.WD.L2000 = getWidth(1000, 2000, c) - ic.WD.L4000 = getWidth(2000, 4000, c) - ic.WD.L8000 = getWidth(4000, 8000, c) - ic.WD.M8000 = getFloat64(c.Find(bson.M{"images.width": bson.M{"$gt": 8000}}).Count()) - - ic.HD.L500 = getHeight(500, 1000, c) - ic.HD.L1000 = getHeight(1000, 2000, c) - ic.HD.L2000 = getHeight(1000, 2000, c) - ic.HD.L4000 = getHeight(2000, 4000, c) - ic.HD.L8000 = getHeight(4000, 8000, c) - ic.HD.M8000 = getFloat64(c.Find(bson.M{"images.height": bson.M{"$gt": 8000}}).Count()) - - ic.LD.L1 = getLayer(0, 1, c) - ic.LD.L2 = getLayer(1, 2, c) - ic.LD.L4 = getLayer(2, 4, c) - ic.LD.L8 = getLayer(4, 8, c) - ic.LD.L16 = getLayer(8, 16, c) - ic.LD.L32 = getLayer(16, 32, c) - ic.LD.L64 = getLayer(32, 64, c) - ic.LD.M64 = getFloat64(c.Find(bson.M{"images.numlayers": bson.M{"$gt": 8000}}).Count()) - - ic.ID.Mb1 = getFileSize(0, 1, c) - ic.ID.Mb5 = getFileSize(1, 5, c) - ic.ID.Mb10 = getFileSize(5, 10, c) - ic.ID.Mb25 = getFileSize(10, 25, c) - ic.ID.Mb50 = getFileSize(25, 50, c) - ic.ID.Mb100 = getFileSize(50, 100, c) - ic.ID.Mb200 = getFileSize(100, 200, c) - ic.ID.Mb400 = getFileSize(200, 400, c) - ic.ID.Mb800 = getFileSize(400, 800, c) - ic.ID.More800 = getFloat64(c.Find(bson.M{"images.size": bson.M{"$gt": 800}}).Count()) - ic.CPD.RGBA = getFloat64(c.Find(bson.M{"images.colorprofile": "RGB/Alpha"}).Count()) - ic.CPD.CMYK = getFloat64(c.Find(bson.M{"images.colorprofile": "CMYK/Alpha"}).Count()) - ic.CPD.Grayscale = getFloat64(c.Find(bson.M{"images.colorprofile": "Grayscale/Alpha"}).Count()) - ic.CPD.Lab = getFloat64(c.Find(bson.M{"images.colorprofile": "L*a*b*/Alpha"}).Count()) - ic.CPD.XYZ = getFloat64(c.Find(bson.M{"images.colorprofile": "XYZ/Alpha"}).Count()) - ic.CPD.YCbCr = getFloat64(c.Find(bson.M{"images.colorprofile": "YCbCr/Alpha"}).Count()) + ic.WD.L500.Count = getWidth(0, 500, c) + ic.WD.L1000.Count = getWidth(500, 1000, c) + ic.WD.L2000.Count = getWidth(1000, 2000, c) + ic.WD.L4000.Count = getWidth(2000, 4000, c) + ic.WD.L8000.Count = getWidth(4000, 8000, c) + ic.WD.M8000.Count = getFloat64(c.Find(bson.M{"images.width": bson.M{"$gt": 8000}}).Count()) + + ic.HD.L500.Count = getHeight(500, 1000, c) + ic.HD.L1000.Count = getHeight(1000, 2000, c) + ic.HD.L2000.Count = getHeight(1000, 2000, c) + ic.HD.L4000.Count = getHeight(2000, 4000, c) + ic.HD.L8000.Count = getHeight(4000, 8000, c) + ic.HD.M8000.Count = getFloat64(c.Find(bson.M{"images.height": bson.M{"$gt": 8000}}).Count()) + + ic.LD.L1.Count = getLayer(0, 1, c) + ic.LD.L2.Count = getLayer(1, 2, c) + ic.LD.L4.Count = getLayer(2, 4, c) + ic.LD.L8.Count = getLayer(4, 8, c) + ic.LD.L16.Count = getLayer(8, 16, c) + ic.LD.L32.Count = getLayer(16, 32, c) + ic.LD.L64.Count = getLayer(32, 64, c) + ic.LD.M64.Count = getFloat64(c.Find(bson.M{"images.numlayers": bson.M{"$gt": 8000}}).Count()) + + ic.ID.Mb1.Count = getFileSize(0, 1, c) + ic.ID.Mb5.Count = getFileSize(1, 5, c) + ic.ID.Mb10.Count = getFileSize(5, 10, c) + ic.ID.Mb25.Count = getFileSize(10, 25, c) + ic.ID.Mb50.Count = getFileSize(25, 50, c) + ic.ID.Mb100.Count = getFileSize(50, 100, c) + ic.ID.Mb200.Count = getFileSize(100, 200, c) + ic.ID.Mb400.Count = getFileSize(200, 400, c) + ic.ID.Mb800.Count = getFileSize(400, 800, c) + ic.ID.More800.Count = getFloat64(c.Find(bson.M{"images.size": bson.M{"$gt": 800}}).Count()) + + ic.CPD.RGBA.Count = getFloat64(c.Find(bson.M{"images.colorprofile": "RGB/Alpha"}).Count()) + ic.CPD.CMYK.Count = getFloat64(c.Find(bson.M{"images.colorprofile": "CMYK/Alpha"}).Count()) + ic.CPD.Grayscale.Count = getFloat64(c.Find(bson.M{"images.colorprofile": "Grayscale/Alpha"}).Count()) + ic.CPD.Lab.Count = getFloat64(c.Find(bson.M{"images.colorprofile": "L*a*b*/Alpha"}).Count()) + ic.CPD.XYZ.Count = getFloat64(c.Find(bson.M{"images.colorprofile": "XYZ/Alpha"}).Count()) + ic.CPD.YCbCr.Count = getFloat64(c.Find(bson.M{"images.colorprofile": "YCbCr/Alpha"}).Count()) agregatedImageInfo = ic } func AgregateActions() { file, err := os.Open("list_actions.txt") CheckErr(err) defer file.Close() var action md.ActionCollected var actions []md.ActionCollected scanner := bufio.NewScanner(file) for scanner.Scan() { action.Name = scanner.Text() action.CountUse = countActionsUse(action.Name) actions = append(actions, action) } agregatedActions = actions err = scanner.Err() CheckErr(err) } func AgregateTools() { file, err := os.Open("list_tools.txt") CheckErr(err) defer file.Close() var ToolUse md.ToolsCollected var ToolActivate md.ToolsCollected var ToolsUse []md.ToolsCollected var ToolsActivate []md.ToolsCollected scanner := bufio.NewScanner(file) for scanner.Scan() { ToolUse.Name = scanner.Text() ToolUse.CountUse, _ = countToolsUse("/Use/" + ToolUse.Name) ToolsUse = append(ToolsUse, ToolUse) ToolActivate.Name = ToolUse.Name ToolActivate.CountUse, _ = countToolsUse("/Activate/" + ToolActivate.Name) ToolsActivate = append(ToolsActivate, ToolUse) } agregatedTools.ToolsActivate = ToolsActivate agregatedTools.ToolsUse = ToolsUse 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) + agreagtedData.Compiler.Type.GCC.Count = getFloat64(c.Find(bson.M{"compiler.type": "GCC"}).Count()) + agreagtedData.Compiler.Type.Clang.Count = getFloat64(c.Find(bson.M{"compiler.type": "Clang"}).Count()) + agreagtedData.Compiler.Type.MSVC.Count = getFloat64(c.Find(bson.M{"compiler.type": "MSVC"}).Count()) + agreagtedData.Compiler.Type.Other.Count = countRecords - agreagtedData.Compiler.Type.GCC.Count - agreagtedData.Compiler.Type.Clang.Count - agreagtedData.Compiler.Type.MSVC.Count + agreagtedData.Compiler.Type.Other.Count = checkOtherCount(agreagtedData.Compiler.Type.Other.Count) //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) + agreagtedData.Platform.Os.Linux.Count = getFloat64(c.Find(bson.M{"platform.os": "linux"}).Count()) + agreagtedData.Platform.Os.Windows.Count = getFloat64(c.Find(bson.M{"platform.os": "windows"}).Count()) + agreagtedData.Platform.Os.Mac.Count = getFloat64(c.Find(bson.M{"platform.os": "mac"}).Count()) + agreagtedData.Platform.Os.Other.Count = countRecords - agreagtedData.Platform.Os.Linux.Count - agreagtedData.Platform.Os.Windows.Count - agreagtedData.Platform.Os.Mac.Count + agreagtedData.Platform.Os.Other.Count = checkOtherCount(agreagtedData.Platform.Os.Other.Count) //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) + agreagtedData.Platform.Version.Windows.V7.Count = getFloat64(c.Find(bson.M{"platform.version": "7"}).Count()) + agreagtedData.Platform.Version.Windows.V8.Count = getFloat64(c.Find(bson.M{"platform.version": "8"}).Count()) + agreagtedData.Platform.Version.Windows.V81.Count = getFloat64(c.Find(bson.M{"platform.version": "8.1"}).Count()) + agreagtedData.Platform.Version.Windows.V10.Count = getFloat64(c.Find(bson.M{"platform.version": "10"}).Count()) + agreagtedData.Platform.Version.Windows.Other.Count = agreagtedData.Platform.Os.Windows.Count - agreagtedData.Platform.Version.Windows.V7.Count - agreagtedData.Platform.Version.Windows.V8.Count - agreagtedData.Platform.Version.Windows.V81.Count - agreagtedData.Platform.Version.Windows.V10.Count + agreagtedData.Platform.Version.Windows.Other.Count = checkOtherCount(agreagtedData.Platform.Version.Windows.Other.Count) //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) + agreagtedData.Platform.Version.Linux.Ubuntu1404.Count = getFloat64(c.Find(bson.M{"platform.version": "ubuntu-14.04"}).Count()) + agreagtedData.Platform.Version.Linux.Ubuntu1410.Count = getFloat64(c.Find(bson.M{"platform.version": "ubuntu-14.10"}).Count()) + agreagtedData.Platform.Version.Linux.Ubuntu1504.Count = getFloat64(c.Find(bson.M{"platform.version": "ubuntu-15.04"}).Count()) + agreagtedData.Platform.Version.Linux.Ubuntu1510.Count = getFloat64(c.Find(bson.M{"platform.version": "ubuntu-15.10"}).Count()) + agreagtedData.Platform.Version.Linux.Ubuntu1604.Count = getFloat64(c.Find(bson.M{"platform.version": "ubuntu-16.04"}).Count()) + agreagtedData.Platform.Version.Linux.Other.Count = agreagtedData.Platform.Os.Linux.Count - agreagtedData.Platform.Version.Linux.Ubuntu1404.Count - agreagtedData.Platform.Version.Linux.Ubuntu1410.Count - agreagtedData.Platform.Version.Linux.Ubuntu1504.Count - agreagtedData.Platform.Version.Linux.Ubuntu1510.Count - agreagtedData.Platform.Version.Linux.Ubuntu1604.Count - agreagtedData.Platform.Version.Linux.Ubuntu1610.Count - agreagtedData.Platform.Version.Linux.Ubuntu1704.Count + agreagtedData.Platform.Version.Linux.Other.Count = checkOtherCount(agreagtedData.Platform.Version.Linux.Other.Count) + + agreagtedData.Platform.Version.Mac.V1012.Count = getFloat64(c.Find(bson.M{"platform.version": "10.12"}).Count()) + agreagtedData.Platform.Version.Mac.Other.Count = agreagtedData.Platform.Os.Mac.Count - agreagtedData.Platform.Version.Mac.V1012.Count + agreagtedData.Platform.Version.Mac.Other.Count = checkOtherCount(agreagtedData.Platform.Version.Linux.Other.Count) + + agreagtedData.Platform.Version.Linux.Ubuntu1404.Proportion = getProportion(agreagtedData.Platform.Version.Linux.Ubuntu1404.Count, countRecords) + agreagtedData.Platform.Version.Linux.Ubuntu1410.Proportion = getProportion(agreagtedData.Platform.Version.Linux.Ubuntu1410.Count, countRecords) + agreagtedData.Platform.Version.Linux.Ubuntu1504.Proportion = getProportion(agreagtedData.Platform.Version.Linux.Ubuntu1504.Count, countRecords) + agreagtedData.Platform.Version.Linux.Ubuntu1510.Proportion = getProportion(agreagtedData.Platform.Version.Linux.Ubuntu1510.Count, countRecords) + agreagtedData.Platform.Version.Linux.Ubuntu1604.Proportion = getProportion(agreagtedData.Platform.Version.Linux.Ubuntu1604.Count, countRecords) + agreagtedData.Platform.Version.Linux.Ubuntu1610.Proportion = getProportion(agreagtedData.Platform.Version.Linux.Ubuntu1610.Count, countRecords) + agreagtedData.Platform.Version.Linux.Ubuntu1704.Proportion = getProportion(agreagtedData.Platform.Version.Linux.Ubuntu1704.Count, countRecords) + agreagtedData.Platform.Version.Linux.Other.Proportion = getProportion(agreagtedData.Platform.Version.Linux.Other.Count, countRecords) //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) + agreagtedData.CPU.Architecture.X86_64.Count = getFloat64(c.Find(bson.M{"cpu.architecture": "x86_64"}).Count()) + agreagtedData.CPU.Architecture.X86.Count = getFloat64(c.Find(bson.M{"cpu.architecture": "i386"}).Count()) + agreagtedData.CPU.Architecture.Other.Count = countRecords - agreagtedData.CPU.Architecture.X86_64.Count - agreagtedData.CPU.Architecture.X86.Count + agreagtedData.CPU.Architecture.Other.Count = checkOtherCount(agreagtedData.CPU.Architecture.Other.Count) + + agreagtedData.CPU.Cores.C1.Count = getFloat64(c.Find(bson.M{"cpu.count": "1"}).Count()) + agreagtedData.CPU.Cores.C2.Count = getFloat64(c.Find(bson.M{"cpu.count": "2"}).Count()) + agreagtedData.CPU.Cores.C3.Count = getFloat64(c.Find(bson.M{"cpu.count": "3"}).Count()) + agreagtedData.CPU.Cores.C4.Count = getFloat64(c.Find(bson.M{"cpu.count": "4"}).Count()) + agreagtedData.CPU.Cores.C6.Count = getFloat64(c.Find(bson.M{"cpu.count": "6"}).Count()) + agreagtedData.CPU.Cores.C8.Count = getFloat64(c.Find(bson.M{"cpu.count": "8"}).Count()) + agreagtedData.CPU.Cores.Other.Count = countRecords - agreagtedData.CPU.Cores.C1.Count - agreagtedData.CPU.Cores.C2.Count - agreagtedData.CPU.Cores.C3.Count - agreagtedData.CPU.Cores.C4.Count - agreagtedData.CPU.Cores.C6.Count - agreagtedData.CPU.Cores.C8.Count + + //language + agreagtedData.Locale.Language.English.Count = getFloat64(c.Find(bson.M{"locale.language": "English"}).Count()) + agreagtedData.Locale.Language.Russian.Count = getFloat64(c.Find(bson.M{"locale.language": "Russian"}).Count()) + agreagtedData.Locale.Language.Other.Count = countRecords - agreagtedData.Locale.Language.English.Count - agreagtedData.Locale.Language.Russian.Count + agreagtedData.Locale.Language.Other.Count = checkOtherCount(agreagtedData.Locale.Language.Other.Count) } // func Agregated(type) string { // out, _ := json.Marshal(agreagtedData) // return string(out) // } func Agregated(dataType string) string { switch dataType { case "install": out, _ := json.Marshal(agreagtedData) return string(out) case "tools": out, _ := json.Marshal(agregatedTools) return string(out) case "actions": out, _ := json.Marshal(agregatedActions) return string(out) case "images": out, _ := json.Marshal(agregatedImageInfo) return string(out) default: return string("error") } } diff --git a/backend/goserver/server/models/collectModel.go b/backend/goserver/server/models/collectModel.go index 3dcff18..aa460d7 100644 --- a/backend/goserver/server/models/collectModel.go +++ b/backend/goserver/server/models/collectModel.go @@ -1,142 +1,147 @@ package models type ActionCollected struct { CountUse float64 Name string } type ToolsCollected struct { CountUse float64 Name string } type ToolsCollectedData struct { ToolsUse []ToolsCollected ToolsActivate []ToolsCollected } +type CountAndProportion struct { + Count float64 + Proportion string +} type CollectedInstallData struct { Platform struct { Os struct { - Windows float64 - Linux float64 - Mac float64 - Other float64 + Windows CountAndProportion + Linux CountAndProportion + Mac CountAndProportion + Other CountAndProportion } Version struct { Windows struct { - V7 float64 - V8 float64 - V81 float64 - V10 float64 - Other float64 + V7 CountAndProportion + V8 CountAndProportion + V81 CountAndProportion + V10 CountAndProportion + Other CountAndProportion } Linux struct { - Ubuntu1404 float64 - Ubuntu1410 float64 - Ubuntu1504 float64 - Ubuntu1510 float64 - Ubuntu1604 float64 - Ubuntu1610 float64 - Ubuntu1704 float64 - Other float64 + Ubuntu1404 CountAndProportion + + Ubuntu1410 CountAndProportion + Ubuntu1504 CountAndProportion + Ubuntu1510 CountAndProportion + Ubuntu1604 CountAndProportion + Ubuntu1610 CountAndProportion + Ubuntu1704 CountAndProportion + Other CountAndProportion } Mac struct { - V1012 float64 - Other float64 + V1012 CountAndProportion + Other CountAndProportion } } } CPU struct { Architecture struct { - X86_64 float64 - X86 float64 //на самом деле x86_64 c маленькой буквы - Other float64 + X86_64 CountAndProportion + X86 CountAndProportion //на самом деле x86_64 c маленькой буквы + Other CountAndProportion } Cores struct { - C1 float64 - C2 float64 - C3 float64 - C4 float64 - C6 float64 - C8 float64 - Other float64 + C1 CountAndProportion + C2 CountAndProportion + C3 CountAndProportion + C4 CountAndProportion + C6 CountAndProportion + C8 CountAndProportion + Other CountAndProportion } } Compiler struct { Type struct { - GCC float64 - Clang float64 - MSVC float64 - Other float64 + GCC CountAndProportion + Clang CountAndProportion + MSVC CountAndProportion + Other CountAndProportion } // Version struct { //подумать что можно сделать // V5dot4 float64 // Other float64 // } } Locale struct { Language struct { - English float64 - Russian float64 - Other float64 + English CountAndProportion + Russian CountAndProportion + Other CountAndProportion } } } //Less or equal then mb* type imageDistribution struct { - Mb1 float64 - Mb5 float64 - Mb10 float64 - Mb25 float64 - Mb50 float64 - Mb100 float64 - Mb200 float64 - Mb400 float64 - Mb800 float64 - More800 float64 + Mb1 CountAndProportion + Mb5 CountAndProportion + Mb10 CountAndProportion + Mb25 CountAndProportion + Mb50 CountAndProportion + Mb100 CountAndProportion + Mb200 CountAndProportion + Mb400 CountAndProportion + Mb800 CountAndProportion + More800 CountAndProportion } type colorProfileDistribution struct { - RGBA float64 - CMYK float64 - Grayscale float64 - XYZ float64 - YCbCr float64 - Lab float64 + RGBA CountAndProportion + CMYK CountAndProportion + Grayscale CountAndProportion + XYZ CountAndProportion + YCbCr CountAndProportion + Lab CountAndProportion } //Less then L* type heightDistribution struct { - L500 float64 - L1000 float64 - L2000 float64 - L4000 float64 - L8000 float64 - M8000 float64 + L500 CountAndProportion + L1000 CountAndProportion + L2000 CountAndProportion + L4000 CountAndProportion + L8000 CountAndProportion + M8000 CountAndProportion } type widthDistribution struct { - L500 float64 - L1000 float64 - L2000 float64 - L4000 float64 - L8000 float64 - M8000 float64 + L500 CountAndProportion + L1000 CountAndProportion + L2000 CountAndProportion + L4000 CountAndProportion + L8000 CountAndProportion + M8000 CountAndProportion } type layersDistribution struct { - L1 float64 - L2 float64 - L4 float64 - L8 float64 - L16 float64 - L32 float64 - L64 float64 - M64 float64 + L1 CountAndProportion + L2 CountAndProportion + L4 CountAndProportion + L8 CountAndProportion + L16 CountAndProportion + L32 CountAndProportion + L64 CountAndProportion + M64 CountAndProportion } type ImageCollected struct { ID imageDistribution CPD colorProfileDistribution HD heightDistribution WD widthDistribution LD layersDistribution //TODO COLORSPACE } diff --git a/frontend/treeview/treeview/settings.py b/frontend/treeview/treeview/settings.py index e1fdcd3..b066769 100644 --- a/frontend/treeview/treeview/settings.py +++ b/frontend/treeview/treeview/settings.py @@ -1,124 +1,124 @@ """ Django settings for treeview project. Generated by 'django-admin startproject' using Django 1.11.3. For more information on this file, see https://docs.djangoproject.com/en/1.11/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.11/ref/settings/ """ import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'h!khjr!+%c_7v5-^w)*x2*sy5e#0g^3dmzyt1@y0wtr6^x)uiq' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] - +ALLOWED_HOSTS = [ + '.akapustin.me', # Allow domain and subdomains + 'localhost', + '127.0.0.1' +] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'treeview_app', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'treeview.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [os.path.join(BASE_DIR,'templates')], + 'DIRS': [os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'treeview.wsgi.application' # Database # https://docs.djangoproject.com/en/1.11/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } # Password validation # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # Internationalization # https://docs.djangoproject.com/en/1.11/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'Europe/Moscow' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.11/howto/static-files/ STATIC_URL = '/static/' -ALLOWED_HOSTS = [ - '.akapustin.me' # Allow domain and subdomains -]