Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmeier committed Jul 20, 2017
1 parent b836656 commit 1cc0410
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 115 deletions.
1 change: 0 additions & 1 deletion Main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ type Message struct {
}

//go:generate go-bindata static/... locales templates
//go:generate rsrc -ico static/icon.ico -o FILE.syso
//go:generate go-astilectron-bindata -c

// map of all supported languages
Expand Down
21 changes: 16 additions & 5 deletions build/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

RELEASENAME=GreatMall

buildTarget() {
export GOOS=$1
export GOARCH=$2
Expand All @@ -16,29 +18,38 @@ buildTarget() {

if [ "$GOOS" == "windows" ]
then
cp ../GroupMatcherDE.lnk tmp/
cp ../GroupMatcherEN.lnk tmp/
rsrc -ico ../static/icon.ico -o ../FILE.syso
cp ../GroupMatcherDE.exe tmp/
cp ../GroupMatcherEN.exe tmp/
fi

cd tmp
if [ "$GOOS" == "windows" ]
then
go build -ldflags -H=windowsgui github.com/veecue/GroupMatcher
zip -r ../out/GroupMatcher-GreatMall-$GOOS-$GOARCH.zip *
echo packing zip file...
zip -r ../out/GroupMatcher-$RELEASENAME-$GOOS-$GOARCH.zip *
else
go build github.com/veecue/GroupMatcher
echo packing tar file...
tar -czf ../out/GroupMatcher-GreatMall-$GOOS-$GOARCH.tar.gz *
tar -czf ../out/GroupMatcher-$RELEASENAME-$GOOS-$GOARCH.tar.gz *
fi
cd ..

if [ "$GOOS" == "windows" ]
then
rm ../FILE.syso
fi

rm -rf tmp
}
rm -rf out
mkdir out

COPY_FILES="locales static"

OS="linux darwin windows"
#OS="linux darwin windows"
OS="windows"
ARCH="386 amd64"

for o in $OS
Expand Down
88 changes: 43 additions & 45 deletions matching/Combination.go
Original file line number Diff line number Diff line change
@@ -1,65 +1,63 @@
package matching

import(

)
import ()

type Combination struct {
Quantity int
Configuration []Part
Quantity int
Configuration []Part
}

type Part struct {
Group *Group
CandidateAmount int
Group *Group
CandidateAmount int
}

//adds a configuration to all combinations it fitts to
func addToAnyIfFitting(config []*Group, c []Combination) bool {
var wasAdded bool
for i := range c {
if c[i].addIfFitting(config) {
wasAdded = true
}
}
return wasAdded
var wasAdded bool
for i := range c {
if c[i].addIfFitting(config) {
wasAdded = true
}
}
return wasAdded
}

//adds config to the combination c if it fitts
func (c *Combination) addIfFitting(config []*Group) bool {
if c.isFitting(config) {
//if config is a subconfiguration of c.Configuration (has less wishes, but the rest is equal) it is added,
//but the function returns false, so that config is also added as a own combination
c.Quantity++
if len(config) == len(c.Configuration){
return true
}else {
return false
}
}
return false
if c.isFitting(config) {
//if config is a subconfiguration of c.Configuration (has less wishes, but the rest is equal) it is added,
//but the function returns false, so that config is also added as a own combination
c.Quantity++
if len(config) == len(c.Configuration) {
return true
} else {
return false
}
}
return false
}

//check if config is equal to c.Configuration (the order doesn't matter)
func (c *Combination) isFitting(config []*Group) bool {
var count int
for i := range c.Configuration {
for j := range config {
if c.Configuration[i].Group.Name == config[j].Name {
count++
}
}
}
if count == len(config) {
for i := range c.Configuration {
for j := range config {
if c.Configuration[i].Group.Name == config[j].Name {
c.Configuration[i].CandidateAmount++
}
}
}
return true
}else {
return false
}
var count int
for i := range c.Configuration {
for j := range config {
if c.Configuration[i].Group.Name == config[j].Name {
count++
}
}
}
if count == len(config) {
for i := range c.Configuration {
for j := range config {
if c.Configuration[i].Group.Name == config[j].Name {
c.Configuration[i].CandidateAmount++
}
}
}
return true
} else {
return false
}
}
3 changes: 1 addition & 2 deletions matching/Group.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (g *Group) deletePerson(p *Person) {
//adds a fitting person to the given group
func (g *Group) insertBestFrom(candidates []*Person, m *Matcher) {
//searching with decreasing preference priority
for i := 0;i < 3;i++ {
for i := 0; i < 3; i++ {
//j := range candidates isn't possible because of changing slice length
for j := len(candidates) - 1; j >= 0; j-- {
if candidates[j].Preferences[i] == g {
Expand All @@ -54,7 +54,6 @@ func (g *Group) insertBestFrom(candidates []*Person, m *Matcher) {
return
}


func FindGroup(name string, groups []*Group) *Group {
for i := 0; i < len(groups); i++ {
if groups[i].Name == name {
Expand Down
53 changes: 26 additions & 27 deletions matching/Matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
package matching

import (
"errors"
"fmt"
"log"
"sync"
"errors"
"time"
"fmt"
)

type Matcher struct {
Expand Down Expand Up @@ -96,7 +96,7 @@ func (m *Matcher) matchMany(n int, hardTimeout time.Duration, softTimeout time.D
start := time.Now()
found := false

defer func(){
defer func() {
dur := time.Since(start)
if dur > hardTimeout {
err = errors.New("hardtimeout")
Expand Down Expand Up @@ -132,8 +132,8 @@ func (m *Matcher) matchMany(n int, hardTimeout time.Duration, softTimeout time.D
}(i)
}
wg.Wait()
matchers = make([]*Matcher,0)
for _,m := range ms {
matchers = make([]*Matcher, 0)
for _, m := range ms {
if m != nil {
matchers = append(matchers, m)
}
Expand Down Expand Up @@ -168,11 +168,11 @@ func (m *Matcher) correct() bool {
for j := range m.Groups {
if len(m.Groups[j].Members) < m.Groups[j].MinSize {
amountNeeded := m.Groups[j].MinSize - len(m.Groups[j].Members)
for k := 0;k < amountNeeded;k++ {
for k := 0; k < amountNeeded; k++ {
freeC, neededC := m.getCandidates(m.Groups[j])
if len(freeC) != 0 {
m.Groups[j].insertBestFrom(freeC, m)
}else{
} else {
m.Groups[j].insertBestFrom(neededC, m)
flag = false
}
Expand All @@ -182,13 +182,13 @@ func (m *Matcher) correct() bool {
}
if flag {
return true
}else{
} else {
return false
}
}

//returns all candidates for a special group
func (m *Matcher) getCandidates(preference *Group) (freeC, neededC []*Person){
func (m *Matcher) getCandidates(preference *Group) (freeC, neededC []*Person) {
var pref, group, member int
for pref = 0; pref < m.getMaxPref(); pref++ {
for group = range m.Groups {
Expand All @@ -198,7 +198,7 @@ func (m *Matcher) getCandidates(preference *Group) (freeC, neededC []*Person){
if m.Groups[group].Members[member].Preferences[pref] == preference {
if m.Groups[group].MinSize >= len(m.Groups[group].Members) {
neededC = append(neededC, m.Groups[group].Members[member])
}else{
} else {
freeC = append(freeC, m.Groups[group].Members[member])
}
}
Expand Down Expand Up @@ -250,11 +250,11 @@ func (m *Matcher) CheckMatcher() (error, string) {
}

//check for basic combination problems
//the algorithm doesn't detect an error if there are two combinations which necessaryly need space in one group
//the algorithm doesn't detect an error if there are two combinations which necessaryly need space in one group
needComma = false
var combinations []Combination
//get all combinations and subcombinations
m.sortByPrefLen()//sort persons by preference length, so that subconfigurations are also put into the main-configuration
m.sortByPrefLen() //sort persons by preference length, so that subconfigurations are also put into the main-configuration
for i := range m.Persons {
if !addToAnyIfFitting(m.Persons[i].Preferences, combinations) {
var configuration []Part
Expand All @@ -273,7 +273,7 @@ func (m *Matcher) CheckMatcher() (error, string) {
//the capacity a group adds to the totalCapacity is limited by the larger one of Capacity or CandidateAmount
if combinations[i].Configuration[j].Group.Capacity < combinations[i].Configuration[j].CandidateAmount {
totalCapacity = totalCapacity + combinations[i].Configuration[j].Group.Capacity
}else{
} else {
totalCapacity = totalCapacity + combinations[i].Configuration[j].CandidateAmount
}
}
Expand All @@ -297,7 +297,6 @@ func (m *Matcher) CheckMatcher() (error, string) {
return errors.New("combination_overfilled"), errString
}


//ceck for total person amount
var totalMin, totalCap int
for i := range m.Groups {
Expand Down Expand Up @@ -334,7 +333,7 @@ func enoughCandidates(group *Group, persons []*Person) bool {
//return number of assigned persons
func (m *Matcher) numberAssigned() (n int) {
for i := range m.Groups {
n+=len(m.Groups[i].Members)
n += len(m.Groups[i].Members)
}
return
}
Expand All @@ -352,10 +351,10 @@ func (m *Matcher) CalcQuote() (quote, percentage float64) {
}
}
if nMaxQuote == 0 {
return 0,0
return 0, 0
}
quote = 1 + float64(nQuote) / float64(nAssigned)
percentage = 100 * (1 - float64(nQuote) / float64(nMaxQuote))
quote = 1 + float64(nQuote)/float64(nAssigned)
percentage = 100 * (1 - float64(nQuote)/float64(nMaxQuote))
return
}

Expand All @@ -372,8 +371,8 @@ func (m *Matcher) getHostGroup(p *Person) *Group {
}

//get maximum length of a persons Preferences
func (m *Matcher)getMaxPref() (max int) {
for _,person := range m.Persons {
func (m *Matcher) getMaxPref() (max int) {
for _, person := range m.Persons {
if max < len(person.Preferences) {
max = len(person.Preferences)
}
Expand All @@ -382,12 +381,12 @@ func (m *Matcher)getMaxPref() (max int) {
}

//orders the persons from many to few wishes
func (m *Matcher) sortByPrefLen(){
func (m *Matcher) sortByPrefLen() {
var persons []*Person
currLen := m.getMaxPref()
for currLen >= 0 {
for i := range m.Persons{
if currLen == len(m.Persons[i].Preferences){
for i := range m.Persons {
if currLen == len(m.Persons[i].Preferences) {
persons = append(persons, m.Persons[i])
}
}
Expand All @@ -397,20 +396,20 @@ func (m *Matcher) sortByPrefLen(){
}

//print groups (testing purpose)
func (m *Matcher) printMatcher(){
func (m *Matcher) printMatcher() {
q, p := m.CalcQuote()

fmt.Println()
fmt.Println()
fmt.Println("Quote:\t", q, "( ~ ", p, " %)")
fmt.Println()

for i := 0;i < len(m.Groups);i++{
for i := 0; i < len(m.Groups); i++ {
fmt.Println()
fmt.Println("--------------------------------------------------------------------------------------")
fmt.Println("Gruppenname: ",m.Groups[i].Name, "\t( ", len(m.Groups[i].Members) ," )")
fmt.Println("Gruppenname: ", m.Groups[i].Name, "\t( ", len(m.Groups[i].Members), " )")
for j := 0; j < len(m.Groups[i].Members); j++ {
fmt.Println(j,"\t:\t\t", m.Groups[i].Members[j].Name, "\t (", m.Groups[i].Members[j].Preferences[0].Name, ")\t(", m.Groups[i].Members[j].Preferences[1].Name, ")\t(", m.Groups[i].Members[j].Preferences[0].Name, ")")
fmt.Println(j, "\t:\t\t", m.Groups[i].Members[j].Name, "\t (", m.Groups[i].Members[j].Preferences[0].Name, ")\t(", m.Groups[i].Members[j].Preferences[1].Name, ")\t(", m.Groups[i].Members[j].Preferences[0].Name, ")")
}
}
}
8 changes: 4 additions & 4 deletions matching/Person.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package matching

import (
"math/rand"
"strings"
"sort"
"strings"
)

type Person struct {
Expand Down Expand Up @@ -50,12 +50,12 @@ func (s slicePerson) Len() int {
return len(s)
}

func (s slicePerson) Less(i,j int) bool {
func (s slicePerson) Less(i, j int) bool {
return strings.Compare(s[i].Name, s[j].Name) < 0
}

func (s slicePerson) Swap(i,j int) {
s[i],s[j] = s[j],s[i]
func (s slicePerson) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

func Sort(s []*Person) {
Expand Down
Loading

0 comments on commit 1cc0410

Please sign in to comment.