remove datatable unit tests
[contractdashboard.git] / heuristics / dateHeuristics.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
<?php
//long contract period (number of weeks/days?)
$heuristics["DATE_LONG_CONTRACT_PERIOD"] = Array(
        "description" => "long contract period (number of weeks/days?)"
);
function DATE_LONG_CONTRACT_PERIOD($cn)
{
        $averageContractPeriod = getAverageContractPeriod();
        $stddevContractPeriod = getstddevContractPeriod();
        $diff = strtotime($cn['contractEnd']) - strtotime($cn['contractStart']);
        $days = intval($diff / (60 * 60 * 24));
        $value = abs($days - $averageContractPeriod) / $stddevContractPeriod;
        return Array(
                "heuristic_value" => $value,
                "raw_value" => $days,
                "mean" => $averageContractPeriod,
                "stddev" => $stddevContractPeriod
        );
}
$averageContractPeriod;
function getAverageContractPeriod()
{
        global $averageContractPeriod, $stddevContractPeriod;
        if (!$averageContractPeriod) {
                getStddevAverageContractPeriod();
        }
        return $averageContractPeriod;
}
$stddevContractPeriod;
function getstddevContractPeriod()
{
        global $averageContractPeriod, $stddevContractPeriod;
        if (!$stddevContractPeriod) {
                getStddevAverageContractPeriod();
        }
        return $stddevContractPeriod;
}
function getStddevAverageContractPeriod()
{
        global $averageContractPeriod, $stddevContractPeriod;
        $query = "select AVG(dateDiff(contractEnd,contractStart)),stddev(dateDiff(contractEnd,contractStart)) from contractnotice";
        $result = mysql_query($query);
        $r = mysql_fetch_array($result, MYSQL_BOTH);
        $averageContractPeriod = $r[0];
        $stddevContractPeriod = $r[1];
}
 
 
//Reported late, 45 days? A late contract is a dodgy contract except maybe for variations?
$heuristics["DATE_REPORTED_LATE"] = Array(
        "description" => "Reported late, 45 days?"
);
function DATE_REPORTED_LATE($cn)
{
        $averageDaysLate = getAverageDaysLate();
        $stddevDaysLate = getStddevDaysLate();
        $diff = strtotime($cn['publishDate']) - strtotime($cn['contractStart']);
        $days = intval($diff / (60 * 60 * 24));
        if ($days <= 0) {
                $value = 0;
        }
        else {
                // +1 demerit for exceeding 45 day requirement
                $value = (abs($days - $averageDaysLate) / $stddevDaysLate) + ($days < 45 ? 0 : 1);
        }
        return Array(
                "heuristic_value" => $value,
                "raw_value" => $days,
                "mean" => $averageDaysLate,
                "stddev" => $stddevDaysLate
        );
}
$averageDaysLate;
function getAverageDaysLate()
{
        global $averageDaysLate;
        if (!$averageDaysLate) {
            getDaysLate();
        }
        return $averageDaysLate;
}
$stddevDaysLate;
function getStddevDaysLate()
{
        global $stddevDaysLate;
        if (!$stddevDaysLate) {
        getDaysLate();
        }
        return $stddevDaysLate;
}
function getDaysLate() {
    
        global $averageDaysLate,$stddevDaysLate;
    
                $query = "select AVG(dateDiff(publishDate,contractStart)), STDDEV(dateDiff(publishDate,contractStart)) from contractnotice";
                $result = mysql_query($query);
                $r = mysql_fetch_array($result, MYSQL_BOTH);
                $averageDaysLate = $r[0];
                        $stddevDaysLate = $r[1];
 
}
?>