Git Product home page Git Product logo

Comments (7)

andrewrt avatar andrewrt commented on July 22, 2024

Here's the code...

package main

import (
	"flag"
	"fmt"

	"bitbucket.org/myapp/db"
	"bitbucket.org/myapp/model"
	"bitbucket.org/myapp/ptmath"

	_ "github.com/chrislusf/glow/driver"
	_ "github.com/chrislusf/glow/flow"
)

//GroupResult - grouping result
type GroupResult struct {
	Leader    *model.PtSet
	GroupSize int
}

//Group2Test - input for grouping test
type Group2Test struct {
	LeaderCandidate *model.PtSet
	PtSet           []model.PtSet
}

func main() {
	flag.Parse()

	//get PointSets from DB
	ptSets := db.GetAvailablePointSets()

	//Convert points to a different Coordinate System before running analysis:
	for idx, ptSet := range ptSets {
		conversionMatrix := ptmath.GetConversionMatrix(ptSet)
		var xyzSlice []model.XyzPt
		for _, pt := range ptSet.PtSourceSlice {
			xyz := ptmath.CalculateXYZ(*conversionMatrix, pt)
			xyzSlice = append(xyzSlice, *xyz)
		}
		ptSets[idx].xyzSlice = xyzSlice
	}

	//map reduce method to find biggest group:
	bestGroupLeader := loadCadidates(ptSets)
	fmt.Println("\nBest candidate ID:", winner.LeaderCandidate.ID, ", GroupSize: ", winner.GroupSize)

}

var (
	f       = flow.New()
	flowOut = make(chan GroupResult)
)

func loadCadidates(ptSets []model.PtSet) *GroupResult {
	var bestCandidate *GroupResult

	f.Source(func(out chan Group2Test) {
		ptSetIdx := 0
		for ptSetIdx < len(ptSets) {
			out <- Group2Test{&ptSets[ptSetIdx], ptSets}
			ptSetIdx++
		}
	}, /*len(ptSets)*/ 10).Map(func(g2Test Group2Test) GroupResult {
		return loadCandidateGroupSize(g2Test.LeaderCandidate, g2Test.PtSet)
	}).Reduce(func(x GroupResult, y GroupResult) GroupResult {
		//find the largest group:
		if x.GroupSize > y.GroupSize {
			return x
		} //else
		return y
	}).Map(func(winner GroupResult) {
		fmt.Println("\nBest ID:", winner.LeaderCandidate.ID, ", GroupSize: ", winner.GroupSize)
		bestCandidate = &winner
	}).Run()

	return bestCandidate
}

func loadCandidateGroupSize(leaderCandidate *model.PtSet, ptSets []model.PtSet) GroupResult {
	//count how many point sets have all points within some distance of a leaderCandidate
	setSize := len(leaderCandidate.xyzSlice)
	limit := 5
	groupSize := 0

	for _, ptSet := range ptSets {
		idx := 0
		maxDist := 0
		for idx < setSize {
			ptDist = ptmath.Distance(ptSet.xyzSlice[idx], leaderCandidate.xyzSlice[idx])
			if ptDist > maxDist {
				maxDist = ptDist
			}
			idx++
		}
		if maxDist < limit {
			groupSize++
		}
	}
	res := GroupResult{}
	res.LeaderCandidate = leaderCandidate
	res.GroupSize = groupSize
	return res
}

from glow.

andrewrt avatar andrewrt commented on July 22, 2024
  1. Agent1 appears to be creating dozens and dozens of 1GB sized dat files.
    Agent2 and Agent3 (if using the provided /etc shell script for my own code) created a few small files and then finished / done.

How can I avoid this file blowup on agent1?

[edit]: looks like the agent bearing the brunt of the work (and thus the dat files) changes run to run.

from glow.

chrislusf avatar chrislusf commented on July 22, 2024

I am not remembering the details of glow now. Please use gleam. It also has a pure go support.

from glow.

andrewrt avatar andrewrt commented on July 22, 2024

Thanks for the response Chris- I hd previously attempted to port the above to gleam, was having some difficulties loading the f.source and f.map - how might one do this with the above (ie- preprocessed data rather than a file/db)?

Thanks again!

from glow.

liuluheng avatar liuluheng commented on July 22, 2024

@andrewrt This may help you.

from glow.

andrewrt avatar andrewrt commented on July 22, 2024

Hi liuluheng,
thanks for the link!

in there io writer is still used in the source (as opposed to channel loading like you can do in glow).

Does this mean you can basically trick the writer to act like a channel?

from glow.

chrislusf avatar chrislusf commented on July 22, 2024

@andrewrt yes

from glow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.