public void LoadData()
        {
            LabeledData <float> shapeData   = LoadData(FitToShape);
            LabeledData <float> toAggregate = LoadData(DataToAggregate);
            LabeledData <float> ret         = new LabeledData <float>();

            // add all of the keys with a zero value
            foreach (var e in shapeData)
            {
                ret.Add(e.Key, 0.0f);
            }
            if (DataMap != null)
            {
                //Load in the map
                using (var reader = new CsvReader(DataMap, true))
                {
                    //burn header
                    reader.LoadLine();
                    while (reader.LoadLine(out int columns))
                    {
                        if (columns >= 3)
                        {
                            reader.Get(out string destName, 0);
                            reader.Get(out string originName, 1);
                            reader.Get(out float toApply, 2);
                            if (!ret.TryGetValue(destName, out float destValue))
                            {
                                continue;
                            }
                            if (!toAggregate.TryGetValue(originName, out float originValue))
                            {
                                continue;
                            }
                            ret[destName] = originValue * toApply + destValue;
                        }
                    }
                }
            }
            else
            {
                var keys = ret.Keys.ToList();
                foreach (var key in keys)
                {
                    if (toAggregate.TryGetValue(key, out float data))
                    {
                        ret[key] = data;
                    }
                }
            }
            _Data  = ret;
            Loaded = true;
        }
Beispiel #2
0
        private void Add <TData>(LabeledData <TData> set, string label, TData data)
        {
            switch (AggregationToApply)
            {
            case Agg.None:
                if (set.ContainsKey(label))
                {
                    throw new XTMFRuntimeException(this, $"In '{Name}' while loading in labeled data a label was loaded multiple times '{label}'!");
                }
                set.Add(label, data);
                break;

            case Agg.Sum:
                if (typeof(TData) == typeof(float))
                {
                    // the optimizer should be able to solve this
                    var fData = (float)(object)data;
                    var fSet  = set as LabeledData <float>;
                    // ReSharper disable once PossibleNullReferenceException
                    fSet.TryGetValue(label, out float alreadyContained);
                    fSet[label] = fData + alreadyContained;
                }
                break;

            case Agg.Multiply:
                if (typeof(TData) == typeof(float))
                {
                    // the optimizer should be able to solve this
                    var fData = (float)(object)data;
                    var fSet  = set as LabeledData <float>;
                    // ReSharper disable once PossibleNullReferenceException
                    if (!fSet.TryGetValue(label, out float alreadyContained))
                    {
                        alreadyContained = 1.0f;
                    }
                    fSet[label] = fData * alreadyContained;
                }
                break;

            case Agg.Count:
                if (typeof(TData) == typeof(float))
                {
                    var fSet = set as LabeledData <float>;
                    // ReSharper disable once PossibleNullReferenceException
                    fSet.TryGetValue(label, out float alreadyContained);
                    fSet[label] = 1 + alreadyContained;
                }
                break;
            }
        }