Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/kotlin/app/FactCodes.kt
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 0 additions & 8 deletions src/main/kotlin/app/FactKey.kt

This file was deleted.

7 changes: 3 additions & 4 deletions src/main/kotlin/app/hashers/CodeLongevity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -150,7 +149,7 @@ class CodeLongevity(private val localRepo: LocalRepo,
val repoAvg = if (repoTotal > 0) { repoSum / repoTotal } else 0
val stats = mutableListOf<Fact>()
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, "
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/app/hashers/FactHasher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package app.hashers

import app.FactKey
import app.FactCodes
import app.Logger
import app.api.Api
import app.model.Author
Expand Down Expand Up @@ -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))
}
}
Expand All @@ -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))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/app/hashers/RepoHasher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions src/main/kotlin/app/model/Fact.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ 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()
) {
@Throws(InvalidParameterException::class)
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)
Expand All @@ -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()
}

Expand Down
12 changes: 8 additions & 4 deletions src/main/proto/sourcerer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions src/test/kotlin/test/tests/hashers/FactHasherTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
}

Expand All @@ -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)))
}

Expand Down