Пример #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()
}
Пример #2
0
func naplndb(db sql.Db, foddily, dzavody, suffix string) {
	db.Createtables()
	// nacist oddily
	oddily := input.Nacti_oddily(foddily)
	log.Printf("Oddilu: %d\n", len(oddily))
	log.Println("-------------")
	// nacist zavod po zavode
	vysledky := nacti_zavody(dzavody, suffix)
	log.Println("-------------")
	for _, vysledek := range vysledky {
		switch suffix {
		case ".txt":
			FromCsoc(db, oddily, vysledek)
		case ".xml":
			FromXml(db, oddily, vysledek)
		}
	}
}
Пример #3
0
func vypis_vysledky(db sql.Db) {
	r := db.Getresults()

	//fmt.Println(r[2])
	//return

	f, err := os.Create("hodnoceni_cpv_2013.html")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	fmt.Fprintf(f, `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body><pre>
`)
	fmt.Fprintf(f, "\n")
	for _, k := range []string{"D", "H"} {
		fmt.Fprintf(f, "%s\n", k)
		fmt.Fprintf(f, "   pořadí  pořadí   ReČ             Jméno        počet    body\n")
		fmt.Fprintf(f, "    ČPV    absol.                               závodů\n")
		for _, l := range r {
			if l.Kategorie[0:1] != k {
				continue
			}
			fmt.Fprintf(f, "%7d %6d %10s %-24s %2d %7d    %s\n",
				l.P_poradi,
				l.Ap_poradi,
				strings.Replace(l.Z_id, "|", "", -1),
				l.Z_prijmeni+", "+l.Z_jmeno,
				l.Nzavodu,
				l.S_body,
				strings.Replace(l.Ap_scores, ",", " ", -1))
		}
		fmt.Fprintf(f, "\n")
	}
	fmt.Fprintf(f, `</pre>
</body>
</html>
`)
}
Пример #4
0
func zpracujdb(db sql.Db) {
	db.Vypocitejsoucty()
	db.Celkoveporadi()
	db.Poradi()
	db.Katporadi()
}
Пример #5
0
func vypis_vysledky(db sql.Db) {
	r := db.Getresults()

	classes := make(map[string]bool)
	for _, v := range r {
		cls := strings.Split(v.Kategorie, ",")
		for _, c := range cls {
			classes[c] = true
		}
	}

	// only classes someone competed in
	// this is a little bit wrong, should iterate over runners
	sclasses := make([]string, 0)
	for c, _ := range classes {
		sclasses = append(sclasses, c)
	}
	sort.Strings(sclasses)

	f, err := os.Create("cpv2012kateg.html")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	fmt.Fprintf(f, `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body><pre>`)
	fmt.Fprintf(f, "Pořadí Českého Poháru Veteránů 2013 dle kategorií\n\n")
	for _, k := range sclasses { // over all categories
		fmt.Fprintf(f, "          KATEGORIE %s\n", k)
		fmt.Fprintf(f, "poř.kat.  poř.ČPV abs.poř.  Reč         Jmeno             počet  body     body dle závodů\n")
		fmt.Fprintf(f, "                                                         závodů celkem  ")
		for i := 1; i <= COLS; i++ {
			fmt.Fprintf(f, "%2d.", i)
		}
		fmt.Fprintf(f, "\n")

		cntr := 1
		prevporadi := 0
		prevkatporadi := 0
		for _, l := range r { // over all runners

			cs := make(map[string]bool) // categories the person competed in
			for _, c := range strings.Split(l.Kategorie, ",") {
				cs[c] = true
			}

			classstr := strings.Split(l.Kategorie, ",")[0][:1] // pohlavi
			class, err := types.NewRegno(strings.Replace(l.Z_id, "|", "", -1)).ClassB()
			if err != nil {

				// max class
				classstr = strings.Split(l.Kategorie, ",")[0]
				for v, _ := range cs {
					if types.ClassLess(types.NewClass(classstr), types.NewClass(v)) {
						classstr = v
					}
				}
				log.Println(l.Z_prijmeni, l.Z_jmeno, l.Z_id, err, classstr)
			} else {
				classstr += fmt.Sprintf("%d", class)
			}
			//fmt.Println(classstr, k)
			if classstr != k {
				continue // skip the runner
			}

			katporadi := prevkatporadi
			if l.Ap_poradi != prevporadi {
				katporadi = cntr
			}

			races := db.Getraceresults(l.Z_id) // map[int]int
			sraces := racesTable(l, races)

			fmt.Fprintf(f, "%7d %6d %6d %10s %-24s %2d %7d    %s\n",
				katporadi, //db.Getkatporadi(l.Z_id, k), //l.Kp_poradi,
				l.P_poradi,
				l.Ap_poradi,
				strings.Replace(l.Z_id, "|", "", -1),
				l.Z_prijmeni+", "+l.Z_jmeno,
				l.Nzavodu,
				l.S_body,
				sraces.String())
			prevkatporadi = katporadi
			prevporadi = l.Ap_poradi
			cntr++
		}
		fmt.Fprintf(f, "\n")
	}
	fmt.Fprintf(f, `</pre>
</body>
</html>`)
}