2024-06-06 11:22:54 +02:00
|
|
|
package de.hs_mannheim.domain;
|
|
|
|
|
2024-06-08 22:02:40 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
import java.net.http.HttpClient;
|
|
|
|
import java.net.http.HttpRequest;
|
|
|
|
import java.net.http.HttpResponse;
|
|
|
|
import java.net.http.HttpResponse.BodyHandlers;
|
2024-06-06 11:22:54 +02:00
|
|
|
import java.util.HashSet;
|
2024-06-06 11:29:09 +02:00
|
|
|
import java.util.TreeSet;
|
2024-06-06 11:22:54 +02:00
|
|
|
|
2024-06-08 22:02:40 +02:00
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2024-06-06 11:22:54 +02:00
|
|
|
public class System {
|
|
|
|
|
|
|
|
private User current_user;
|
2024-06-08 15:44:40 +02:00
|
|
|
private String api_key;
|
|
|
|
|
|
|
|
public String getApi_key() {
|
|
|
|
return api_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setApi_key(String api_key) {
|
|
|
|
this.api_key = api_key;
|
|
|
|
}
|
2024-06-06 11:22:54 +02:00
|
|
|
|
|
|
|
public HashSet<User> get_all_user(){
|
|
|
|
return new HashSet<User>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean sign_in_user(String username, String password){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean sign_up_user(String username, String password, String hometown, int zip,
|
|
|
|
String car_name, double car_co2_km, double car_avg_kmh, double bike_avg_kmh){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sign_out_user(){}
|
|
|
|
|
|
|
|
public boolean change_user_details(String username, String password, String hometown, int zip,
|
|
|
|
String car_name, double car_co2_km, double car_avg_kmh, double bike_avg_kmh){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-06-06 11:29:09 +02:00
|
|
|
public TreeSet<String> search(String hometown_or_zip){
|
|
|
|
return new TreeSet<String>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public TreeSet<String> random_destinations(){
|
|
|
|
return new TreeSet<String>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String[] destination_details(String destination_zip){
|
|
|
|
return new String[1];
|
|
|
|
}
|
|
|
|
|
2024-06-08 22:02:40 +02:00
|
|
|
public String current_weather() throws URISyntaxException, IOException, InterruptedException{
|
|
|
|
|
|
|
|
String weather = "Fehler";
|
|
|
|
double temperature = 1;
|
|
|
|
|
|
|
|
HttpClient http_client = HttpClient.newHttpClient();
|
|
|
|
|
|
|
|
HttpRequest get_request = HttpRequest.newBuilder()
|
|
|
|
.uri(new URI("https://api.openweathermap.org/data/2.5/weather?zip="+current_user.getZip()+",de&appid="+api_key+"&units=metric&lang=de)"))
|
|
|
|
.GET()
|
|
|
|
.build();
|
|
|
|
|
|
|
|
HttpResponse get_response = http_client.send(get_request, BodyHandlers.ofString());
|
|
|
|
|
|
|
|
JSONObject json = new JSONObject(get_response.body());
|
|
|
|
weather = json.getJSONArray("weather").getJSONObject(0).getString("description");
|
|
|
|
temperature = json.getJSONObject("main").getDouble("temp");
|
|
|
|
|
|
|
|
if(weather.equals("Fehler"))
|
|
|
|
return "Es ist ein Fehler aufgetreten!";
|
|
|
|
else
|
|
|
|
return weather + ": " + temperature + " °C";
|
|
|
|
|
2024-06-06 11:29:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String weather_forecast(String destination_zip){
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
public String distance(String destination_zip){
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
public String[] travel_time(String destination_zip){
|
|
|
|
return new String[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
public String calc_co2(String destination_zip){
|
|
|
|
return "";
|
|
|
|
}
|
2024-06-06 11:22:54 +02:00
|
|
|
}
|
|
|
|
|