diff --git a/src/main/kotlin/app/FactCodes.kt b/src/main/kotlin/app/FactCodes.kt new file mode 100644 index 00000000..b212f5a1 --- /dev/null +++ b/src/main/kotlin/app/FactCodes.kt @@ -0,0 +1,8 @@ +package app + +object FactCodes { + val COMMITS_DAY_WEEK = 1 + val COMMITS_DAY_TIME = 2 + val LINE_LONGEVITY = 3 + val LINE_LONGEVITY_REPO = 4 +} diff --git a/src/main/kotlin/app/FactKey.kt b/src/main/kotlin/app/FactKey.kt deleted file mode 100644 index 60ef9a80..00000000 --- a/src/main/kotlin/app/FactKey.kt +++ /dev/null @@ -1,8 +0,0 @@ -package app - -object FactKey { - val COMMITS_DAY_WEEK = "commits-day-week-" - val COMMITS_DAY_TIME = "commits-day-time-" - val LINE_LONGEVITY = "line-longevity-avg" - val LINE_LONGEVITY_REPO = "line-longevity-repo-avg" -} diff --git a/src/main/kotlin/app/hashers/CodeLongevity.kt b/src/main/kotlin/app/hashers/CodeLongevity.kt index 96edf6c3..f359d29d 100644 --- a/src/main/kotlin/app/hashers/CodeLongevity.kt +++ b/src/main/kotlin/app/hashers/CodeLongevity.kt @@ -3,10 +3,9 @@ package app.hashers -import app.FactKey +import app.FactCodes import app.Logger import app.api.Api -import app.config.Configurator import app.model.Author import app.model.LocalRepo import app.model.Repo @@ -150,7 +149,7 @@ class CodeLongevity(private val localRepo: LocalRepo, val repoAvg = if (repoTotal > 0) { repoSum / repoTotal } else 0 val stats = mutableListOf() stats.add(Fact(repo = serverRepo, - key = FactKey.LINE_LONGEVITY_REPO, + code = FactCodes.LINE_LONGEVITY_REPO, value = repoAvg.toDouble())) val repoAvgDays = repoAvg / secondsInDay Logger.info("Repo average code line age is $repoAvgDays days, " @@ -160,7 +159,7 @@ class CodeLongevity(private val localRepo: LocalRepo, val total = totals[email] ?: 0 val avg = if (total > 0) { sums[email]!! / total } else 0 stats.add(Fact(repo = serverRepo, - key = FactKey.LINE_LONGEVITY, + code = FactCodes.LINE_LONGEVITY, value = avg.toDouble(), author = Author(email = email))) if (email == localRepo.author.email) { diff --git a/src/main/kotlin/app/hashers/FactHasher.kt b/src/main/kotlin/app/hashers/FactHasher.kt index 04cf2426..0154f70e 100644 --- a/src/main/kotlin/app/hashers/FactHasher.kt +++ b/src/main/kotlin/app/hashers/FactHasher.kt @@ -3,7 +3,7 @@ package app.hashers -import app.FactKey +import app.FactCodes import app.Logger import app.api.Api import app.model.Author @@ -59,7 +59,7 @@ class FactHasher(private val localRepo: LocalRepo, list.forEachIndexed { hour, count -> if (count > 0) { facts.add(Fact(serverRepo, - FactKey.COMMITS_DAY_TIME + hour, + FactCodes.COMMITS_DAY_TIME, hour, count.toDouble(), author)) } } @@ -68,7 +68,7 @@ class FactHasher(private val localRepo: LocalRepo, list.forEachIndexed { day, count -> if (count > 0) { facts.add(Fact(serverRepo, - FactKey.COMMITS_DAY_WEEK + day, + FactCodes.COMMITS_DAY_WEEK, day, count.toDouble(), author)) } } diff --git a/src/main/kotlin/app/hashers/RepoHasher.kt b/src/main/kotlin/app/hashers/RepoHasher.kt index 975e2f44..6123dfcc 100644 --- a/src/main/kotlin/app/hashers/RepoHasher.kt +++ b/src/main/kotlin/app/hashers/RepoHasher.kt @@ -57,7 +57,7 @@ class RepoHasher(private val localRepo: LocalRepo, private val api: Api, observable.connect() // TODO(anatoly): CodeLongevity hash from observable. - CodeLongevity(localRepo, serverRepo, api, git) + CodeLongevity(localRepo, serverRepo, api, git).update() // Confirm hashing completion. postRepoToServer() diff --git a/src/main/kotlin/app/model/Fact.kt b/src/main/kotlin/app/model/Fact.kt index 3c59b1cc..43e1e92b 100644 --- a/src/main/kotlin/app/model/Fact.kt +++ b/src/main/kotlin/app/model/Fact.kt @@ -9,7 +9,8 @@ import java.security.InvalidParameterException */ data class Fact( var repo: Repo = Repo(), - var key: String = "", + var code: Int = 0, + var key: Int = 0, var value: Double = 0.0, var author: Author = Author() ) { @@ -17,8 +18,9 @@ data class Fact( constructor(proto: Protos.Fact) : this() { repo = Repo(rehash = proto.repoRehash) author = Author("", proto.email) + code = proto.code key = proto.key - value = proto.value + value = proto.value1.toDoubleOrNull() ?: 0.0 } @Throws(InvalidProtocolBufferException::class) @@ -30,8 +32,9 @@ data class Fact( return Protos.Fact.newBuilder() .setRepoRehash(repo.rehash) .setEmail(author.email) + .setCode(code) .setKey(key) - .setValue(value) + .setValue1(value.toString()) .build() } diff --git a/src/main/proto/sourcerer.proto b/src/main/proto/sourcerer.proto index e85dbc85..efa1ca90 100644 --- a/src/main/proto/sourcerer.proto +++ b/src/main/proto/sourcerer.proto @@ -57,10 +57,14 @@ message CommitGroup { // Key-value statistics for fun facts. message Fact { - string key = 1; - double value = 2; - string email = 3; - string repo_rehash = 4; + int32 code = 1; + int32 key = 2; + string value1 = 3; + string value2 = 4; + string value3 = 5; + string value4 = 6; + string email = 7; + string repo_rehash = 8; } // Used to send multiple stats in one request. diff --git a/src/test/kotlin/test/tests/hashers/FactHasherTest.kt b/src/test/kotlin/test/tests/hashers/FactHasherTest.kt index 3da42935..ba0de54e 100644 --- a/src/test/kotlin/test/tests/hashers/FactHasherTest.kt +++ b/src/test/kotlin/test/tests/hashers/FactHasherTest.kt @@ -3,7 +3,7 @@ package test.tests.hashers -import app.FactKey +import app.FactCodes import app.api.MockApi import app.hashers.CommitCrawler import app.hashers.FactHasher @@ -60,9 +60,9 @@ class FactHasherTest : Spek({ .updateFromObservable(observable) assertEquals(2, facts.size) - assertTrue(facts.contains(Fact(repo, FactKey.COMMITS_DAY_TIME + 13, + assertTrue(facts.contains(Fact(repo, FactCodes.COMMITS_DAY_TIME, 13, 1.0, author1))) - assertTrue(facts.contains(Fact(repo, FactKey.COMMITS_DAY_WEEK + 6, + assertTrue(facts.contains(Fact(repo, FactCodes.COMMITS_DAY_WEEK, 6, 1.0, author1))) } @@ -84,13 +84,13 @@ class FactHasherTest : Spek({ .updateFromObservable(observable) assertEquals(5, facts.size) - assertTrue(facts.contains(Fact(repo, FactKey.COMMITS_DAY_TIME + 18, + assertTrue(facts.contains(Fact(repo, FactCodes.COMMITS_DAY_TIME, 18, 1.0, author2))) - assertTrue(facts.contains(Fact(repo, FactKey.COMMITS_DAY_WEEK + 0, + assertTrue(facts.contains(Fact(repo, FactCodes.COMMITS_DAY_WEEK, 0, 1.0, author2))) - assertTrue(facts.contains(Fact(repo, FactKey.COMMITS_DAY_TIME + 13, + assertTrue(facts.contains(Fact(repo, FactCodes.COMMITS_DAY_TIME, 13, 2.0, author1))) - assertTrue(facts.contains(Fact(repo, FactKey.COMMITS_DAY_WEEK + 0, + assertTrue(facts.contains(Fact(repo, FactCodes.COMMITS_DAY_WEEK, 0, 1.0, author1))) }