blackopsrepl/portfolio-optimization-python
1
1function replaceSolverForgeAutoHeaderFooter() {2 const solverforgeHeader = $("header#solverforge-auto-header");3 if (solverforgeHeader != null) {4 solverforgeHeader.addClass("bg-black")5 solverforgeHeader.append(6 $(`<div class="container-fluid">7 <nav class="navbar sticky-top navbar-expand-lg navbar-dark shadow mb-3">8 <a class="navbar-brand" href="https://www.solverforge.org">9 <img src="/solverforge/img/solverforge-horizontal-white.svg" alt="SolverForge logo" width="200">10 </a>11 </nav>12 </div>`));13 }14 const solverforgeFooter = $("footer#solverforge-auto-footer");15 if (solverforgeFooter != null) {16 solverforgeFooter.append(17 $(`<footer class="bg-black text-white-50">18 <div class="container">19 <div class="hstack gap-3 p-4">20 <div class="ms-auto"><a class="text-white" href="https://www.solverforge.org">SolverForge</a></div>21 <div class="vr"></div>22 <div><a class="text-white" href="https://www.solverforge.org/docs">Documentation</a></div>23 <div class="vr"></div>24 <div><a class="text-white" href="https://github.com/SolverForge/solverforge-legacy">Code</a></div>25 <div class="vr"></div>26 <div class="me-auto"><a class="text-white" href="mailto:info@solverforge.org">Support</a></div>27 </div>28 </div>29 <div id="applicationInfo" class="container text-center"></div>30 </footer>`));31 32 applicationInfo();33 }34 35}36 37function showSimpleError(title) {38 const notification = $(`<div class="toast" role="alert" aria-live="assertive" aria-atomic="true" style="min-width: 50rem"/>`)39 .append($(`<div class="toast-header bg-danger">40 <strong class="me-auto text-dark">Error</strong>41 <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>42 </div>`))43 .append($(`<div class="toast-body"/>`)44 .append($(`<p/>`).text(title))45 );46 $("#notificationPanel").append(notification);47 notification.toast({delay: 30000});48 notification.toast('show');49}50 51function showError(title, xhr) {52 var serverErrorMessage = !xhr.responseJSON ? `${xhr.status}: ${xhr.statusText}` : xhr.responseJSON.message;53 var serverErrorCode = !xhr.responseJSON ? `unknown` : xhr.responseJSON.code;54 var serverErrorId = !xhr.responseJSON ? `----` : xhr.responseJSON.id;55 var serverErrorDetails = !xhr.responseJSON ? `no details provided` : xhr.responseJSON.details;56 57 if (xhr.responseJSON && !serverErrorMessage) {58 serverErrorMessage = JSON.stringify(xhr.responseJSON);59 serverErrorCode = xhr.statusText + '(' + xhr.status + ')';60 serverErrorId = `----`;61 }62 63 console.error(title + "\n" + serverErrorMessage + " : " + serverErrorDetails);64 const notification = $(`<div class="toast" role="alert" aria-live="assertive" aria-atomic="true" style="min-width: 50rem"/>`)65 .append($(`<div class="toast-header bg-danger">66 <strong class="me-auto text-dark">Error</strong>67 <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>68 </div>`))69 .append($(`<div class="toast-body"/>`)70 .append($(`<p/>`).text(title))71 .append($(`<pre/>`)72 .append($(`<code/>`).text(serverErrorMessage + "\n\nCode: " + serverErrorCode + "\nError id: " + serverErrorId))73 )74 );75 $("#notificationPanel").append(notification);76 notification.toast({delay: 30000});77 notification.toast('show');78}79 80// ****************************************************************************81// Application info82// ****************************************************************************83 84function applicationInfo() {85 $.getJSON("info", function (info) {86 $("#applicationInfo").append("<small>" + info.application + " (version: " + info.version + ", built at: " + info.built + ")</small>");87 }).fail(function (xhr, ajaxOptions, thrownError) {88 console.warn("Unable to collect application information");89 });90}91 92// ****************************************************************************93// TangoColorFactory94// ****************************************************************************95 96const SEQUENCE_1 = [0x8AE234, 0xFCE94F, 0x729FCF, 0xE9B96E, 0xAD7FA8];97const SEQUENCE_2 = [0x73D216, 0xEDD400, 0x3465A4, 0xC17D11, 0x75507B];98 99var colorMap = new Map;100var nextColorCount = 0;101 102function pickColor(object) {103 let color = colorMap[object];104 if (color !== undefined) {105 return color;106 }107 color = nextColor();108 colorMap[object] = color;109 return color;110}111 112function nextColor() {113 let color;114 let colorIndex = nextColorCount % SEQUENCE_1.length;115 let shadeIndex = Math.floor(nextColorCount / SEQUENCE_1.length);116 if (shadeIndex === 0) {117 color = SEQUENCE_1[colorIndex];118 } else if (shadeIndex === 1) {119 color = SEQUENCE_2[colorIndex];120 } else {121 shadeIndex -= 3;122 let floorColor = SEQUENCE_2[colorIndex];123 let ceilColor = SEQUENCE_1[colorIndex];124 let base = Math.floor((shadeIndex / 2) + 1);125 let divisor = 2;126 while (base >= divisor) {127 divisor *= 2;128 }129 base = (base * 2) - divisor + 1;130 let shadePercentage = base / divisor;131 color = buildPercentageColor(floorColor, ceilColor, shadePercentage);132 }133 nextColorCount++;134 return "#" + color.toString(16);135}136 137function buildPercentageColor(floorColor, ceilColor, shadePercentage) {138 let red = (floorColor & 0xFF0000) + Math.floor(shadePercentage * ((ceilColor & 0xFF0000) - (floorColor & 0xFF0000))) & 0xFF0000;139 let green = (floorColor & 0x00FF00) + Math.floor(shadePercentage * ((ceilColor & 0x00FF00) - (floorColor & 0x00FF00))) & 0x00FF00;140 let blue = (floorColor & 0x0000FF) + Math.floor(shadePercentage * ((ceilColor & 0x0000FF) - (floorColor & 0x0000FF))) & 0x0000FF;141 return red | green | blue;142}143 