diff --git a/backend/goserver/goserver b/backend/goserver/goserver index 2ab198d..2f54f2d 100755 Binary files a/backend/goserver/goserver and b/backend/goserver/goserver differ diff --git a/backend/goserver/list_color_profiles.txt b/backend/goserver/list_color_profiles.txt new file mode 100644 index 0000000..2f10eff --- /dev/null +++ b/backend/goserver/list_color_profiles.txt @@ -0,0 +1,6 @@ +ACEScg-elle-V4-g10.icc +ClayRGB-elle-V4-srgbtrc.icc +sRGB built-in +sRGB-elle-V2-g10.icc +sRGB-elle-V2-srgbtrc.icc + diff --git a/backend/goserver/main.go b/backend/goserver/main.go index a416e1f..41f9fd2 100644 --- a/backend/goserver/main.go +++ b/backend/goserver/main.go @@ -1,99 +1,115 @@ 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)) + //fmt.Println(string(bodyBuffer)) sw.InsertActionInfo(bodyBuffer) } -func handlerHello(w http.ResponseWriter, r *http.Request) { - temp := sw.Agregated() +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("/agregatedData", handlerAgregatedData) - http.HandleFunc("/GoogleLogin", sw.HandleGoogleLogin) http.HandleFunc("/GoogleCallback", sw.HandleGoogleCallback) - http.HandleFunc("/", handlerHello) + + 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.Second * 10) + 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 4bbc846..8a3386e 100644 --- a/backend/goserver/server/agregateInfo.go +++ b/backend/goserver/server/agregateInfo.go @@ -1,191 +1,270 @@ package server import ( "bufio" "encoding/json" "fmt" md "kritaServers/backend/goserver/server/models" "os" + mgo "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" ) -var agreagtedData md.CollectedData +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 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()) + + 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) - agreagtedData.Actions = append(agreagtedData.Actions, action) + 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) - agreagtedData.ToolsUse = append(agreagtedData.ToolsUse, ToolUse) + ToolsUse = append(ToolsUse, ToolUse) ToolActivate.Name = ToolUse.Name ToolActivate.CountUse, _ = countToolsUse("/Activate/" + ToolActivate.Name) - agreagtedData.ToolsActivate = append(agreagtedData.ToolsActivate, ToolUse) + 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) //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 { +// func Agregated(type) string { +// out, _ := json.Marshal(agreagtedData) +// return string(out) +// } + +func Agregated(dataType string) string { switch dataType { case "install": - return agreagtedData + 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: - var err md.CustomError - err.Message = "Wrong request" + return string("error") } - return agreagtedData } diff --git a/backend/goserver/server/models/collectModel.go b/backend/goserver/server/models/collectModel.go index 3b3fe84..3dcff18 100644 --- a/backend/goserver/server/models/collectModel.go +++ b/backend/goserver/server/models/collectModel.go @@ -1,87 +1,142 @@ package models type ActionCollected struct { CountUse float64 Name string } type ToolsCollected struct { CountUse float64 Name string } -type CollectedData struct { + +type ToolsCollectedData struct { + ToolsUse []ToolsCollected + ToolsActivate []ToolsCollected +} + +type CollectedInstallData 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 - ToolsUse []ToolsCollected - ToolsActivate []ToolsCollected +//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 +} +type colorProfileDistribution struct { + RGBA float64 + CMYK float64 + Grayscale float64 + XYZ float64 + YCbCr float64 + Lab float64 +} - Tools struct { - KisToolBrush float64 - KisToolLine float64 - } +//Less then L* +type heightDistribution struct { + L500 float64 + L1000 float64 + L2000 float64 + L4000 float64 + L8000 float64 + M8000 float64 +} +type widthDistribution struct { + L500 float64 + L1000 float64 + L2000 float64 + L4000 float64 + L8000 float64 + M8000 float64 +} +type layersDistribution struct { + L1 float64 + L2 float64 + L4 float64 + L8 float64 + L16 float64 + L32 float64 + L64 float64 + M64 float64 +} +type ImageCollected struct { + ID imageDistribution + CPD colorProfileDistribution + HD heightDistribution + WD widthDistribution + LD layersDistribution + //TODO COLORSPACE } diff --git a/backend/goserver/server/models/imagesInfo.go b/backend/goserver/server/models/imagesInfo.go index c511720..ead29b5 100644 --- a/backend/goserver/server/models/imagesInfo.go +++ b/backend/goserver/server/models/imagesInfo.go @@ -1,13 +1,14 @@ package models type Image struct { Images []ImageInternal `json:"Images"` } type ImageInternal struct { ColorProfile string `json:"colorProfile"` ColorSpace string `json:"colorSpace"` Height float64 `json:"height"` Width float64 `json:"width"` Size float64 `json:"size"` NumLayers float64 `json:"numLayers"` } + diff --git a/frontend/treeview/treeview_app/static/treeview_app/img/404.png b/frontend/treeview/treeview_app/static/treeview_app/img/404.png new file mode 100644 index 0000000..4d5b2ae Binary files /dev/null and b/frontend/treeview/treeview_app/static/treeview_app/img/404.png differ diff --git a/frontend/treeview/treeview_app/templates/treeview_app/actions_info.html b/frontend/treeview/treeview_app/templates/treeview_app/actions_info.html new file mode 100644 index 0000000..b4cbaaf --- /dev/null +++ b/frontend/treeview/treeview_app/templates/treeview_app/actions_info.html @@ -0,0 +1,29 @@ + +{% load staticfiles %} + + + json tree example + + + + + + +
+ + + + \ No newline at end of file diff --git a/frontend/treeview/treeview_app/templates/treeview_app/error_page.html b/frontend/treeview/treeview_app/templates/treeview_app/error_page.html new file mode 100644 index 0000000..7c3653e --- /dev/null +++ b/frontend/treeview/treeview_app/templates/treeview_app/error_page.html @@ -0,0 +1,73 @@ + +{% load staticfiles %} + + + 404 – page not found + + + + + +
+ Something went wrong! +
+ + \ No newline at end of file diff --git a/frontend/treeview/treeview_app/templates/treeview_app/images_info.html b/frontend/treeview/treeview_app/templates/treeview_app/images_info.html new file mode 100644 index 0000000..b4cbaaf --- /dev/null +++ b/frontend/treeview/treeview_app/templates/treeview_app/images_info.html @@ -0,0 +1,29 @@ + +{% load staticfiles %} + + + json tree example + + + + + + +
+ + + + \ No newline at end of file diff --git a/frontend/treeview/treeview_app/templates/treeview_app/post_list.html b/frontend/treeview/treeview_app/templates/treeview_app/post_list.html deleted file mode 100644 index 4f4bdf7..0000000 --- a/frontend/treeview/treeview_app/templates/treeview_app/post_list.html +++ /dev/null @@ -1,4 +0,0 @@ - -

Hi there!

-

It works!

- diff --git a/frontend/treeview/treeview_app/templates/treeview_app/start_page.html b/frontend/treeview/treeview_app/templates/treeview_app/start_page.html new file mode 100644 index 0000000..61dcf1a --- /dev/null +++ b/frontend/treeview/treeview_app/templates/treeview_app/start_page.html @@ -0,0 +1,40 @@ + + +

Main page

+ + + + + + + + + + + + +
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
\ No newline at end of file diff --git a/frontend/treeview/treeview_app/templates/treeview_app/tools_info.html b/frontend/treeview/treeview_app/templates/treeview_app/tools_info.html new file mode 100644 index 0000000..b4cbaaf --- /dev/null +++ b/frontend/treeview/treeview_app/templates/treeview_app/tools_info.html @@ -0,0 +1,29 @@ + +{% load staticfiles %} + + + json tree example + + + + + + +
+ + + + \ No newline at end of file diff --git a/frontend/treeview/treeview_app/tests.py b/frontend/treeview/treeview_app/tests.py index 9331e78..a39b155 100644 --- a/frontend/treeview/treeview_app/tests.py +++ b/frontend/treeview/treeview_app/tests.py @@ -1,2 +1 @@ -from django.test import TestCase # Create your tests here. diff --git a/frontend/treeview/treeview_app/urls.py b/frontend/treeview/treeview_app/urls.py index 35665a3..186024e 100644 --- a/frontend/treeview/treeview_app/urls.py +++ b/frontend/treeview/treeview_app/urls.py @@ -1,11 +1,11 @@ from django.conf.urls import url from . import views from jsonview.decorators import json_view - urlpatterns = [ - url(r'^$', views.post_list, name='post_list'), - url(r'^installInfo/$', views.show_install_info,name='show_install_info'), - + url(r'^$', views.start_list, name='star_list'), + url(r'^installInfo/$', views.show_install_info, name='show_install_info'), + url(r'^actions/$', views.show_actions_info, name='show_actions_info'), + url(r'^tools/$', views.show_tools_info, name='show_tools_info'), + url(r'^images/$', views.show_images_info, name='show_images_info'), ] - diff --git a/frontend/treeview/treeview_app/views.py b/frontend/treeview/treeview_app/views.py index ccc87d3..9198206 100644 --- a/frontend/treeview/treeview_app/views.py +++ b/frontend/treeview/treeview_app/views.py @@ -1,23 +1,78 @@ -from django.shortcuts import render -from jsonview.decorators import json_view +from django.core.serializers import json import json -from django.shortcuts import render_to_response -from treeview_app.models import MainModel +from django.shortcuts import render + import http.client + # Create your views here. def show_install_info(request): - conn = http.client.HTTPConnection("akapustin.me:8080") - conn.request("GET","/") - r1 = conn.getresponse() - response = r1.read() #what will happen if response code will be not 200 - conn.close() - #json_string = json.dumps({"timestamp1": 22, "timestamp2": 14}) - - return render(request,"treeview_app/install_info.html", {'json_string': response}) -# def show_genres(request): -# return render("treeview_app/genres.html", -# {'nodes':Genre.objects.all()}) -def post_list(request): - return render(request, 'treeview_app/post_list.html', {}) + # response = json.dumps({"timestamp1": 22, "timestamp2": 14}) + response = json.dumps({"there should be ": "error request"}) # temporary solution + try: + conn = http.client.HTTPConnection("localhost:8080") + conn.request("GET", "/get/install") + r1 = conn.getresponse() + response = r1.read() # what will happen if response code will be not 200 + conn.close() + print(response) + except Exception as e: + print("error") + return render(request, "treeview_app/error_page.html") + + return render(request, "treeview_app/install_info.html", {'json_string': response}) + + +def show_images_info(request): + # response = json.dumps({"timestamp1": 22, "timestamp2": 14}) + response = json.dumps({"there should be ": "error request"}) # temporary solution + try: + conn = http.client.HTTPConnection("localhost:8080") + conn.request("GET", "/get/images") + r1 = conn.getresponse() + response = r1.read() # what will happen if response code will be not 200 + conn.close() + print(response) + except Exception as e: + print("error") + return render(request, "treeview_app/error_page.html") + + return render(request, "treeview_app/images_info.html", {'json_string': response}) + + +def show_tools_info(request): + # response = json.dumps({"timestamp1": 22, "timestamp2": 14}) + response = json.dumps({"there should be ": "error request"}) # temporary solution + try: + conn = http.client.HTTPConnection("localhost:8080") + conn.request("GET", "/get/tools") + r1 = conn.getresponse() + response = r1.read() # what will happen if response code will be not 200 + conn.close() + print(response) + except Exception as e: + print("error") + return render(request, "treeview_app/error_page.html") + + return render(request, "treeview_app/tools_info.html", {'json_string': response}) + +def show_actions_info(request): + # response = json.dumps({"timestamp1": 22, "timestamp2": 14}) + response = json.dumps({"there should be ": "error request"}) # temporary solution + try: + conn = http.client.HTTPConnection("localhost:8080") + conn.request("GET", "/get/actions") + r1 = conn.getresponse() + response = r1.read() # what will happen if response code will be not 200 + conn.close() + print(response) + except Exception as e: + print("error") + return render(request, "treeview_app/error_page.html") + + return render(request, "treeview_app/actions_info.html", {'json_string': response}) + + +def start_list(request): + return render(request, 'treeview_app/start_page.html', {})