Skip to content

Instantly share code, notes, and snippets.

@ScullWM
Created June 20, 2018 11:03
Show Gist options
  • Save ScullWM/5c6bfdad0cc7a89fae07e5e9ffa8934b to your computer and use it in GitHub Desktop.
Save ScullWM/5c6bfdad0cc7a89fae07e5e9ffa8934b to your computer and use it in GitHub Desktop.
package main
import (
"encoding/csv"
"fmt"
"github.com/traildb/traildb-go"
"log"
"os"
)
var SESSION_LIMIT = uint64(30 * 60)
func main() {
db, err := tdb.Open("forum.tdb")
if err != nil {
panic(err)
}
trail, err := tdb.NewCursor(db)
if err != nil {
panic(err)
}
file, err := os.Create("result.csv")
if err != nil {
log.Fatal(err)
}
defer file.Close()
writer := csv.NewWriter(file)
defer writer.Flush()
fmt.Println("Number of trails: ", db.NumTrails)
count := 0
for i := uint64(0); i < db.NumTrails; i++ {
err := tdb.GetTrail(trail, i)
if err != nil {
panic(err)
}
line := []string{}
transformed := "0"
for {
evt := trail.NextEvent()
if evt == nil {
break
}
evtMap := evt.ToMap()
if evtMap["action"] != "" {
fmt.Println("Action done: ", evtMap["action"])
line = append(line, evtMap["action"])
count += 1
}
if evtMap["action"] == "registration_ok" {
transformed = "1"
}
}
line = append([]string{transformed}, line...)
err = writer.Write(line)
if err != nil {
panic(err)
}
fmt.Println("--------")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment