Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 25 additions & 2 deletions front_end/src/components/charts/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isNil } from "lodash";
import { DomainTuple, VictoryThemeDefinition } from "victory";

import {
Expand Down Expand Up @@ -126,9 +127,14 @@ export function buildNumericChartData({
});

const latestTimestamp = actualCloseTime
? Math.min(actualCloseTime / 1000, Date.now() / 1000)
? Math.max(
Math.min(actualCloseTime / 1000, Date.now() / 1000),
myForecasts?.latest ? myForecasts.latest.start_time : 0
)
: Date.now() / 1000;
if (aggregation.latest?.end_time === null) {
if (isNil(actualCloseTime) && aggregation.latest?.end_time === null) {
// we don't have an actual close time and last aggregation hasn't ended,
// so put a point at the end of the timeline
line.push({
x: latestTimestamp,
y: aggregation.latest.centers?.[aggregationIndex] ?? 0,
Expand All @@ -138,6 +144,23 @@ export function buildNumericChartData({
y0: aggregation.latest.interval_lower_bounds?.[aggregationIndex] ?? 0,
y: aggregation.latest.interval_upper_bounds?.[aggregationIndex] ?? 0,
});
} else if (
actualCloseTime &&
(aggregation.latest?.end_time === null ||
(aggregation.latest?.end_time &&
aggregation.latest.end_time >= actualCloseTime))
) {
// we have an actual close time and the aggregation outlives it,
// trucate it to the actualCloseTime
line[line.length - 1] = {
x: actualCloseTime / 1000,
y: aggregation.latest.centers?.[aggregationIndex] ?? 0,
};
area[area.length - 1] = {
x: actualCloseTime / 1000,
y0: aggregation.latest.interval_lower_bounds?.[aggregationIndex] ?? 0,
y: aggregation.latest.interval_upper_bounds?.[aggregationIndex] ?? 0,
};
} else if (
aggregation.latest?.end_time &&
aggregation.latest.end_time >= latestTimestamp
Expand Down
11 changes: 3 additions & 8 deletions posts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,9 @@ def prefetch_user_forecasts(self, user_id: int):
prefetches += [
Prefetch(
f"{rel}__user_forecasts",
# only retrieve forecasts that were made before question close
queryset=Forecast.objects.filter(author_id=user_id)
.annotate(actual_close_time=F("question__actual_close_time"))
.filter(
Q(actual_close_time__isnull=True)
| Q(start_time__lte=F("actual_close_time"))
)
.order_by("start_time"),
queryset=Forecast.objects.filter(author_id=user_id).order_by(
"start_time"
),
to_attr="request_user_forecasts",
),
Prefetch(
Expand Down
15 changes: 0 additions & 15 deletions questions/serializers/aggregate_forecasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,6 @@ def serialize_question_aggregations(
"movement": None,
}

# Debug method for building aggregation history from scratch
# Will be replaced in favour of aggregation explorer
if not minimize:
aggregate_forecasts_by_method = get_aggregation_history(
question,
aggregation_methods=[
AggregationMethod.RECENCY_WEIGHTED,
AggregationMethod.UNWEIGHTED,
],
minimize=False,
include_stats=True,
include_bots=question.include_bots_in_aggregates,
histogram=True,
)

if question.is_cp_hidden:
# don't show any forecasts
aggregate_forecasts_by_method = {}
Expand Down
Loading