Beispiel #1
0
func (api *APIHandler) create(request *restful.Request, response *restful.Response) {
	var err error
	var tasks graph.Tasks
	t := graph.Task{
		End:          math.MaxInt64,
		Dependencies: graph.MakeTaskIDSet(),
	}
	request.ReadEntity(&t)
	t.Id, err = api.todo.AddTask(t)

	if err != nil {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
		return
	}

	tasks, err = api.todo.GetUnblockedDependencies(t.Id)
	if err != nil {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
	} else {
		response.WriteEntity(json.Response{
			Info:  t,
			Tasks: tasks.Values(),
		})
	}
}
Beispiel #2
0
func MakeTestTasksN(height, width, connectivity int) graph.Tasks {
	t := make(graph.Tasks)

	levels := make([][]*graph.Task, height)
	for i := range levels {
		levels[i] = make([]*graph.Task, width)
		for j := range levels[i] {
			task := &graph.Task{
				Id:           graph.TaskID(strconv.FormatInt(rand.Int63(), 10)),
				Start:        rand.Int63(),
				End:          rand.Int63(),
				Completed:    rand.Int()%2 == 0,
				Dependencies: graph.MakeTaskIDSet(),
			}
			t[task.Id] = task
			levels[i][j] = task
		}
	}

	for depth, level := range levels[:height-1] {
		for _, task := range level {
			connections := rand.Int31n(int32(connectivity))
			for i := 0; i < int(connections); i++ {
				row, col := rand.Int31n(int32(height-depth-1)), rand.Int31n(int32(width))
				task.Dependencies.Add(levels[depth+int(row)+1][col].Id)
			}
		}
	}
	return t
}