Created
September 2, 2013 04:57
-
-
Save chespinoza/6409314 to your computer and use it in GitHub Desktop.
Playing with Go data structures...
This file contains 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 ( | |
"fmt" | |
"math/rand" | |
"time" | |
) | |
type Cc struct { | |
name string | |
dep int | |
date time.Time | |
} | |
type Aux struct { | |
accum int | |
cant int | |
} | |
func main() { | |
var ccs []Cc | |
horas := make(map[int]Aux) | |
f1 := time.Now() | |
for i := 0; i < 10; i++ { | |
f1 = f1.Add(20 * time.Minute) | |
ccs = append(ccs, Cc{name: "cespinoza", dep: rand.Intn(1000), date: f1}) | |
} | |
for _, e := range ccs { | |
for i := 0; i < 25; i++ { | |
if e.date.Hour() == i { | |
horas[i] = Aux{horas[i].accum + e.dep, horas[i].cant + 1 } | |
} | |
} | |
fmt.Printf("%v %v %v\n", e.name, e.dep, e.date) | |
} | |
fmt.Println(horas) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Finally I'm getting ten records , maps with the value's sum for every hour and cantity, ready to average by hour:
hour:{sum values_cant}, ..