Browse Source

Bearbeitungsstand vom 9.6.2017

master
Klaus Wendel 6 years ago
parent
commit
444b943577
  1. 67
      go2lgl_l09/go2lgl_l09.go
  2. 4
      go2lgl_l09/myGui/myGui.go
  3. 3
      go2lgl_l09/myGui/qml/formular.ui
  4. 107
      go2lgl_l10/go2lgl_l10.go
  5. 87
      go2lgl_l11/go2lgl_l11.go
  6. 78
      go2lgl_l12/go2lgl_l12.go

67
go2lgl_l09/go2lgl_l09.go

@ -19,6 +19,8 @@ import (
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/widgets"
"github.com/0xAX/notificator"
)
const (
@ -28,12 +30,19 @@ const (
var timestamp [2]int64
var notify *notificator.Notificator
var wg, wgcli, wggui sync.WaitGroup // !
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
timestamp[0] = time.Now().UnixNano()
notify = notificator.New(notificator.Options{
DefaultIcon: "icon/default.png",
AppName: "LGL-Demo",
})
var töpfchenAlle []int = make([]int, anzahlTöpfchen, anzahlTöpfchen)
var c chan bool = make(chan bool, 1)
@ -56,34 +65,44 @@ func main() {
ui_progressBar.SetValue(i)
})
//ui_graphicsView.ConnectPaintEvent(func(e *gui.QPaintEvent) {
// //ui_graphicsView.DrawBackground(gui.QPainter.SetBrush(gui.NewQBrush()), rect)
//})
/*
ui_graphicsView.ConnectPaintEvent(func(e *gui.QPaintEvent) {
//ui_graphicsView.DrawBackground(gui.QPainter.SetBrush(gui.NewQBrush()), rect)
img := gui.NewQImage3(32, 32, gui.QImage__Format_ARGB32)
for i := 0; i < 32; i++ {
for j := 0; j < 32; j++ {
//img.SetPixelColor2(i, j, gui.NewQColor3(j*8, i*2, i*2, 255))
img.SetPixelColor2(i, j, gui.NewQColor3(255, 255, 0, 255))
}
}
})*/
ui_graphicsView.ConnectResizeEvent(func(e *gui.QResizeEvent) {
//ui_graphicsView.FitInView(c_scene.ItemsBoundingRect(), core.Qt__KeepAspectRatio)
ui_graphicsView.FitInView(c_scene.ItemsBoundingRect(), core.Qt__KeepAspectRatio)
fmt.Println("Hallo")
})
//pinsel := ui_graphicsView.ForegroundBrush()
// paintengine := ui_graphicsView.PaintEngine()
dx, dy := 32, 32
dx, dy := int(anzahlTöpfchen), int(anzahlTöpfchen)
img := gui.NewQImage3(dx, dy, gui.QImage__Format_ARGB32)
//c_img := gui.NewQImage()
c_img := gui.NewQPainter() // NewQImage3(dx, dy, gui.QImage__Format_ARGB32)
for i := 0; i < dx; i++ {
/*for i := 0; i < dx; i++ {
for j := 0; j < dy; j++ {
img.SetPixelColor2(i, j, gui.NewQColor3(j*8, i*2, i*2, 255))
//c_img.SetPixelColor2(i, j, gui.NewQColor3(j*8, i*2, i*2, 255))
c_img.SetPixelColor2(i, j, gui.NewQColor3(232, 232, 232, 255))
}
}
img = img.Scaled2(ui_graphicsView.Height(), ui_graphicsView.Width(), core.Qt__IgnoreAspectRatio, core.Qt__FastTransformation)
Item := widgets.NewQGraphicsPixmapItem2(gui.NewQPixmap().FromImage(img, 0), nil)
}*/
c_scene.AddItem(Item)
//c_img = c_img.Scaled2(ui_graphicsView.Height(), ui_graphicsView.Width(), core.Qt__IgnoreAspectRatio, core.Qt__FastTransformation)
c_item := widgets.NewQGrap //NewQGraphicsPixmapItem2(gui.NewQPixmap().FromImage(c_img, 0), nil)
c_scene.AddItem(c_item)
c_img = c_img.Scaled2(ui_graphicsView.Height(), ui_graphicsView.Width(), core.Qt__IgnoreAspectRatio, core.Qt__FastTransformation)
ui_graphicsView.SetScene(c_scene)
ui_graphicsView.Show()
@ -106,12 +125,29 @@ func main() {
ui_textBrowser.Append(fmt.Sprint("\u2690", *t))
ui_lcdNummer.Display2(int(anzahlKugeln))
ui_progressBar.SetValue(100)
return
default:
ui_textBrowser.Append(fmt.Sprint("\u231B ", *t, runtime.NumGoroutine()))
ui_lcdNummer.Display2(i)
ui_progressBar.SetValue(int(math.Floor((float64(i) / float64(anzahlKugeln) * 100) + .5)))
/* for i, v := range *t {
c_img.SetPixelColor2(i+1*(ui_graphicsView.Width()/int(anzahlTöpfchen)), (ui_graphicsView.Height()/int(anzahlKugeln)*20)*v, gui.NewQColor3(255, 0, 0, 255))
fmt.Println(i, v)
}
c_img.SetPixelColor2(100, 100, gui.NewQColor3(255, 0, 255, 255))
c_img.SetPixelColor2(100, 101, gui.NewQColor3(255, 0, 255, 255))
c_img.SetPixelColor2(100, 102, gui.NewQColor3(255, 0, 255, 255))
c_img.SetPixelColor2(100, 103, gui.NewQColor3(255, 0, 255, 255))
c_img.SetPixelColor2(101, 100, gui.NewQColor3(255, 0, 255, 255))
c_img.SetPixelColor2(101, 101, gui.NewQColor3(255, 0, 255, 255))
c_img.SetPixelColor2(101, 102, gui.NewQColor3(255, 0, 255, 255))
c_img.SetPixelColor2(101, 103, gui.NewQColor3(255, 0, 255, 255))
c_img = c_img.Scaled2(ui_graphicsView.Height(), ui_graphicsView.Width(), core.Qt__IgnoreAspectRatio, core.Qt__FastTransformation)
c_item2 := widgets.NewQGraphicsPixmapItem2(gui.NewQPixmap().FromImage(c_img, 0), nil)
c_scene.AddItem(c_item2)
*/
time.Sleep(time.Second * 1)
}
}
@ -136,7 +172,8 @@ func main() {
close(c)
timestamp[1] = time.Now().UnixNano()
fmt.Printf("\nProzess ist fertig und hat %v Sekunden gedauert!\n\n", (float64(timestamp[1]-timestamp[0]) * math.Pow(10, -9)))
notify.Push("LGL-Demo", fmt.Sprintf("\nProzess ist fertig und hat %v Sekunden gedauert!\n\n", (float64(timestamp[1]-timestamp[0])*math.Pow(10, -9))), "/home/user/icon.png", notificator.UR_CRITICAL)
}

4
go2lgl_l09/myGui/myGui.go

@ -32,6 +32,10 @@ func ErzeugeLayout(widget *widgets.QWidget, formWidget *widgets.QWidget, t *[]in
widget.SetWindowTitle("go LGL")
widget.ShowMaximized()
//ui_graphicsView.SetBackgroundBrush(gui.NewQBrush2(core.Qt__Dense4Pattern))
//ui_graphicsView.SetHorizontalScrollBarPolicy(core.Qt__ScrollBarAlwaysOff)
//ui_graphicsView.SetVerticalScrollBarPolicy(core.Qt__ScrollBarAlwaysOff)
return ui_textBrowser, ui_lcdNummer, ui_progressBar, ui_graphicsView
}

3
go2lgl_l09/myGui/qml/formular.ui

@ -37,6 +37,9 @@
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<property name="backgroundBrush">
<brush brushstyle="NoBrush">
<color alpha="255">

107
go2lgl_l10/go2lgl_l10.go

@ -1,47 +1,94 @@
/*
Landesamt für Geoinformation und Landentwicklung, Referat 35
Einführung in die Sprache Go, 25.7.2017
Lektion 10: Ganz einfacher Webserver
Lektion 10: Performancesteigerung durch Go-Nebenläufigkeit (Routinen und Prozesse)
*/
package main
import (
"fmt"
"net/http"
"math"
"runtime"
"strconv"
"sync"
"time"
)
func handler00(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Guckuck %s!", r.URL.Path[1:])
fmt.Println(r.URL)
}
var (
maxThreads, maxRoutines int8
func handler01(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Testseite 01</title>
</head>
<body>Du befindest Dich auf Seite `+"%s!"+`</body>
</html>`, r.URL.Path[1:])
}
gesuchteZahl int = 8978793242417717171
timestamp [2]int64
)
const ThreadFaktor int8 = 4 //!
var wg sync.WaitGroup
func is_prime(n *int) bool {
if *n == 2 { // 2 ist die einzige gerade Primzahl
return true
} else if *n < 2 || *n&1 == 0 { // falls zahl < 2 oder gerade Zahl -> keine Primzahl (1 keine Primzahl)
return false
} else {
var reportChannel, stopChannel chan bool = make(chan bool, maxRoutines), make(chan bool, maxRoutines-1)
func handler02(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `<?xml version='1.0' encoding='iso-8859-1'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="de" xml:lang="de">
<head>
<meta charset="UTF-8"/>
<title>Testseite 01</title>
</head>
<body><b>Du</b> befindest Dich jetzt auf <i>Seite `+"%s!"+`</i></body>
</html>`, r.URL.Path[1:])
maxSchleife := int(math.Sqrt(float64(*n)))
for start := int8(3); start <= 3+(maxRoutines-1)*2; start += 2 {
wg.Add(1)
go func(s int8, e, g *int, mf *int8, cr, cs chan bool) {
defer wg.Done()
select {
case <-cs: // Heh, Ihr könnt aufhören
return
default:
for i := int(s); i <= *e; i += int(*mf) * 2 {
//fmt.Println(i)
if *g%i == 0 {
select {
case cr <- true:
default:
fmt.Println("Channel voll!")
}
return
}
}
}
cr <- false
}(start, &maxSchleife, n, &maxRoutines, reportChannel, stopChannel)
}
select {
case cvalue, cstatus := <-reportChannel:
if cstatus && cvalue == true {
for i := int8(1); i < maxRoutines; i++ { // 1 to < maxThreads ist effizienter als 0 to < maxThreads-1
stopChannel <- true
}
wg.Wait()
close(reportChannel)
close(stopChannel)
return false
}
}
return true
}
}
func main() {
maxThreads = int8(runtime.NumCPU()) //!
maxRoutines = maxThreads * ThreadFaktor
runtime.GOMAXPROCS(int(maxThreads))
timestamp[0] = time.Now().UnixNano()
if is_prime(&gesuchteZahl) == true {
fmt.Println(strconv.Itoa(gesuchteZahl) + " IST eine Primzahl")
} else {
fmt.Println(strconv.Itoa(gesuchteZahl) + " ist KEINE Primzahl")
}
timestamp[1] = time.Now().UnixNano()
http.HandleFunc("/", handler00)
http.HandleFunc("/aa", handler01)
http.HandleFunc("/bb", handler02)
http.ListenAndServe(":8080", nil)
fmt.Printf("\nProzess ist fertig und hat mit %v Routinen, verteilt auf %v Threads, %v Sekunden gedauert!\n\n", maxRoutines, maxThreads, (float64(timestamp[1]-timestamp[0]) * math.Pow(10, -9)))
}

87
go2lgl_l11/go2lgl_l11.go

@ -1,78 +1,47 @@
/*
Landesamt für Geoinformation und Landentwicklung, Referat 35
Einführung in die Sprache Go, 25.7.2017
Lektion 11: Ein simpler Listener
Lektion 11: Ganz einfacher Webserver
*/
package main
import (
"bytes"
"fmt"
"io"
"log"
"net"
"strconv"
"strings"
"net/http"
)
const (
constNET_PROTOCOL = "tcp"
constNET_PORT = 1234
)
type dasOhr struct {
dasGehörte *string
}
func (f dasOhr) Write(b []byte) (int, error) {
//fmt.Println(*f.dasGehörte, string(b))
*f.dasGehörte = string(b)
return len(strings.TrimSpace(string(b))), nil
func handler00(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Guckuck %s!", r.URL.Path[1:])
fmt.Println(r.URL)
}
func Concatstring(args ...string) string {
var buffer bytes.Buffer
for _, v := range args {
buffer.WriteString(v)
}
return buffer.String()
func handler01(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Testseite 01</title>
</head>
<body>Du befindest Dich auf Seite `+"%s!"+`</body>
</html>`, r.URL.Path[1:])
}
type Concatablestring string
func (f *Concatablestring) Join(args ...string) string {
var buffer bytes.Buffer
buffer.WriteString(string(*f))
for _, v := range args {
buffer.WriteString(v)
}
return buffer.String()
func handler02(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `<?xml version='1.0' encoding='iso-8859-1'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="de" xml:lang="de">
<head>
<meta charset="UTF-8"/>
<title>Testseite 01</title>
</head>
<body><b>Du</b> befindest Dich jetzt auf <i>Seite `+"%s!"+`</i></body>
</html>`, r.URL.Path[1:])
}
func main() {
bb := dasOhr{new(string)}
//gsocks := Concatstring(":", strconv.Itoa(constNET_PORT)) // Lausche an TCP port 1234
var javaLoversLikeObjekts Concatablestring = ":"
gsocks := javaLoversLikeObjekts.Join(strconv.Itoa(constNET_PORT))
l, err := net.Listen(constNET_PROTOCOL, gsocks)
if err != nil {
log.Fatal(err)
}
defer l.Close()
for {
// Warte auf eine Connection
conn, err := l.Accept()
if err != nil {
log.Fatal(err)
}
//io.CopyBuffer(tt, conn, make([]byte, 18))
io.Copy(bb, conn)
fmt.Print("Televisor meldet: ", *bb.dasGehörte)
fmt.Printf("Dieses Gedankenverbrechen wurde präsentiert von %v\n", conn.RemoteAddr())
conn.Close()
}
http.HandleFunc("/", handler00)
http.HandleFunc("/aa", handler01)
http.HandleFunc("/bb", handler02)
http.ListenAndServe(":8080", nil)
}

78
go2lgl_l12/go2lgl_l12.go

@ -0,0 +1,78 @@
/*
Landesamt für Geoinformation und Landentwicklung, Referat 35
Einführung in die Sprache Go, 25.7.2017
Lektion 12: Ein simpler Listener
*/
package main
import (
"bytes"
"fmt"
"io"
"log"
"net"
"strconv"
"strings"
)
const (
constNET_PROTOCOL = "tcp"
constNET_PORT = 1234
)
type dasOhr struct {
dasGehörte *string
}
func (f dasOhr) Write(b []byte) (int, error) {
//fmt.Println(*f.dasGehörte, string(b))
*f.dasGehörte = string(b)
return len(strings.TrimSpace(string(b))), nil
}
func Concatstring(args ...string) string {
var buffer bytes.Buffer
for _, v := range args {
buffer.WriteString(v)
}
return buffer.String()
}
type Concatablestring string
func (f *Concatablestring) Join(args ...string) string {
var buffer bytes.Buffer
buffer.WriteString(string(*f))
for _, v := range args {
buffer.WriteString(v)
}
return buffer.String()
}
func main() {
bb := dasOhr{new(string)}
//gsocks := Concatstring(":", strconv.Itoa(constNET_PORT)) // Lausche an TCP port 1234
var javaLoversLikeObjekts Concatablestring = ":"
gsocks := javaLoversLikeObjekts.Join(strconv.Itoa(constNET_PORT))
l, err := net.Listen(constNET_PROTOCOL, gsocks)
if err != nil {
log.Fatal(err)
}
defer l.Close()
for {
// Warte auf eine Connection
conn, err := l.Accept()
if err != nil {
log.Fatal(err)
}
//io.CopyBuffer(tt, conn, make([]byte, 18))
io.Copy(bb, conn)
fmt.Print("Televisor meldet: ", *bb.dasGehörte)
fmt.Printf("Dieses Gedankenverbrechen wurde präsentiert von %v\n", conn.RemoteAddr())
conn.Close()
}
}
Loading…
Cancel
Save