Using DateTime in Polymer Google Web Components - google-visualization

I'm using the google-chart component and want to use a DateTime in one of my columns. I can't figure out how to pass the value in though. My code looks like this:
<google-chart
type='line'
options='{"legend": "none"}'
cols='[{"label":"Dates", "type": "datetime"}, {"label":"Numbers", "type": "number"}]'
rows='[["2012-03-19T07:22:00Z", 73628]]'>
</google-chart>
The "DateTime" in the code above is my latest try, which also doesn't work. I've tried multiple different versions (e.g. "2012-04-21T18:25:43-05:00", DateTime("Mon, 25 Dec 1995 13:30:00 GMT"),...).
All failed with the following error message:
Error: Type mismatch. Value 2012-03-19T07:22:00Z does not match type datetime in column index 0
I would highly appreciate if someone could tell me how to pass in a value.

Live example, as Plunk or JSbin, would help mostly to answer the question.
But, generally you need to convert the value to date type:
...
rows='[[rows_date, 73628]]'>
...
<script>
Polymer({
rows_date: new Date(),
//or
domReady: function(){
this.rows_date = new Date(this.rows_date);
},
});
</script>
Values in attributes are always strings. If you want Polymer to
convert an attribute string to another type, you have to hint the type
you want.

Related

Invalid filter value on Power BI chart

I'm using a Power BI embedded chart, with filters passed in from Javascript. Because of the way the filters are defined in a database, there is a possibility that a filter could be applied with the wrong type (a string supplied for a filter that's expecting a integer, for example). If this happens then the filter is invalid, and not applied, meaning a user can potentially see information that they shouldn't.
The code for setting up the chart is:
var powerBiDashboard = powerbi.load(embedContainer, config);
powerBiDashboard.on('error', function () {
console.log('error');
});
powerBiDashboard.on('loaded', function (event) {
console.log('Loaded');
powerBiDashboard.setFilters(
[{ $schema: "http://powerbi.com/product/schema#basic",
filterType: 1,
target:
{ table: "DummyData", column: "Count" },
operator: "In",
values: ["150"],
displaySettings: { isLockedInViewMode: true }
}])
.catch(function (errors) {
console.log(errors);
});
powerBiDashboard.render();
});
(note the incorrect value of "150" for the integer filter)
This produces a chart with this in the filter:
...instead of:
If this happens, I want to not display the chart, and instead navigate away to an error page.
So... how can I tell if the filter is invalid? The error event doesn't get fired on the powerBiDashboard object, and the catch on the setFilters method call doesn't get executed either. And I can't find any properties on the powerBiDashboard object that would help.
Thanks.
First of all, Power BI JS filters are not recommended to be used with sensitive data. Instead, apply RLS on report.
As of today, the Power BI JS does not have this feature where invalid filter values throw exceptions. The Power BI Embedded team is aware of this scenario and they will add support for it in future releases.
To circumvent the scenario today, you can check the type of value before applying and accordingly show warnings/errors to users.
Visit docs for more details about applying filters using Power BI JavaScript.

Azue Map Search: unique ID and normalized name

I use azure maps for cities autocomplete on my site.
I use this API method: https://learn.microsoft.com/en-us/rest/api/maps/search/getsearchaddress
Request: https://atlas.microsoft.com/search/address/json?params and parameters are:
query=mosco - I'm looking for Moscow
typehand=true
api-version=1.0
subscription-key=...my key...
Result is
{
...
results: [
{
type: "Geography",
id: "RU/GEO/p0/116970,
...
address: {
municipality: "Moscow",
countryCode: "RU",
freeformAddress: "Moscow"
}
},
...
],
}
Ok, it's Moscow.
But I have a few questions.
What is id? Doc say it is "property id". It is persistent? Moscow will always be "116970"?
How can I get normalize name of a city?
I can write "Москва" (Moscow in Russian) and it works and id is same, but names in the object address are different (Москва, Moscow).
If I write "mos" then id is same but address is "Moskva" (instead Moscow).
Can I get name of a geo object by id?
This is a unique id but is not guaranteed to be persistent. The main purpose of this id is for debugging purposes.
We are aware of the "en" issue and are updating the docs.
I sure this is a unique ID, but want proof from documentation :)
Problem solved by parameter language=en-GB now result always is "Moscow". I was misled by the manual when specified only en (it leads to error). https://learn.microsoft.com/en-us/azure/azure-maps/supported-languages

Exact field input mongoose for nodejs

I've recently been attempting to pull my hair out getting stuck on what I would call a trivial issue.
The way mongoose in nodejs handles the specific field inputs. I have a specific issue where mongoose is not doing the same as mongodb is doing.
The issue is the following, if I use a "-" symbol in my field name, mongoose seems to run some weird operation on it, instead of accepting it as part of a string.
I've tried running several regex commands, some / escapes, however it should literally just take the input, as I know the specific data I'm looking for.
The code causing the issue is the following:
datapoints.find({type: "charging-type", device: device._id})
.exec(function(err, objects){
if(!objects){
log("Can't find objects");
}
});
Going straight into mongo shell and typing:
db.datapoints.count({type: "charging-type", device: device._id})
taking out the type makes everything work, changing the type to for example: shuntvoltage, current, ... all work perfectly.
The problem thus occurs with the usage of this - symbol.
What would be the way to enter this inputstring with a special character as an exact string?
Any help would be much appreciated.
Edit as per request; I don't get any error, I get objects==undefined (or !objects), schema is below.
var datapointSchema = mongoose.Schema({
type: { type: String, lowercase: true},
value: { type: Number},
timestamp: { type: Number},
device: { type: ObjectId, ref: "devices"}
});
module.exports = mongoose.model('datapoints', datapointSchema)
Manually updated the field in mongodb from charging-status to chargingstatus, as no useful answer was produced.
It's a workaround and should be considered unresolved.
Final code ended up looking as such:
var cursor = calcpoints.find({device: device._id}).where('type').equals('chargingstatus').sort({timestamp: 1}).cursor();

Field expansion with 'since' and 'until' for insights

I'm trying to get a subset of adsets with the corresponding insights for a specific daterange (2015-11-01 to 2015-11-30)
my_campaign_id/?fields=campaign,insights.fields(impressions)
.since(1463752380).until(1463752380)
but I get back
"insights": {
"data": [
{
"impressions": "1470",
"date_start": "2015-11-30",
"date_stop": "2015-12-01"
}
],
which is wrong because it's counting impressions for Dec 1st too, in fact date_stop is "2015-12-01" and not "2015-11-30".
What't the correct way of filtering expanded fields? I couldn't find any other way in the documentation/forums.
The documentation under time_range says that unix timestamp is not supported. You have to use isoformat instead, referring to the local time of you timezone. But I have to admit I have seen an error message that stated that the time had to be defined in isoformat OR unix time.
https://developers.facebook.com/docs/marketing-api/insights/parameters/v2.6
Anyway, try this:
<campaign_id>/insights?fields=impressions&time_range[since]=2015-11-01&time_range[until]=2015-11-30

ember-data with Spring/Hibernate Backend

I am wondering how I can use ember-data working with a Spring/Hibernate Java backend. I would usually use Jackson to return JSON but that does not appear support the specifications required by jsonapi.org.
Currently beans are returned in a hierarchical nature like this.
{
"id" : 1,
"name" : "Bill",
"surname" : "Smith",
"address" : {
"id" : 23,
"number" : 21,
"street" : "Vincent st",
"state" : {
"id" : 44,
"name" : "Victoria"
"abbreviation" : "VIC"
}
"postcode" : 9000
}
}
I am not stuck to this structure and it can be modified to suite jsonapi, however, I can't find any jackson plugin that will serialize/deserialize my objects to the jsonapi specification.
What are my options here? I know that I am able to write my own serializer/deserializer for ember-data but that would be a huge pain, surely there are other people using ember with a java backend.
This looks familiar to an issue I had parsing json with DataFX (using javaFX), json was also generated by Spring...
I ended up returning a Page which wraps your Person and creates some json that is parseable.
Just my 2cts... I added the following requestmapping to my PersonController:
#RequestMapping(value="/persons", method=RequestMethod.GET, headers="Accept=application/json, application/xml")
public #ResponseBody Page<Person> getPersons(
#RequestParam(value="page",required=false,defaultValue="0") String page,
#RequestParam(value="size",required=false,defaultValue="20") String size,
#RequestParam(value="orderby",required=false,defaultValue="name") String orderby){
PersonRepository repository = context.getBean(PersonRepository.class);
final PageRequest pr = new PageRequest( Integer.parseInt(page), Integer.parseInt(size), Direction.ASC, orderby);
Page<Person> persons = (Page<Person>) repository.findAll(pr);
return persons;
}
I'm new to ember and still in the design stages with php as a backend, but I believe I have the same problem and found what looks like a fix. You're right that messing with jackson would be a difficult approach. It seems like it's much easier to make the change on the ember side. This guide (http://lab.empirio.no/emberjs-say-hello-to-apigility.html) discusses creating our own serializer in js based on ember data's ActiveModelSerializer and then modify the RestAdapter. The example is discussing building the standard ToDo app that I'm sure you've seen used as an example already.
The problem is the backend uses this format:
{"name":"Testing","is_completed":false}
While ember uses:
{"todo":{"name":"Testing","is_completed":false}}
Here's some same code:
App.ApplicationSerializer = DS.ActiveModelSerializer.extend({
primaryKey: 'todos_id',
extract: function(store, type, payload, id, requestType) {
this.extractMeta(store, type, payload);
if(payload._embedded)
payload = payload._embedded;
if(requestType == 'updateRecord' || requestType == 'createRecord'){
var data = {};
data[type.typeKey] = payload;
payload = data;
}
var specificExtract = "extract" + requestType.charAt(0).toUpperCase() + requestType.substr(1);
return this[specificExtract](store, type, payload, id, requestType);
}
});
... "we manipulate the payload by extending (copying from the RESTAdapter).
the createRecord-function changes the behavior on the adapter like this: "
createRecord: function(store, type, record) {
var data = {};
var serializer = store.serializerFor(type.typeKey);
serializer.serializeIntoHash(data, type, record, { includeId: true });
return this.ajax(this.buildURL(type.typeKey), "POST", { data: data[type.typeKey] });
},
I'm sure I'm missing a lot here and probably missing some steps since I haven't even tried to build the app yet, but this was a problem I knew I needed to address before I committed to ember and this seems like a viable solution. I hope its a step in the right direction for you anyway.
edit: I know you didn't want to change the format for the sake of sticking to the standard, but there really isn't a standard for JSON APIs and content types yet, not one that's accepted anyway. This guide uses HAL + JSON which doesn't look any different from what I see at jsonapi.org if that's what you were talking about. Regardless, everyone seems to be having this issue regardless of backend language or frameworks.I think the ember team recognizes this and are trying to be flexible. Also, since ember-data is still in beta, I'd be more apt to make the changes there instead of writing the java side to support a changing library. Who knows? Maybe ember-data will have better support for different backends before its 1.0 release, although I haven't heard any mention of it on the roadmap.