Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat probabilistic numbers in tooltip #435

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
55 changes: 11 additions & 44 deletions apps/nowcasting-app/components/charts/remix-line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,23 @@ export type ChartData = {
"4HR_PAST_FORECAST"?: number;
DELTA?: number;
DELTA_BUCKET?: DELTA_BUCKET;
PROBABILISTIC_UPPER_BOUND?: number;
PROBABILISTIC_LOWER_BOUND?: number;
PROBABILISTIC_RANGE?: Array<number>;
braddf marked this conversation as resolved.
Show resolved Hide resolved
formattedDate: string; // "2022-05-16T15:00",
};

const toolTiplabels: Record<string, string> = {
GENERATION: "PV Live estimate",
GENERATION_UPDATED: "PV Actual",
PROBABILISTIC_UPPER_BOUND: "OCF 90%",
FORECAST: "OCF Forecast",
PAST_FORECAST: "OCF Forecast",
// "4HR_FORECAST": `OCF ${getRounded4HoursAgoString()} Forecast`,
PROBABILISTIC_LOWER_BOUND: "OCF 10%",
"4HR_FORECAST": `OCF 4hr+ Forecast`,
"4HR_PAST_FORECAST": "OCF 4hr Forecast",
DELTA: "Delta",
PROBABILISTIC_RANGE: "P"
DELTA: "Delta"
};

const toolTipColors: Record<string, string> = {
Expand All @@ -63,7 +66,8 @@ const toolTipColors: Record<string, string> = {
"4HR_FORECAST": orange,
"4HR_PAST_FORECAST": orange,
DELTA: deltaPos,
PROBABILISTIC_RANGE: yellow
PROBABILISTIC_UPPER_BOUND: yellow,
PROBABILISTIC_LOWER_BOUND: yellow
};
type RemixLineProps = {
timeOfInterest: string;
Expand Down Expand Up @@ -428,9 +432,11 @@ const RemixLine: React.FC<RemixLineProps> = ({
return null;
if (key.includes("4HR") && (!show4hView || !visibleLines.includes(key)))
return null;

const textClass = ["FORECAST", "PAST_FORECAST"].includes(name)
if (key.includes("PROBABILISTIC") && Math.round(value * 100) < 0) return null;
const textClass = ["FORECAST", "PAST_FORECAST"].includes(key)
? "font-semibold"
: ["PROBABILISTIC_UPPER_BOUND", "PROBABILISTIC_LOWER_BOUND"].includes(key)
? "text-xs"
rachel-labri-tipton marked this conversation as resolved.
Show resolved Hide resolved
: "font-normal";
const sign = ["DELTA"].includes(key) ? (Number(value) > 0 ? "+" : "") : "";
const color = ["DELTA"].includes(key)
Expand Down Expand Up @@ -461,45 +467,6 @@ const RemixLine: React.FC<RemixLineProps> = ({
</li>
);
})}
{/* adding probabilistic values to the tooltip */}
{Object.entries(toolTiplabels).map(([key, name]) => {
const value = data[key];
const color = toolTipColors[key];
const pLevelLabels = ["P 10%", "P 90%"];
const pLevelComputed = pLevelLabels.map((pLevel: any) => (
<li key={key + pLevel}>{pLevel}:</li>
));
if (key === "PROBABILISTIC_RANGE" && !value) return null;
if (key === "PROBABILISTIC_RANGE" && deltaView) return null;
if (
key === "PROBABILISTIC_RANGE" &&
typeof value[0] !== "number" &&
typeof value[1] !== "number"
)
return null;
if (
key === "PROBABILISTIC_RANGE" &&
(Math.round(value[0] * 100) < 0 || Math.round(value[1] * 100) < 0)
)
return null;
const pLevelValue =
key === "PROBABILISTIC_RANGE" && value
? value.map((v: any, index: number) => (
<li key={key + String(index)} className={`flex justify-end`}>
{prettyPrintYNumberWithCommas(String(v), 1).replace("-", "")}
</li>
))
: null;
if (key === "PROBABILISTIC_RANGE" && !deltaView)
return (
<li className={`font-sans`} style={{ color }}>
<div className={`flex justify-between`}>
<div className={`font-sans ml-14`}>{pLevelComputed}</div>
<div>{pLevelValue}</div>
</div>
</li>
);
})}
<li className={`flex justify-between pt-4 text-sm text-white font-sans`}>
<div className="pr-4">
{formatISODateStringHumanNumbersOnly(formattedDate)}{" "}
Expand Down
22 changes: 21 additions & 1 deletion apps/nowcasting-app/components/charts/use-format-chart-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,32 @@ const useFormatChartData = ({
addDataToMap(
fc,
(db) => db.targetTime,
//add an array here for the probabilistic range. it'll be two numbers [lower, upper]
//add an array here for the probabilistic area in the chart
(db) => ({
PROBABILISTIC_RANGE: [db.plevels.plevel_10, db.plevels.plevel_90]
})
);
}
if (fc.plevels?.plevel_10) {
addDataToMap(
fc,
(db) => db.targetTime,
// probabilistic lower bound for the tooltip to use
(db) => ({
PROBABILISTIC_LOWER_BOUND: db.plevels.plevel_10
})
);
}
if (fc.plevels?.plevel_90) {
addDataToMap(
fc,
(db) => db.targetTime,
(db) => ({
// probabilistic upper bound for the tooltip to use
PROBABILISTIC_UPPER_BOUND: db.plevels.plevel_90
})
);
}
});

if (fourHourData) {
Expand Down