コード例 #1
0
ファイル: csos.go プロジェクト: jirkadanek/veterani
func ReadCsos(fname string) []Csos {
	f, err := os.Open(fname)
	if err != nil {
		log.Fatal(err)
	}

	s := bufio.NewScanner(f)

	for s.Scan() {
		line := s.Text()
		if len(line) > 0 && line[0] == '-' {
			break
		}
	}

	if err := s.Err(); err != nil {
		log.Fatal(err)
	}

	rs := make([]Csos, 0)

	i := 1
	prevposition := 0
	prevresult := ""
	prevclass := ""
	for s.Scan() {
		line := []rune(s.Text())

		if len(line) != 49 {
			log.Printf("len(line) != 49, %d '%s'\n", len(line), string(line))
			continue
		}

		category := string(line[0:10])
		familyGiven := string(line[10:35])
		regno := string(line[35:42])
		license := string(line[42:43])
		result := string(line[43:49])

		// restart counter
		if prevclass != category {
			i = 1
			prevresult = ""
			prevposition = 0
		}

		position := i
		if prevresult == result {
			position = prevposition
		}

		r := Csos{Position: position,
			Class:       types.NewClass(strings.TrimSpace(category)),
			FamilyGiven: strings.TrimSpace(familyGiven),
			Regno:       types.NewRegno(strings.TrimSpace(regno)),
			License:     strings.TrimSpace(license),
			Result:      strings.TrimSpace(result)}

		rs = append(rs, r)

		if err := s.Err(); err != nil {
			log.Fatal(err)
		}
		i++
		prevclass = category
		prevresult = result
		prevposition = position
	}
	return rs
}
コード例 #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>`)
}