func TestAggregator(t *testing.T) { text := `2015-07-06T08:00:00-07:00 2015-07-06T08:30:00-07:00 misc email, update basecamp 2015-07-06T08:30:00-07:00 2015-07-06T11:00:00-07:00 ArchivesSpace running through migration process, updating notes, testing 2015-07-06T11:00:00-07:00 2015-07-06T11:45:00-07:00 misc update Mac 2015-07-03T08:00:00-07:00 2015-07-03T15:30:00-07:00 Holiday 4th of July observed 2015-07-02T07:45:00-07:00 2015-07-02T09:30:00-07:00 misc email, review stuff 2015-07-02T09:30:00-07:00 2015-07-02T10:30:00-07:00 DLD meeting 2015-07-02T10:30:00-07:00 2015-07-02T12:00:00-07:00 ArchivesSpace running through migration process 2015-07-02T03:00:00-07:00 2015-07-02T03:30:00-07:00 ArchivesSpace Hangouts with Tommy to upgrade cls-arch.library.caltech.edu to v1.3.0, go over migration questions 2015-07-01T07:45:00-07:00 2015-07-01T09:30:00-07:00 ArchivesSpace continue reading docs, articles about approach and what problems are being solved. 2015-07-01T09:30:00-07:00 2015-07-01T11:00:00-07:00 ArchivesSpace meeting in SFL's MCR (3rd floot Multi-media Conference Room)` aggregation := new(EntryAggregation) entry := new(stn.Entry) lines := strings.Split(text, "\n") linesTotal := 0 for i, line := range lines { if entry.FromString(line) == true { if aggregation.Aggregate(entry) != true { log.Fatalf("Can't aggregate entry %d: %v", i, entry) } linesTotal++ } else { log.Fatalf("Can't read line no. %d: [%s]\n", i, line) } } outText := aggregation.Summarize([]int{0}) outLines := strings.Split(outText, "\n") ok.Ok(t, len(outLines) == 8, fmt.Sprintf("lines %d: [%s]\n", linesTotal, outText)) }
func main() { var ( version bool columns string ) flag.BoolVar(&version, "version", false, "Display version information.") flag.BoolVar(&version, "v", false, "Display version information.") flag.StringVar(&columns, "columns", "0", "A comma delimited List of zero indexed columns to report") flag.Parse() if version == true { revision() } reader := bufio.NewReader(os.Stdin) entry := new(stn.Entry) aggregation := new(report.EntryAggregation) lineNo := 0 for { line, err := reader.ReadString('\n') if err != nil || line == "" { break } lineNo++ //fmt.Printf("DEBUG line %d: [%s]", lineNo, line) if entry.FromString(line) != true { log.Fatalf("line no. %d: can't filter [%s]\n", lineNo, line) os.Exit(1) } else { aggregation.Aggregate(entry) } } var cols []int s := strings.Split(columns, ",") for _, val := range s { i, err := strconv.Atoi(val) if err != nil { fmt.Fprintf(os.Stderr, "Column number error: %s, %s", columns, err) os.Exit(1) } cols = append(cols, i) } fmt.Println(aggregation.Summarize(cols)) }
func main() { var ( version bool showLine = true startTime time.Time endTime time.Time activeDate time.Time err error ) flag.StringVar(&match, "match", "", "Match text in annotations.") flag.StringVar(&start, "start", "", "Start of inclusive date range.") flag.StringVar(&end, "end", "", "End of inclusive date range.") flag.BoolVar(&asJSON, "json", false, "Output in JSON format.") flag.BoolVar(&help, "help", false, "Display this help document.") flag.BoolVar(&help, "h", false, "Display this help document.") flag.BoolVar(&version, "version", false, "Display version information.") flag.BoolVar(&version, "v", false, "Display version information.") flag.Parse() if help == true { usage(0, "") } if version == true { revision() } activeDate = time.Now() if start != "" { startTime, err = time.Parse("2006-01-02 15:04:05", start+" 00:00:00") if err != nil { log.Fatalf("Start date error: %s\n", err) os.Exit(1) } if end == "" { endTime = activeDate } else { endTime, err = time.Parse("2006-01-02 15:04:05", end+" 23:59:59") if err != nil { log.Fatalf("End date error: %s\n", err) os.Exit(1) } } } reader := bufio.NewReader(os.Stdin) entry := new(stn.Entry) lineNo := 0 for { showLine = true line, err := reader.ReadString('\n') if err != nil { break } lineNo++ if entry.FromString(line) != true { log.Fatalf("line no. %d: can't filter [%s]\n", lineNo, line) os.Exit(1) } if start != "" { showLine = entry.IsInRange(startTime, endTime) } if showLine == true && match != "" { showLine = entry.IsMatch(match) } if showLine == true { fmt.Printf("%s", line) } } }