Skip to content

Commit

Permalink
Fix the "enabled by default" nature of the benchmark feature - #77
Browse files Browse the repository at this point in the history
  • Loading branch information
tsumaru720 committed Feb 22, 2023
1 parent 4c204e1 commit 0c7b11b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Main {
public static $outputMethod = 'html';

// The current expected database schema version.
public static $expectedSchema = 4;
public static $expectedSchema = 5;

// variable initialization
private $config = null;
Expand Down
8 changes: 8 additions & 0 deletions schema/5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

$q = $db->query(<<<'EOT'
ALTER TABLE `settings` CHANGE `value` `value` VARCHAR(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL;
UPDATE `settings` SET `value` = '5' WHERE `settings`.`setting` = 'db_version';
EOT
);
10 changes: 10 additions & 0 deletions themes/default/app/item_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public function __construct(&$main, &$twig, $vars) {
}
}

$q = $this->db->query("SELECT value from settings WHERE setting = 'benchmark_url' LIMIT 1");
if ($r = $this->db->fetch($q)) {
if (array_key_exists('value', $r)) {
if (filter_var($r['value'], FILTER_VALIDATE_URL)) {
$vars['enable_benchmark'] = true;
$vars['benchmark_url'] = $r['value'];
}
}
}

$vars['hide_total_pct'] = true;

$vars['payments'] = [];
Expand Down
32 changes: 20 additions & 12 deletions themes/default/html/item_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ <h4><small>Adjusted TWR<br>{{ mostRecent.twr_str_adj }}%</small></h4>
{% endfor %}
];

{% if enable_benchmark == true %}
//////////////////////////////////////////////////////////////////////////////////////////

var data5 = new Array();
Expand All @@ -266,7 +267,8 @@ <h4><small>Adjusted TWR<br>{{ mostRecent.twr_str_adj }}%</small></h4>
];

bench = new Array();
var dataURL = "https://cache1.agari.co/4d0eabfdf45f0ba15f6a10797dcef522/global.php";
var dataURL = "{{ benchmark_url }}";
//var dataURL = "https://cache1.agari.co/4d0eabfdf45f0ba15f6a10797dcef522/global.php";
//var dataURL = "https://cache1.agari.co/4d0eabfdf45f0ba15f6a10797dcef522/us.php";
//var dataURL = "https://cache1.agari.co/4d0eabfdf45f0ba15f6a10797dcef522/nasdaq.php";
fetch(dataURL).then(response => response.json()).then(function(data) {
Expand Down Expand Up @@ -304,7 +306,20 @@ <h4><small>Adjusted TWR<br>{{ mostRecent.twr_str_adj }}%</small></h4>
growth_chart.update();
});

benchmark_hash = {
label: 'Benchmark',
borderColor: 'rgb(180, 180, 180)',
backgroundColor: 'rgb(180, 180, 180)',
fill: false,
lineTension: 0.3,
data: data5,
hidden: false,
borderWidth: 1.5,
pointRadius: 1
};

//////////////////////////////////////////////////////////////////////////////////////////
{% endif %}

var ctx = document.getElementById('growth_chart');
var growth_chart = new Chart(ctx, {
Expand Down Expand Up @@ -355,17 +370,10 @@ <h4><small>Adjusted TWR<br>{{ mostRecent.twr_str_adj }}%</small></h4>
data: data2,
hidden: {% if std_dev <= 5 %}false{% else %}true{% endif %},
borderWidth: 1
}, {
label: 'Benchmark',
borderColor: 'rgb(180, 180, 180)',
backgroundColor: 'rgb(180, 180, 180)',
fill: false,
lineTension: 0.3,
data: data5,
hidden: false,
borderWidth: 1.5,
pointRadius: 1
}]
},
{% if enable_benchmark == true %}
benchmark_hash
{% endif %}]
},
options: {
animation: false,
Expand Down

0 comments on commit 0c7b11b

Please sign in to comment.