-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[TAN-536] Publish data for more graphs
- Loading branch information
Showing
28 changed files
with
464 additions
and
426 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...s/commercial/report_builder/app/services/report_builder/queries/analytics/active_users.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module ReportBuilder | ||
class Queries::Analytics::ActiveUsers < Queries::Analytics::Base | ||
protected | ||
|
||
def query(start_at: nil, end_at: nil, project_id: nil, resolution: nil, **_other_props) | ||
time_series_query = { | ||
fact: 'participation', | ||
filters: { | ||
'dimension_user.role': ['citizen', nil], | ||
**project_filter('dimension_project_id', project_id), | ||
**date_filter('dimension_date_created', start_at, end_at) | ||
}, | ||
groups: "dimension_date_created.#{interval(resolution)}", | ||
aggregations: { | ||
dimension_user_id: 'count', | ||
'dimension_date_created.date': 'first' | ||
} | ||
} | ||
|
||
active_users_whole_period_query = { | ||
fact: 'participation', | ||
filters: { | ||
'dimension_user.role': ['citizen', nil], | ||
**project_filter('dimension_project_id', project_id), | ||
**date_filter('dimension_date_created', start_at, end_at) | ||
}, | ||
aggregations: { | ||
dimension_user_id: 'count' | ||
} | ||
} | ||
|
||
[time_series_query, active_users_whole_period_query] | ||
end | ||
end | ||
end |
37 changes: 37 additions & 0 deletions
37
...mmercial/report_builder/app/services/report_builder/queries/analytics/comments_by_time.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module ReportBuilder | ||
class Queries::Analytics::CommentsByTime < Queries::Analytics::Base | ||
protected | ||
|
||
def query(start_at: nil, end_at: nil, project_id: nil, resolution: nil, **_other_props) | ||
time_series_query = { | ||
fact: 'participation', | ||
filters: { | ||
**date_filter('dimension_date_created', start_at, end_at), | ||
**project_filter('dimension_project_id', project_id), | ||
'dimension_type.name': 'comment', | ||
'dimension_type.parent': %w[idea initiative] | ||
}, | ||
groups: "dimension_date_created.#{interval(resolution)}", | ||
aggregations: { | ||
all: 'count', | ||
'dimension_date_created.date': 'first' | ||
} | ||
} | ||
|
||
comments_by_time_total = { | ||
fact: 'participation', | ||
filters: { | ||
**date_filter('dimension_date_created', nil, end_at), | ||
**project_filter('dimension_project_id', project_id), | ||
'dimension_type.name': 'comment', | ||
'dimension_type.parent': %w[idea initiative] | ||
}, | ||
aggregations: { | ||
all: 'count' | ||
} | ||
} | ||
|
||
[time_series_query, comments_by_time_total] | ||
end | ||
end | ||
end |
37 changes: 37 additions & 0 deletions
37
.../commercial/report_builder/app/services/report_builder/queries/analytics/posts_by_time.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module ReportBuilder | ||
class Queries::Analytics::PostsByTime < Queries::Analytics::Base | ||
protected | ||
|
||
def query(start_at: nil, end_at: nil, project_id: nil, resolution: nil, **_other_props) | ||
time_series_query = { | ||
fact: 'post', | ||
filters: { | ||
**date_filter('dimension_date_created', start_at, end_at), | ||
**project_filter('dimension_project_id', project_id), | ||
'dimension_type.name': 'idea', | ||
publication_status: 'published' | ||
}, | ||
groups: "dimension_date_created.#{interval(resolution)}", | ||
aggregations: { | ||
all: 'count', | ||
'dimension_date_created.date': 'first' | ||
} | ||
} | ||
|
||
posts_by_time_total = { | ||
fact: 'post', | ||
filters: { | ||
**date_filter('dimension_date_created', nil, end_at), | ||
**project_filter('dimension_project_id', project_id), | ||
'dimension_type.name': 'idea', | ||
publication_status: 'published' | ||
}, | ||
aggregations: { | ||
all: 'count' | ||
} | ||
} | ||
|
||
[time_series_query, posts_by_time_total] | ||
end | ||
end | ||
end |
25 changes: 25 additions & 0 deletions
25
...ommercial/report_builder/app/services/report_builder/queries/analytics/traffic_sources.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module ReportBuilder | ||
class Queries::Analytics::TrafficSources < Queries::Analytics::Base | ||
protected | ||
|
||
def query(start_at: nil, end_at: nil, project_id: nil, resolution: nil, **_other_props) | ||
{ | ||
fact: 'visit', | ||
filters: { | ||
'dimension_user.role': ['citizen', nil], | ||
**project_filter('dimension_projects.id', project_id), | ||
**date_filter( | ||
'dimension_date_first_action', | ||
start_at, | ||
end_at | ||
) | ||
}, | ||
groups: 'dimension_referrer_type.id', | ||
aggregations: { | ||
all: 'count', | ||
'dimension_referrer_type.name': 'first' | ||
} | ||
} | ||
end | ||
end | ||
end |
47 changes: 47 additions & 0 deletions
47
...gines/commercial/report_builder/app/services/report_builder/queries/analytics/visitors.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module ReportBuilder | ||
class Queries::Analytics::Visitors < Queries::Analytics::Base | ||
protected | ||
|
||
def query(start_at: nil, end_at: nil, project_id: nil, resolution: nil, **_other_props) | ||
totals_whole_period_query = { | ||
fact: 'visit', | ||
filters: { | ||
'dimension_user.role': ['citizen', nil], | ||
**project_filter('dimension_projects.id', project_id), | ||
**date_filter( | ||
'dimension_date_first_action', | ||
start_at, | ||
end_at | ||
) | ||
}, | ||
aggregations: { | ||
all: 'count', | ||
visitor_id: 'count', | ||
duration: 'avg', | ||
pages_visited: 'avg' | ||
} | ||
} | ||
|
||
time_series_query = { | ||
fact: 'visit', | ||
filters: { | ||
'dimension_user.role': ['citizen', nil], | ||
**project_filter('dimension_projects.id', project_id), | ||
**date_filter( | ||
'dimension_date_first_action', | ||
start_at, | ||
end_at | ||
) | ||
}, | ||
groups: "dimension_date_first_action.#{interval(resolution)}", | ||
aggregations: { | ||
all: 'count', | ||
visitor_id: 'count', | ||
'dimension_date_first_action.date': 'first' | ||
} | ||
} | ||
|
||
[totals_whole_period_query, time_series_query] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useNode } from '@craftjs/core'; | ||
import useGraphDataUnitsPublished from 'api/graph_data_units/useGraphDataUnitsPublished'; | ||
import { useReportContext } from 'containers/Admin/reporting/context/ReportContext'; | ||
|
||
import { useLocation } from 'react-router-dom'; | ||
import { isPage } from 'utils/helperUtils'; | ||
|
||
import { BaseResponseData } from 'utils/cl-react-query/fetcher'; | ||
import useGraphDataUnitsLive from './useGraphDataUnitsLive'; | ||
import { PropsLive, ResolvedName } from './types'; | ||
|
||
interface Props { | ||
resolvedName: ResolvedName; | ||
queryParameters: PropsLive; | ||
onSuccess?: () => void; | ||
} | ||
|
||
const useGraphDataUnits = <Response extends BaseResponseData>({ | ||
resolvedName, | ||
queryParameters, | ||
onSuccess, | ||
}: Props) => { | ||
const { pathname } = useLocation(); | ||
const { id: graphId } = useNode(); | ||
const isAdminPage = isPage('admin', pathname); | ||
const { reportId } = useReportContext(); | ||
|
||
const { data: analyticsLive } = useGraphDataUnitsLive<Response>( | ||
{ | ||
resolvedName, | ||
props: queryParameters, | ||
}, | ||
{ enabled: isAdminPage, onSuccess } | ||
); | ||
|
||
const { data: analyticsPublished } = useGraphDataUnitsPublished<Response>( | ||
{ | ||
reportId, | ||
graphId, | ||
}, | ||
{ enabled: !isAdminPage } | ||
); | ||
|
||
const analytics = analyticsLive ?? analyticsPublished; | ||
|
||
return analytics; | ||
}; | ||
|
||
export default useGraphDataUnits; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
front/app/components/admin/GraphCards/CommentsByTimeCard/useCommentsByTime/query.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.