예제 #1
0
func FromCsoc(db sql.Db, oddily map[string]bool, vysledek input.Zavod) {
	csos := input.ReadCsos(vysledek.Fname)

	cs := make(map[types.Class]bool) // all classes

	for _, r := range csos {
		cs[r.Class] = true
	}

	rs := input.GetValid(csos, oddily, vysledek) // valid results

	nconts := make(map[types.Class]int) // number of classified runners
	for _, r := range rs {
		nconts[r.Class] += 1
	}

	//recount positions
	var prevp int
	var prevclass types.Class
	var prevrposition int
	for _, r := range rs {
		// different class
		if prevclass != r.Class {
			prevp = 0
			prevrposition = 0
		}
		// don't advance on ties
		p := prevp
		if r.Position != prevrposition {
			p++ // counting from 1
		}

		classrank := bodovani.SubClassRank(cs, r.Class)

		if r.FamilyGiven == "Gryc Jan" {
			log.Println(vysledek.Cislo, r.Class, classrank, p, nconts[r.Class])
		}

		b := bodovani.Score(classrank, p, nconts[r.Class], vysledek.Veteraniada)

		id := fmt.Sprintf("%s|%s", r.Regno.C, r.Regno.N)
		pts := strings.SplitN(r.FamilyGiven, " ", 2)
		family := pts[0]
		given := ""
		if len(pts) > 1 {
			given = pts[1]
		}

		db.Pridejvysledek(id, given, family, vysledek.Cislo, b, r.Class.A, r.Class.B)
		prevp = p
		prevclass = r.Class
		prevrposition = r.Position
	}
	fmt.Println()
}