Skip to content

Commit d31fb4d

Browse files
committed
collect all heats in lenex import, otherwise empty starts were imported
1 parent 98aed95 commit d31fb4d

File tree

2 files changed

+85
-79
lines changed

2 files changed

+85
-79
lines changed

importer/lenex_importer.go

Lines changed: 76 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
5252

5353
// EVENT IMPORT
5454
fmt.Printf("%d", event.Number)
55-
if !IsEventImportable(event.Number, exclude, include) {
56-
print(" => no import")
57-
continue
58-
}
5955

6056
println("event import")
6157

@@ -84,74 +80,79 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
8480
importEvent.Distance = event.SwimStyle.RelayCount * event.SwimStyle.Distance
8581
}
8682

87-
newEvent, created, err3 := ec.ImportEvent(importEvent, string(event.SwimStyle.Stroke), session.Number)
88-
if err3 != nil {
89-
return nil, err3
90-
}
83+
if IsEventImportable(event.Number, exclude, include) { // only import if in import list, but do not skip, heats need to be set
84+
newEvent, created, err3 := ec.ImportEvent(importEvent, string(event.SwimStyle.Stroke), session.Number)
85+
if err3 != nil {
86+
return nil, err3
87+
}
9188

92-
if created {
93-
stats.Created.Events++
94-
print("(+) ")
95-
} else {
96-
print("( ) ")
97-
}
98-
println(newEvent.Number)
89+
if created {
90+
stats.Created.Events++
91+
print("(+) ")
92+
} else {
93+
print("( ) ")
94+
}
95+
println(newEvent.Number)
9996

100-
stats.Imported.Events++
97+
stats.Imported.Events++
10198

102-
// AGE GROUP IMPORT
103-
for _, ageGroup := range event.AgeGroups {
104-
minAge := meetingYear - ageGroup.AgeMin
105-
maxAge := meetingYear - ageGroup.AgeMax
99+
// AGE GROUP IMPORT
100+
for _, ageGroup := range event.AgeGroups {
101+
minAge := meetingYear - ageGroup.AgeMin
102+
maxAge := meetingYear - ageGroup.AgeMax
106103

107-
if ageGroup.AgeMax <= 0 {
108-
maxAge = 1900
109-
}
104+
if ageGroup.AgeMax <= 0 {
105+
maxAge = 1900
106+
}
110107

111-
importAgeGroup := meetingModel.AgeGroup{
112-
Meeting: meeting,
113-
Event: event.Number,
114-
Default: false,
115-
MinAge: strconv.Itoa(minAge),
116-
MaxAge: strconv.Itoa(maxAge),
117-
IsYear: true,
118-
Name: ageGroup.Name,
119-
}
108+
importAgeGroup := meetingModel.AgeGroup{
109+
Meeting: meeting,
110+
Event: event.Number,
111+
Default: false,
112+
MinAge: strconv.Itoa(minAge),
113+
MaxAge: strconv.Itoa(maxAge),
114+
IsYear: true,
115+
Name: ageGroup.Name,
116+
}
120117

121-
switch ageGroup.Gender {
122-
case enums.AgeGroupGenderFemale:
123-
importAgeGroup.Gender = "FEMALE"
124-
break
125-
case enums.AgeGroupGenderMale:
126-
importAgeGroup.Gender = "MALE"
127-
break
128-
case enums.AgeGroupGenderMixed:
129-
importAgeGroup.Gender = "MIXED"
130-
default:
131-
importAgeGroup.Gender = "UNSET"
132-
}
118+
switch ageGroup.Gender {
119+
case enums.AgeGroupGenderFemale:
120+
importAgeGroup.Gender = "FEMALE"
121+
break
122+
case enums.AgeGroupGenderMale:
123+
importAgeGroup.Gender = "MALE"
124+
break
125+
case enums.AgeGroupGenderMixed:
126+
importAgeGroup.Gender = "MIXED"
127+
default:
128+
importAgeGroup.Gender = "UNSET"
129+
}
133130

134-
newAgeGroup, created, err5 := gc.ImportAgeGroup(importAgeGroup)
135-
if err5 != nil {
136-
return nil, err5
137-
}
131+
newAgeGroup, created, err5 := gc.ImportAgeGroup(importAgeGroup)
132+
if err5 != nil {
133+
return nil, err5
134+
}
138135

139-
if created {
140-
stats.Created.AgeGroups++
141-
print("(+) ")
142-
} else {
143-
print("( ) ")
144-
}
145-
println(newAgeGroup.Name)
136+
if created {
137+
stats.Created.AgeGroups++
138+
print("(+) ")
139+
} else {
140+
print("( ) ")
141+
}
142+
println(newAgeGroup.Name)
146143

147-
stats.Imported.AgeGroups++
144+
stats.Imported.AgeGroups++
148145

149-
// COLLECT RANKS
150-
for _, ranking := range ageGroup.Rankings {
151-
if ranks[ranking.ResultId].Place < ranking.Place {
152-
ranks[ranking.ResultId] = ranking
146+
// COLLECT RANKS
147+
for _, ranking := range ageGroup.Rankings {
148+
if ranks[ranking.ResultId].Place < ranking.Place {
149+
ranks[ranking.ResultId] = ranking
150+
}
153151
}
154152
}
153+
154+
} else {
155+
print(" => no import")
155156
}
156157

157158
// HEATS
@@ -178,20 +179,24 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
178179
continue
179180
}
180181

181-
// IMPORT HEAT
182-
newHeat, c, err := hc.ImportHeat(heatModel)
183-
if err != nil {
184-
importError(fmt.Sprintf("import heat request failed for heat %d/%d!", event.Number, heat.Number), err)
185-
continue
186-
}
187-
fmt.Printf("[ o ] import heat: event: '%d', number: '%d', start: '%s', start before: '%s'\n", newHeat.Event, newHeat.Number, newHeat.StartEstimation, startTime)
182+
if IsEventImportable(event.Number, exclude, include) { // only import if in import list, but do not skip, heats need to be set
183+
// IMPORT HEAT
184+
newHeat, c, err := hc.ImportHeat(heatModel)
185+
if err != nil {
186+
importError(fmt.Sprintf("import heat request failed for heat %d/%d!", event.Number, heat.Number), err)
187+
continue
188+
}
189+
fmt.Printf("[ o ] import heat: event: '%d', number: '%d', start: '%s', start before: '%s'\n", newHeat.Event, newHeat.Number, newHeat.StartEstimation, startTime)
188190

189-
if c {
190-
stats.Created.Heats++
191+
if c {
192+
stats.Created.Heats++
193+
}
194+
stats.Imported.Heats++
195+
196+
heatModel = *newHeat
191197
}
192-
stats.Imported.Heats++
193198

194-
heats[heat.HeatId] = *newHeat
199+
heats[heat.HeatId] = heatModel
195200
}
196201
}
197202
}

model/import_file_request.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package model
22

33
type ImportFileRequest struct {
4-
Url string `json:"url"` // url where file is located
5-
Text string `json:"text"` // text to import
6-
FileExtension string `json:"file_extension"` // file extension, either PDF or DSV or PDF_TXT
7-
FileType string `json:"file_type"` // file type: DEFINITION; START_LIST; RESULT_LIST;
8-
ExcludeEvents []int `json:"exclude_events"` // events to exclude from import as array
9-
IncludeEvents []int `json:"include_events"` // events to include in import process as array
10-
Meeting string `json:"meeting"` // meeting in which to import the data
11-
SessionID string `json:"session_id"` // optional session ID for progress streaming
4+
Url string `json:"url"` // url where file is located
5+
Text string `json:"text"` // text to import
6+
FileExtension string `json:"file_extension"` // file extension, either PDF or DSV or PDF_TXT
7+
FileType string `json:"file_type"` // file type: DEFINITION; START_LIST; RESULT_LIST;
8+
ExcludeEvents []int `json:"exclude_events"` // events to exclude from import as array
9+
IncludeEvents []int `json:"include_events"` // events to include in import process as array
10+
Meeting string `json:"meeting"` // meeting in which to import the data
11+
SessionID string `json:"session_id"` // optional session ID for progress streaming
12+
Features []string `json:"features"` // included features are imported, missing features are ignored, options: event, age_group, heat, start, result, disqualification, athlete, team
1213
}

0 commit comments

Comments
 (0)