Giter VIP home page Giter VIP logo

Comments (3)

pylipp avatar pylipp commented on September 14, 2024

User story: beneficiary demographics

We'd like to obtain the number of beneficiaries (fact) for all sets of gender, age(-bin), and creation date (dimensions).

BE implementation

Such data can be obtained by first querying beneficiary rows, then transforming it into a pivot table (e.g. using the pandas framework; id as values, gender, created_on, age as index, count as aggfunc), and finally transforming this table into single data points again.

However due to the simplicity of the aggregation, the data can be obtained directly from the DB via

    bin_width = 5
    gender = fn.IF(Beneficiary.gender == "", "D", Beneficiary.gender)
    created_on = db.database.truncate_date("day", Beneficiary.created_on)
    age = fn.FLOOR((date.today().year - Beneficiary.date_of_birth.year) / bin_width)

    demographics = (
        Beneficiary.select(
            gender.alias("gender"),
            created_on.alias("created_on"),
            age.alias("age"),
            fn.COUNT(Beneficiary.id).alias("count"),
        )
        .where(Beneficiary.deleted.is_null())  # add base IDs
        .group_by(SQL("gender"), SQL("age"), SQL("created_on"))
    )

The final implemenation will contain a filter for base IDs, too.

Data format

The resulting data format is an object with a facts attribute that contains a list of objects with keys age, gender, createdOn, tagIds, and count; and with a dimensions attribute that contains a tag field.

GraphQL interface

To return the data via GraphQL the following extension is proposed:

type Query {
  ...
  beneficiaryDemographics(baseIds: [Int]): BeneficiaryDemographicsData
}

type BeneficiaryDemographicsData {
  facts: [BeneficiaryDemographicsResult]
  dimensions: BeneficiaryDemographicsDimensions
}

type BeneficiaryDemographicsResult {
  age: Int
  gender: HumanGender
  createdOn: Datetime
  tagIds: [Int!]
  count: Int
}

type BeneficiaryDemographicsDimensions {
  tag: [ResultIdName]
}

type ResultIdName {
  id: ID
  name: String
}

from boxtribute.

pylipp avatar pylipp commented on September 14, 2024

@MaikNeubert @HaGuesto please see the above proposal. Experimental implementation lives in this branch

from boxtribute.

HaGuesto avatar HaGuesto commented on September 14, 2024

works from my side

from boxtribute.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.