@@ -11,11 +11,12 @@ import (
1111 meetingModel "github.com/swimresults/meeting-service/model"
1212 startModel "github.com/swimresults/start-service/model"
1313 "io"
14+ "slices"
1415 "strconv"
1516 "time"
1617)
1718
18- func ImportLenexFile (file string , meeting string , exclude []int , include []int , stg importModel.ImportSetting ) (* importModel.ImportFileStats , error ) {
19+ func ImportLenexFile (file string , meeting string , exclude []int , include []int , features [] string , stg importModel.ImportSetting ) (* importModel.ImportFileStats , error ) {
1920 var stats importModel.ImportFileStats
2021
2122 buf , err1 := getFileReader (file )
@@ -81,20 +82,22 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
8182 }
8283
8384 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- }
85+ if slices .Contains (features , "event" ) {
86+ newEvent , created , err3 := ec .ImportEvent (importEvent , string (event .SwimStyle .Stroke ), session .Number )
87+ if err3 != nil {
88+ return nil , err3
89+ }
8890
89- if created {
90- stats .Created .Events ++
91- print ("(+) " )
92- } else {
93- print ("( ) " )
94- }
95- println (newEvent .Number )
91+ if created {
92+ stats .Created .Events ++
93+ print ("(+) " )
94+ } else {
95+ print ("( ) " )
96+ }
97+ println (newEvent .Number )
9698
97- stats .Imported .Events ++
99+ stats .Imported .Events ++
100+ }
98101
99102 // AGE GROUP IMPORT
100103 for _ , ageGroup := range event .AgeGroups {
@@ -128,27 +131,31 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
128131 importAgeGroup .Gender = "UNSET"
129132 }
130133
131- newAgeGroup , created , err5 := gc .ImportAgeGroup (importAgeGroup )
132- if err5 != nil {
133- return nil , err5
134- }
134+ if slices .Contains (features , "age_group" ) {
135135
136- if created {
137- stats .Created .AgeGroups ++
138- print ("(+) " )
139- } else {
140- print ("( ) " )
141- }
142- println (newAgeGroup .Name )
136+ newAgeGroup , created , err5 := gc .ImportAgeGroup (importAgeGroup )
137+ if err5 != nil {
138+ return nil , err5
139+ }
140+
141+ if created {
142+ stats .Created .AgeGroups ++
143+ print ("(+) " )
144+ } else {
145+ print ("( ) " )
146+ }
147+ println (newAgeGroup .Name )
143148
144- stats .Imported .AgeGroups ++
149+ stats .Imported .AgeGroups ++
150+ }
145151
146152 // COLLECT RANKS
147153 for _ , ranking := range ageGroup .Rankings {
148154 if ranks [ranking .ResultId ].Place < ranking .Place {
149155 ranks [ranking .ResultId ] = ranking
150156 }
151157 }
158+
152159 }
153160
154161 } else {
@@ -181,19 +188,22 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
181188
182189 if IsEventImportable (event .Number , exclude , include ) { // only import if in import list, but do not skip, heats need to be set
183190 // 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 )
190191
191- if c {
192- stats .Created .Heats ++
193- }
194- stats .Imported .Heats ++
192+ if slices .Contains (features , "heat" ) {
193+ newHeat , c , err := hc .ImportHeat (heatModel )
194+ if err != nil {
195+ importError (fmt .Sprintf ("import heat request failed for heat %d/%d!" , event .Number , heat .Number ), err )
196+ continue
197+ }
198+ fmt .Printf ("[ o ] import heat: event: '%d', number: '%d', start: '%s', start before: '%s'\n " , newHeat .Event , newHeat .Number , newHeat .StartEstimation , startTime )
195199
196- heatModel = * newHeat
200+ if c {
201+ stats .Created .Heats ++
202+ }
203+ stats .Imported .Heats ++
204+
205+ heatModel = * newHeat
206+ }
197207 }
198208
199209 heats [heat .HeatId ] = heatModel
@@ -381,12 +391,14 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
381391 ResultType : "registration" ,
382392 }
383393
384- _ , _ , err3 := sc .ImportResult (* newStart , resultModel )
385- if err3 != nil {
386- return & stats , err3
394+ if slices .Contains (features , "result" ) {
395+ _ , _ , err3 := sc .ImportResult (* newStart , resultModel )
396+ if err3 != nil {
397+ return & stats , err3
398+ }
399+ stats .Created .Results ++
400+ stats .Imported .Results ++
387401 }
388- stats .Created .Results ++
389- stats .Imported .Results ++
390402 }
391403
392404 // IMPORT TIME SPLITS
@@ -398,12 +410,14 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
398410 LapMeters : split .Distance ,
399411 }
400412
401- _ , _ , err3 := sc .ImportResult (* newStart , lapResult )
402- if err3 != nil {
403- return & stats , err3
413+ if slices .Contains (features , "result" ) {
414+ _ , _ , err3 := sc .ImportResult (* newStart , lapResult )
415+ if err3 != nil {
416+ return & stats , err3
417+ }
418+ stats .Created .Results ++
419+ stats .Imported .Results ++
404420 }
405- stats .Created .Results ++
406- stats .Imported .Results ++
407421 }
408422
409423 // IMPORT RESULT
@@ -413,12 +427,14 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
413427 ResultType : "result_list" ,
414428 }
415429
416- _ , _ , err3 := sc .ImportResult (* newStart , resultModel )
417- if err3 != nil {
418- return & stats , err3
430+ if slices .Contains (features , "result" ) {
431+ _ , _ , err3 := sc .ImportResult (* newStart , resultModel )
432+ if err3 != nil {
433+ return & stats , err3
434+ }
435+ stats .Created .Results ++
436+ stats .Imported .Results ++
419437 }
420- stats .Created .Results ++
421- stats .Imported .Results ++
422438 }
423439
424440 // DISQUALIFICATION
@@ -442,17 +458,19 @@ func ImportLenexFile(file string, meeting string, exclude []int, include []int,
442458 }
443459
444460 if disqType != "" {
445- disqualification , created , err4 := dc .ImportDisqualification (* newStart , result .Comment , disqType , time .UnixMicro (0 ))
446- if err4 != nil {
447- return & stats , err4
448- }
449- cs := 'o'
450- if created {
451- cs = '+'
452- stats .Created .Disqualifications ++
461+ if slices .Contains (features , "disqualification" ) {
462+ disqualification , created , err4 := dc .ImportDisqualification (* newStart , result .Comment , disqType , time .UnixMicro (0 ))
463+ if err4 != nil {
464+ return & stats , err4
465+ }
466+ cs := 'o'
467+ if created {
468+ cs = '+'
469+ stats .Created .Disqualifications ++
470+ }
471+ stats .Imported .Disqualifications ++
472+ fmt .Printf ("[ %c ] > id: %s, type: %s, reason: %s\n " , cs , disqualification .Identifier , disqualification .Type , disqualification .Reason )
453473 }
454- stats .Imported .Disqualifications ++
455- fmt .Printf ("[ %c ] > id: %s, type: %s, reason: %s\n " , cs , disqualification .Identifier , disqualification .Type , disqualification .Reason )
456474 }
457475
458476 }
0 commit comments