forked from nlmaca/Enecsys_Dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtop_tiles.php
143 lines (128 loc) · 4.9 KB
/
top_tiles.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
include ('currency_symbols.php');
// $getYear = mysqli_query($connect,"select date_format(ts, '%Y')as year from enecsys_report group by year(ts)");
//$getMonth = mysqli_query($connect,"select date_format(ts, '%b')as month from enecsys_report group by month(ts)");
//$getDay = mysqli_query($connect,"select date_format(ts, '%d')as day from enecsys_report group by day(ts)");
//block 1 + 2
//$currentNow = mysqli_query($connect, "select dcpower as current from enecsys where id = 0 order by ts desc limit 1");
//block 3
//get total inverters
$invertersTotal = mysqli_query($connect, "SELECT count(*) as countinv from inverters");
//block 4
//calculate opbrengst
$todayTotal = mysqli_query($connect, "SELECT max(wh) - min(wh) as whtotal from enecsys where id = 0 and date(ts) = curdate()");
while($row = mysqli_fetch_array($todayTotal)){
$whtotal = $row['whtotal'];
}
$PricekWh = mysqli_query($connect, "select lang, currency, kwh_price from system_settings limit 1");
while($row = mysqli_fetch_array($PricekWh)){
$PriceNew = $row['kwh_price'];
$cur = $row['currency'];
$currency = $currency_symbols[$cur];
}
$PriceSet = ($whtotal / 1000) * $PriceNew;
$whtotal_All = $whtotal / 1000;
if ($language == 'ENG') {
$price_today = number_format($PriceSet, 2, '.', '');
$earnings_today = number_format($whtotal_All, 2, '.', '');
// $currency = "P ";
}
elseif ($language == 'NL'){
$price_today = number_format($PriceSet, 2, ',', '');
$earnings_today = number_format($whtotal_All, 2, ',', '');
// $currency = "K ";
}
//block 5
// calculate total days on data
$totalUptime = mysqli_query($connect, "select datediff(max(ts), min(ts)) as uptime from enecsys_report");
while($row = mysqli_fetch_array($totalUptime)){
$uptime = $row['uptime'];
}
$totalDaysData = $uptime ;
//block 6
//current date
$currentDate = date("Y-m-d");
//next line below the blocks
//calculate if latest pulse data (id=0) is older than 1 hour
$latestPulse = mysqli_query($connect, "SELECT ts, dcpower FROM `enecsys` where id = 0 order by ts desc limit 0,1");
if ($latestPulse->num_rows > 0) {
while($row = mysqli_fetch_array($latestPulse)){
$outputTime = $row['ts'];
//$currentNow = $row['dcpower'];
if(strtotime($outputTime) < strtotime('-1 hour')){
$lastpulse = "<span class='count_bottom'>" . $LANG_TOPTILE_LAST_PULSE . "<i class='red'>" . $outputTime . "</i> / Longer than 1 hour ago</span>";
$currentNow = 0;
}
else {
$lastpulse = "<span class='count_bottom'>" . $LANG_TOPTILE_LAST_PULSE . "<i class='green'>" . $outputTime . "</i></span>";
$currentNow = $row['dcpower'];
}
}
}
else {
$outputTime = 0;
$currentNow = 0;
$lastpulse = "<span class='count_bottom'><b><i class='red'>" . $LANG_TOPTILE_NO_INPUT . $LANG_TOPTILE_LAST_PULSE . $outputTime . $LANG_TOPTILE_OVERTIME . "</i></b></span>";
}
?>
<div class="row tile_count">
<div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count">
<div class="left"></div>
<div class="right">
<span class="count_top"><i class="fa fa-plug"></i> <?php echo $LANG_TOPTILE_CURRENT; ?></span>
<div class="count">
<?php echo $currentNow . ' W'; ?>
</div>
</div>
</div>
<div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count">
<div class="left"></div>
<div class="right">
<span class="count_top"><i class="fa fa-bolt"></i> <?php echo $LANG_TOPTILE_CURRENT_TT; ?></span>
<div class="count">
<?php
echo $earnings_today . " kWh";
?>
</div>
</div>
</div>
<div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count">
<div class="left"></div>
<div class="right">
<span class="count_top"><i class="fa fa-wifi"></i> <?php echo $LANG_TOPTILE_CURRENT_TINV; ?></span>
<div class="count">
<?php
while($row = mysqli_fetch_assoc($invertersTotal)){
echo $row['countinv'];
}
?>
</div>
</div>
</div>
<div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count">
<div class="left"></div>
<div class="right">
<span class="count_top"><i class="fa fa-money"></i> <?php echo $LANG_TOPTILE_CURRENT_ET; ?></span>
<div class="count">
<?php
echo $currency . " " . $price_today;
?>
</div>
</div>
</div>
<div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count">
<div class="left"></div>
<div class="right">
<span class="count_top"><i class="fa fa-clock-o"></i> <?php echo $LANG_TOPTILE_CURRENT_DOD; ?></span>
<div class="count"><?php echo $totalDaysData; ?></div>
</div>
</div>
<div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count">
<div class="left"></div>
<div class="right">
<span class="count_top"><i class="fa fa-calendar"></i> <?php echo $LANG_TOPTILE_CURRENT_DATE; ?></span>
<div class="count"><?php echo $currentDate; ?></div>
</div>
</div>
</div>
<?php echo $lastpulse; ?> <br>