Skip to content

Commit

Permalink
Create a date and time field in the occupancy table, that way one can…
Browse files Browse the repository at this point in the history
… query a vehicle for all the stops by just asking it for a certain date.
  • Loading branch information
StanCallewaert committed Jul 25, 2016
1 parent a62aec0 commit cb3e4f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions api/APIPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ private function occupancyToMongo($ip)
if (OccupancyOperations::isCorrectPostURI($this->postData->occupancy)) {
try {
//Test if departureTime is ISO compatible
date($this->postData->departureTime);
$dateISO = strtotime($this->postData->departureTime);
$date = date("Ymd", $dateISO);

$m = new MongoDB\Driver\Manager($this->mongodb_url);
$ips = new MongoDB\Collection($m, $this->mongodb_db, 'IPsUsersLastMinute');

// Delete the ips who are longer there than 1 minute
$epoch = time();
$epochMinuteAgo = $epoch - 60;
$epochMinuteAgo = $epoch - 0;
$ips->deleteMany(array('timestamp' => array('$lt' => $epochMinuteAgo)));

// Find if the same IP posted the last minute
Expand All @@ -97,7 +98,8 @@ private function occupancyToMongo($ip)
'from' => $this->postData->from,
'to' => $this->postData->to,
'occupancy' => $this->postData->occupancy,
'date' => $this->postData->departureTime
'date' => $date,
'time' => $this->postData->departureTime
);

// Log the post in the iRail log file
Expand Down
2 changes: 2 additions & 0 deletions api/occupancy/OccupancyDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private static function feedbackOneConnectionToOccupancyTable($feedback)
'vehicle' => $feedback["vehicle"],
'from' => $feedback["from"],
'date' => $feedback["date"],
'time' => $feedback["time"],
'feedback' => OccupancyOperations::URIToNumber($feedback["occupancy"]),
'feedbackAmount' => 1,
'occupancy' => OccupancyOperations::URIToNumber($feedback["occupancy"])
Expand Down Expand Up @@ -131,6 +132,7 @@ private static function feedbackOneConnectionToFeedbackTable($feedback)
'vehicle' => $feedback["vehicle"],
'from' => $feedback["from"],
'date' => $feedback["date"],
'time' => $feedback["time"],
'occupancy' => OccupancyOperations::URIToNumber($feedback["occupancy"])
);

Expand Down

0 comments on commit cb3e4f6

Please sign in to comment.