Skip to content
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
Binary file added stream_data_ML/.mvn/wrapper/maven-wrapper.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions stream_data_ML/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
53 changes: 53 additions & 0 deletions stream_data_ML/API/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.project</groupId>
<artifactId>Project-spring-boot-with-kafka</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/de.flapdoodle.embed/de.flapdoodle.embed.mongo -->
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>2.2.0</version>
<scope>test</scope>
</dependency>


<!-- https://mvnrepository.com/artifact/me.paulschwarz/spring-dotenv -->
<dependency>
<groupId>me.paulschwarz</groupId>
<artifactId>spring-dotenv</artifactId>
<version>2.5.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.2</version>
</dependency>

</dependencies>

<!-- <groupId>net.javaguides</groupId>-->
<artifactId>API</artifactId>

<properties>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.project.Controller;

import com.project.Entity.Route;
import com.project.Entity.Shape;
import com.project.Entity.VehicleInfoEntity;
import com.project.Service.RouteService;
import com.project.Service.ShapeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "http://localhost:8082/")
public class BackendController {

private RouteService routeService;

private ShapeService shapeService;
private static final Logger logger = LoggerFactory.getLogger(BackendController.class);

public BackendController(RouteService routeService, ShapeService shapeService) {
this.routeService = routeService;
this.shapeService = shapeService;
}

@GetMapping("/getRoute")
public ResponseEntity<List<Route>> getListOfRoutesByRouteId(@RequestParam("routeId") String routeId) {
logger.info("Request received for routeId: {}", routeId);
List<Route> routes = routeService.getListOfRoutesByRouteId(routeId);
logger.info("Route found: {}", routes);
return ResponseEntity.ok(routes);
}

@GetMapping("/getSegments/{shapeId}")
public ResponseEntity<List<Shape>> getListOfShapesByShapeId(@PathVariable("shapeId") String shapeId) {
List<Shape> shapes = shapeService.getListOfShapesByShapeId(shapeId);
if(shapes == null || shapes.isEmpty()) {
logger.info("shapes list is null");
} else {
logger.info("shapes list is not null");
logger.info("shapes list size: " + shapes.size());
shapes.forEach(shape -> logger.info("each shape is: " + shape.toString()));
}
return ResponseEntity.ok(shapes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.project.Controller;

import com.project.Entity.VehicleInfoEntity;
import com.project.Service.BusDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BusDataController {

@Autowired
private BusDataService busDataService;

@GetMapping("/listBusData")
public List<VehicleInfoEntity> listBusData() {
return busDataService.returnBusDataLessThanOneHour();
}

@DeleteMapping("/deleteBusData")
public ResponseEntity<String> deleteBusData() {
busDataService.deleteBusDataLessThanOneHour();
// If the deletion is successful, return an "OK" response
return ResponseEntity.ok("Deletion was successful");
}

@GetMapping("/getLatestBusData")
public VehicleInfoEntity getLatestBusData(@RequestParam String vehicleId) {
return busDataService.getLatestBusData(vehicleId);
}

@GetMapping("/getAllBusData")
public List<VehicleInfoEntity> getAllBusData() {
return busDataService.getAllBusData();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.project.Controller;

import com.project.Entity.VehicleInfoEntity;
import com.project.Service.ConvertListOfDocumentsToJson;
import com.project.Service.VehicleInfoService;
import com.project.Service.WriteToJsonFile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class VehicleInfoController {

private VehicleInfoService vehicleInfoService;

private ConvertListOfDocumentsToJson convertListOfDocumentsToJson;

private WriteToJsonFile writeToJsonFile;

public VehicleInfoController(VehicleInfoService vehicleInfoService, ConvertListOfDocumentsToJson convertListOfDocumentsToJson, WriteToJsonFile writeToJsonFile) {
this.vehicleInfoService = vehicleInfoService;
this.convertListOfDocumentsToJson = convertListOfDocumentsToJson;
this.writeToJsonFile = writeToJsonFile;
}

@GetMapping("/generate-json")
public String generateJsonFile() {
List<VehicleInfoEntity> documents = vehicleInfoService.getAllDocuments();
String json = convertListOfDocumentsToJson.convertDocumentsToJson(documents);

// Write the JSON data to a file (adjust the file path)
String filePath = "./vehicle_position.json";
writeToJsonFile.writeFile(filePath, json);

return "JSON file generated successfully.";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.project.Controller;

import com.project.Service.WriteToJsonFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WriteTrainingDataListToFile {

@Autowired
private WriteToJsonFile writeToJsonFile;

private static final String FILE_PATH = "./training_data.json";
@GetMapping("/trainingData/generateJson")
public ResponseEntity<String> generateJson(String filePath) {
writeToJsonFile.convertContentsInFileToListOfJsonObjects(FILE_PATH);
return ResponseEntity.ok("Successfully generate Json");
}
}
23 changes: 23 additions & 0 deletions stream_data_ML/API/src/main/java/com/project/Entity/Position.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.project.Entity;



import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Position {

private double latitude;

private double longitude;

private int bearing;

private double speed = 0;
}
37 changes: 37 additions & 0 deletions stream_data_ML/API/src/main/java/com/project/Entity/Route.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.project.Entity;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.List;

@Document(collection = "routes")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Route {

@Id
private String id; // "id" must be included as a required field in MongoDB document, or else Repository returns Null

private String routeId;

private String routeName;

private List<ShapeInRoute> shapes;

@Override
public String toString() {
return "Route{" +
"id='" + id + '\'' +
", routeId='" + routeId + '\'' +
", routeName='" + routeName + '\'' +
", shapes=" + shapes +
'}';
}
}
39 changes: 39 additions & 0 deletions stream_data_ML/API/src/main/java/com/project/Entity/Segment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.project.Entity;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Field;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Segment {

// @Id
// private String id;

private String segmentId;

@Field("stop_src")
private SegmentStopSrc stop_src;

@Field("stop_dest")
private SegmentStopDest stop_dest;

@Id
private String id;

@Override
public String toString() {
return "Segment{" +
"id='" + id + '\'' +
", segmentId='" + segmentId + '\'' +
", stop_src=" + stop_src.toString() +
", stop_dest=" + stop_dest.toString() +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.project.Entity;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.mongodb.core.mapping.Field;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SegmentStopDest {

@Field("stop_lat")
private double stopLat;

@Field("stop_lon")
private double stopLon;

@Override
public String toString() {
return "SegmentStopDest{" +
"stopLat=" + stopLat +
", stopLon=" + stopLon +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.project.Entity;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.mongodb.core.mapping.Field;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SegmentStopSrc {

@Field("stop_lat")
private double stopLat;

@Field("stop_lon")
private double stopLon;

@Override
public String toString() {
return "SegmentStopSrc{" +
"stopLat=" + stopLat +
", stopLon=" + stopLon +
'}';
}
}
Loading