Keplergl Filters : multiple attributes per field? - kepler.gl

Is the keplergl filter system able to parse arrays with multiple categories ?
For example a point representing a industrial building who would have all of thoses attributes in the same field ["Non-hazardous waste", "Hazardous waste", "Inert waste"]
if not is there a way to inject the filter action or the data parsing action ?

This feature does not seem to be implemented yet
Kepler's data-processor parses Arrays and Objects as it is GeoJson
processors/data-processor.js line 399
switch (aType) {
case DATE:
return ALL_FIELD_TYPES.date;
case TIME:
case DATETIME:
return ALL_FIELD_TYPES.timestamp;
case FLOAT:
return ALL_FIELD_TYPES.real;
case INT:
return ALL_FIELD_TYPES.integer;
case BOOLEAN:
return ALL_FIELD_TYPES.boolean;
case GEOMETRY:
case GEOMETRY_FROM_STRING:
case PAIR_GEOMETRY_FROM_STRING:
case ARRAY:
case OBJECT:
// TODO: create a new data type for objects and arrays
return ALL_FIELD_TYPES.geojson;
case NUMBER:
case STRING:
case ZIPCODE:
return ALL_FIELD_TYPES.string;
default:
globalConsole.warn(`Unsupported analyzer type: ${aType}`);
return ALL_FIELD_TYPES.string;
}

Related

How to filter list of objects by the value of the one field in Kotlin?

I have got list of objects
listOf(User("John",32), User("Katy",15), User("Sam",43))
How can write a function which returns me the User object if in parameter I pass a name. For example getUser("John") and it suppose to return me User("John",32)
One possibility is also using firstOrNull:
val list = listOf(User("John",32), User("Katy",15), User("Sam",43))
list.firstOrNull { it.name == "John" }

Vuejs pass arguments from body to function like pure JS

I'm trying to pass in an argument to a function that I enter into my view in order to run code on said function.
Currently I have a 5 functions that all basically do the same thing, and I'm trying to refactor them into 1 that takes the values I pass and performs some logic. It might be easier to explain what I'm trying to do with code.
This is my current code in my view:
<v-card-text :class="darkBodyPurpleCardClassFix">Manage</v-card-text>
<v-card-text :class="lightBodyPurpleCardClassFix">Fees</v-card-text>
And then here are those two functions bound to class both under computed:
lightBodyPurpleCardClassFix(){
switch (this.$vuetify.breakpoint.name) {
case 'xs': return '450px';
case 'sm': return this.mediumLightPurpleBodyCLassList;
case 'md': return this.mediumLightPurpleBodyCLassList;
case 'lg': return this.largeLightPurpleBodyCLassList;
case 'xl': return this.largeLightPurpleBodyCLassList;
}
},
darkBodyPurpleCardClassFix(){
switch (this.$vuetify.breakpoint.name) {
case 'xs': return '450px';
case 'sm': return this.mediumDarkPurpleBodyClassList;
case 'md': return this.mediumDarkPurpleBodyClassList;
case 'lg': return this.largeDarkPurpleClassList;
case 'xl': return this.largeDarkPurpleClassList;
}
},
What I'd love to do is to just pass in some arguments, and use those arguments in the function. Something along these lines
<v-card-text :class="classFix(purple, light)">Manage</v-card-text>
And then use those in a function something like this:
classFix(color, value ){
doSomethingWithColor(color);
this.data = value;
};
That color and value are arguments that I would enter into my own code so I could adjust the class list all with 1 function instead of the handful I have now.
EDIT:
This is what some of the data elements look like:
mediumPurpleCreateClassList: ['body-2', 'pb-3', 'pt-2', 'px-2', 'my_dark_purple_section'],
largePurpleCreateClassList: ['subheading', 'pb-3', 'pt-2', 'px-2', 'my_dark_purple_section'],
And what I'd like to do is just pass into a function medium & purple & create and then run my logic off of those arguments.
You could create a method like:
methods: {
// ...
classFix(darkOrLight, color) {
switch (this.$vuetify.breakpoint.name) {
case 'xs': return '450px';
case 'sm': return this['medium' + darkOrLight + color + 'ClassList'];
case 'md': return this['medium' + darkOrLight + color + 'ClassList'];
case 'lg': return this['large' + darkOrLight + color + 'ClassList'];
case 'xl': return this['large' + darkOrLight + color + 'ClassList'];
}
}
}
And use (bind) it in the template as follows:
<v-card-text :class="classFix('dark', 'purple')">Manage</v-card-text>
<v-card-text :class="classFix('light', 'purple')">Fees< /v-card-text>
Reasoning:
This alternative takes advantage of JavaScript's property accessor syntax.
Basically, any property present like:
this.mediumLightPurpleBodyCLassList
Can be acessed through:
this['mediumLightPurpleBodyCLassList']
Notice that what is between [ and ] are strings. And being strings, you can use any variable:
var myField = 'mediumLightPurpleBodyCLassList';
this[myField];
And create/manipulate that variable in anyway you would with any regular string variable:
var myColor = 'LightPurple';
var myField = 'medium' + color + 'BodyCLassList';
this[myField];
And, in the above suggested classFix method, those variables are the functions arguments (which, in the end of the day, are local variables).

Ncalc how to evaluate multi-value string parameters

I am using Ncalc to evaluate the presence of some string values
if (#Xval = 'Z','T','F')
this works well when #xval is inputted as a parameter as a single value(#Xval = 'Z'). That will return a true evaluation. I am now looking to evaluate the same formula when #Xval may be say 'Z','H' in other words Xval contains those 2 values and Im trying to find if 'Z' is among them.
The same goes for if (in (#Xval,'Z','H','M'),'T','F') where Im looking for the value of Xval in a group of options (Z,H,M).
Can I do this via custom functions? If so how? Any other ideas?
Thank you
You can try
Expression e = new Expression("if (iscontians("ZHM",#Xval),'T','F')", EvaluateOptions.IgnoreCase);
e.EvaluateFunction += evalFunction;
Write a custom function
private void evalFunction(string name, FunctionArgs args)
{
switch (name.ToUpper())
{
case "ISCONTAINS":
if (args.Parameters.Length < 2)
throw new ArgumentException("isContains() takes at least 2 arguments");
args.Result = args.Parameters[0].Evaluate().ToString().Contains(args.Parameters[1].Evaluate().ToString());
break;
default:
break;
}
}

how to return the sum of a value in a table with where clause in grails 2.5.0

Domain class:
class Transaction {
String roundId
BigDecimal amount
:
}
The SQL we wish to execute the following:
"select sum(t.amount) from transaction t where t.roundId = xxx"
We have been unable to find an example which does not return Transaction rows.
We assume there are two approaches:
Use projections and/or criteria etc? All the examples we have found only return lists of transaction rows, not the sum.
Use raw SQL. How do we call SQL, and get a handle on the BigDecimal it returns?
I tried this:
class bla{
def sessionFactory
def someMethod() {
def SQLsession = sessionFactory.getCurrentSession()
def results = SQLsession.createSQLQuery("select sum(t.credit) from transaction t where t.round_id = :roundId", [roundId: roundId])
But this fails with
groovy.lang.MissingMethodException: No signature of method: org.hibernate.internal.SessionImpl.createSQLQuery() is applicable for argument types: (java.lang.String, java.util.LinkedHashMap)
Also, I have no idea what the return type would be (cant find any documentation). I am guessing it will be a list of something: Arrays? Maps?
==== UPDATE ====
Found one way which works (not very elegant or grails like)
def SQLsession = sessionFactory.getCurrentSession()
final query = "select sum(t.credit) from transaction t where t.round_id = :roundId"
final sqlQuery = SQLsession.createSQLQuery(query)
final results = sqlQuery.with {
setString('roundId', roundId)
list() // what is this for? Is there a better return value?
}
This seems to return an array, not a list as expected, so I can do this:
if (results?.size == 1) {
println results[0] // outputs a big decimal
}
Strangely, results.length fails, but results.size works.
Using Criteria, you can do
Transaction.withCriteria {
eq 'roundId', yourRoundIdValueHere
projections {
sum 'amount'
}
}
https://docs.jboss.org/hibernate/core/3.3/api/org/hibernate/classic/Session.html
Query createSQLQuery(String sql, String[] returnAliases, Class[] returnClasses)
Query createSQLQuery(String sql, String returnAlias, Class returnClass)
The second argument of createSQLQuery is one or more returnAliases and not meant for binding the statement to a value.
Instead of passing your values in the 2nd argument, use the setters of your Query object i.e. setString, setInteger, etc.
results.setInteger('roundId',roundId);

Passing a list to SQL each row call Groovy

I am currently rendering a list of sql rows from a database using:
Sql sql = new Sql(dataSource)
def list = []
def index = 0
params.mrnaIds.each { mrnaName ->
sql.eachRow ("select value from patient_mrna where mrna_id=$mrnaId") { row ->
list[index] = row.value
index++
}
}
render list
However I would like to avoid assigning the values to a list before rendering them.
The variable params.mrnaIds is coming from a multi select input, so it could either be a single string or a string array containing ids. Is there a way to iterate through these ids inside the eachRow method?
I would like to be able to execute something like:
render sql.eachRow ("select value from patient_mrna where mrna_id=?", params.mrnaIds) { row ->
list[index] = row.value
index++
}
But I'm not completely sure that there is a way to call eachRow with this functionality. If there is not, is there some other way to render the results without storing them in a list?
I think you can render each row:
sql.eachRow( someQuery, someParams ){ row ->
render row as JSON
}
There is rows() to return a list instead ok working with it (like eachRow() is used for). It also shares all the different arguments. E.g.:
render sql.rows("select value from patient_mrna where mrna_id=?", params).collect{ it.value }