Skip to content

Commit

Permalink
Fixed errors when there are multiple of the same CPU/memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaGupta1 committed Apr 5, 2016
1 parent 0f83684 commit f424e5e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ plugins {

apply plugin: 'net.minecraftforge.gradle.forge'

version = "1.0"
version = "1.0-beta"
group= "org.redfrog404.mobycraft" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "mobycraft"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,39 +148,38 @@ public static void heatMap() {
sendFeedbackMessage("Loading...");

refreshRunning();
Map<Double, BoxContainer> finalUsagesMap = new HashMap<Double, BoxContainer>();

Map<Double, BoxContainer> usagesMap = new HashMap<Double, BoxContainer>();
List<Double> sortedUsages = new ArrayList<Double>();
Map<Double, Integer> andOthers = new HashMap<Double, Integer>();
for (BoxContainer container : boxContainers) {
double usage = 0D;
if (arg1.equalsIgnoreCase("cpu")) {
usagesMap.put(container.getCpuUsage(), container);
usage = container.getCpuUsage();
} else {
usagesMap.put(container.getMemoryUsage(), container);
usage = container.getMemoryUsage();
}
}

List<Double> sortedUsages = new ArrayList<Double>();

for (BoxContainer container : boxContainers) {
if (arg1.equalsIgnoreCase("cpu")) {
sortedUsages.add(container.getCpuUsage());
if (usagesMap.containsKey(usage)) {
if (andOthers.containsKey(usage)) {
andOthers.put(usage, andOthers.get(usage) + 1);
} else {
andOthers.put(usage, 1);
}
} else {
sortedUsages.add(container.getMemoryUsage());
usagesMap.put(usage, container);
}
}

sortedUsages.addAll(usagesMap.keySet());
sortedUsages = Lists.reverse(asSortedList(sortedUsages));

int maxNumber = 0;

if (boxContainers.size() >= 5) {
if (usagesMap.size() >= 5) {
maxNumber = 5;
} else {
maxNumber = boxContainers.size();
}
for (int i = 0; i < maxNumber; i++) {
finalUsagesMap.put(sortedUsages.get(i),
usagesMap.get(sortedUsages.get(i)));
maxNumber = usagesMap.size();
}

if (arg1.equalsIgnoreCase("cpu")) {
Expand All @@ -193,17 +192,31 @@ public static void heatMap() {

int number = 1;
NumberFormat formatter = new DecimalFormat("#0.00");

List<Double> finishedUsages = new ArrayList<Double>();

for (double usage : sortedUsages.subList(0, maxNumber)) {
sendMessage(EnumChatFormatting.GOLD + "" + number + ". "
if (finishedUsages.contains(usage) && andOthers.containsKey(usage)) {
continue;
}
String message = EnumChatFormatting.GOLD + "" + number + ". "
+ EnumChatFormatting.DARK_AQUA
+ finalUsagesMap.get(usage).getName()
+ EnumChatFormatting.GOLD + " - "
+ usagesMap.get(usage).getName();
if (andOthers.containsKey(usage)) {
if (andOthers.get(usage) == 1) {
message = message + " and " + andOthers.get(usage) + " other";
} else {
message = message + " and " + andOthers.get(usage) + " others";
}
}
message = message + EnumChatFormatting.GOLD + " - "
+ EnumChatFormatting.DARK_AQUA
+ finalUsagesMap.get(usage).getImage()
+ EnumChatFormatting.GOLD + " - " + EnumChatFormatting.AQUA
+ formatter.format(usage) + "%");
+ usagesMap.get(usage).getImage() + EnumChatFormatting.GOLD
+ " - " + EnumChatFormatting.AQUA + formatter.format(usage)
+ "%";
sendMessage(message);
number++;
finishedUsages.add(usage);
}
refresh();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ public MainCommand() {
new String[] { "ps [options]",
"Does not show stopped containers by default",
"[options]: \"-a\" to show all containers, including stopped ones" });
specificHelpMessages
.put("heat_map",
new String[] { "heat_map <cpu | memory>",
"Shows in the format of (container name) - (image) - (usage)",
"If there are multiple containers with the same usage, the container name will say \"and (number) others\"",
"If there are multiple containers with the same usage, the image refers to the one whose name is shown in the (container name)" });

byteSuffixNumbers.put(0, "B");
byteSuffixNumbers.put(1, "KB");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@Mod(modid = Mobycraft.MODID, version = Mobycraft.VERSION)
public final class Mobycraft {
public static final String MODID = "moby";
public static final String VERSION = "1.0";
public static final String VERSION = "1.0-beta";

public static Configuration config;

Expand Down

0 comments on commit f424e5e

Please sign in to comment.