// SummarizeTask summarizes the man-day used for different tasks
// Tag is used as a search terms to filter the result
// TODO: bygroup is used to print the result by project group first. Now use [xxx] format.
SummarizeTask summarizes the man-day used for different tasks
Tag is used as a search terms to filter the result
TODO: bygroup is used to print the result by project group first. Now use [xxx] format.
// SummarizeTask summarizes the man - day used for different tasks // Tag is used as a search terms to filter the result // TODO : bygroup is used to print the result by project group first . Now use [ xxx ] format .
func SummarizeTask(path string, tag string, bygroup bool) error {
	tag = strings.ToLower(strings.TrimSpace(tag))
	_ = bygroup
	tasks, err := ReadTasks(path)
	if err != nil {
		return err
	}
	for i, _ := range tasks {
		tasks[i].Name = trimStringFromChar(tasks[i].Name, "-")
	}
	dateMap := make(map[string][]string) 
	taskMap := make(map[string][]string) 
	doneMap := make(map[string]string)   
	for _, task := range tasks {
		if val, ok := dateMap[task.Date]; ok {
			dateMap[task.Date] = append(val, task.Name)
		} else {
			dateMap[task.Date] = []string{task.Name}
		}
		if val, ok := taskMap[task.Name]; ok {
			taskMap[task.Name] = append(val, task.Date)
		} else {
			taskMap[task.Name] = []string{task.Date}
		}
		if val, ok := doneMap[task.Name]; ok {
			if val == "x" {
			} else {
				doneMap[task.Name] = task.Done
			}
		} else {
			doneMap[task.Name] = task.Done
		}
	}
	var dates []string 
	dateWeight := make(map[string]float64)
	for k, v := range dateMap {
		var weight float64
		if len(v) > 0 {
			weight = 1 / float64(len(v))
		}
		dateWeight[k] = weight
		dates = append(dates, k)
	}
	taskWeight := make(map[string]float64)
	for k, v := range taskMap {
		var weight float64
		if len(v) > 0 {
			for _, day := range v {
				weight = weight + dateWeight[day]
			}
		}
		taskWeight[k] = weight
	}
	keys := make([]string, 0, len(taskWeight))
	for key := range taskWeight {
		keys = append(keys, key)
	}
	sort.Slice(keys, func(i, j int) bool { return taskWeight[keys[i]] > taskWeight[keys[j]] })
	fmt.Printf("\nid\ttime\t\tdone\ttodo\n")
	fmt.Printf("--\t----\t\t----\t----\n")
	for i, key := range keys {
		j := i + 1
		line := fmt.Sprintf("%d\t%.1f days\t [%s]\t%s\n",
			j,
			taskWeight[keys[i]],
			doneMap[keys[i]],
			key)
		if tag != "" {
			if strings.Contains(strings.ToLower(line), tag) {
			} else {
				continue 
			}
		}
		fmt.Printf(line)
	}
	sort.Strings(dates)
	fmt.Printf("\nTotal of %d days\n    %v\n\n", len(dates), dates)
	return nil
}
func SummarizeTask ( path string , tag string , bygroup bool ) error { tag = strings . ToLower ( strings . TrimSpace ( tag ) ) _ = bygroup tasks , err := ReadTasks ( path ) if err != nil { return err } for i , _ := range tasks { tasks [ i ] . Name = trimStringFromChar ( tasks [ i ] . Name , " " ) } dateMap := make ( map [ string ] [ ] string ) taskMap := make ( map [ string ] [ ] string ) doneMap := make ( map [ string ] string ) for _ , task := range tasks { if val , ok := dateMap [ task . Date ] ; ok { dateMap [ task . Date ] = append ( val , task . Name ) } else { dateMap [ task . Date ] = [ ] string { task . Name } } if val , ok := taskMap [ task . Name ] ; ok { taskMap [ task . Name ] = append ( val , task . Date ) } else { taskMap [ task . Name ] = [ ] string { task . Date } } if val , ok := doneMap [ task . Name ] ; ok { if val == " " { } else { doneMap [ task . Name ] = task . Done } } else { doneMap [ task . Name ] = task . Done } } var dates [ ] string dateWeight := make ( map [ string ] float64 ) for k , v := range dateMap { var weight float64 if len ( v ) > 0 { weight = 1 / float64 ( len ( v ) ) } dateWeight [ k ] = weight dates = append ( dates , k ) } taskWeight := make ( map [ string ] float64 ) for k , v := range taskMap { var weight float64 if len ( v ) > 0 { for _ , day := range v { weight = weight + dateWeight [ day ] } } taskWeight [ k ] = weight } keys := make ( [ ] string , 0 , len ( taskWeight ) ) for key := range taskWeight { keys = append ( keys , key ) } sort . Slice ( keys , func ( i , j int ) bool { return taskWeight [ keys [ i ] ] > taskWeight [ keys [ j ] ] } ) fmt . Printf ( " \n \t \t \t \t \n " ) fmt . Printf ( " \t \t \t \t \n " ) for i , key := range keys { j := i + 1 line := fmt . Sprintf ( " \t \t \t \n " , j , taskWeight [ keys [ i ] ] , doneMap [ keys [ i ] ] , key ) if tag != " " { if strings . Contains ( strings . ToLower ( line ) , tag ) { } else { continue } } fmt . Printf ( line ) } sort . Strings ( dates ) fmt . Printf ( " \n \n \n \n " , len ( dates ) , dates ) return nil }
SummarizeTask summarizes the man-day used for different tasks
Tag is used as a search terms to filter the result
TODO: bygroup is used to print the result by project group first.
SummarizeTask summarizes the man - day used for different tasks Tag is used as a search terms to filter the result TODO : bygroup is used to print the result by project group first .
// Remove additional information for tasks name (ignore after hypen) // Derive mappings for each day / task // dateMap - key: date, value: [tasks]. Later calulate weightings per day // taskMap - key: task, value: [dates]. Later sum up weightings per day // doneMap - key: task, value: [done]. If at least one record is done, then done // dateMap // taskMap // doneMap // skip. Already done // Derive date weightings for each day // get list of unique dates // Derive man-day for each task // Sort task by man-day before display // Display result // print //skip