double getSolarpanelPowerWatt(IMySolarPanel SolarPanel) { debug("Detail (" + SolarPanel.CustomName + ") > " + SolarPanel.DetailedInfo); DetailedInfo DI = new DetailedInfo(SolarPanel); return(parsePower(DI.getValue(1).getValue())); }
private double getAverageLoadingState(List <IMyBatteryBlock> Batteries) { double allMax = 0.0; double allStored = 0.0; double average = 0; for (int i = 0; i < Batteries.Count; i++) { IMyBatteryBlock Battery = Batteries[i]; DetailedInfo DI = new DetailedInfo(Battery); allMax += parsePower(DI.getValue(BATTERY_VALUE_INDEX_MAX).getValue()); allStored += parsePower(DI.getValue(BATTERY_VALUE_INDEX_STORED).getValue()); } if (allMax > 0) { average = allStored / allMax; } return(average * 100); }
private void initCommands(Environment env) { env.Debug.newScope("initCommands"); //begin info command availableCommands.Add("info", new Command("info", "show short info of a command", env, (BaconArgs Args, Environment Env) => { StringBuilder result = new StringBuilder(); if (Args.getArguments().Count > 0) { for (int i = 0; i < Args.getArguments().Count; i++) { string cmd = Args.getArguments()[i]; if (availableCommands.ContainsKey(cmd)) { result.AppendLine(availableCommands[cmd].name + ": " + availableCommands[cmd].info); } else { result.AppendLine("unknown command: " + cmd); } } } else { List <Command> commands = new List <Command>(availableCommands.Values); for (int i = 0; i < commands.Count; i++) { result.AppendLine(commands[i].name + ": " + commands[i].info); } } return(result); })); availableCommands["info"].help.AppendLine("info [command [...]]"); availableCommands["info"].help.AppendLine(availableCommands["info"].info); availableCommands["info"].help.AppendLine("no argument: info for all available commands"); availableCommands["info"].help.AppendLine("give one ore more arguments to display info for these"); //end info command //begin help command availableCommands.Add("help", new Command("help", "show help of a command", env, (BaconArgs Args, Environment Env) => { StringBuilder result = new StringBuilder(); for (int i = 0; i < Args.getArguments().Count; i++) { if (availableCommands.ContainsKey(Args.getArguments()[i])) { result.Append(availableCommands[Args.getArguments()[i]].help.ToString()); } } return(result); })); availableCommands["help"].help.AppendLine("help command [...]"); availableCommands["help"].help.AppendLine(availableCommands["help"].info); availableCommands["help"].help.AppendLine("shows help for the given command(s)"); //end help commnd //begin details command availableCommands.Add("details", new Command("details", "show detailed info of a block", env, (BaconArgs Args, Environment Env) => { StringBuilder result = new StringBuilder(); for (int i_arg = 0; i_arg < Args.getArguments().Count; i_arg++) { string tag = Args.getArguments()[i_arg]; List <IMyTerminalBlock> Blocks = new List <IMyTerminalBlock>(); Env.GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(Blocks, (IMyTerminalBlock x) => x.CustomName.Contains(tag) && (!(Args.getFlag('t') == 0) || x.CubeGrid.Equals(Env.GridProgram.Me.CubeGrid))); for (int i_blocks = 0; i_blocks < Blocks.Count; i_blocks++) { if (Args.getFlag('b') > 0) { result.AppendLine(Blocks[i_blocks].CustomName); } if (Args.getOption("line").Count > 0) { DetailedInfo info = new DetailedInfo(Blocks[i_blocks]); for (int i = 0; i < Args.getOption("line").Count; i++) { int line = 0; if (int.TryParse(Args.getOption("line")[i], out line)) { DetailedInfo.DetailedInfoValue data = info.getValue(line); result.AppendLine((data != null)?data.k + ": " + data.v:"null"); } } } else { result.AppendLine(Blocks[i_blocks].DetailedInfo); } } } return(result); }) ); availableCommands["details"].help.AppendLine("details tag [tag [...]] [--line=N [...]] [-t] [-b]"); availableCommands["details"].help.AppendLine(availableCommands["details"].info); availableCommands["details"].help.AppendLine("tag: filter block by a tag in it's name"); availableCommands["details"].help.AppendLine("--line=N: show only detailed info from line N"); availableCommands["details"].help.AppendLine("-t: find only blocks of same grid"); availableCommands["details"].help.AppendLine("-b: add the Blockname on top of the info"); //end details command env.Debug.leaveScope(); }
double getSolarpanelPowerWatt(IMySolarPanel SolarPanel) { DetailedInfo DI = new DetailedInfo(SolarPanel); return(parsePower(DI.getValue(1).getValue())); }