Exemplo n.º 1
0
func getIndex(input ListOfRefOfMapOfStringToValue, vrw types.ValueReadWriter) MapOfStringToRefOfListOfPitch {
	pitcherMu := sync.Mutex{}
	inningMu := sync.Mutex{}
	pitchers := map[string]string{}
	innings := []map[string][]PitchDef{}

	// Walk through the list in inputDataset and basically switch
	// on the top-level key to know if it's an inning or a pitcher.
	input.IterAllP(512, func(item RefOfMapOfStringToValue, i uint64) {
		m := item.TargetValue(vrw)

		if key := "inning"; m.Has(key) {
			inning := processInning(m.Get(key).(MapOfStringToValue))
			inningMu.Lock()
			innings = append(innings, inning)
			inningMu.Unlock()
		}

		if key := "Player"; m.Has(key) {
			id, name := processPitcher(m.Get(key).(MapOfStringToValue))

			if id != "" && name != "" {
				pitcherMu.Lock()
				pitchers[id] = name
				pitcherMu.Unlock()
			}
		}
	})

	pitchCounts := map[string]ListOfPitchDef{}
	for _, inning := range innings {
		for id, p := range inning {
			pitchCounts[id] = append(pitchCounts[id], p...)
		}
	}

	namedPitchCounts := MapOfStringToRefOfListOfPitchDef{}
	for id, p := range pitchCounts {
		if name, ok := pitchers[id]; d.Chk.True(ok, "Unknown pitcher: %s", id) {
			namedPitchCounts[name] = vrw.WriteValue(p.New()).TargetRef()
		}
	}
	return namedPitchCounts.New()
}
Exemplo n.º 2
0
func resolveImports(aliases map[string]string, includePath string, vrw types.ValueReadWriter) map[string]ref.Ref {
	canonicalize := func(path string) string {
		if filepath.IsAbs(path) {
			return path
		}
		return filepath.Join(includePath, path)
	}
	imports := map[string]ref.Ref{}

	for alias, target := range aliases {
		var r ref.Ref
		if d.Try(func() { r = ref.Parse(target) }) != nil {
			canonical := canonicalize(target)
			inFile, err := os.Open(canonical)
			d.Chk.NoError(err)
			defer inFile.Close()
			parsedDep := ParseNomDL(alias, inFile, filepath.Dir(canonical), vrw)
			imports[alias] = vrw.WriteValue(parsedDep.Package).TargetRef()
		} else {
			imports[alias] = r
		}
	}
	return imports
}