reap - $b->reap; } function merger_cmp($a, $b) { return $a->predicted_appearance - $b->predicted_appearance; } function sort_rooms($room_struct) { $ntier = count($room_struct); for($curtier = 0; $curtier < $ntier; $curtier++) { usort($room_struct[$curtier], "room_cmp"); } return $room_struct; } function sort_mergers($room_list) { usort($room_list, "merger_cmp"); return $room_list; } function time_to_event($is_ready, $reap_time) { $retval = "-"; if($is_ready) { $retval = "Ready"; } else { $hours = ($reap_time - ($reap_time % 3600)) / 3600; $hours = "" . $hours; if(strlen($hours) == 1) $hours = "0" . $hours; $retval = $hours . ":" . date("i", $reap_time) . ":" . date("s", $reap_time); } return $retval; } function build_table($room_struct, $table_title, $use_white) { $table_struct = build_table_rows($room_struct); echo "\n"; echo ""; $tiercounter = 0; for($i = 0; $i < 5; $i++) { echo ""; for($j = 0; $j < 4; $j++) { $tier = 20 - ($tiercounter + $j); echo ""; } echo "\n"; for($tablerow = 0; $tablerow < $table_struct[$i]->maxrooms; $tablerow++) { echo ""; for($j = 0; $j < 4; $j++) { $tier = 20 - ($tiercounter + $j); if(count($room_struct[$tier]) > $tablerow) { $bgcolor = $use_white ? "FFFFFF" : ($room_struct[$tier][$tablerow]->merge_predicted ? "FCFC3A" : "00F210"); echo ""; echo ""; echo ""; } else { echo ""; } } echo "\n"; } $tiercounter+=4; } echo "
" . $table_title . "
"; echo $tier; echo "
"; echo $room_struct[$tier][$tablerow]->name; echo ""; echo time_to_event( $room_struct[$tier][$tablerow]->ready , $room_struct[$tier][$tablerow]->reap); echo ""; if($room_struct[$tier][$tablerow]->predicted_to_merge) { echo time_to_event( $room_struct[$tier][$tablerow]->predicted_merge_time <= 0 , $room_struct[$tier][$tablerow]-> predicted_merge_time); } else { echo "-"; } echo "
\n"; } $monstrouspacejsonurl = "https://monstrouspeace.com/robintracker/json.php"; //$monstrouspacejsonurl = "http://localhost/~justin/robintable/json.data"; $monstrouspacejson = file_get_contents($monstrouspacejsonurl); $monstrousdata = json_decode($monstrouspacejson); $curtime = time();// - 3600; //guid //room //tier //children //child_names //count //grow //stay //abandon //novote //formation //reap //time //beacons function allocate_tiers() { $out_tiers = array(); for($i = 0; $i < 20; $i++) { $out_tiers[$i] = new Tier(); } return $out_tiers; } function allocate_rooms() { $out_rooms = array(); for($i = 0; $i < 20; $i++) { $out_rooms[$i] = array(); } return $out_rooms; } function allocate_table_rows() { $out_tablerows = array(); for($i = 0; $i < 5; $i++) { $out_tablerows[$i]->maxrooms = 0; } return $out_tablerows; } function build_rooms_from_json($in_monstrousdata, $curtime) { $out_rooms = allocate_rooms(); $datarows = count($in_monstrousdata); for($i = 0; $i < $datarows; $i++) { $room = new Room(); $room->name = $in_monstrousdata[$i]->{'room'}; $room->tier = $in_monstrousdata[$i]->{'tier'}; $room->reap = $in_monstrousdata[$i]->{'reap'} - $curtime; $room->count = $in_monstrousdata[$i]->{'count'}; $room->ready = $room->reap <= 0; if($room->ready) $room->reap = 0; if(is_numeric($room->tier)) { $nrooms = count($out_rooms[$room->tier]); $out_rooms[$room->tier][$nrooms] = $room; } } return sort_rooms($out_rooms); } function build_table_rows($in_rooms) { $tier_count = count($in_rooms); $out_tablerows = allocate_table_rows(); for($cur_tier = 0; $cur_tier < $tier_count; $cur_tier++) { $cur_tablerow = 4 - (($cur_tier - 1) - (($cur_tier - 1) % 4)) / 4; $cur_tier_rooms = count($in_rooms[$cur_tier]); if($out_tablerows[$cur_tablerow]->maxrooms < $cur_tier_rooms) { $out_tablerows[$cur_tablerow]->maxrooms = $cur_tier_rooms; } } return $out_tablerows; } function compute_metadata($in_rooms) { $out_metadata = new OverallMetadata(); $out_metadata->tiers = allocate_tiers(); $tier_count = count($in_rooms); $out_metadata->total_rooms = 0; $out_metadata->total_people = 0; for($cur_tier = 0; $cur_tier < $tier_count; $cur_tier++) { $out_metadata->tiers[$cur_tier]->rooms = count($in_rooms[$cur_tier]); $out_metadata->tiers[$cur_tier]->people_below = $out_metadata->total_people; for($curroom = 0; $curroom < $out_metadata->tiers[$cur_tier]->rooms ; $curroom++) { $out_metadata->total_rooms++; $out_metadata->tiers[$cur_tier]->people = $in_rooms[$cur_tier][$curroom]->count; $out_metadata->total_people += $out_metadata->tiers[$cur_tier]->people; } } for($cur_tier = 0; $cur_tier < $tier_count; $cur_tier++) { $out_metadata->tiers[$cur_tier]->people_above = $out_metadata->total_people - ($out_metadata->tiers[$cur_tier]->people + $out_metadata->tiers[$cur_tier]->people_below); } return $out_metadata; } function tier_info_table($in_tier_data) { //#CACECF Grey $tier_count = count($in_tier_data); echo "\n"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; for($cur_tier = 0; $cur_tier < 18; $cur_tier++) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
"; echo "Tier Info"; echo "
"; echo "Tier"; echo ""; echo "Rooms"; echo ""; echo "People in Tier"; echo ""; echo "People Above Tier"; echo ""; echo "People Below Tier"; echo "
"; echo $cur_tier; echo ""; echo $in_tier_data[$cur_tier]->rooms; echo ""; echo $in_tier_data[$cur_tier]->people; echo ""; echo $in_tier_data[$cur_tier]->people_above; echo ""; echo $in_tier_data[$cur_tier]->people_below; echo "
"; } class MergerData { public $predicted_mergers = array(); public $rooms_after_merge = array(); public $new_room_count = 0; public $room_struct_after_merge = 0; } function assign_names(&$in_rooms, $start_counting_at) { $ct = count($in_rooms); $name_ct = $start_counting_at; for($i = 0; $i < $ct; $i++) { if(!$in_rooms[$i]->has_been_named) { $in_rooms[$i]->name = "new_" . $name_ct; $in_rooms[$i]->has_been_named = true; $name_ct++; //echo "NAME: " . $in_rooms[$i]->name . "
"; //echo "MERGE: " . $in_rooms[$i]->predicted_appearance . "
"; //echo "REAP: " . $in_rooms[$i]->reap . "
"; } } } function tier_time_to_merge($in_tier) { $out_time = pow(2, $in_tier) - 1; if($out_time > 31) $out_time = 31; return $out_time; } function predict_mergers(&$in_rooms, $start_counting_at) { $out_data = new MergerData(); $out_data->predicted_mergers = array(); $out_data->new_room_count = 0; $ntier = count($in_rooms); for($curtier = 0; $curtier < $ntier; $curtier++) { $nrooms = count($in_rooms[$curtier]); for($curroom = 0; ($curroom + 1) < $nrooms; $curroom+=2) { $room_a = $in_rooms[$curtier][$curroom]; $room_b = $in_rooms[$curtier][$curroom + 1]; $room_a->predicted_to_merge = true; $room_a->predicted_merge_time = $room_b->reap; $room_b->predicted_to_merge = true; $room_b->predicted_merge_time = $room_b->reap; $room_new = new Room(); $room_new->has_been_named = false; //$room_new->name = "new_" . $out_data->new_room_count; $room_new->merge_predicted = true; $room_new->predicted_appearance = $room_a->predicted_merge_time; $room_new->merge_from_a = $room_a; $room_new->merge_from_b = $room_b; $room_new->tier = $room_a->tier + 1; $room_new->ready =false; $tier_time = tier_time_to_merge($room_new->tier); $room_new->reap = $room_new->predicted_appearance + ($tier_time * 60) ; $out_data->new_room_count++; array_push($out_data->predicted_mergers, $room_new); array_push($out_data->rooms_after_merge, $room_new); } if($curroom < $nrooms) { array_push($out_data->rooms_after_merge , $room_a = $in_rooms[$curtier][$curroom]); } } $out_data->predicted_mergers = sort_mergers($out_data->predicted_mergers); $out_data->rooms_after_merge = sort_mergers($out_data->rooms_after_merge); assign_names($out_data->predicted_mergers, $start_counting_at); assign_names($out_data->rooms_after_merge, $start_counting_at); return $out_data; } function room_list_to_room_struct($in_room_list) { $out_rooms = allocate_rooms(); $room_count = count($in_room_list); for($cur_room = 0; $cur_room < $room_count; $cur_room++) { $cur_room_struct = $in_room_list[$cur_room]; array_push($out_rooms[$cur_room_struct->tier], $cur_room_struct); } return $out_rooms; } function predicted_mergers_table($in_merge_list) { //#CACECF Grey $merger_count = count($in_merge_list); echo "\n"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; for($cur_merger = 0; $cur_merger < $merger_count; $cur_merger++) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
"; echo "Predicted Mergers"; echo "
"; echo "Name Placeholder"; echo ""; echo "New Tier"; echo ""; echo "Room A"; echo ""; echo "Room B"; echo ""; echo "Time To Merge"; echo ""; echo "Time To Reap"; echo "
"; echo $in_merge_list[$cur_merger]->name; echo ""; echo $in_merge_list[$cur_merger]->tier; echo ""; echo $in_merge_list[$cur_merger]->merge_from_a->name; echo ""; echo $in_merge_list[$cur_merger]->merge_from_b->name; echo ""; echo time_to_event($in_merge_list[$cur_merger]->predicted_appearance <=0 , $in_merge_list[$cur_merger]->predicted_appearance); echo ""; echo time_to_event($in_merge_list[$cur_merger]->reap <=0 , $in_merge_list[$cur_merger]->reap); echo "
"; } $current_rooms=build_rooms_from_json($monstrousdata, $curtime); $post_merger_1 = predict_mergers($current_rooms, 0); //$current_tiers = count_tier_info($current_rooms); $current_metadata = compute_metadata($current_rooms); $post_merger_1->room_struct_after_merge = room_list_to_room_struct($post_merger_1->rooms_after_merge); $new_room_list = $post_merger_1->predicted_mergers; $final_merge = $post_merger_1; while($final_merge->new_room_count >0) { $final_merge = predict_mergers($final_merge->room_struct_after_merge , count($new_room_list)); $final_merge->room_struct_after_merge = room_list_to_room_struct($final_merge->rooms_after_merge); $new_room_list = array_merge($new_room_list, $final_merge->predicted_mergers); } ?>

room_struct_after_merge , "State After 1 Round of Merging", false); ?> room_struct_after_merge , "Final System State", false); ?> tiers) ?>

total_rooms . "
" . "Total People Found: " . $current_metadata->total_people; ?>