feat: add wind direction ascii
This commit is contained in:
parent
5e006b2b4d
commit
3c1ddbc291
@ -20,20 +20,63 @@ class WeatherData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum WindDirection {
|
||||||
|
N("🡩"),
|
||||||
|
NE("🡭"),
|
||||||
|
E("🡪"),
|
||||||
|
SE("🡮"),
|
||||||
|
S("🡫"),
|
||||||
|
SW("🡯"),
|
||||||
|
W("🡨"),
|
||||||
|
NW("🡬"),
|
||||||
|
ERROR("E");
|
||||||
|
|
||||||
|
private String desc;
|
||||||
|
WindDirection(String desc) {this.desc = desc;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){ return this.desc;};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private City city;
|
private City city;
|
||||||
private Instant date;
|
private Instant date;
|
||||||
private float temp;
|
private float temp;
|
||||||
private Condition condition; // cloudly, sunny ...
|
private Condition condition; // cloudly, sunny ...
|
||||||
private float windSpeed;
|
private float windSpeed;
|
||||||
private float windDirection;
|
private float windDirectionAngle;
|
||||||
|
private WindDirection windDirection;
|
||||||
|
|
||||||
WeatherData(City city, Instant date, float temp, float windSpeed, float windDirection, Condition condition) {
|
|
||||||
|
private WindDirection getWindDirection(float windDirectionAngle) {
|
||||||
|
if (windDirectionAngle >= 337.5 || windDirectionAngle <= 22.5)
|
||||||
|
return WindDirection.N;
|
||||||
|
if (windDirectionAngle > 22.5 && windDirectionAngle <= 67.5)
|
||||||
|
return WindDirection.NE;
|
||||||
|
if (windDirectionAngle > 67.5 && windDirectionAngle <= 112.5)
|
||||||
|
return WindDirection.E;
|
||||||
|
if (windDirectionAngle > 112.5 && windDirectionAngle <= 157.5)
|
||||||
|
return WindDirection.SE;
|
||||||
|
if (windDirectionAngle > 157.5 && windDirectionAngle <= 202.5)
|
||||||
|
return WindDirection.S;
|
||||||
|
if (windDirectionAngle > 202.5 && windDirectionAngle <= 247.5)
|
||||||
|
return WindDirection.SW;
|
||||||
|
if (windDirectionAngle > 247.5 && windDirectionAngle <= 292.5)
|
||||||
|
return WindDirection.W;
|
||||||
|
if (windDirectionAngle > 292.5 && windDirectionAngle <= 337.5)
|
||||||
|
return WindDirection.NW;
|
||||||
|
|
||||||
|
return WindDirection.ERROR;
|
||||||
|
|
||||||
|
}
|
||||||
|
WeatherData(City city, Instant date, float temp, float windSpeed, float windDirectionAngle, Condition condition) {
|
||||||
this.city = city;
|
this.city = city;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
this.temp = temp;
|
this.temp = temp;
|
||||||
this.condition = condition;
|
this.condition = condition;
|
||||||
this.windSpeed = windSpeed;
|
this.windSpeed = windSpeed;
|
||||||
this.windDirection = windDirection;
|
this.windDirectionAngle = windDirectionAngle;
|
||||||
|
this.windDirection = this.getWindDirection(windDirectionAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public City getCity() {
|
public City getCity() {
|
||||||
@ -56,7 +99,9 @@ class WeatherData {
|
|||||||
return windSpeed;
|
return windSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getWindDirection() {
|
public float getWindDirectionAngle() {return this.windDirectionAngle;}
|
||||||
|
|
||||||
|
public WindDirection getWindDirection() {
|
||||||
return windDirection;
|
return windDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,17 +125,18 @@ class WeatherData {
|
|||||||
this.windSpeed = windSpeed;
|
this.windSpeed = windSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWindDirection(float windDirection) {
|
public void setWindDirectionAngle(float windDirectionAngle) {
|
||||||
this.windDirection = windDirection;
|
this.windDirectionAngle = windDirectionAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%05.2f° %s %05.2fkm/h %06.2f°",
|
return String.format("%05.2f° %s %05.2fkm/h %06.2f° %s",
|
||||||
this.getTemp(),
|
this.getTemp(),
|
||||||
this.getCondition().toString(),
|
this.getCondition().toString(),
|
||||||
this.getWindSpeed(),
|
this.getWindSpeed(),
|
||||||
this.getWindDirection()
|
this.getWindDirectionAngle(),
|
||||||
|
this.getWindDirection().toString()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user