Skip to content

Commit

Permalink
Fix interval counts
Browse files Browse the repository at this point in the history
  • Loading branch information
webjunkie committed Dec 22, 2023
1 parent 5f5b75f commit fc8b843
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions frontend/src/scenes/retention/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ActorsQuery, NodeKind, RetentionQuery } from '~/queries/schema'
export function retentionToActorsQuery(query: RetentionQuery, selectedInterval: number, offset = 0): ActorsQuery {
const group = query.aggregation_group_type_index !== undefined
const selectActor = group ? 'group' : 'person'
const totalIntervals = query.retentionFilter.total_intervals || 11
const totalIntervals = (query.retentionFilter.total_intervals || 11) - selectedInterval
const selects = Array.from({ length: totalIntervals }, (_, intervalNumber) => `interval_${intervalNumber}`)
return {
kind: NodeKind.ActorsQuery,
Expand Down Expand Up @@ -36,7 +36,7 @@ export async function queryForActors(
const response = await query(actorsQuery)
const results: RetentionTableAppearanceType[] = response.results.map((row) => ({
person: row[0],
appearances: row.slice(1, row.length - 1),
appearances: row.slice(1, row.length),
}))
return {
result: results,
Expand Down
17 changes: 13 additions & 4 deletions frontend/src/scenes/retention/retentionModalLogic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { actions, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'
import { retentionToActorsQuery } from 'scenes/retention/queries'
Expand All @@ -19,7 +21,14 @@ export const retentionModalLogic = kea<retentionModalLogicType>([
key(keyForInsightLogicProps(DEFAULT_RETENTION_LOGIC_KEY)),
path((key) => ['scenes', 'retention', 'retentionModalLogic', key]),
connect((props: InsightLogicProps) => ({
values: [insightVizDataLogic(props), ['querySource'], groupsModel, ['aggregationLabel']],
values: [
insightVizDataLogic(props),
['querySource'],
groupsModel,
['aggregationLabel'],
featureFlagLogic,
['featureFlags'],
],
actions: [retentionPeopleLogic(props), ['loadPeople']],
})),
actions(() => ({
Expand Down Expand Up @@ -56,9 +65,9 @@ export const retentionModalLogic = kea<retentionModalLogicType>([
},
],
exploreUrl: [
(s) => [s.actorsQuery],
(actorsQuery): string | null => {
if (!actorsQuery) {
(s) => [s.actorsQuery, s.featureFlags],
(actorsQuery, featureFlags): string | null => {
if (!actorsQuery || !featureFlags?.[FEATURE_FLAGS.HOGQL_INSIGHTS_RETENTION]) {
return null
}
const query: DataTableNode = {
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql_queries/insights/retention_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def to_actors_query(self, interval: Optional[int] = None) -> ast.SelectQuery:
timings=self.timings,
)
# We want to expose each interval as a separate column
for i in range(self.query_date_range.total_intervals):
for i in range(self.query_date_range.total_intervals - interval):
retention_query.select.append(
ast.Alias(
alias=f"interval_{i}",
Expand Down

0 comments on commit fc8b843

Please sign in to comment.