GithubHelp home page GithubHelp logo

mwater / mwater-expressions Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 3.0 2.01 MB

Expressions for the mWater platform

License: GNU Lesser General Public License v3.0

JavaScript 37.72% TypeScript 62.28%

mwater-expressions's People

Contributors

broncha avatar grassick avatar mbriau avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mwater-expressions's Issues

Calculating population data for admin boundaries

When listing the population data for an admin boundary in a pivot table it defaults to the Total operator. However this sums up the population allocated for the level as well as all the levels below it, leading to a much inflated figure. Selecting 'Max' is a workaround for at least the second-lowest and lowest levels, but it's not intuitive for users to select that.

We need a more intuitive alternative for bringing through only the level-appropriate pop data.

Add spatial joins

Allow joining to another table, using location, calculating an aggregate value with a filter.

4.9s/100k vs 3.5s without cosine adjustment

select name, code,
(select count(*) from entities.household as hh 
  where 
 hh.location && st_expand(wp.location, 1000/cos(ST_YMin(ST_Transform(wp.location, 4326)) / 57))
 and
 st_dwithin(
	 wp.location,
	 hh.location, 
	 1000/cos(ST_YMin(ST_Transform(wp.location, 4326)) / 57)))

from (select * from entities.water_point as wp limit 100000) as wp

Faster (3.6s):

select name, code,
(select count(*) from entities.household as hh 
 where 
 hh.location && st_expand(wp.location, 1000/cos(ST_YMin(ST_Transform(wp.location, 4326)) / 57))
 and
 st_distance(
	 wp.location,
	 hh.location) <
	 1000/cos(ST_YMin(ST_Transform(wp.location, 4326)) / 57)
)
from (select * from entities.water_point as wp limit 100000) as wp

Simplify joins

Should only contain:

toTable, type? (1-1, 1-n, n-n, n-1?) and either:

fromColumn, toColumn

or

jsonql: which is expr with {from} and {to} aliases.

Allow Date and Datetime comparisons

When a user wants to see a date between two dates and one is a date data type and the other datetime, we should allow this to work. In these instances can we convert the datetime to a date, or else use the midnight time or similar?

Add aggregate expressions

Three types: literal, non-aggregate (better name) and aggregate.

Only aggregate and non-aggregate can't be combined. Any other combination goes to the bigger one (e.g. aggregate).

Cleaning should do what? e.g. clean aggr to non-aggr? clean non-aggr to aggr?

aggr expressions (sum, etc) take literal or non-aggr. They produce aggrs.

Problem: aggr expressions can contain group by clauses! You just need to group on them... But it has the same effect as min or max of it, so ignoring.

Add relative date ops

thisyear, lastyear, thismonth, lastmonth, today, yesterday, last7days, last30days, last365days

These are all new ops that only work on date and datetime fields. They should compile to jsonql that is a simple literal >= "2014-05-31" for example, depending on the current date when compiled.

Change .ordering to be table column, not database column

Orderings use raw database column which adds complexity and prevents abstracting the database.

  • Fix and doc in mwater-expressions
  • Remove getOrdering from Row instance
  • Change in mwater-vis compiler
  • Correct in database for adhoc table
  • Review mwater-forms
  • Test adhoc visualization
  • Release server and portal and blue

Deprecate and replace "expr" type in schema

Should have expr property instead. Having as type prevents using enums as values since we can't specify enumValues.

  • Change in definition
  • Leave in expr handling but deprecated
  • Change schema builders
  • Property editor should have as extra control, not option
  • Change exprType to expr in features of PropertyListComponent
  • Change all existing indicators with expr properties
  • Change aggregations in indicators to require type and enumValues?
  • Prevent selecting in indicator calc builder
  • Restrict calculations in forms to numbers

Consider enum[] type

enum[] types are relatively common (multi-check questions). They can be a section of booleans instead but it is slightly awkward to use as you can't do one condition with multiple values.

ops needed:
= any to find if any intersection (&& if arrays, ?| with text[] rhs for jsonb)
= all to find if LHS contains all of RHS (@> if arrays, ?& with text[] rhs for jsonb))

RHS would need to be a literal (or use json_array_elements_text?).

Add scoring

{ type: "score", input: <expr of enum/enumset>, scores: { } }

0 if null

Add deprecated schema fields support

Allow table and fields to have "deprecated" true. Should not be displayed in any selection ui but still work if present.

  • Add to schema wiki definition
  • Add to properties definition
  • Modify scalar expr picker to support
  • Add to table picker
  • Add to schema builder for properties
  • Add to schema builder for joins to deprecated tables

Make priority data source

Make an object called PriorityDataQueue which takes a DataSource as a constructor parameter and a concurrency. It has one function: createPriorityDataSource which takes a parameter priority (integer). That returns a DataSource (a subclass, probably called PriorityDataSource) that looks like a data source but passes all calls to the original data source in priority order (highest first).

Different data type in case statement

When cases in expressions are of different data type, currently we are only looking at the first one. This causes issues when we have different types.
eg. text type in case 0 and enumset in case 1.

If the second condition is met, the enum values are not transformed

Complete ExprEvaluator

  • Make async
  • Support aggregation
  • Implement all functions

Aggregation takes N rows and produces one value (row?). i.e. does aggregation take N rows and produce 1 value?

Value disappears when you immediately add another branch to expression

To reproduce, create an expression with an if/then. Put in a value for the 'then' box, then immediately click on the '+if' to create another if case for the same statement. The value you entered disappears.

I noticed that if you enter the value, click on some dead space in the box (making the cursor disappear from the box), then +if, the value stays.

Add date math

date - date
datetime - datetime

  • add expressions
  • compile
  • interpret
  • ui

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.