Skip to content

Commit 5c23dbd

Browse files
committed
wip: post distances.
1 parent 1d4f2e4 commit 5c23dbd

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

src/main/kotlin/app/hashers/Colleagues.kt

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package app.hashers
66
import app.FactCodes
77
import app.api.Api
88
import app.model.Author
9+
import app.model.AuthorDistance
910
import app.model.Fact
1011
import app.model.Repo
1112
import io.reactivex.Observable
@@ -42,22 +43,20 @@ class AuthorDistanceHasher(
4243
authorScores[email] = authorScores[email]!! + score
4344
}
4445
}, onError, {
45-
val stats = mutableListOf<Fact>()
46-
val author = Author(email = userEmails.toList()[0])
46+
val stats = mutableListOf<AuthorDistance>()
4747
authorScores.forEach { email, value ->
4848
if (email !in userEmails) {
49-
stats.add(Fact(serverRepo, FactCodes.COLLEAGUES, value =
50-
email, value2 = value.toString(), author = author))
49+
stats.add(AuthorDistance(serverRepo, email, value))
5150
}
5251
}
5352

5453
postDistancesToServer(stats)
5554
})
5655
}
5756

58-
private fun postDistancesToServer(stats: List<Fact>) {
57+
private fun postDistancesToServer(stats: List<AuthorDistance>) {
5958
if (stats.isNotEmpty()) {
60-
api.postFacts(stats).onErrorThrow()
59+
api.postAuthorDistances(stats).onErrorThrow()
6160
}
6261
}
6362
}

src/test/kotlin/test/tests/hashers/AuthorDistanceHasherTest.kt

+9-14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import app.api.MockApi
88
import app.hashers.AuthorDistanceHasher
99
import app.hashers.CommitCrawler
1010
import app.model.Author
11+
import app.model.AuthorDistance
1112
import app.model.Fact
1213
import app.model.Repo
1314
import org.eclipse.jgit.api.Git
@@ -62,21 +63,15 @@ class AuthorDistanceHasherTest : Spek({
6263
hashSetOf(author2.email)).updateFromObservable(observable,
6364
onError = { _ -> fail("exception") })
6465

65-
assertTrue(api.receivedFacts.contains(
66-
Fact(repo = serverRepo,
67-
code = FactCodes.COLLEAGUES,
68-
author = author2,
69-
value = author1.email,
70-
value2 = (1.0).toString())
71-
))
66+
assertTrue(api.receivedDistances.contains(
67+
AuthorDistance(repo = serverRepo,
68+
email = author1.email,
69+
score = 1.0)))
7270

73-
assertTrue(api.receivedFacts.contains(
74-
Fact(repo = serverRepo,
75-
code = FactCodes.COLLEAGUES,
76-
author = author2,
77-
value = author3.email,
78-
value2 = (0.0).toString())
79-
))
71+
assertTrue(api.receivedDistances.contains(
72+
AuthorDistance(repo = serverRepo,
73+
email = author3.email,
74+
score = 0.0)))
8075
}
8176

8277
afterGroup {

0 commit comments

Comments
 (0)