gobm65.go
changeset 18 f6646f63b11a
parent 17 d83a4f6556e4
child 19 afbb4d9ae536
equal deleted inserted replaced
17:d83a4f6556e4 18:f6646f63b11a
    26 // Display the latest 3 records with the average:
    26 // Display the latest 3 records with the average:
    27 // % gobm65 -l 3 --average
    27 // % gobm65 -l 3 --average
    28 // Display all records since a specific date:
    28 // Display all records since a specific date:
    29 // % gobm65 --since "2016-06-01"
    29 // % gobm65 --since "2016-06-01"
    30 // Display all records before a specific date:
    30 // Display all records before a specific date:
    31 // % gobm65 --before "2016-06-30"
    31 // % gobm65 --to-date "2016-06-30"
    32 // Display all records of the last 7 days:
    32 // Display all records of the last 7 days:
    33 // % gobm65 --since "$(date "+%F" -d "7 days ago")"
    33 // % gobm65 --since "$(date "+%F" -d "7 days ago")"
    34 //
    34 //
    35 // Display statistics for morning records:
    35 // Display statistics for morning records:
    36 // % gobm65 --from-time 06:00 --to-time 12:00 --stats
    36 // % gobm65 --from-time 06:00 --to-time 12:00 --stats
   397 
   397 
   398 func main() {
   398 func main() {
   399 	inFile := flag.String([]string{"-input-file", "i"}, "", "Input JSON file")
   399 	inFile := flag.String([]string{"-input-file", "i"}, "", "Input JSON file")
   400 	outFile := flag.String([]string{"-output-file", "o"}, "", "Output JSON file")
   400 	outFile := flag.String([]string{"-output-file", "o"}, "", "Output JSON file")
   401 	limit := flag.Uint([]string{"-limit", "l"}, 0, "Limit number of items to N first")
   401 	limit := flag.Uint([]string{"-limit", "l"}, 0, "Limit number of items to N first")
   402 	before := flag.String([]string{"-before"}, "",
   402 	toDate := flag.String([]string{"-to-date"}, "",
   403 		"Filter records before date (YYYY-mm-dd HH:MM:SS)")
   403 		"Filter records before date (YYYY-mm-dd HH:MM:SS)")
   404 	since := flag.String([]string{"-since", "-after"}, "",
   404 	fromDate := flag.String([]string{"-from-date", "-since"}, "",
   405 		"Filter records from date (YYYY-mm-dd HH:MM:SS)")
   405 		"Filter records from date (YYYY-mm-dd HH:MM:SS)")
   406 	format := flag.String([]string{"-format", "f"}, "", "Output format (csv, json)")
   406 	format := flag.String([]string{"-format", "f"}, "", "Output format (csv, json)")
   407 	avg := flag.Bool([]string{"-average", "a"}, false, "Compute average")
   407 	avg := flag.Bool([]string{"-average", "a"}, false, "Compute average")
   408 	stats := flag.Bool([]string{"-stats"}, false, "Compute statistics")
   408 	stats := flag.Bool([]string{"-stats"}, false, "Compute statistics")
   409 	merge := flag.Bool([]string{"-merge", "m"}, false,
   409 	merge := flag.Bool([]string{"-merge", "m"}, false,
   441 		} else {
   441 		} else {
   442 			endTime = t
   442 			endTime = t
   443 		}
   443 		}
   444 	}
   444 	}
   445 
   445 
   446 	startDate, err := parseDate(*since)
   446 	startDate, err := parseDate(*fromDate)
   447 	if err != nil {
   447 	if err != nil {
   448 		log.Fatal("Could not parse date: ", err)
   448 		log.Fatal("Could not parse date: ", err)
   449 	}
   449 	}
   450 
   450 
   451 	endDate, err := parseDate(*before)
   451 	endDate, err := parseDate(*toDate)
   452 	if err != nil {
   452 	if err != nil {
   453 		log.Fatal("Could not parse date: ", err)
   453 		log.Fatal("Could not parse date: ", err)
   454 	}
   454 	}
   455 
   455 
   456 	var items []measurement
   456 	var items []measurement