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; } } }
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; } }
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); } } }
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"); } }