-
Notifications
You must be signed in to change notification settings - Fork 3
/
trait_eau.php
220 lines (178 loc) · 6.77 KB
/
trait_eau.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
/*************************************************************************************/
/* ### Report conso Eau eedomus SQL V1.0 ### */
/* */
/* Developpement par [email protected] */
/* */
/*************************************************************************************/
include ('parametres.php');
mysql_connect($server, $sqllogin, $sqlpass) OR die('Erreur de connexion à la base');
mysql_select_db('historique') OR die('Erreur de sélection de la base');
$requete = mysql_query('SELECT SUM(conso) FROM eau WHERE WEEK(date) = WEEK(curdate()) AND YEAR(date) = YEAR(curdate())') OR die('Erreur de la requête MySQL');
while($resultat = mysql_fetch_row($requete))
{
$consohebdo = $resultat[0];
}
mysql_connect($server, $sqllogin, $sqlpass) OR die('Erreur de connexion à la base');
mysql_select_db('historique') OR die('Erreur de sélection de la base');
$requete = mysql_query('SELECT SUM(conso) FROM eau WHERE MONTH(date) = MONTH(curdate()) AND YEAR(date) = YEAR(curdate())') OR die('Erreur de la requête MySQL');
while($resultat = mysql_fetch_row($requete))
{
$consomensuelle = $resultat[0];
}
mysql_connect($server, $sqllogin, $sqlpass) OR die('Erreur de connexion à la base');
mysql_select_db('historique') OR die('Erreur de sélection de la base');
$requete = mysql_query('SELECT SUM(conso) FROM eau WHERE YEAR(date) = YEAR(curdate())') OR die('Erreur de la requête MySQL');
while($resultat = mysql_fetch_row($requete))
{
$consoannuelle = $resultat[0];
}
mysql_close();
// conversion en m3
$consohebdom3 = ($consohebdo / 1000);
$consomensuellem3 = ($consomensuelle / 1000);
$consoannuellem3 = ($consoannuelle / 1000);
// Tarifs
$consohebdoprix = ($consohebdom3 * $prix_m3);
$consomensuelleprix = ($consomensuellem3 * $prix_m3);
$consoannuelleprix = ($consoannuellem3 * $prix_m3);
//******************************************** Changement d'année ***********************************************
$annee_jour = date('Y');
$annee_veille = strftime("%Y", mktime(0, 0, 0, date('m'), date('d')-1, date('Y')));
if ($annee_jour > $annee_veille)
{
$consoannuellem3 = 0;
$consoannuelleprix = 0;
}
//******************************************** Update conso hebdo***********************************************
$url = "http://$IPeedomus/api/set?action=periph.value";
$url .= "&api_user=$api_user";
$url .= "&api_secret=$api_secret";
$url .= "&periph_id=$periph_hebdo";
$url .= "&value=$consohebdoprix";
$result = file_get_contents($url);
if (strpos($result, '"success": 1') == false)
{
echo "Une erreur est survenue sur l'update hebdo: [".$result."]";
}
else
{
echo "update hebdo ok<br/>";
}
//******************************************** Update conso mensuelle***********************************************
$url = "http://$IPeedomus/api/set?action=periph.value";
$url .= "&api_user=$api_user";
$url .= "&api_secret=$api_secret";
$url .= "&periph_id=$periph_mensuel";
$url .= "&value=$consomensuelleprix";
$result = file_get_contents($url);
if (strpos($result, '"success": 1') == false)
{
echo "Une erreur est survenue sur l'update mensuel: [".$result."]";
}
else
{
echo "update mensuel ok<br/>";
}
//******************************************** Update conso annuelle***********************************************
$url = "http://$IPeedomus/api/set?action=periph.value";
$url .= "&api_user=$api_user";
$url .= "&api_secret=$api_secret";
$url .= "&periph_id=$periph_annuel";
$url .= "&value=$consoannuelleprix";
$result = file_get_contents($url);
if (strpos($result, '"success": 1') == false)
{
echo "Une erreur est survenue sur l'update annuel: [".$result."]";
}
else
{
echo "update annuel ok<br/>";
}
//******************************************** Update conso hebdo m3***********************************************
$url = "http://$IPeedomus/api/set?action=periph.value";
$url .= "&api_user=$api_user";
$url .= "&api_secret=$api_secret";
$url .= "&periph_id=$periph_hebdom3";
$url .= "&value=$consohebdom3";
$result = file_get_contents($url);
if (strpos($result, '"success": 1') == false)
{
echo "Une erreur est survenue sur l'update kwh hebdo: [".$result."]";
}
else
{
echo "update m3 hebdo ok<br/>";
}
//******************************************** Update conso mensuelle m3***********************************************
$url = "http://$IPeedomus/api/set?action=periph.value";
$url .= "&api_user=$api_user";
$url .= "&api_secret=$api_secret";
$url .= "&periph_id=$periph_mensuelm3";
$url .= "&value=$consomensuellem3";
$result = file_get_contents($url);
if (strpos($result, '"success": 1') == false)
{
echo "Une erreur est survenue sur l'update kwh mensuel: [".$result."]";
}
else
{
echo "update m3 mensuel ok<br/>";
}
//******************************************** Update conso annuelle m3***********************************************
$url = "http://$IPeedomus/api/set?action=periph.value";
$url .= "&api_user=$api_user";
$url .= "&api_secret=$api_secret";
$url .= "&periph_id=$periph_annuelm3";
$url .= "&value=$consoannuellem3";
$result = file_get_contents($url);
if (strpos($result, '"success": 1') == false)
{
echo "Une erreur est survenue sur l'update kwh annuel: [".$result."]";
}
else
{
echo "update m3 annuel ok<br/>";
}
//-----------------------Import des données de comparaison--------------------------
mysql_connect($server, $sqllogin, $sqlpass) OR die('Erreur de connexion à la base');
mysql_select_db('historique') OR die('Erreur de sélection de la base');
$requete = mysql_query('SELECT conso FROM eau ORDER BY id DESC');
while($resultat = mysql_fetch_row($requete))
{
$consoj1 = $resultat[0];
}
mysql_close();
mysql_connect($server, $sqllogin, $sqlpass) OR die('Erreur de connexion à la base');
mysql_select_db('historique') OR die('Erreur de sélection de la base');
$requete = mysql_query('SELECT conso FROM eau ORDER BY id DESC LIMIT 1,1');
while($resultat = mysql_fetch_row($requete))
{
$consoj2 = $resultat[0];
}
mysql_close();
if ($consoj1 < $consoj2){
$bilan = '1';
}
elseif ($consoj1 > $consoj2) {
$bilan = '0';
}
//******************************************** Update bilan***********************************************
$url = "http://$IPeedomus/api/set?action=periph.value";
$url .= "&api_user=$api_user";
$url .= "&api_secret=$api_secret";
$url .= "&periph_id=$etatbilan";
$url .= "&value=$bilan";
$result = file_get_contents($url);
if (strpos($result, '"success": 1') == false)
{
echo "Une erreur est survenue sur l'update bilan: [".$result."]";
}
else
{
echo "update bilan ok<br/>";
}
echo $consoj1;
echo $consoj2;
echo $bilan;
?>