Ejemplo n.º 1
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>
`)
}
Ejemplo n.º 2
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>`)
}