Esempio n. 1
0
        public void Compute(WorldBuilder worldBuilder, Plugs plugs)
        {
            foreach (var pair in worldBuilder[_source].SeriesByName)
            {
                var count  = plugs[_count];
                var offset = 0;
                var cycle  = (int)plugs[_cycle];
                while (count > 0m)
                {
                    var ratio = Math.Min(1m, count);
                    count--;

                    var value = TimeSeries.Scale(ratio, pair.Value);
                    value = new TimeSeries(value.Range.Begin + offset, value.Values);
                    if (worldBuilder[_target].TryGetValue(pair.Key, out var existing))
                    {
                        value = TimeSeries.Sum(new List <TimeSeries> {
                            existing, value
                        });
                    }
                    worldBuilder[_target][pair.Key] = value;

                    offset += cycle;
                }
            }
        }
Esempio n. 2
0
 public void Compute(WorldBuilder worldBuilder, Plugs plugs)
 {
     foreach (var pair in worldBuilder[_child].SeriesByName)
     {
         var ratio = _hole == null ? _ratio : plugs[_hole];
         var value = TimeSeries.Scale(ratio, pair.Value);
         if (worldBuilder[_parent].TryGetValue(pair.Key, out var existing))
         {
             value = TimeSeries.Sum(new List <TimeSeries> {
                 existing, value
             });
         }
         worldBuilder[_parent][pair.Key] = value;
     }
 }
Esempio n. 3
0
        public void Compute(WorldBuilder worldBuilder, Plugs plugs)
        {
            var keyValuePairs = new List <KeyValuePair <string, TimeSeries> >(worldBuilder[_node].SeriesByName);

            foreach (var pair in keyValuePairs)
            {
                var name = pair.Key;
                if (name.EndsWith("production"))
                {
                    worldBuilder[_node][name] = TimeSeries.Scale(plugs[_production], pair.Value);
                }
                if (name.EndsWith("costs"))
                {
                    worldBuilder[_node][name] = TimeSeries.Scale(plugs[_costs], pair.Value);
                }
            }
        }
Esempio n. 4
0
        private static void Truncate(int truncationMonth, WorldBuilder worldBuilder, string node, string seriesName)
        {
            if (!worldBuilder[node].TryGetValue(seriesName, out var series))
            {
                return;
            }
            var values          = series.Values;
            var truncatedValues = new decimal[values.Length];

            for (var i = 0; i < values.Length; ++i)
            {
                if (i + series.Range.Begin >= truncationMonth)
                {
                    break;
                }
                truncatedValues[i] = values[i];
            }

            worldBuilder[node][$"truncated_{seriesName}"] = new TimeSeries(series.Range.Begin, truncatedValues);
        }
Esempio n. 5
0
        public void Compute(WorldBuilder worldBuilder, Plugs plugs)
        {
            var nodeBuilder  = worldBuilder[_production];
            var seriesByName = new List <KeyValuePair <string, TimeSeries> >(nodeBuilder.SeriesByName);

            foreach (var pair in seriesByName)
            {
                if (!pair.Key.EndsWith("production"))
                {
                    continue;
                }
                var matchingPriceName = pair.Key.Replace("production", "price");
                if (!worldBuilder[_price].TryGetValue(matchingPriceName, out var priceSeries))
                {
                    continue;
                }
                var revenue = TimeSeries.Product(new List <TimeSeries> {
                    pair.Value, priceSeries
                });
                nodeBuilder[pair.Key.Replace("production", "revenue")] = revenue;
            }
        }
Esempio n. 6
0
        public void Compute(WorldBuilder worldBuilder, Plugs plugs)
        {
            var costs            = worldBuilder[_group]["costs"];
            var revenue          = worldBuilder[_group]["revenue"];
            var operating_income = TimeSeries.Sum(new List <TimeSeries> {
                TimeSeries.Scale(-1m, costs), revenue
            });

            worldBuilder[_group]["operating_income"] = operating_income;

            var cum       = 0m;
            var maxcum    = 0m;
            var maxcumpos = -1;
            var i         = 0;

            foreach (var value in operating_income.Values)
            {
                cum += value;
                if (cum > maxcum)
                {
                    maxcum    = cum;
                    maxcumpos = i;
                }

                i++;
            }

            var truncationMonth = maxcumpos + operating_income.Range.Begin + 1;

            Truncate(truncationMonth, worldBuilder, _group, "operating_income");
            Truncate(truncationMonth, worldBuilder, _group, "revenue");
            Truncate(truncationMonth, worldBuilder, _group, "costs");
            foreach (var member in _members)
            {
                Truncate(truncationMonth, worldBuilder, member, "revenue");
                Truncate(truncationMonth, worldBuilder, member, "costs");
            }
        }