From 052cad063116905ade983aa25e4df3f78ba03fba Mon Sep 17 00:00:00 2001 From: Daniele Guido Date: Thu, 26 Sep 2024 13:33:24 +0200 Subject: [PATCH] fix textreusecluster label when timedifference is not given --- src/components/modules/lists/ItemLabel.vue | 6 +++--- src/models/TextReuseCluster.js | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/modules/lists/ItemLabel.vue b/src/components/modules/lists/ItemLabel.vue index 906934e84..4080bbd81 100644 --- a/src/components/modules/lists/ItemLabel.vue +++ b/src/components/modules/lists/ItemLabel.vue @@ -104,7 +104,7 @@ export default { ? this.$tc('numbers.clusterSize', item.clusterSize, { n: this.$n(item.clusterSize) }) - : '' + : 'size' const lexicalOverlapLabel = item.lexicalOverlap != null ? this.$tc('numbers.lexicalOverlap', item.lexicalOverlap, { @@ -134,7 +134,7 @@ export default { return this.$t('textReuseClusterSummary', { shortId: item.shortId, textSampleExcerpt: item.textSampleExcerpt, - clusterSize: clusterSizeLabel, + size: clusterSizeLabel, lexicalOverlap: lexicalOverlapLabel, timespan: this.$tc('numbers.days', item.timeDifferenceDay, { n: item.timeDifferenceDay @@ -162,7 +162,7 @@ export default { "numbers": { "days": "the same day|over {n} day|over {n} days" }, - "textReuseClusterSummary": "cluster {shortId}
{lexicalOverlap} {timespan} ({dates}).
{textSampleExcerpt}
" + "textReuseClusterSummary": "cluster {shortId} ({size})
{lexicalOverlap} {timespan} ({dates}).
{textSampleExcerpt}
" } } diff --git a/src/models/TextReuseCluster.js b/src/models/TextReuseCluster.js index 931a3f429..74edf36f8 100644 --- a/src/models/TextReuseCluster.js +++ b/src/models/TextReuseCluster.js @@ -27,7 +27,7 @@ export default class TextReuseCluster { minDate = new Date(), clusterSize = 0, lexicalOverlap = 0, - connectedClusters = [], + connectedClusters = [] } = {}) { this.id = String(id) this.shortId = this.id.split('-').pop() @@ -37,9 +37,18 @@ export default class TextReuseCluster { this.textSampleContent = String(textSampleContent) this.textSampleExcerpt = String(textSampleExcerpt) this.textSampleDate = String(textSampleDate) - this.timeDifferenceDay = parseInt(timeDifferenceDay, 10) this.maxDate = maxDate this.minDate = minDate + // recalculate timedifferencedya using dates + const computedTimeDifferenceDay = Math.floor( + (this.maxDate - this.minDate) / (24 * 60 * 60 * 1000) + ) + if (computedTimeDifferenceDay !== timeDifferenceDay) { + console.warn('recalculating timeDifferenceDay', this.timeDifferenceDay, timeDifferenceDay) + this.timeDifferenceDay = computedTimeDifferenceDay + } else { + this.timeDifferenceDay = timeDifferenceDay + } this.clusterSize = parseInt(clusterSize, 10) this.connectedClusters = connectedClusters this.lexicalOverlap = parseFloat(lexicalOverlap) @@ -48,7 +57,7 @@ export default class TextReuseCluster { static fromSolrResponse(response) { return response.map(cluster => { return new TextReuseCluster({ - id: cluster.id, + id: cluster.id }) }) } @@ -62,7 +71,7 @@ export default class TextReuseCluster { const maxDate = new Date(item.date) const minDate = new Date( - +maxDate - item.textReuseCluster.timeDifferenceDay * 24 * 60 * 60 * 1000, + +maxDate - item.textReuseCluster.timeDifferenceDay * 24 * 60 * 60 * 1000 ) return new TextReuseCluster({ id: item.textReuseCluster.id, @@ -77,7 +86,7 @@ export default class TextReuseCluster { minDate, clusterSize: item.textReuseCluster.clusterSize, lexicalOverlap: item.textReuseCluster.lexicalOverlap, - connectedClusters: item.connectedClusters, + connectedClusters: item.connectedClusters }) } }