Skip to content

Commit

Permalink
Differentiate between cumulative and rolling counters
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Nov 13, 2018
1 parent d10ddb5 commit 38dcc71
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 23 deletions.
2 changes: 1 addition & 1 deletion sync-remote-cfg.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

if($sourceNeedsUpdate) {
echo "Updating source..." . PHP_EOL;
rename($cfgPath, "$cfgPath.old");
copy($cfgPath, $cfgPath . ".old");
file_put_contents($cfgPath, $json->serialized);
}

Expand Down
29 changes: 19 additions & 10 deletions www/logbox/output.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,30 @@
$lowerKey = strtolower($key);
$name = $cfg["{$lowerKey}_name"];

if(empty($name)) {
continue;
}
if(!empty($name)) {
$formula = $cfg["{$lowerKey}_formula"] ?: "x";

$formula = str_replace("x", $value, $formula);
$calcValue = exec("echo \"$formula\" | bc");

$mins = $cfg["{$lowerKey}_mins"] ?: 0;
if($mins > 0) {
$value = getValueOverTime($key, $mins);
echo "$name\t$calcValue" . PHP_EOL;
}

$formula = $cfg["{$lowerKey}_formula"] ?: "x";
$mins_name = $cfg["{$lowerKey}_mins_name"];
if(!empty($mins_name)) {
$value = 0;

$formula = str_replace("x", $value, $formula);
$calcValue = exec("echo \"$formula\" | bc");
$mins = $cfg["{$lowerKey}_mins"] ?: 0;
if($mins > 0) {
$value = getValueOverTime($key, $mins);
}

echo "$name\t$calcValue" . PHP_EOL;
$formula = $cfg["{$lowerKey}_mins_formula"] ?: "x";
$formula = str_replace("x", $value, $formula);
$calcValue = exec("echo \"$formula\" | bc");

echo "$mins_name\t$calcValue" . PHP_EOL;
}
}
echo PHP_EOL . "</pre>";

Expand Down
48 changes: 36 additions & 12 deletions www/logbox/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,44 +51,68 @@
<span>Name</span>
<input name="c1_name" value="<?php echo $data['c1_name'] ?? '';?>" />
</label>
<label>
<span>Minutes</span>
<input type="num" name="c1_mins" value="<?php echo $data['c1_mins'] ?? '';?>" />
</label>
<label>
<span>Formula</span>
<input name="c1_formula" placeholder="e.g. (x + 220) / 2" value="<?php echo $data['c1_formula'] ?? '';?>" />
</label>
<label>
<span>Cumulative name</span>
<input name="c1_mins_name" value="<?php echo $data['c1_mins_name'] ?? '';?>" />
</label>
<label>
<span>Cumulative Minutes</span>
<input type="num" name="c1_mins" value="<?php echo $data['c1_mins'] ?? '';?>" />
</label>
<label>
<span>Cumulative formula</span>
<input name="c1_mins_formula" value="<?php echo $data['c1_mins_formula'] ?? '';?>" />
</label>
</fieldset>
<fieldset>
<h1>C2</h1>
<label class="large">
<span>Name</span>
<input name="c2_name" value="<?php echo $data['c2_name'] ?? '';?>" />
</label>
<label>
<span>Minutes</span>
<input type="num" name="c2_mins" value="<?php echo $data['c2_mins'] ?? '';?>" />
</label>
<label>
<span>Formula</span>
<input name="c2_formula" placeholder="e.g. (x + 220) / 2" value="<?php echo $data['c2_formula'] ?? '';?>" />
</label>
<label>
<span>Cumulative name</span>
<input name="c2_mins_name" value="<?php echo $data['c2_mins_name'] ?? '';?>" />
</label>
<label>
<span>Cumulative Minutes</span>
<input type="num" name="c2_mins" value="<?php echo $data['c2_mins'] ?? '';?>" />
</label>
<label>
<span>Cumulative formula</span>
<input name="c2_mins_formula" value="<?php echo $data['c2_mins_formula'] ?? '';?>" />
</label>
</fieldset>
<fieldset>
<h1>C3</h1>
<label class="large">
<span>Name</span>
<input name="c3_name" value="<?php echo $data['c3_name'] ?? '';?>" />
</label>
<label>
<span>Minutes</span>
<input type="num" name="c3_mins" value="<?php echo $data['c3_mins'] ?? '';?>" />
</label>
<label>
<span>Formula</span>
<input name="c3_formula" placeholder="e.g. (x + 220) / 2" value="<?php echo $data['c3_formula'] ?? '';?>" />
</label>
<label>
<span>Cumulative name</span>
<input name="c3_mins_name" value="<?php echo $data['c3_mins_name'] ?? '';?>" />
</label>
<label>
<span>Cumulative Minutes</span>
<input type="num" name="c3_mins" value="<?php echo $data['c3_mins'] ?? '';?>" />
</label>
<label>
<span>Cumulative formula</span>
<input name="c3_mins_formula" value="<?php echo $data['c3_mins_formula'] ?? '';?>" />
</label>
</fieldset>

<fieldset>
Expand Down

0 comments on commit 38dcc71

Please sign in to comment.