-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpredict.php
211 lines (161 loc) · 6.14 KB
/
predict.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
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://d3js.org/d3.v4.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<div id="my_dataviz"></div>
</body>
</html>
<?php
// Connect to the database using PDO
$servername = "localhost";
$port_no = 3306;
$username = "Thanish";
$password = "Thanish@123";
$myDB = "josaa"; //Name of the database to access
try {
$conn = new PDO("mysql:host=$servername;port=$port_no;dbname=$myDB", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//echo "Connected successfully";
// Retrieve form inputs
$rank = $_POST['rank'];
$category = $_POST['category'];
$gender = $_POST['gender'];
// Prepare and execute the SQL query
$stmt = $conn->prepare("SELECT `Institute`,`Academic Program Name` FROM josaa WHERE Round = 6 AND `Year`=2022 AND `Seat Type` = :category AND Gender = :gender AND 0.9*`OR`<= :rank AND 1.1*`Closing Rank`>=:rank ORDER BY `Closing Rank`-`OR` LIMIT 10 ");
$stmt->bindParam(':category', $category);
$stmt->bindParam(':gender', $gender);
$stmt->bindParam(':rank', $rank);
$stmt->execute();
$results = $stmt->fetchAll();
$temp = 0;
// print_r($results);
$stats = array();
$information = array();
foreach ($results as $result) {
$institute = $result['Institute'];
$program = $result['Academic Program Name'];
$stmt = $conn->prepare("SELECT `OR`,`Closing Rank`,`Year` FROM josaa WHERE `Institute` = :institute AND `Academic Program Name` = :program AND `Round` = 6 AND `Seat Type` = :category AND Gender =:gender");
$stmt->bindParam(':institute', $institute);
$stmt->bindParam(':program', $program);
$stmt->bindParam(':category', $category);
$stmt->bindParam(':gender', $gender);
$stmt->execute();
$stat = $stmt->fetchALL();
$info['institute'] = $institute;
$info['program'] = $program;
$information[] = $info;
$stats[] = $stat;
}
print_r($stats);
// Display the result to the user
if ($results) {
echo "<p>Congratulations! You have a chance of getting a seat </p>";
} else {
echo "<p>Sorry, you do not have a chance of getting a seat in any IIT.</p>";
}
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
<script type="text/javascript">
function getRandomDarkColor() {
var letters = '0123456789ABCDEF';
var color = '#';
// Generate a random dark color
for (var i = 0; i < 6; i++) {
var index = Math.floor(Math.random() * 16); // Generate random index from 0 to 9
color += letters[index];
}
return color;
}
var ors = [];
var crs = [];
var years = [0];
var points = []
var options = <?php echo json_encode($stats); ?>;
for (let i = 0; i < options.length; i++) {
var users = options[0];
var maxx = users.length;
var maxy = parseInt(users[users.length - 1][0]);
for (let i = 0; i < users.length - 1; i++) {
let js = {};
js.x1 = i;
js.y1 = users[i][0];
js.x2 = i + 1;
js.y2 = users[i + 1][0];
points.push(js);
}
var margin = {
top: 20,
right: 20,
bottom: 30,
left: 40
};
// Calculate chart width and height based on the available space
var width = 600 - margin.left - margin.right;
var height = 600 - margin.top - margin.bottom;
const xScale = d3.scaleLinear()
.domain([0, maxx + 1]) // Adjust the domain based on your data
.range([0, width]);
const yScale = d3.scaleLinear()
.domain([0, maxy + 80]) // Adjust the domain based on your data
.range([height, 0]);
for (let i = 0; i < users.length; i++) {
ors.push(parseInt(users[i][0]));
crs.push(parseInt(users[i][1]));
years.push(parseInt(users[i][2]));
}
var svg = d3.select('body').append('svg').attr('width', 1000).attr('height', 1000);
// const xAxis = d3.axisBottom(xScale);
const yAxis = d3.axisLeft(yScale);
var xdata = years
var linear = d3.scaleLinear()
.domain([0, maxx + 1])
.range([0, width]);
var xAxis = d3.axisBottom(xScale)
.ticks(maxx)
.tickFormat(function(d) {
return xdata[d];
});
var lines = d3.select('svg').selectAll("liness").data(points).enter()
.append("line")
.attr('x1', function(d) {
return (xScale(d.x1 + 1) + margin.left)
})
.attr('y1', function(d) {
return yScale(d.y1 - margin.top)
}).attr('x2', function(d) {
return (xScale(d.x2 + 1) + margin.left)
}).attr('y2', function(d) {
return yScale(d.y2 - margin.top)
}).attr('stroke-width', 2)
.attr('stroke', getRandomDarkColor());
var dots = d3.select('svg').selectAll('circles').data(ors).enter()
.append("circle")
.attr('cx', function(d, i) {
return (xScale(i + 1) + margin.left)
})
.attr('cy', function(d) {
return (yScale(d - margin.top))
}).attr('r', 6)
.attr('fill', getRandomDarkColor());
const axisGroup = d3.select('svg').append("g")
.attr("class", "axis-group")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// Step 4: Call the axis generators
axisGroup.append("g")
.attr("class", "x-axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
axisGroup.append("g")
.attr("class", "y-axis")
.call(yAxis);
}
</script>