forked from stravos97/Smart_Meter_Prjct
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
98 lines (84 loc) · 3.42 KB
/
index.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
<?php
require_once('Models/ConnectionConsumption.php');
//require_once ('Models/Prediction.php');
//require_once('Models/ConnectionWeather.php');
//require_once ('Models/ConnectionLocation.php');
require_once ('Models/BudgetDb.php');
session_start();
$view = new stdClass();
$view->pageTitle = 'Homepage';
$view->type='BOTH';
$elecConsum = new ConnectionConsumption('ELEC','PT1H', 'first day of this month 00:00:00', 'now');
$elecDataSet = $elecConsum->getData();
$gasConsum = new ConnectionConsumption('GAS','PT1H', 'first day of this month 00:00:00','now');
$gasDataSet = $gasConsum->getData();
$view->totalElec = $elecDataSet->getElecCost();
$view->totalGas = $gasDataSet->getGasCost();
////!!!! WEATHER DATA AND PREDICTION DATA MOVED TO /Request.php
//$url = new ConnectionLocation();
//$location = $url->getData();
////changes the url for the weather api
//$url = new ConnectionWeather('forecast', 'Salford');
//// weather for 5 days in the future
//$view->weatherPredictionSet = ($url->getData('forecast'))->getPredictedWeather();
//// predicted weather converted to a usable array for k nn
//$testWeatherArray = ($url->getData('forecast'))->createTestWeatherArray();
//$url = new ConnectionWeather('weather','Salford');
//// weather for the current time of access to the app
//$view->weatherNow = ($url->getData('weather'))->getWeatherArray()[0];
//
//// classifier initialised
//$prediction = new Prediction(7);
//// classifier trained on the training data set
//$prediction->train('Elec');
//// predicted usage for the 5 days saved for the view
//$view->predictedUsageElec = [];
//$count = 0;
//foreach ($testWeatherArray as $value) {
// $view->predictedUsageElec[] = new ConsumptionData($view->weatherPredictionSet[$count]->getTime()->getTimeStamp(),
// floatval($prediction->predict(array($value[0], $value[1], $value[2]))));
//}
//$prediction->train('Gas');
//// predicted usage for the 5 days saved for the view
//$view->predictedUsageGas = [];
//$count = 0;
//foreach ($testWeatherArray as $value) {
// $view->predictedUsageGas[] = new ConsumptionData($view->weatherPredictionSet[$count]->getTime()->getTimeStamp(),
// floatval($prediction->predict(array($value[0], $value[1], $value[2]))));
// $count++;
//}
// Doughnut Chart and colour classes
$budgetConnection = new BudgetDb();
//$view->setBudget;
if ($budgetConnection->getBudget('[email protected]')['electricityPrice'] > 0){
$view->elecBudget = $budgetConnection->getBudget('[email protected]')['electricityPrice'];
}
if ($budgetConnection->getBudget('[email protected]')['gasPrice'] > 0) {
$view->gasBudget = $budgetConnection->getBudget('[email protected]')['gasPrice'];
}
$colour= [];
if(isset($view->elecBudget)){
if($view->totalElec < $view->elecBudget/2) {
$colour[0] = 'green';
$view->colourElectric = 'color-green';
}elseif($view->totalElec < ($view->elecBudget*4)/5){
$colour[0] = 'gold';
$view->colourElectric = 'color-gold';
}else {
$colour[0] = 'red';
$view->colourElectric = 'color-red';
}
}
if(isset($view->elecBudget)) {
if ($view->totalGas < $view->gasBudget / 2) {
$colour[1] = 'green';
$view->colourGas = 'color-green';
} elseif ($view->totalGas < ($view->gasBudget * 4) / 5) {
$colour[1] = 'gold';
$view->colourGas = 'color-gold';
} else {
$colour[1] = 'red';
$view->colourGas = 'color-red';
}
}
require_once ('Views/index.phtml');