django-vector
the data access layer
Why do we need another data access layer?
calculate
,
expand
)
1 query
+ vectorized calculations
supports pagination
{ quote: { system: { site: { address_1: '564 Market St' } } } }
{ solar_pmts_net_sum_yrs: 9155.44, solar_pmts_net_yr0: 0.0, solar_pmts_net_yr1: 610.36 ... }
django-vector
Reads from database in a standard way - less room for error
* in theory
apps/solar/product/metrics.py
class ProductNameMetric(FieldMetric):
model = SolarProduct
identifier = 'product_name'
field = 'name'
class ProductNamesMetric(ListAggregationMetric):
identifier = 'product_names'
dependencies = [ProductNameMetric]
def _build_solarsite_dataframe(solarsites):
metrics = [
AddressLine1Metric,
CityNameMetric,
ContactNameMetric,
SolarSiteLastUpdatedMetric,
SolarSiteIDMetric,
StateAbbreviationMetric,
ZipcodeMetric
]
return django_vector.build_dataframe(
solarsites,
metrics
)
build_dataframe
+ build_single
# django_vector/metrics.py
class FieldMetric
class ConcatenationMetric
class ListAggregationMetric
# coming soon: more aggregation
class AverageAggregationMetric
class CountMetric
# future work
class DateFieldChangedMetric
class DateQuoteSignedMetric(DateFieldChangedMetric):
model = Quote
identifier = 'date_quote_signed'
field = 'status'
value = 'SIGN'
class Metric():
"""Base class which defines the Metric interface."""
dependencies = []
def calculate(self, df):
raise NotImplementedError
def get_dependency_fields(self):
raise NotImplementedError
"Hey customer can we turn off this field"
https://engine.sighten.io/api/data/
https://github.com/sighten/django-vector