-
Notifications
You must be signed in to change notification settings - Fork 0
/
anomaly.go
49 lines (39 loc) · 1.26 KB
/
anomaly.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package site
import (
"fmt"
"time"
"github.com/iand/genster/model"
)
func ScanTimelineEventForAnomalies(ev model.TimelineEvent) []*model.Anomaly {
var anomalies []*model.Anomaly
for _, cit := range ev.GetCitations() {
anoms := ScanGeneralCitationForAnomalies(cit)
if len(anoms) > 0 {
for _, anom := range anoms {
// TODO: add context
anom.Context += " for " + ev.Type() + " " + ev.GetDate().When()
anomalies = append(anomalies, anom)
}
}
}
return anomalies
}
func ScanGeneralCitationForAnomalies(cit *model.GeneralCitation) []*model.Anomaly {
var anomalies []*model.Anomaly
var name string
if cit.Source != nil && cit.Source.Title != "" {
name = cit.Source.Title
} else {
name = cit.Detail
}
recent := model.Year(time.Now().Year() - 60)
if len(cit.TranscriptionText) != 0 && !cit.TranscriptionDate.IsUnknown() && cit.TranscriptionDate.SortsBefore(recent) {
// Transcription date might be the date of the original record
anomalies = append(anomalies, &model.Anomaly{
Category: "Citation",
Text: fmt.Sprintf("%q might be the date of the original record, it should be the date the transcription was made.", cit.TranscriptionDate.String()),
Context: "Transcription date for citation of " + name,
})
}
return anomalies
}