Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function round_prct(number) {
- return Math.round((number + Number.EPSILON) * 10000) / 100;
- }
- function round_2d(number) {
- return Math.round((number + Number.EPSILON) * 100) / 100;
- }
- function get_number(cells, position) {
- return cells.eq(position).text().replaceAll(",","");
- }
- function build_cell(data_n, display_n, processing_func) {
- var red_color = ((data_n <= 0 || isNaN(data_n)) ? 0 : processing_func(data_n));
- var bg_color, black_text;
- if (data_n < 0 || isNaN(data_n)) {
- bg_color = "white";
- black_text = true;
- } else {
- bg_color = "rgb(" + red_color + ", " + (255 - red_color) + ", 0)";
- black_text = red_color > 210 || red_color < 80;
- }
- var text_color = black_text ? "black" : "white";
- return '<td style="font-weight: bold; text-align:right; background-color:' + bg_color + '; color: ' + text_color + '">' + display_n + '</td>';
- }
- function log(number) {
- return Math.min((Math.log10(number) + 2) * 255);
- }
- function arctan(number) {
- return 510 * Math.atan(number) / Math.PI;
- }
- function active_fun(number) {
- if (number > 20000)
- return 255;
- if (number > 10000)
- return 200;
- if (number > 5000)
- return 150;
- if (number > 1000)
- return 120;
- if (number > 100)
- return 50;
- return 0;
- }
- function new_fun(number) {
- if (number > 500)
- return 255;
- if (number > 200)
- return 200;
- if (number > 100)
- return 150;
- if (number > 50)
- return 120;
- if (number > 10)
- return 50;
- return 0;
- }
- var countries_rows = $("#main_table_countries_yesterday tr");
- var size = countries_rows.length;
- countries_rows.each(function(i, e) {
- if (i == 0) {
- $(this).append('<th class="sorting">Deaths/ cases</th>');
- //$(this).append('<th class="sorting">Deaths/ 1M pop </th>');
- $(this).append('<th class="sorting">Active/ 1M pop </th>');
- $(this).append('<th class="sorting">New/ 1M pop </th>');
- } else if (i == size - 1) {
- $(this).append('<td></td>');
- } else {
- var cells = $(this).children("td");
- var cases_total = get_number(cells, 2);
- var deaths = get_number(cells, 4);
- var cases_per_cap = get_number(cells, 9);
- var population = get_number(cells, 13);
- var active = get_number(cells, 7);
- var new_cases = get_number(cells, 3);
- var new_deaths = get_number(cells, 5);
- var deaths_to_cases = deaths / cases_total;
- var deaths_to_pop = (deaths * cases_per_cap) / cases_total;
- var active_to_pop = active * (10 ** 6) / population;
- var new_to_pop = new_cases * (10 ** 6) / population;
- var new_deaths_to_pop = new_deaths * (10 ** 6) / population;
- var rounded_dtc = round_prct(deaths_to_cases);
- var rounded_dtp = round_2d(deaths_to_pop);
- var rounded_atp = round_2d(active_to_pop);
- var rounded_ntp = round_2d(new_to_pop);
- var rounded_ndtp = round_2d(new_deaths_to_pop);
- if (deaths != "") {
- $(this).append(build_cell(deaths_to_cases, rounded_dtc + '%', log));
- } else {
- $(this).append(build_cell(-1, "N/A"));
- }
- //$(this).append(build_cell(deaths_to_pop, rounded_dtp, arctan));
- if (!isNaN(active) && active != "" && population > 0) {
- $(this).append(build_cell(active_to_pop, rounded_atp, active_fun));
- } else {
- $(this).append(build_cell(-1, "N/A"));
- }
- if (!isNaN(new_cases) && new_cases != "" && population > 0) {
- $(this).append(build_cell(new_to_pop, rounded_ntp, new_fun));
- } else {
- $(this).append(build_cell(-1, "N/A"));
- }
- if (!isNaN(new_deaths) && new_deaths != "" && population > 0) {
- $(this).append(build_cell(new_deaths_to_pop, rounded_ndtp, new_fun));
- } else {
- $(this).append(build_cell(-1, "N/A"));
- }
- }
- });
Add Comment
Please, Sign In to add comment