Created
June 30, 2014 23:43
-
-
Save shanemhansen/83849c8ff287167ca990 to your computer and use it in GitHub Desktop.
Read "csv"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"github.com/davecheney/profile" | |
"os" | |
"strings" | |
) | |
type AggregationKey struct { | |
Country string | |
Idcategory string | |
Iddevice string | |
Idos string | |
Date string | |
} | |
type Aggregation struct { | |
AggregationKey | |
Hits int | |
Value float64 | |
} | |
func main() { | |
defer profile.Start(profile.CPUProfile).Stop() | |
aggregation := make(map[AggregationKey]*Aggregation) | |
scanner := bufio.NewScanner(os.Stdin) | |
for scanner.Scan() { | |
line := string(scanner.Bytes()) | |
record := strings.Split(strings.TrimSpace(line), "|") | |
date := record[0][:10] | |
aggregationKey := AggregationKey{ | |
record[2], record[9], record[12], record[8], date, | |
} | |
if aggregate, ok := aggregation[aggregationKey]; ok { | |
aggregate.Hits++ | |
} else { | |
aggregation[aggregationKey] = &Aggregation{ | |
aggregationKey, | |
0, | |
0.0, | |
} | |
} | |
} | |
fmt.Printf("Aggregated a total of >>%d<< rows from >><<\n", len(aggregation)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment