Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package logic;
- import be.kdg.se3legacy.proxy.UserCallbackListener;
- import interfaces.Controle;
- import interfaces.Response;
- import model.CameraResponse;
- import model.LicensePlate;
- import model.Message;
- import model.Offense;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * Created by Steven on 1-11-2014.
- */
- public class SegmentControlenew implements UserCallbackListener {
- private Map<CameraResponse, Message> messages = new HashMap<CameraResponse, Message>();
- private Message latestMessage;
- private Response latestReponse;
- private CameraResponse response;
- private double speed;
- boolean found = false;
- public void addMessageAndResponse(Message m, Response r) {
- latestMessage = m;
- latestReponse = r;
- messages.put((CameraResponse) latestReponse, latestMessage);
- }
- public void checkIfIlligal(Message message){
- for (Map.Entry<CameraResponse, Message> entry : messages.entrySet()) {
- response = entry.getKey();
- Message firstMessage = entry.getValue();
- if(response.segment.connectedCamera == message.getCameraId() && firstMessage.getLicensePlate().equals(message.getLicensePlate()) ){
- calcSpeed(response.segment.distance,firstMessage.getTimeStamp(),message.getTimeStamp(),response.segment.speedLimit,message.getLicensePlate());
- messages.remove(response,firstMessage);
- }
- }
- }
- public void calcSpeed(int distance, Date beginTime, Date endTime, int limit, String plate) {
- double speed = 0.00;
- double diff = endTime.getTime() - beginTime.getTime();
- double diffHour = diff / (60 * 60 * 1000) % 60;
- speed = distance / diffHour;
- System.out.println("speed: " + speed);
- if (speed > limit) {
- this.speed = speed;
- System.out.println(speed);
- new UserService(plate, this);
- }
- }
- @Override
- public void onUserInfo(String s) {
- Offense offense = new Offense();
- offense.setCarType(latestMessage.getCarType());
- LicensePlate plate = new LicensePlate();
- plate.setPlate(latestMessage.getLicensePlate());
- offense.setLicensePlate(plate);
- offense.setOwner(s);
- offense.setTimeOffense(new Date());
- offense.setSpeed(speed);
- double[] location = response.getLocation();
- offense.setLocation(Double.toString(location[0]) + "-" + Double.toString(location[1]));
- System.out.println("License plate: " + latestMessage.getLicensePlate() + " gave result: " + s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement