Skip to content

Commit

Permalink
fix date filter, bind start/end dates, fix frequency bar chart
Browse files Browse the repository at this point in the history
  • Loading branch information
josefaidt committed Apr 21, 2023
1 parent c954508 commit b750c05
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 45 deletions.
84 changes: 40 additions & 44 deletions src/routes/dashboard/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,53 @@
guild,
} = data
let today = new Date()
let endDate = today
let startDate = new Date(today.getFullYear(), today.getMonth() - 3, 1)
let dates: Date[] = timeBetweenDates('months', [startDate, endDate])
const today = new Date()
/**
* Selected start date
* @default "3 months ago"
*/
let selectedStartDate = new Date(today.getFullYear(), today.getMonth() - 3, 1)
/**
* Selected end date
* @default "today"
*/
let selectedEndDate = today
/**
* Selected time period
*/
let selectedTimePeriod: TimePeriod = TIME_PERIODS.MONTH
/**
* Selected post tags
*/
let selectedTags: string[] = [...availableTags]
/**
* Selected channels
*/
let selectedChannels: string[] = [...allHelpChannels]
/**
* Dates between selected start and end dates
*/
let dates: Date[] = timeBetweenDates(selectedTimePeriod, [
selectedStartDate,
selectedEndDate,
])
let filteredContributors: Contributor[] = filterAnswers(
allHelpChannels,
[dates[0], today],
[dates[0], selectedEndDate],
contributors.all
)
let filteredStaffContributors: Contributor[] = filterAnswers(
allHelpChannels,
[dates[0], today],
[dates[0], selectedEndDate],
contributors.staff
)
/**
* @todo refactor contributor tables to component
*/
let topOverallPromise = getTopContributors(contributors.all, gitHubStaff, 9)
let topStaffPromise = getTopContributors(contributors.staff, gitHubStaff, 9)
Expand All @@ -62,17 +94,6 @@
{ key: 'answers', value: 'Answers' },
]
$: filteredContributors = filterAnswers(
allHelpChannels,
[dates[0], today],
contributors.all
)
$: filteredStaffContributors = filterAnswers(
allHelpChannels,
[dates[0], today],
contributors.staff
)
$: topStaffPromise = getTopContributors(
filteredStaffContributors,
gitHubStaff,
Expand All @@ -84,29 +105,6 @@
9
)
/**
* Selected start date
* @default "3 months ago"
*/
let selectedStartDate = new Date(today.getFullYear(), today.getMonth() - 3, 1)
/**
* Selected end date
* @default "today"
*/
let selectedEndDate = today
/**
* Selected time period
*/
let selectedTimePeriod: TimePeriod = TIME_PERIODS.MONTH
/**
* Selected post tags
*/
let selectedTags: string[] = [...availableTags]
/**
* Selected channels
*/
let selectedChannels: string[] = [...allHelpChannels]
/**
* @todo rename this when we have finished the migration to the revised helpers
* @todo fix the need to typecast
Expand Down Expand Up @@ -208,8 +206,6 @@
),
},
]
$: console.log()
</script>

<svelte:head>
Expand Down Expand Up @@ -247,9 +243,9 @@
bind:channels="{selectedChannels}"
bind:tags="{selectedTags}"
bind:timePeriod="{selectedTimePeriod}"
bind:startDate="{selectedStartDate}"
bind:endDate="{selectedEndDate}"
today="{today}"
startDate="{startDate}"
endDate="{endDate}"
/>
<Row padding>
<Column>
Expand Down
8 changes: 7 additions & 1 deletion src/routes/dashboard/QuestionBarChart.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { BarChartStacked } from '@carbon/charts-svelte'
import { COHORTS } from './constants'
import { COHORTS, TIME_PERIODS } from './constants'
import { groupQuestions } from './helpers/group-questions'
import type { TimePeriod, Question } from './types'
Expand Down Expand Up @@ -36,7 +36,12 @@
byDateOptions: { period: timePeriod },
})
for (const [date, questionsGroupedByDate] of Object.entries(grouped)) {
const isGroupedByDayOrWeek = [
TIME_PERIODS.DAY as string,
TIME_PERIODS.WEEK as string,
].includes(timePeriod)
const key = new Date(date).toLocaleDateString('en-US', {
day: isGroupedByDayOrWeek ? 'numeric' : undefined,
month: 'short',
year: 'numeric',
})
Expand Down Expand Up @@ -84,6 +89,7 @@
}
$: data = createBarChartData(questions, timePeriod)
$: console.log({ timePeriod, data })
</script>

<BarChartStacked
Expand Down
1 change: 1 addition & 0 deletions src/routes/dashboard/helpers/filter-answers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Contributor } from '../types'
/**
* Filter answers by channel and date range
* @TODO refactor this to be more generic
* @deprecated
*/
export function filterAnswers(
channels: string[],
Expand Down

0 comments on commit b750c05

Please sign in to comment.