Skip to content
This repository was archived by the owner on Jul 21, 2021. It is now read-only.

Commit 74d669b

Browse files
committed
[build] Fix line endings; Travis config.
1 parent 17d04fb commit 74d669b

File tree

6 files changed

+486
-477
lines changed

6 files changed

+486
-477
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ matrix:
1212

1313
before_install:
1414
- go get github.com/mitchellh/gox
15+
1516
install:
1617
- # skip
1718

@@ -20,17 +21,16 @@ script:
2021
- diff -u <(echo -n) <(gofmt -d .)
2122
- go vet $(go list ./... | grep -v /vendor/)
2223
- go test -v -race ./...
23-
- if [ "${LATEST}" = "true" ]; then gox -os="linux darwin" -arch="amd64" -output="centimentd.."
24-
-ldflags "-X main.Rev=`git rev-parse --short HEAD`" -verbose ./...; fi
24+
- if [ "${LATEST}" = "true" ]; then gox -os="linux darwin" -arch="amd64" -output="centimentd.{{.OS}}.{{.Arch}}" -ldflags "-X main.Rev=`git rev-parse --short HEAD`" -verbose ./...; fi
2525

2626
deploy:
2727
provider: releases
2828
skip_cleanup: true
2929
api_key:
3030
secure: i3RaRoIL+BYxBHemfLF4m8yMtGn7W/r12+jXyJlLCOvTV22Z2bZLXGeyxnHz/gj4W9xN5g/nyPLOIY9ak1/IsYajKQXZRmmDljLyLQnCh7DYGvWfLxDnsE0C5BUyTtn5a2c8hK+9kudpK77OMYwuw1HMfRt/JyYo/i8RHdaK3TzMCvp+c+58DhwpJm5YU+8iO3LKwb0lQGaF5JJBNJd1nR3K8L/tkWC9oZ7mv5528RhxtpIYgU4Lsk70RpvcwgSYcjwIb0M4wZgNlXFCuO2WDb3TY7CVzO6hoUymE65rW2iTQrc4EP7U4ulxjUgF6QcLblyQZ8Oz+kzJf/D4BkdNg4pu6MrQLmeMt7DEjliafMqPgWJmKBch/5W0BSkIp5ksDFNHck3qIK79KcCsCbnBYXyOYYfA+Pl6uZXgpeZ+ti7N/Z+eKrCT2FemSkxEzbQ65bWzINC+26Hy6/tpNzzWvmKgM91DvNi3axEn+IuvzzTfKohSvd03Ti3zHBOUwxkG6Tu7VNAHODghbIiyGCOFikcvRyGjYDzLIE8sdgG9WfpNSg9lDCoY+dj2uc73v5Y8NnGp9pfot3A8dBYwXeVcftrwTYVuZ0o3Kd7lHMgqcNtQCNn9eoy9xsQGOC11Pgi7vXGSwEQOvxebfUksseevdMceO4+ZgD4gxt5e92saFjc=
3131
file:
32-
- centimentd.darwin.amd64
33-
- centimentd.linux.amd64
32+
- "centimentd.darwin.amd64"
33+
- "centimentd.linux.amd64"
3434
on:
3535
repo: elithrar/centiment
3636
tags: true

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2017, Matt Silverlock
3+
Copyright (c) 2017-2018, Matt Silverlock
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

aggregate.go

Lines changed: 103 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,103 @@
1-
package centiment
2-
3-
import (
4-
"context"
5-
6-
"github.com/go-kit/kit/log"
7-
"github.com/pkg/errors"
8-
)
9-
10-
// Aggregator aggregates results from an analysis run.
11-
type Aggregator struct {
12-
logger log.Logger
13-
db DB
14-
}
15-
16-
// NewAggregator creates a new Aggregator: call Run to collect results and save
17-
// them to the given DB.
18-
func NewAggregator(logger log.Logger, db DB) (*Aggregator, error) {
19-
agg := &Aggregator{
20-
db: db,
21-
logger: logger,
22-
}
23-
24-
return agg, nil
25-
}
26-
27-
// Run an aggregatation on the provided results.
28-
func (ag *Aggregator) Run(ctx context.Context, results <-chan *AnalyzerResult) error {
29-
var sentiments = make(map[string]*Sentiment)
30-
31-
// TODO(matt): Handle cancellation. Use for-select here with two cases.
32-
for res := range results {
33-
topic := res.SearchTerm.Topic
34-
if sentiments[topic] == nil {
35-
sentiments[topic] = &Sentiment{}
36-
}
37-
38-
// Update the rolling aggregate for each topic.
39-
sentiments[topic] = ag.updateAggregate(
40-
res.Score,
41-
res.Magnitude,
42-
res.TweetID,
43-
sentiments[topic],
44-
)
45-
46-
sentiments[topic].populateWithSearch(res.SearchTerm)
47-
}
48-
49-
for topic, sentiment := range sentiments {
50-
sentiment.finalize()
51-
id, err := ag.db.SaveSentiment(ctx, *sentiment)
52-
if err != nil {
53-
// TODO(matt): Implement retry logic w/ back-off.
54-
ag.logger.Log(
55-
"err", errors.Wrap(err, "failed to save topic"),
56-
"topic", topic,
57-
)
58-
continue
59-
}
60-
61-
ag.logger.Log(
62-
"state", "saved",
63-
"topic", sentiment.Topic,
64-
"slug", sentiment.Slug,
65-
"id", id,
66-
"score", sentiment.Score,
67-
"count", sentiment.Count,
68-
"stddev", sentiment.StdDev,
69-
"variance", sentiment.Variance,
70-
)
71-
}
72-
73-
return nil
74-
}
75-
76-
func (ag *Aggregator) updateAggregate(score float32, magnitude float32, tweetID int64, sentiment *Sentiment) *Sentiment {
77-
sentiment.Count++
78-
oldAverage := sentiment.Score
79-
sentiment.Score = updateAverage(score, sentiment.Score, sentiment.Count)
80-
sentiment.Variance = updateVariance(
81-
score,
82-
sentiment.Variance,
83-
oldAverage,
84-
sentiment.Score,
85-
sentiment.Count,
86-
)
87-
88-
// Record the largest (newest) Tweet ID we've seen across our results for this
89-
// topic, as the checkpoint for future searches.
90-
if tweetID > sentiment.LastSeenID {
91-
sentiment.LastSeenID = tweetID
92-
}
93-
94-
return sentiment
95-
}
96-
97-
func updateAverage(value float32, currentAverage float64, count int64) float64 {
98-
return currentAverage + ((float64(value) - currentAverage) / float64(count))
99-
}
100-
101-
func updateVariance(value float32, variance float64, oldAverage float64, newAverage float64, count int64) float64 {
102-
return variance + (float64(value)-oldAverage)*(float64(value)-newAverage)
103-
}
1+
package centiment
2+
3+
import (
4+
"context"
5+
6+
"github.com/go-kit/kit/log"
7+
"github.com/pkg/errors"
8+
)
9+
10+
// Aggregator aggregates results from an analysis run.
11+
type Aggregator struct {
12+
logger log.Logger
13+
db DB
14+
}
15+
16+
// NewAggregator creates a new Aggregator: call Run to collect results and save
17+
// them to the given DB.
18+
func NewAggregator(logger log.Logger, db DB) (*Aggregator, error) {
19+
agg := &Aggregator{
20+
db: db,
21+
logger: logger,
22+
}
23+
24+
return agg, nil
25+
}
26+
27+
// Run an aggregatation on the provided results.
28+
func (ag *Aggregator) Run(ctx context.Context, results <-chan *AnalyzerResult) error {
29+
var sentiments = make(map[string]*Sentiment)
30+
31+
// TODO(matt): Handle cancellation. Use for-select here with two cases.
32+
for res := range results {
33+
topic := res.SearchTerm.Topic
34+
if sentiments[topic] == nil {
35+
sentiments[topic] = &Sentiment{}
36+
}
37+
38+
// Update the rolling aggregate for each topic.
39+
sentiments[topic] = ag.updateAggregate(
40+
res.Score,
41+
res.Magnitude,
42+
res.TweetID,
43+
sentiments[topic],
44+
)
45+
46+
sentiments[topic].populateWithSearch(res.SearchTerm)
47+
}
48+
49+
for topic, sentiment := range sentiments {
50+
sentiment.finalize()
51+
id, err := ag.db.SaveSentiment(ctx, *sentiment)
52+
if err != nil {
53+
// TODO(matt): Implement retry logic w/ back-off.
54+
ag.logger.Log(
55+
"err", errors.Wrap(err, "failed to save topic"),
56+
"topic", topic,
57+
)
58+
continue
59+
}
60+
61+
ag.logger.Log(
62+
"state", "saved",
63+
"topic", sentiment.Topic,
64+
"slug", sentiment.Slug,
65+
"id", id,
66+
"score", sentiment.Score,
67+
"count", sentiment.Count,
68+
"stddev", sentiment.StdDev,
69+
"variance", sentiment.Variance,
70+
)
71+
}
72+
73+
return nil
74+
}
75+
76+
func (ag *Aggregator) updateAggregate(score float32, magnitude float32, tweetID int64, sentiment *Sentiment) *Sentiment {
77+
sentiment.Count++
78+
oldAverage := sentiment.Score
79+
sentiment.Score = updateAverage(score, sentiment.Score, sentiment.Count)
80+
sentiment.Variance = updateVariance(
81+
score,
82+
sentiment.Variance,
83+
oldAverage,
84+
sentiment.Score,
85+
sentiment.Count,
86+
)
87+
88+
// Record the largest (newest) Tweet ID we've seen across our results for this
89+
// topic, as the checkpoint for future searches.
90+
if tweetID > sentiment.LastSeenID {
91+
sentiment.LastSeenID = tweetID
92+
}
93+
94+
return sentiment
95+
}
96+
97+
func updateAverage(value float32, currentAverage float64, count int64) float64 {
98+
return currentAverage + ((float64(value) - currentAverage) / float64(count))
99+
}
100+
101+
func updateVariance(value float32, variance float64, oldAverage float64, newAverage float64, count int64) float64 {
102+
return variance + (float64(value)-oldAverage)*(float64(value)-newAverage)
103+
}

0 commit comments

Comments
 (0)