Skip to content

Commit

Permalink
Merge pull request #1000 from datacite/fair-viz-feature-11
Browse files Browse the repository at this point in the history
Flattened Person-Worktype facets for Sankey Visualizations
  • Loading branch information
jrhoads authored Aug 24, 2023
2 parents 655944a + b364111 commit cae3f7a
Show file tree
Hide file tree
Showing 9 changed files with 636 additions and 5 deletions.
22 changes: 22 additions & 0 deletions app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,28 @@ def facet_by_creators_and_contributors(arr)
_facet_by_general_contributor(arr, "creators_and_contributors", "creators_and_contributors")
end

def multi_facet_by_contributors_and_worktype(arr)
outer = _facet_by_general_contributor(arr, "creators_and_contributors", "creators_and_contributors")
outer.map do |hsh|
creator_hash = arr.find { |h| h["key"] == hsh["id"] }
inner = facet_by_combined_key(creator_hash.dig("work_types", "buckets"))
hsh.merge("inner" => inner)
end
end

def flatten_muti_facet(arr)
arr.map do |hsh|
outer_title = hsh["title"]
inner = hsh.fetch("inner", [])
inner.map do |ihsh|
{
"data" => [outer_title, ihsh["title"]],
"count" => ihsh["count"]
}
end
end.flatten
end

def add_other(arr, other_count)
if other_count > 0
arr << {
Expand Down
90 changes: 90 additions & 0 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ type AudiovisualConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -1010,6 +1012,8 @@ type BookChapterConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -1060,6 +1064,8 @@ type BookConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -1432,6 +1438,8 @@ type CollectionConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -1756,6 +1764,8 @@ type ConferencePaperConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -2372,6 +2382,8 @@ type DataManagementPlanConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -2696,6 +2708,8 @@ type DataPaperConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -3045,6 +3059,8 @@ type DatasetConnectionWithTotal implements WorkFacetsInterface {
"""
pageInfo: PageInfo!
personConnectionCount: Int!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
publicationConnectionCount: Int!
published: [Facet!]
registrationAgencies: [Facet!]
Expand Down Expand Up @@ -3462,6 +3478,8 @@ type DissertationConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -4477,6 +4495,21 @@ type FieldOfScience {
name: String
}

"""
Flattened Count Type for Multi-level Facets
"""
type FlattenedCount {
"""
Count
"""
count: Int

"""
Flattened facets
"""
data: [String!]
}

"""
Information about funders
"""
Expand Down Expand Up @@ -5015,6 +5048,8 @@ type ImageConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -5339,6 +5374,8 @@ type InstrumentConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -5663,6 +5700,8 @@ type InteractiveResourceConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -5992,6 +6031,8 @@ type JournalArticleConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -6612,6 +6653,8 @@ type ModelConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand All @@ -6633,6 +6676,31 @@ type ModelEdge {
node: Model
}

"""
Multi-level Facets
"""
type MultiFacet {
"""
Count
"""
count: Int

"""
ID
"""
id: String

"""
Inner facets
"""
inner: [Facet!]

"""
Title
"""
title: String
}

type Mutation {
createClaim(doi: ID!, id: ID, sourceId: String): CreateClaimPayload!
deleteClaim(id: ID!): DeleteClaimPayload!
Expand Down Expand Up @@ -7108,6 +7176,8 @@ type OtherConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -7457,6 +7527,8 @@ type PeerReviewConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -7918,6 +7990,8 @@ type PhysicalObjectConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -8295,6 +8369,8 @@ type PreprintConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -8623,6 +8699,8 @@ type PublicationConnectionWithTotal implements WorkFacetsInterface {
"""
pageInfo: PageInfo!
personConnectionCount: Int!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
publicationConnectionCount: Int!
published: [Facet!]
registrationAgencies: [Facet!]
Expand Down Expand Up @@ -9588,6 +9666,8 @@ type ServiceConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
pidEntities: [Facet!]
published: [Facet!]
registrationAgencies: [Facet!]
Expand Down Expand Up @@ -9942,6 +10022,8 @@ type SoftwareConnectionWithTotal implements WorkFacetsInterface {
"""
pageInfo: PageInfo!
personConnectionCount: Int!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
publicationConnectionCount: Int!
published: [Facet!]
registrationAgencies: [Facet!]
Expand Down Expand Up @@ -10268,6 +10350,8 @@ type SoundConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -10803,6 +10887,8 @@ type WorkConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -10839,6 +10925,8 @@ interface WorkFacetsInterface {
languages: [Facet!]
licenses: [Facet!]
openLicenseResourceTypes: [Facet!]
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down Expand Up @@ -11148,6 +11236,8 @@ type WorkflowConnectionWithTotal implements WorkFacetsInterface {
Information to aid in pagination.
"""
pageInfo: PageInfo!
personToWorkTypesFlat: [FlattenedCount!]
personToWorkTypesMultilevel: [MultiFacet!]
published: [Facet!]
registrationAgencies: [Facet!]
repositories: [Facet!]
Expand Down
8 changes: 8 additions & 0 deletions app/graphql/types/flattened_count_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class FlattenedCountType < BaseObject
description "Flattened Count Type for Multi-level Facets"

field :count, Int, null: true, description: "Count"
field :data, [String], null: true, description: "Flattened facets"
end
21 changes: 21 additions & 0 deletions app/graphql/types/interfaces/work_facets_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ module Interfaces::WorkFacetsInterface
field :fields_of_science_repository, [FacetType], null: true, cache: true
field :licenses, [FacetType], null: true, cache: true
field :languages, [FacetType], null: true, cache: true
field :person_to_work_types_multilevel, [MultiFacetType], null: true, cache: true
field :person_to_work_types_flat, [FlattenedCountType], null: true, cache: true

def person_to_work_types_multilevel
if object.aggregations.creators_and_contributors
multi_facet_by_contributors_and_worktype(object.aggregations.creators_and_contributors.buckets)
else
[]
end
end

def person_to_work_types_flat
if object.aggregations.creators_and_contributors
contributors_works = multi_facet_by_contributors_and_worktype(
object.aggregations.creators_and_contributors.buckets
)
flatten_muti_facet(contributors_works)
else
[]
end
end

def total_count
object.total_count
Expand Down
10 changes: 10 additions & 0 deletions app/graphql/types/multi_facet_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class MultiFacetType < BaseObject
description "Multi-level Facets"

field :id, String, null: true, description: "ID"
field :title, String, null: true, description: "Title"
field :count, Int, null: true, description: "Count"
field :inner, [FacetType], null: true, description: "Inner facets"
end
Loading

0 comments on commit cae3f7a

Please sign in to comment.