forked from yuhanfang/riot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_bigquery_aggregator.go
52 lines (48 loc) · 1.49 KB
/
example_bigquery_aggregator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Demonstrates how to use a BigQuery aggregator to aggregate match data from
// the Riot API into a queryable table.
package main
import (
"context"
"log"
"net/http"
"os"
"time"
"cloud.google.com/go/bigquery"
"cloud.google.com/go/datastore"
"github.com/Tilo-K/riot/analytics/data_aggregation"
"github.com/Tilo-K/riot/analytics/data_aggregation/bigquery_aggregator"
"github.com/Tilo-K/riot/apiclient"
"github.com/Tilo-K/riot/cachedclient"
"github.com/Tilo-K/riot/cachedclient/google"
"github.com/Tilo-K/riot/constants/queue"
"github.com/Tilo-K/riot/constants/region"
"github.com/Tilo-K/riot/ratelimit"
)
func main() {
project := os.Getenv("GOOGLE_CLOUD_PROJECT")
key := os.Getenv("RIOT_APIKEY")
ctx := context.Background()
ds, err := datastore.NewClient(ctx, project)
if err != nil {
log.Fatal(err)
}
bq, err := bigquery.NewClient(ctx, project)
if err != nil {
log.Fatal(err)
}
ba := bigquery_aggregator.New("TestAggregator", "TestAggregatorDataset", "matches", ds, bq)
limiter := ratelimit.NewLimiter()
httpClient := http.DefaultClient
underlying := apiclient.New(key, httpClient, limiter)
cache, err := google.NewDatastore(ctx, project, "TestAggregatorCache")
if err != nil {
log.Fatal(err)
}
client := cachedclient.New(underlying, cache)
agg := data_aggregation.NewAggregator(client, ba)
err = agg.AggregateChallengerLeagueMatches(ctx, region.NA1, queue.RankedSolo5x5, time.Now().Add(-10*time.Minute))
if err != nil {
log.Fatal(err)
}
log.Print("saved challenger matches")
}