Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Theme : Travelling

API's USED :
https://indianrailapi.com/api/v2/AllTrainOnStation

https://indianrailapi.com/api/v2/TrainSchedule

*PROBLEM STATEMENT*

Whenever we are in a rush to visit any place, often the primary approach to most of the Indian community would be railways. Railways provide decent services at reduced costs which is more preferable compared to any other means of transport. But, what if the buffer time between booking tickets and the actual date of train travel is less than a week? That's where the problem starts, in such situations, you cannot find a suitable direct point-to-point train that picks you from your city and drops you at the desired location. Such trains usually have their tickets sold out if you check a week before the scheduled travel day.

*SOLUTION*

When you don't find a suitable direct train from your source to your destination, you pick a station in between and try to find trains till that point and from there to your final destination. We designed an algorithm that helps you pick a station in between the source and destination. Considering that station we find trains that go till the station and from the station to your final destination.


*Working*

The algorithm takes two inputs from the user i.e the station code of his/her source and destination. From these inputs, we find that long train's route whose tickets would be most probably sold out. We monitor the stop time of this train at each platform and then determine a station to be vast if it has a larger stop time. Optimizing furthermore, we select only such stations that fall under 40%-70% of the total distance so that a station nearer to the source or destination is not selected. From here on we get to find the trains that let us reach the middle station selected with the algorithm and give us suitable options to get there easily, saving time.
31 changes: 31 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const express = require('express');
const request = require('request');
const hbs = require('hbs');
const bodyparser = require('body-parser');
const app =express();
const path = require('path');

const port = process.env.PORT || 3000;
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({ extended: false }))

app.use(express.static(path.join(__dirname,'public')));

app.set('views',path.join(__dirname,'templates/views'));
app.set('view engine','hbs');

app.use(express.urlencoded({extended: true}));
app.use(express.json());

app.get('/', function(req,res){
// res.render('index');
res.render('homescreen')
});

app.use('/auth',require('./routes/auth'));

app.listen(port,()=>{
console.log(`servewr is on port ${port}`);
});

module.exports = app;
145 changes: 145 additions & 0 deletions auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
const express = require('express');
const router = express.Router();
const bcrypt = require('bcryptjs')
const request = require('request');
const { json } = require('express');

router.post('/check',function(req,res)
{
var source = req.body.from;
var destination = req.body.to;
console.log(source);
console.log(destination);

_External_URL = `https://indianrailapi.com/api/v2/AllTrainOnStation/apikey/72a4b65e030c0f6316343d8564fe3e34/StationCode/${source}/`;
request(_External_URL , {json: true}, (err,res,body) => {
if(err)
{
console.log(err);
}
else
{
const trainsFromStation = body;
var trainnumberlist = [];
var k=0;
for(var i=0;i<trainsFromStation.Trains.length;i++)
{
if(trainsFromStation.Trains[i].Destination==destination && trainsFromStation.Trains[i].Source==source)
{
console.log(trainsFromStation.Trains[i]);
trainnumberlist[k] = trainsFromStation.Trains[i].TrainNo;
k=k+1;
}

}

for(var j=0;j<trainnumberlist.length;j++)
{
_Extern_URL = `https://indianrailapi.com/api/v2/TrainSchedule/apikey/72a4b65e030c0f6316343d8564fe3e34/TrainNumber/${trainnumberlist[j]}/`;
request(_Extern_URL , {json: true}, (err1,res1,body1) => {
if(err1)
{
console.log(err);
}
else
{
const trainStationsList = body1.Route;
var soudis;
var destdis;
for(var qq=0;qq<trainStationsList.length;qq++)
{
if(trainStationsList[qq].StationCode == source)
{
soudis =trainStationsList[qq].Distance;
}
if(trainStationsList[qq].StationCode == destination)
{
destdis = trainStationsList[qq].Distance;
}
}

var dist = parseInt(destdis) - parseInt(soudis);
console.log(dist);
var lowestdistance = (dist*0.4)+parseInt(soudis);
var maximumdistance = (dist*0.7) + parseInt(soudis);
var possiblestation = [];
var possiblestationtime = [];
var mm=0;
for(var m = 0 ; m< trainStationsList.length; m++)
{
if(trainStationsList[m].Distance >= lowestdistance && trainStationsList[m].Distance <= maximumdistance)
{
possiblestation[mm]=trainStationsList[m].StationCode;
var timefirst = trainStationsList[m].ArrivalTime;
var timesecond = trainStationsList[m].DepartureTime;
var af = timefirst.split(':'); // split it at the colons
var bf = timesecond.split(':');
var minutesfirst = (+af[0]) * 60 + (+af[1]);
var minutesecond = (+bf[0]) * 60 + (+bf[1]);
possiblestationtime[mm] = (minutesecond-minutesfirst);
mm++;
}
}
for (var inn=0; inn < mm-1; inn++)
{
for ( var jn = 0; jn < mm-inn-1; jn++)
{
if (possiblestationtime[jn] > possiblestationtime[jn+1])
{
var temp = possiblestationtime[jn];
possiblestationtime[jn] = possiblestationtime[jn+1];
possiblestationtime[jn+1]=temp;

var tempn = possiblestation[jn];
possiblestation[jn] = possiblestation[jn+1];
possiblestation[jn+1]=tempn;
}
}
}
console.log(possiblestation);
console.log(possiblestationtime);
for(var stt = mm-1;stt>=0;stt--)
{
var findtrain = possiblestation[stt];
for(var ilt=0;ilt<trainsFromStation.Trains.length;ilt++)
{
if(trainsFromStation.Trains[ilt].Destination==findtrain)
{
if(trainsFromStation.Trains[ilt].Source==source)
{
console.log(findtrain);
console.log(trainsFromStation.Trains[ilt])
}
}
}
}
}});
}
}});
});
module.exports = router;

function middle(findtrain,destination){
_Exter_URL = `https://indianrailapi.com/api/v2/AllTrainOnStation/apikey/72a4b65e030c0f6316343d8564fe3e34/StationCode/${findtrain}/`;
request(_Exter_URL , {json: true}, (err2,res2,body2) => {
if(err2)
{
console.log(err2);
}
else
{
const trainsFromMid = body2;
const trainsmidlist=[];
var s=0;
for(var ilt1=0;ilt1<trainsFromMid.Trains.length;ilt1++)
{
if(trainsFromMid.Trains[ilt1].Source==findtrain && trainsFromMid.Trains[ilt1].Destination==destination)
{
console.log(findtrain);
trainsmidlist[s]=trainsFromMid.Trains[ilt1];
console.log(trainsmidlist[s]);
s++;
}
}
}});
}
25 changes: 25 additions & 0 deletions homescreen.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<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>
</head>
<body>
<form action="/check" method="POST">
<h2>Login Form</h2>

<div class="container">
<label for="uname"><b>search by train number</b></label>
<input type="text" placeholder="train number" name="trainnumber" >

<label for="password"><b> search by train name</b></label>
<input type="text" placeholder="train name" name="trainname" >

<button type="submit">submit</button>


</form>
</body>
</html>
51 changes: 51 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="C:\Users\anujp\OneDrive\Documents\RailConnect\styles.css">
<head>
<title>RailConnect</title>
</head>
<header>
<div class="header-title">
<p>RAIL-CONNECT</p>
</div>

</header>
<body>
<div class="row">
<div class="column">
<div class="container">
<form action="#">
<div class="form-group">
<label>FROM : </label>
<input placeholder="Station code of Start" type="text" id="from" name="from" class="form-control" required>
</div>
<div class="form-group">
<label>TO : </label>
<input placeholder="Station code of Destination" type="text" id="to" name="to" class="form-control" required>
</div>
<input type="submit" onclick="storeValues()" class="btn" value="Submit">
</form>
</div>
</div>
<div class="column">
<div class="container">
<div class="form-group">
<h1>OUTPUT</h1>
</div>
</div>
</div>
</div>
<script>
function storeValues(){
var from = document.getElementById("from");
var to = document.getElementById("to");
console.log(from.value);
console.log(to.value);
}
</script>
</body>
<footer>
<h3>Developed by Team-13 DigestMeIfYouCan</h3>
<h1>Anuj Pillai | Raunak Jaiswal</h1>
</footer>
</html>
78 changes: 78 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
header {
text-align: left;
padding: 15px;
background-color: #3aafa9;
color: white;
}
.header-title{
font-size: 30px;
font-weight: 600;
text-align: left;
padding-left: 30px;
}
body{
background-color: rgb(255, 255, 255);
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
}
.container{
height: 450px;
width: 500px;
margin: auto;
max-width: 90%;
max-height: 90%;
}
.container form{
font-size: 25px ;
font-weight: 600;
height: 80%;
width: 80%;
padding : 30px;
background:white;
border-radius: 4px;
box-shadow: 0,8px,16px rgba(0, 0, 0, 0.3);
}
.container form .form-control{
width:100%;
height: 40px;
background:white;
border: 1px solid silver ;
border-radius: 4px;
margin: 10px 0 18px 0;
padding : 0 10px;
}
.column {
float: left;
width: 40%;
padding: 0 10px;
}
.row {
margin: 0 -5px;
}
.row:after {
content: "";
display: table;
clear: both;
}
.container form .btn{
font-size: 30px ;
font-weight: 600;
margin-left:50%;
margin-top: 10%;
transform:translateX(-50%);
width: 120px;
height: 34px;
border: none;
outline : none;
background:#3aafa9;
cursor:pointer;
font-size: 16px;
color :white;
border-radius: 4px;
transition: .3s;
}
footer {
text-align: center;
padding: 3px;
background-color: #3aafa9;
color: white;
}