public void Initialize() { indexCalculator = new IndexCalculator(indexFormula); }
/** * public override Dictionary<string, decimal> CalculateIntervalTime(ulong interval, ulong start, ulong end, string product, * ParallelQuery<ProductResult> filtredProductResult, ParallelQuery<MachineState> fitredMachineStates, string index) * { * throw new NotImplementedException(); * } * * public override Dictionary<string, decimal> CalculateTime(ulong start, ulong end, string product, ParallelQuery<ProductResult> filtredProductResult, * ParallelQuery<MachineState> fitredMachineStates, string index) * { * throw new NotImplementedException(); * } * * public override Dictionary<string, decimal> CalculateIndirectForOneProduct(string product, ParallelQuery<ProductResult> filtredProductResult, * ParallelQuery<MachineState> fitredMachineStates, string index) * { * throw new NotImplementedException(); * } * * public override Dictionary<string, decimal> CalculatePerProduct(string product, ParallelQuery<ProductResult> filtredProductResult, ParallelQuery<MachineState> fitredMachineStates, * string index) * { * throw new NotImplementedException(); * } * * public override Dictionary<string, decimal> CalculatePerMachine(ParallelQuery<ProductResult> filtredProductResult, ParallelQuery<MachineState> fitredMachineStates, string index) * { * throw new NotImplementedException(); * } * * public override Dictionary<string, decimal> CalculateIndirectPerMachine(ParallelQuery<ProductResult> filtredProductResult, ParallelQuery<MachineState> fitredMachineStates, * string index) * { * throw new NotImplementedException(); * } * * public override Dictionary<string, decimal> CalculateIndex(ParallelQuery<ProductResult> filtredProductResult, ParallelQuery<MachineState> fitredMachineStates, string index) * { * throw new NotImplementedException(); * } * **/ private decimal CalculateInterval(ulong start, ulong end, string index) { var tableOrdered = (from i in SourceTableOrdered where i.ModelNode == ResultId && i.Start > start && i.Start < end select i).ToList(); if (!tableOrdered.Any()) { return(0); } var f = ProductResults(tableOrdered); decimal count = f.Count(); var sumUsed = f.Sum(t => t.Total, null); decimal intervaltime = end - start; var downtime = Downtime(start, end); var idletime = Idletime(start, end); decimal result = 0; if (index == "Processed per hour") { result += count / (intervaltime / 3600000); } else if (index == "Processed") { result += count; } else if (IndexCalculator.Indexes.Any(t => t.IndexName == index)) { var dic = new Dictionary <Consumable, decimal>(); foreach (State state in States) { foreach (Consumption consumption in state.Consumptions) { var res = consumption.Amount; if (!consumption.Static) { res /= 3600000; if (state.Name == "Processing" || state.Name == "Used") { res += res * sumUsed; } else if (state.Name == "Down") { res += res * downtime; } else if (state.Name == "Idle") { res += res * idletime; } } else { res = res * count; } if (dic.ContainsKey(consumption.Consumable)) { dic[consumption.Consumable] += res / count; } else { dic.Add(consumption.Consumable, res / count); } } } result += IndexCalculator.Calculate(dic, index); } else { foreach (State state in States) { var consumption = state.Consumptions.FirstOrDefault(t => t.Consumable.Name == index); if (consumption != default(Consumption)) { var res = consumption.Amount; if (!consumption.Static) { res /= 3600000; switch (state.Name) { case "Used": case "Processing": res += res * sumUsed; break; case "Down": res += res * downtime; break; case "Idle": res += res * idletime; break; } } else { res = res * count; } result += res; } } } return(result); }