Skip to content

Commit

Permalink
Added more problems and tool for size Estimations.
Browse files Browse the repository at this point in the history
  • Loading branch information
neerazz committed Sep 25, 2021
1 parent 401e67f commit b24fff0
Show file tree
Hide file tree
Showing 4 changed files with 416 additions and 2 deletions.
196 changes: 196 additions & 0 deletions Algorithms/Neeraj/Tools/back_of_the_envolop_calculation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<!doctype html>
<html lang="en">

<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">

<!-- Bootstrap CSS -->
<link crossorigin="anonymous" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" rel="stylesheet">

<title>Size Estimates</title>
</head>

<body>

<nav class="navbar navbar-light" style="background-color: #e3f2fd;">
<a class="navbar-brand" href="#">Size Estimates</a>
</nav>

<div class="card-group">
<div class="card text-dark bg-light mb-3">
<ul class="list-group list-group-flush">
<li class="list-group-item">
<div class="input-group mb-3">
<span class="input-group-text">Calls per day:</span>
<input aria-describedby="basic-addon3" class="form-control" id="calls-per-day"
placeholder="Ex: 1m, 1b, 50k"
type="text">
</div>
</li>
<li class="list-group-item">
<div class="input-group mb-3">
<span class="input-group-text">Size Per Object:</span>
<input aria-describedby="basic-addon3" class="form-control" id="size-per-object"
placeholder="In KB. Ex: 10 for 10kb. 1000"
type="text">
</div>
</li>
<li class="list-group-item">
<div class="input-group mb-3">
<span class="input-group-text">Latency:</span>
<input aria-describedby="basic-addon3" class="form-control" id="latency"
placeholder="In milli seconds."
type="text">
</div>
</li>
</ul>
</div>
<div class="card text-dark bg-light mb-3">
<img class="img-fluid rounded mx-auto d-block"
src="https://www.dnsstuff.com/wp-content/uploads/2020/12/image-11.png">
</div>
<div class="card text-white bg-success mb-3">
<div class="card-body">
<p class="fst-italic">Request per Second:
<input class="fst-italic" disabled id="rps" type="text"></input>
</p>
<p class="fst-italic">Bandwidth:
<input class="fst-italic" disabled id="bandwidth" type="text"> Mbps</input>
</p>
<p class="fst-italic">Storage per day:
<input class="fst-italic" disabled id="per-day" type="text"></input>
</p>
<p class="fst-italic">Storage per year:
<input class="fst-italic" disabled id="per-year" type="text"></input>
</p>
<p class="fst-italic">Storage for 5 years:
<input class="fst-italic" disabled id="per-5-year" type="text"></input>
</p>
</div>
</div>
</div>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script crossorigin="anonymous" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>

<script crossorigin="anonymous"
integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ"
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>

<script>

$("#calls-per-day").on('input', function (e) {
var calls_per_day = get_calls_perDay();
console.log("calls_per_day is : " + calls_per_day);
var rps = get_rps(calls_per_day);
set_rps(rps);
});

$("#size-per-object").on('input', function (e) {
var size = get_size_per_object();
console.log("Size Per entity is : " + size);
var calls_per_day = get_calls_perDay();
var rps = get_rps(calls_per_day)
var bandwidth = get_bandwidth(rps, size);
set_bandwidth(bandwidth);
set_rps(rps);
set_storage_per_day(get_storage_in_years(calls_per_day, size, 1 / 365));
set_storage_per_year(get_storage_in_years(calls_per_day, size, 1));
set_storage_for_5_year(get_storage_in_years(calls_per_day, size, 5));
});

function get_calls_perDay() {
var str = $('#calls-per-day').val();
var val = unhumanize_number(str);
console.log("Converted " + str + " to " + val + ".");
return val;
}

function get_size_per_object(){
var str = $('#size-per-object').val();
var val = unhumanize_memory(str);
console.log("Converted " + str + " to " + val + ".");
return val;
}

function get_storage_in_years(calls_per_day, size, years) {
var total = calls_per_day * size * 365 * years;
console.log("Memory for " + years + " years is : " + total);
return total;
}

function get_bandwidth(rps, size) {
var bandwidth = rps * size * 8 * (1 / 1000000);
console.log("Calculated Bandwidth: " + bandwidth);
return bandwidth;
};

function get_rps(calls_per_day) {
var rps = (calls_per_day) / (24 * 60 * 60)
console.log("Calculated RPS " + rps);
return rps;
};

function set_rps(rps) {
console.log("Setting up RPS: " + rps);
$("#rps").val(rps);
};

function set_bandwidth(bandwidth) {
console.log("Setting up Bandwidth: " + bandwidth);
$("#bandwidth").val(bandwidth);
};

function set_storage_per_day(size) {
var readable = bytesToSize(size);
console.log("Setting 1 Years Storage to " + readable);
$("#per-day").val(readable);
};
function set_storage_per_year(size) {
var readable = bytesToSize(size);
console.log("Setting 1 Years Storage to " + readable);
$("#per-year").val(readable);
};

function set_storage_for_5_year(size) {
var readable = bytesToSize(size);
console.log("Setting 5 Years Storage to " + readable);
$("#per-5-year").val(readable);
};

function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PetByte', 'Exabyte'];
if (bytes == 0) return '0 Byte';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
}

function unhumanize_number(val) {
multiplier = val.substr(-1).toLowerCase();
if (multiplier == "k" || multiplier == "K")
return parseFloat(val) * 1000;
else if (multiplier == "m" || multiplier == "M")
return parseFloat(val) * 1000000;
else if (multiplier == "b" || multiplier == "B")
return parseFloat(val) * 1000000;
}

function unhumanize_memory(text) {
var powers = { 'k': 1, 'm': 2, 'g': 3, 't': 4 };
var regex = /(\d+(?:\.\d+)?)\s?(k|m|g|t)?b?/i;
var res = regex.exec(text);
return res[1] * Math.pow(1024, powers[res[2].toLowerCase()]);
}



</script>

</body>

</html>
160 changes: 158 additions & 2 deletions Algorithms/Neeraj/Tools/javascript_tools.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<body>

<nav class="navbar navbar-light" style="background-color: #e3f2fd;">
<a class="navbar-brand" href="#">weekly.MyTool:</a>
<a class="navbar-brand" href="#">Tools:</a>
</nav>

<div class="card-group">
Expand Down Expand Up @@ -47,6 +47,61 @@ <h5 class="card-title">Array Input:</h5>
</div>
</div>

<div class="card-group">
<div class="card text-dark bg-light mb-3">
<ul class="list-group list-group-flush">
<li class="list-group-item">
<div class="input-group mb-3">
<span class="input-group-text">Calls per day:</span>
<input aria-describedby="basic-addon3" class="form-control" id="calls-per-day"
placeholder="Ex: 1m, 1b, 50k"
type="text">
</div>
</li>
<li class="list-group-item">
<div class="input-group mb-3">
<span class="input-group-text">Size Per Object:</span>
<input aria-describedby="basic-addon3" class="form-control" id="size-per-object"
placeholder="In KB. Ex: 10 for 10kb. 1000"
type="text">
</div>
</li>
<li class="list-group-item">
<div class="input-group mb-3">
<span class="input-group-text">Latency:</span>
<input aria-describedby="basic-addon3" class="form-control" id="latency"
placeholder="In milli seconds."
type="text">
</div>
</li>
</ul>
</div>
<div class="card text-dark bg-light mb-3">
<img class="img-fluid rounded mx-auto d-block"
src="https://www.dnsstuff.com/wp-content/uploads/2020/12/image-11.png">
</div>
<div class="card text-white bg-success mb-3">
<div class="card-body">
<p class="fst-italic">Request per Second:
<input class="fst-italic" disabled id="rps" type="text"></input>
</p>
<p class="fst-italic">Bandwidth:
<input class="fst-italic" disabled id="bandwidth" type="text"> Mbps</input>
</p>
<p class="fst-italic">Storage per day:
<input class="fst-italic" disabled id="per-day" type="text"></input>
</p>
<p class="fst-italic">Storage per year:
<input class="fst-italic" disabled id="per-year" type="text"></input>
</p>
<p class="fst-italic">Storage for 5 years:
<input class="fst-italic" disabled id="per-5-year" type="text"></input>
</p>
</div>
</div>
</div>


<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script crossorigin="anonymous"
Expand Down Expand Up @@ -93,7 +148,108 @@ <h5 class="card-title">Array Input:</h5>




$("#calls-per-day").on('input', function (e) {
var calls_per_day = get_calls_perDay();
console.log("calls_per_day is : " + calls_per_day);
var rps = get_rps(calls_per_day);
set_rps(rps);
});

$("#size-per-object").on('input', function (e) {
var size = get_size_per_object();
console.log("Size Per entity is : " + size);
var calls_per_day = get_calls_perDay();
var rps = get_rps(calls_per_day)
var bandwidth = get_bandwidth(rps, size);
set_bandwidth(bandwidth);
set_rps(rps);
set_storage_per_day(get_storage_in_years(calls_per_day, size, 1 / 365));
set_storage_per_year(get_storage_in_years(calls_per_day, size, 1));
set_storage_for_5_year(get_storage_in_years(calls_per_day, size, 5));
});

function get_calls_perDay() {
var str = $('#calls-per-day').val();
var val = unhumanize_number(str);
console.log("Converted " + str + " to " + val + ".");
return val;
}

function get_size_per_object(){
var str = $('#size-per-object').val();
var val = unhumanize_memory(str);
console.log("Converted " + str + " to " + val + ".");
return val;
}

function get_storage_in_years(calls_per_day, size, years) {
var total = calls_per_day * size * 365 * years;
console.log("Memory for " + years + " years is : " + total);
return total;
}

function get_bandwidth(rps, size) {
var bandwidth = rps * size * 8 * (1 / 1000000);
console.log("Calculated Bandwidth: " + bandwidth);
return bandwidth;
};

function get_rps(calls_per_day) {
var rps = (calls_per_day) / (24 * 60 * 60)
console.log("Calculated RPS " + rps);
return rps;
};

function set_rps(rps) {
console.log("Setting up RPS: " + rps);
$("#rps").val(rps);
};

function set_bandwidth(bandwidth) {
console.log("Setting up Bandwidth: " + bandwidth);
$("#bandwidth").val(bandwidth);
};

function set_storage_per_day(size) {
var readable = bytesToSize(size);
console.log("Setting 1 Years Storage to " + readable);
$("#per-day").val(readable);
};
function set_storage_per_year(size) {
var readable = bytesToSize(size);
console.log("Setting 1 Years Storage to " + readable);
$("#per-year").val(readable);
};

function set_storage_for_5_year(size) {
var readable = bytesToSize(size);
console.log("Setting 5 Years Storage to " + readable);
$("#per-5-year").val(readable);
};

function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PetByte', 'Exabyte'];
if (bytes == 0) return '0 Byte';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
}

function unhumanize_number(val) {
multiplier = val.substr(-1).toLowerCase();
if (multiplier == "k" || multiplier == "K")
return parseFloat(val) * 1000;
else if (multiplier == "m" || multiplier == "M")
return parseFloat(val) * 1000000;
else if (multiplier == "b" || multiplier == "B")
return parseFloat(val) * 1000000;
}

function unhumanize_memory(text) {
var powers = { 'k': 1, 'm': 2, 'g': 3, 't': 4 };
var regex = /(\d+(?:\.\d+)?)\s?(k|m|g|t)?b?/i;
var res = regex.exec(text);
return res[1] * Math.pow(1024, powers[res[2].toLowerCase()]);
}



Expand Down
Loading

0 comments on commit b24fff0

Please sign in to comment.