1
0

ClimaCell API v4 (#8)

* gets lan/lon from map geo

* climacell v4 endpoints

* Uses ClimaCell API v4, adds Sunrise-Sunset API
This commit is contained in:
Eric
2021-01-28 19:46:11 -06:00
committed by GitHub
parent 6456d30dba
commit 5882f41615
12 changed files with 187 additions and 135 deletions
@@ -87,16 +87,22 @@ const createChartOptions = ({
const chartColors = {
blue: "rgba(63, 127, 191, 0.5)",
gray: "rgba(127, 127, 127, 0.5)",
gray2: "rgba(127, 127, 127, 0.3)",
};
const mapChartData = ({ data, tempUnit, speedUnit, altMode, lengthUnit }) => {
const mapChartData = ({
data: weatherData,
tempUnit,
speedUnit,
altMode,
lengthUnit,
}) => {
const data = weatherData?.data?.timelines?.[0]?.intervals;
if (!data) {
return null;
}
return {
labels: data.map((e) => {
const date = new Date(e.observation_time.value);
const date = new Date(e.startTime);
const adjustedTimestamp =
date.getTime() + date.getTimezoneOffset() * 60 * 1000;
return format(new Date(adjustedTimestamp), "EEEEE");
@@ -104,37 +110,30 @@ const mapChartData = ({ data, tempUnit, speedUnit, altMode, lengthUnit }) => {
datasets: [
{
radius: 0,
label: altMode ? "High Wind Speed" : "High Temp",
label: altMode ? "Wind Speed" : "Temp",
data: data.map((e) => {
const {
values: { windSpeed, temperature },
} = e;
return altMode
? convertSpeed(e.wind_speed[1].max.value, speedUnit)
: convertTemp(e.temp[1].max.value, tempUnit);
? convertSpeed(windSpeed, speedUnit)
: convertTemp(temperature, tempUnit);
}),
yAxisID: "y-axis-1",
borderColor: chartColors.gray,
backgroundColor: chartColors.gray,
fill: false,
},
{
radius: 0,
label: altMode ? "Low Wind Speed" : "Low Temp",
data: data.map((e) => {
return altMode
? convertSpeed(e.wind_speed[0].min.value, speedUnit)
: convertTemp(e.temp[0].min.value, tempUnit);
}),
yAxisID: "y-axis-1",
borderColor: chartColors.gray2,
backgroundColor: chartColors.gray2,
fill: false,
},
{
radius: 0,
label: "Precipitation",
data: data.map((e) => {
const {
values: { precipitationIntensity, precipitationProbability },
} = e;
return altMode
? convertLength(e.precipitation[0].max.value, lengthUnit)
: e.precipitation_probability.value;
? convertLength(precipitationIntensity, lengthUnit)
: precipitationProbability;
}),
yAxisID: "y-axis-2",
borderColor: chartColors.blue,
@@ -90,25 +90,26 @@ const chartColors = {
};
const mapChartData = ({
data,
data: weatherData,
tempUnit,
speedUnit,
clockTime,
altMode,
lengthUnit,
}) => {
const data = weatherData?.data?.timelines?.[0]?.intervals;
if (!data) {
return null;
}
return {
labels: data.map((e) => {
if (clockTime === "12") {
return `${format(new Date(e.observation_time.value), "h")}${format(
new Date(e.observation_time.value),
return `${format(new Date(e.startTime), "h")}${format(
new Date(e.startTime),
"aaaaa"
)}`;
} else {
return `${format(new Date(e.observation_time.value), "HH")}`;
return `${format(new Date(e.startTime), "HH")}`;
}
}),
datasets: [
@@ -116,9 +117,12 @@ const mapChartData = ({
radius: 0,
label: altMode ? "Wind Speed" : "Temp",
data: data.map((e) => {
const {
values: { windSpeed, temperature },
} = e;
return altMode
? convertSpeed(e.wind_speed.value, speedUnit)
: convertTemp(e.temp.value, tempUnit);
? convertSpeed(windSpeed, speedUnit)
: convertTemp(temperature, tempUnit);
}),
yAxisID: "y-axis-1",
borderColor: chartColors.gray,
@@ -129,9 +133,12 @@ const mapChartData = ({
radius: 0,
label: "Precipitation",
data: data.map((e) => {
const {
values: { precipitationIntensity, precipitationProbability },
} = e;
return altMode
? convertLength(e.precipitation.value, lengthUnit)
: e.precipitation_probability.value;
? convertLength(precipitationIntensity, lengthUnit)
: precipitationProbability;
}),
yAxisID: "y-axis-2",
borderColor: chartColors.blue,
@@ -196,7 +203,7 @@ const HourlyChart = () => {
/>
</div>
);
}else if (hourlyWeatherDataErr) {
} else if (hourlyWeatherDataErr) {
return (
<div
className={`${darkMode ? styles.dark : styles.light} ${