Skip to content

Commit fbe581a

Browse files
committed
Merge branch 'main' of github.com:openenergymonitor/heatpumpmonitor.org into heat_pump_image_upload
2 parents 3959230 + 3080d60 commit fbe581a

6 files changed

Lines changed: 370 additions & 107 deletions

File tree

scripts/coldest_day.php

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
define('EMONCMS_EXEC', 1);
23
$dir = dirname(__FILE__);
34
chdir("$dir/../www");
45

@@ -16,46 +17,69 @@
1617

1718
$start_1year_ago = time() - 60*60*24*365;
1819

20+
$apply_changes = true;
21+
1922
$data = $system->list_admin();
2023
foreach ($data as $row) {
2124
$systemid = $row->id;
22-
// print "System: " . $row->id." ".$row->name . "\n";
25+
echo "System ".$row->id." ".$row->location."\n";
26+
27+
// Get current values from system_meta to compare
28+
$result2 = $mysqli->query("SELECT measured_outside_temp_coldest_day, measured_room_temp_coldest_day, measured_mean_flow_temp_coldest_day FROM system_meta WHERE `id` = '$systemid' LIMIT 1");
29+
$row2 = $result2->fetch_object();
30+
$last_outsideT = $row2->measured_outside_temp_coldest_day;
31+
$last_roomT = $row2->measured_room_temp_coldest_day;
32+
$last_flowT = $row2->measured_mean_flow_temp_coldest_day;
2333

24-
$n = 0;
2534

26-
$result = $mysqli->query("SELECT * FROM system_stats_daily WHERE `id` = '$systemid' AND `timestamp` > '$start_1year_ago' ORDER BY `combined_outsideT_mean` ASC LIMIT 50");
35+
$result = $mysqli->query("SELECT * FROM system_stats_daily WHERE `id` = '$systemid' AND `timestamp` > '$start_1year_ago' ORDER BY `combined_outsideT_mean` ASC LIMIT 1");
2736

2837
while ($row = $result->fetch_object()) {
29-
$roomT = $row->combined_roomT_mean;
30-
$outsideT = $row->combined_outsideT_mean;
38+
$roomT = $row->running_roomT_mean;
39+
$outsideT = $row->weighted_outsideT;
3140
$combined_cop = $row->combined_cop;
32-
$flowT = $row->running_flowT_mean;
33-
34-
$room_minus_outside = $roomT - $outsideT;
41+
$flowT = $row->weighted_flowT;
3542

3643
if ($outsideT>-10 && $outsideT<5 && $combined_cop>0) {
3744

38-
$date = new DateTime();
39-
// London
40-
$date->setTimezone(new DateTimeZone('Europe/London'));
41-
$date->setTimestamp($row->timestamp);
42-
43-
// update system_meta measured_outside_temp_coldest_day
44-
$mysqli->query("UPDATE system_meta SET measured_outside_temp_coldest_day = '$outsideT' WHERE `id` = '$systemid'");
45-
46-
$mysqli->query("UPDATE system_meta SET measured_room_temp_coldest_day = '$roomT' WHERE `id` = '$systemid'");
47-
48-
49-
// update system_meta measured_mean_flow_temp_coldest_day
50-
$mysqli->query("UPDATE system_meta SET measured_mean_flow_temp_coldest_day = '$flowT' WHERE `id` = '$systemid'");
51-
52-
echo $systemid."\t".$outsideT . "\t" . $roomT . "\t" . $room_minus_outside. "\t" .$combined_cop . "\t" . $date->format('Y-m-d') . "\n";
53-
$n++;
54-
if ($n>=1) {
55-
break;
45+
echo_status($outsideT, $last_outsideT, "outside temp");
46+
echo_status ($roomT, $last_roomT, "room temp");
47+
echo_status ($flowT, $last_flowT, "flow temp");
48+
49+
// update system_meta with all coldest day measurements in a single query
50+
if ($apply_changes) {
51+
52+
// Update each field individually if numeric
53+
if (is_numeric($outsideT)) {
54+
$mysqli->query("UPDATE system_meta SET measured_outside_temp_coldest_day = '$outsideT' WHERE `id` = '$systemid'");
55+
} else {
56+
echo " Skipping outside temp update - invalid value: $outsideT\n";
57+
}
58+
59+
if (is_numeric($roomT)) {
60+
$mysqli->query("UPDATE system_meta SET measured_room_temp_coldest_day = '$roomT' WHERE `id` = '$systemid'");
61+
} else {
62+
echo " Skipping room temp update - invalid value: $roomT\n";
63+
}
64+
65+
if (is_numeric($flowT)) {
66+
$mysqli->query("UPDATE system_meta SET measured_mean_flow_temp_coldest_day = '$flowT' WHERE `id` = '$systemid'");
67+
} else {
68+
echo " Skipping flow temp update - invalid value: $flowT\n";
69+
}
5670
}
5771
}
5872
}
5973

60-
// die;
74+
//die;
75+
}
76+
77+
function echo_status($new, $old, $variable_name) {
78+
if ($new > $old) {
79+
echo " New $variable_name: $new warmer than $old\n";
80+
} else if ($new == $old) {
81+
echo " $variable_name: $new same as $old\n";
82+
} else {
83+
echo " $variable_name: $new colder than $old\n";
84+
}
6185
}

scripts/max_4h_output.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
2+
23
$dir = dirname(__FILE__);
34
chdir("$dir/www");
45

6+
define('EMONCMS_EXEC', 1);
57
require "Lib/load_database.php";
68

79
require("Modules/user/user_model.php");

www/Modules/system/system_list.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
<script src="https://cdn.jsdelivr.net/npm/vue-select@3.20.4/dist/vue-select.min.js"></script>
1111
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.4.0/axios.min.js"></script>
1212
<script src="https://cdn.plot.ly/plotly-2.16.1.min.js"></script>
13+
<script src="https://cdn.jsdelivr.net/npm/jstat@1.9.6/dist/jstat.min.js"></script>
1314
<script src="Lib/clipboard.js"></script>
14-
<script src="<?php echo $path; ?>Modules/system/system_list_chart.js?v=27"></script>
15+
<script src="<?php echo $path; ?>Modules/system/system_list_chart.js?v=42"></script>
1516

1617
<link rel="stylesheet" href="<?php echo $path; ?>Lib/autocomplete.css?v=4">
1718
<script src="Lib/autocomplete.js?v=8"></script>
@@ -348,7 +349,7 @@
348349
<div class="row">
349350

350351
<!-- X-axis grouped by group -->
351-
<div class="col-lg-4">
352+
<div class="col-lg-3">
352353
<div class="input-group mb-3">
353354
<span class="input-group-text">X-axis</span>
354355
<select class="form-control" v-model="selected_xaxis" @change="draw_scatter">
@@ -360,7 +361,7 @@
360361
</div>
361362

362363
<!-- Y-axis grouped by group -->
363-
<div class="col-lg-4">
364+
<div class="col-lg-3">
364365
<div class="input-group mb-3">
365366
<span class="input-group-text">Y-axis</span>
366367
<select class="form-control" v-model="selected_yaxis" @change="draw_scatter">
@@ -372,7 +373,7 @@
372373
</div>
373374

374375
<!-- Colour map -->
375-
<div class="col-lg-4">
376+
<div class="col-lg-3">
376377
<div class="input-group mb-3">
377378
<span class="input-group-text">Colour map</span>
378379
<select class="form-control" v-model="selected_color" @change="draw_scatter">
@@ -382,8 +383,21 @@
382383
</select>
383384
</div>
384385
</div>
386+
387+
<!-- Select between no linear regression, OLS and Orthogonal -->
388+
<div class="col-lg-3">
389+
<div class="input-group mb-3">
390+
<span class="input-group-text">Best fit</span>
391+
<select class="form-control" v-model="line_best_fit_type" @change="draw_scatter">
392+
<option value="none">None</option>
393+
<option value="ols">Ordinary Least Squares (OLS)</option>
394+
<option value="tls">Orthogonal Regression (TLS)</option>
395+
</select>
396+
</div>
397+
</div>
398+
385399
</div>
386-
<p>{{ chart_info }} <input type="checkbox" v-model="enable_line_best_fit" @change="draw_scatter"></p>
400+
<p v-if="line_best_fit_type!='none'">{{ chart_info }}</p>
387401
<div id="chart"></div>
388402
</div>
389403
</div>
@@ -480,9 +494,9 @@
480494
hpint: 0,
481495
errors: 0,
482496
chart: 0,
483-
selected_xaxis: 'running_flowT_mean',
497+
selected_xaxis: 'weighted_flowT_minus_outsideT',
484498
selected_yaxis: 'combined_cop',
485-
selected_color: 'combined_heat_kwh',
499+
selected_color: 'weighted_prc_carnot',
486500
};
487501

488502
if (mode != 'public') {
@@ -949,8 +963,8 @@
949963
selected_yaxis: page_settings.selected_yaxis,
950964
selected_color: page_settings.selected_color,
951965
chart_info: '',
952-
enable_line_best_fit: true,
953966
admin_restricted_list: true,
967+
line_best_fit_type: 'ols',
954968

955969
// Photo lightbox
956970
lightboxOpen: false,

0 commit comments

Comments
 (0)