DAL

By the end, you'll know so much about

 

  • Metrics
  • django-vector
  • /api/data endpoint

 

You'll want to say "Bazinga!"

Anatomy of a Metric

class InitialPaymentMetric(FieldMetric):
    model = Quote
    identifier = 'initial_payment'
    field = 'inipmt'

Metric types

 

  • FieldMetric
  • DependencyMetric
  • ConcatenationMetric
  • ListAggregationMetric

  • CountMetric

  • SeriesMetric

 

Math metrics

                   + - * / 

 

How do I

  • make a new metric
  • do custom logic (beyond fieldmetric)
  • add metrics to a new app

 

Make a new metric

  • make a new class in any app's metrics.py
  • metrics are autodiscovered

Custom Metric Logic

  • Implement `calculate`

 

class QuoteCount10X(DependencyMetric):

    identifier = '10x'

    dependencies = [QuoteCountMetric]

 

    def calculate(self, df):

        return df[QuoteCountMetric.identifier] * 10

Add metrics to a new app

 

settings.py

 

METRICS_APPS = (
    'webapp.apps.energy',
    'webapp.apps.ops',
    'webapp.apps.solar',
    'webapp.apps.solar.product',
    'webapp.apps.solar.system',
    'webapp.apps.user'
)

 

django-vector interfaces

  • build_dataframe(queryset, [metric])

  • build_single(object, [metric])

  •  coming soon metric_value(object, metric)

Use cases

  • reporting: build_dataframe is speedy
  • glossary: make use of metric identifiers
  • custom api endpoint: specify identifiers

 

  • product rules
  • quote table example
Made with Slides.com