-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph1.php
More file actions
410 lines (168 loc) · 4.98 KB
/
graph1.php
File metadata and controls
410 lines (168 loc) · 4.98 KB
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
<?php
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_line.php');
// Definitions
define( 'DB_HOST', 'localhost' );
define( 'DB_USER', 'camscsco_admin' );
define( 'DB_PASS', 'CAMSCSC!' );
define( 'DB_NAME', 'camscsco_ctf' );
// Debug
ini_set( 'display_errors', '1' );
// Database
$database = new mysqli( DB_HOST, DB_USER, DB_PASS, DB_NAME );
$database->set_charset("utf8");
if( !$database )
{
die( 'MySQL: Wrong credentials' );
}
function dateDifference($date_1 , $date_2 , $differenceFormat = '%a' )
{
$datetime1 = date_create($date_1);
$datetime2 = date_create($date_2);
$interval = date_diff($datetime1, $datetime2);
return $interval->format($differenceFormat);
}
function score_progression()
{
global $database;
$start = "2014-9-3";
$today = date( "Y-m-d" );
$date = $start;
$names = array();
for( $i = 0; $i <= (int) dateDifference($start, $today); $i++ )
{
$date = date( 'Y-m-d', strtotime( $date. ' + 1 days' ) );
$result = $database->query
(
"SELECT
teams.id,
teams.name,
locations.members,
locations.code,
(
SELECT
COALESCE( SUM( challenges.score ), 0 ) + COALESCE( SUM( attacks.additional ), 0 ) + ( SELECT COALESCE( SUM( interact.value ), 0 ) FROM interact WHERE interact.to = teams.id AND interact.success = 1 AND interact.date <= '$date' ) + ( SELECT COALESCE( SUM( bonus.value ), 0 ) FROM bonus WHERE bonus.team = teams.id AND bonus.date <= '$date')
FROM
challenges, attacks
WHERE
attacks.team = teams.id
AND attacks.challenge = challenges.id
AND attacks.date <= '$date'
AND teams.id != 1
) AS score
FROM
teams
JOIN
locations
ON
teams.location = locations.id
ORDER BY
teams.id ASC"
);
while( $reply = mysqli_fetch_assoc( $result ) )
{
${ "data" . $reply['id'] }[$i] = $reply['score'];
if( $i == 0 )
{
array_push( $names, $reply['name'] );
}
}
}
$graph = new Graph(1920,1080);
$graph->SetScale('int');
$theme_class = new UniversalTheme();
$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(true);
$graph->title->Set('CTF Score Progression');
$graph->title->SetFont(FF_DV_SANSSERIF, FS_BOLD, 50);
$graph->SetBox(false);
$graph->img->SetAntiAliasing();
//$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
$graph->legend->SetColumns(6);
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xgrid->SetColor('#E3E3E3');
$counter = 0;
$max = $database->query( "SELECT MAX(id) AS max FROM teams" ); $maxi = mysqli_fetch_assoc( $max );
for( $i = 0; $i <= $maxi['max']; $i++ )
{
if( isset( ${ "data" . $i } ) )
{
${ "p" . $i } = $p1 = new LinePlot( ${ "data" . $i } );
$graph->Add( ${ "p" . $i } );
$p1->SetLegend( $names[$counter] );
$counter += 1;
}
}
$graph->legend->SetFrameWeight(1);
// Output line
$graph->Stroke();
}
function attack_progression()
{
global $database;
$start = "2014-11-1";
$today = date( "Y-m-d" );
$date = $start;
$names = array();
for( $i = 0; $i <= (int) dateDifference($start, $today); $i++ )
{
$date = date( 'Y-m-d', strtotime( $date. ' + 1 days' ) );
$result = $database->query
(
"SELECT
teams.id,
teams.name,
(
SELECT COALESCE( (SUM( interact.value ) * -1), 0 ) FROM interact WHERE interact.from = teams.id AND interact.date <= '$date'
) AS ap
FROM
teams"
);
while( $reply = mysqli_fetch_assoc( $result ) )
{
${ "data" . $reply['id'] }[$i] = $reply['ap'];
if( $i == 0 )
{
array_push( $names, $reply['name'] );
}
}
}
$graph = new Graph(1920,1080);
$graph->SetScale('int');
$graph->yaxis->scale->SetGrace(10);
$theme_class = new UniversalTheme();
$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(true);
$graph->title->Set('CTF AP Progression');
$graph->title->SetFont(FF_DV_SANSSERIF, FS_BOLD, 50);
$graph->SetBox(false);
$graph->img->SetAntiAliasing();
//$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xgrid->SetColor('#E3E3E3');
$counter = 0;
$max = $database->query( "SELECT MAX(id) AS max FROM teams" ); $maxi = mysqli_fetch_assoc( $max ); for( $i = 0; $i <= $maxi['max']; $i++ )
{
if( isset( ${ "data" . $i } ) )
{
${ "p" . $i } = $p1 = new LinePlot( ${ "data" . $i } );
$graph->Add( ${ "p" . $i } );
$p1->SetLegend( $names[$counter] );
$counter += 1;
}
}
$graph->legend->SetFrameWeight(1);
// Output line
$graph->Stroke();
}
score_progression();
?>