Use date from e-mails to set item date

This commit is contained in:
Eike Kettner
2020-05-16 14:18:59 +02:00
parent 5e6ce1737c
commit d65c1e0d36
6 changed files with 85 additions and 18 deletions

View File

@ -43,6 +43,17 @@ case class MetaProposal(proposalType: MetaProposalType, values: NonEmptyList[Can
object MetaProposal {
def apply(pt: MetaProposalType, v0: Candidate, vm: Candidate*): MetaProposal =
MetaProposal(pt, NonEmptyList.of(v0, vm: _*))
def docDate(ts: Timestamp, origin: Option[NerLabel]): MetaProposal = {
val label = ts.toUtcDate.toString
MetaProposal(
MetaProposalType.DocDate,
Candidate(IdRef(Ident.unsafe(label), label), origin.toSet)
)
}
def parseDate(cand: Candidate): Option[LocalDate] =
parseDate(cand.ref.id)

View File

@ -38,6 +38,9 @@ case class MetaProposalList private (proposals: List[MetaProposal]) {
def change(f: MetaProposal => MetaProposal): MetaProposalList =
new MetaProposalList(proposals.map(f))
def filter(f: MetaProposal => Boolean): MetaProposalList =
new MetaProposalList(proposals.filter(f))
def sortByWeights: MetaProposalList =
change(_.sortByWeight)
}

View File

@ -42,10 +42,12 @@ object MetaProposalListTest extends SimpleTestSuite {
test("sort by weights") {
val cand1 = Candidate(IdRef(Ident.unsafe("123"), "name"), Set.empty, Some(0.1))
val cand2 = Candidate(IdRef(Ident.unsafe("456"), "name"), Set.empty, Some(0.05))
val mpl = MetaProposalList.of(
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand1)),
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand2))
).sortByWeights
val mpl = MetaProposalList
.of(
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand1)),
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand2))
)
.sortByWeights
val candidates = mpl.find(MetaProposalType.CorrOrg).get.values
assertEquals(candidates.head, cand2)
@ -55,10 +57,12 @@ object MetaProposalListTest extends SimpleTestSuite {
test("sort by weights: unset is last") {
val cand1 = Candidate(IdRef(Ident.unsafe("123"), "name"), Set.empty, Some(0.1))
val cand2 = Candidate(IdRef(Ident.unsafe("456"), "name"), Set.empty)
val mpl = MetaProposalList.of(
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand1)),
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand2))
).sortByWeights
val mpl = MetaProposalList
.of(
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand1)),
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand2))
)
.sortByWeights
val candidates = mpl.find(MetaProposalType.CorrOrg).get.values
assertEquals(candidates.head, cand1)