How to filter nested fields in rethinkdb - rethinkdb

How to query and return all channels with matching channelId, from a document:
As an example, my rethink table contains the following document:
{
"agreement_id": "5",
"channels": [
{
"channelId": "8deb-6b37-4678115-917d-ad365ae57e19",
"lab_cost": 333,
"learner_cost": 30,
"net_revenue": 20.87,
"orgId": "gmudam",
"publisher": "oci-jumpstart",
"publisher_revenue": 4.97,
"ql_revenue": 16.9,
"realm_cost": 1.13
},
{
"channelId": "8deb-6b37-4678115-917d-ad365ae57e19",
"lab_cost": 444,
"learner_cost": 30,
"net_revenue": 20.87,
"orgId": "gmudam",
"publisher": "oci-jumpstart",
"publisher_revenue": 4.97,
"ql_revenue": 16.9,
"realm_cost": 1.13
}
]
}

To extract all channels by channelId from a document, you can do the following:
r.db("DB").table("TABLE").get("agreement_id")("channels")
.filter(function(channel){
return channel("channelId").eq("8deb-6b37-4678115-917d-ad365ae57e19")})
This will give you all channels with the id "8deb-6b37-4678115-917d-ad365ae57e19". E.g:
[
{
"channelId": "8deb-6b37-4678115-917d-ad365ae57e19",
"lab_cost": 333,
"learner_cost": 30,
"net_revenue": 20.87,
"orgId": "gmudam",
"publisher": "oci-jumpstart",
"publisher_revenue": 4.97,
"ql_revenue": 16.9,
"realm_cost": 1.13
},
{
"channelId": "8deb-6b37-4678115-917d-ad365ae57e19",
"lab_cost": 444,
"learner_cost": 30,
"net_revenue": 20.87,
"orgId": "gmudam",
"publisher": "oci-jumpstart",
"publisher_revenue": 4.97,
"ql_revenue": 16.9,
"realm_cost": 1.13
}
]

Related

Can't get severity info via API

Java 11
SonarQube 8.9.2 LTS
For my java project the SonarQube show the next issues info:
Severity
Blocker 1.3k
Minor 1.1k
Critical 5.8k
Info 233
Major 1.3k
So I need to get this information via SonarQube WEB API.
I found only this api method:
GET http://some_url_sonar_qube/api/issues/search
And its return all issues on page = 1
And its return all issues on page = 1 with detail info
{
"total": 10049,
"p": 1,
"ps": 100,
"paging": {
"pageIndex": 1,
"pageSize": 100,
"total": 10049
},
"effortTotal": 50995,
"issues": [
{
"key": "dddd",
"rule": "css:S4670",
"severity": "CRITICAL",
...
This:
GET http://some_url_sonar_qube/api/issues/search?p=2
And its return all issues on page = 2
and so on.
Response example:
As you can see has 10049 issues. It's 100 pages.
But I need summary info. Smt like this in json format:
{
"Severity": {
"Blocker": 1300,
"Minor": 1100,
"Critical": 5800,
"Info": 233,
"Major": 1300
}
}
I'm not found api method for this
I found solution (thanks for #gawkface)
Use this method:
GET http://some_url_sonar_qube/api/issues/search?componentKeys=my_project_key&facets=severities
And here result (on section facets)
{
"total": 10049,
"p": 1,
"ps": 100,
"paging": {
"pageIndex": 1,
"pageSize": 100,
"total": 10049
},
"effortTotal": 50995,
"issues": [...],
"components": [...],
"facets": [
{
"property": "severities",
"values": [
{
"val": "CRITICAL",
"count": 5817
},
{
"val": "MAJOR",
"count": 1454
},
{
"val": "BLOCKER",
"count": 1286
},
{
"val": "MINOR",
"count": 1161
},
{
"val": "INFO",
"count": 331
}
]
}
]
}

October cms file attachment with only path?

I'm a new in October CMS. Now i have an issue with file attachment. In Model :
public $attachOne = [
'cover_image' => ['System\Models\File']
];
Now in controller :
$comic = Comic::with('cover_image)->find($id);
it return:
{
"id": 24,
"title": "Comic example detail",
"description": "Comic example detail",
"total_page": "14",
"cover_image": {
"id": 165,
"disk_name": "5d5a21ca68bf9280597931.png",
"file_name": "img06.png",
"file_size": 142958,
"content_type": "image/png",
"title": null,
"description": null,
"field": "cover_image",
"sort_order": 165,
"created_at": "2019-08-19 04:12:58",
"updated_at": "2019-08-19 04:15:23",
"path": "http://localhost:10080/storage/app/uploads/public/5d5/a21/ca6/5d5a21ca68bf9280597931.png",
"extension": "png"
}
}
I want cover_image return only some field, like below:
"cover_image": {
"id": 165,
"file_name": "img06.png",
"path": "http://localhost:10080/storage/app/uploads/public/5d5/a21/ca6/5d5a21ca68bf9280597931.png",
}
how can i do it?
use constraint eager loading
see in the doc https://octobercms.com/docs/database/relations#constraining-eager-loads
it is explained with where statement but you can use select statement and you can get only required attributes.
I am sure it will help you.

Elasticsearch Nest Getting and updating a single Document

I would like to be able to select a single document here is a sample of how a document looks
{
"_index": "myindex_products",
"_type": "product",
"_id": "8Wct9mEBlkDZwzEMRfbG",
"_version": 1,
"_score": 1,
"_source": {
"productId": 5749,
"name": "Product Name Here",
"productCode": "PRODCODE",
"productCategoryId": 73,
"length": 6,
"height": 0,
"productTypeId": 1,
"url": "product-name-here",
"productBrandId": 7,
"width": 0,
"dispatchTimeInDays": 10,
"leadTimeInDays": 6,
"stockAvailable": 0,
"weightKg": 0.001,
"reviewRating": 5,
"reviewRatingCount": 17,
"limitedStock": false,
"price": 16.3,
"productImage": "28796-14654.jpg",
"productCategory": {
"productCategoryId": 73,
"name": "Accessories - New",
"fullPath": "Accessories - New",
"code": "00057"
},
"productSpecification": [
{
"productSpecificationId": 127151,
"productId": 5749,
"specificationId": 232,
"name": "Brand",
"value": "Brand1"
}
,
{
"productSpecificationId": 127175,
"productId": 5749,
"specificationId": 10,
"name": "Guarantee",
"value": "10 years"
}
]
}
}
_id is being generated when I index so I don't know this at the point I want to update. I have the productId value and I would like to use this to select a document to then update/delete is there a way to return a single document if you know a particular exact value.
Thanks
While indexing, you can use something like PUT your_index/5749 (5749 being your product id) and ES will use its value for the _id field instead of auto-generating it.

"Creating Apps in Kivy" openweathermap API Key Error

That's my first stackoverflow question.
I started with kivy and bought the book "Crating Apps in Kivy" from Dusty Phillips and all went well till he got to the openweatherapp chapter. (Which after a search other users had problems too...)
There you use the Openweather API to search for a location with a button and it should print the results in a list.
It's not the original code anymore. Others pointed out that the Link to the website changed, you have to use the API key. Of course I linked it correctly, I just typed "myAPIKey" here so it's not accesssable. The JSOn File on the bottom is what the site prints!
Also, the book formated cities in found location like that: d['name], d['sys']['country'] which I guess was also wrong, maybe the site changed here too?
My problem is that the UrlRequest from kivy doesn't seem to load anything. Or the iteration in found location is wrong, I don't know. It always says "KeyError: city" And I guess it's because it doesn't read it correctly at all. I tried a different approach with the python class requests - and it works perfectly fine! But I still want to know why this solution doesn't work.
My Questions: Where is my error with the json iteration? I have really problems with understanding because I'm also new to python.
Also: Why is request in the methode head? Where is it used?
Here the code from the book (I hope everything is typed correctly. If there is still an error with variables please point it out but I typed the code multiple times - my problem will probably be somewhere else...):
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.network.urlrequest import UrlRequest
import json
class AddLocationForm(BoxLayout):
search_input = ObjectProperty()
search_results = ObjectProperty()
def search_location(self):
search_template = "http://api.openweathermap.org/data/2.5/forecast/daily?APPID=myAPIKey=" + "{}"
search_url = search_template.format(self.search_input.text)
request = UrlRequest(search_url, self.found_location)
def found_location(self, request, data):
data = json.loads(data.decode()) if not isinstance(data, dict) else data
cities = ["{} ({})".format(d["city"]["name"], d["city"]["country"])for d in data["list"]]
self.search_results.item_strings = cities
KV File:
AddLocationForm:
<AddLocationForm>:
orientation: "vertical"
search_input: search_box
search_results: search_results_list
BoxLayout:
height: "40dp"
size_hint_y: None
TextInput:
id: search_box
size_hint_x: 50
Button:
text: "Search"
size_hint_x: 25
on_press: root.search_location()
Button:
text: "Current Location"
size_hint_x: 25
ListView:
id: search_results_list
item_strings: []
JSON File:
{
"city": {
"id": 2761369,
"name": "Vienna",
"coord": {
"lon": 16.37208,
"lat": 48.208488
},
"country": "AT",
"population": 0
},
"cod": "200",
"message": 0.0098,
"cnt": 7,
"list": [{
"dt": 1476439200,
"temp": {
"day": 285.58,
"min": 283.71,
"max": 285.58,
"night": 283.71,
"eve": 285.43,
"morn": 285.58
},
"pressure": 985.46,
"humidity": 73,
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}],
"speed": 7.16,
"deg": 154,
"clouds": 0
}, {
"dt": 1476525600,
"temp": {
"day": 287.33,
"min": 282.7,
"max": 291.08,
"night": 285.72,
"eve": 291.01,
"morn": 283.35
},
"pressure": 983.21,
"humidity": 71,
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"speed": 4.51,
"deg": 150,
"clouds": 32,
"rain": 0.23
}, {
"dt": 1476612000,
"temp": {
"day": 286.88,
"min": 283.94,
"max": 287.15,
"night": 283.94,
"eve": 286.44,
"morn": 286.26
},
"pressure": 989.94,
"humidity": 98,
"weather": [{
"id": 501,
"main": "Rain",
"description": "moderate rain",
"icon": "10d"
}],
"speed": 4.36,
"deg": 315,
"clouds": 92,
"rain": 5.51
}, {
"dt": 1476698400,
"temp": {
"day": 287.39,
"min": 283.49,
"max": 287.39,
"night": 284.89,
"eve": 285.05,
"morn": 283.49
},
"pressure": 984.76,
"humidity": 0,
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"speed": 1.64,
"deg": 132,
"clouds": 69,
"rain": 1.55
}, {
"dt": 1476784800,
"temp": {
"day": 285.91,
"min": 283.52,
"max": 285.91,
"night": 283.52,
"eve": 284.45,
"morn": 284.18
},
"pressure": 982.64,
"humidity": 0,
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"speed": 3.23,
"deg": 137,
"clouds": 81,
"rain": 2.4
}, {
"dt": 1476871200,
"temp": {
"day": 283.71,
"min": 282.37,
"max": 283.71,
"night": 282.37,
"eve": 282.52,
"morn": 282.59
},
"pressure": 978.26,
"humidity": 0,
"weather": [{
"id": 502,
"main": "Rain",
"description": "heavy intensity rain",
"icon": "10d"
}],
"speed": 2.68,
"deg": 128,
"clouds": 96,
"rain": 14.37
}, {
"dt": 1476957600,
"temp": {
"day": 286.52,
"min": 282.13,
"max": 286.52,
"night": 282.13,
"eve": 282.72,
"morn": 282.19
},
"pressure": 975.05,
"humidity": 0,
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"speed": 1.47,
"deg": 173,
"clouds": 13,
"rain": 2.83
}]
}
Btw, it's not a duplicate from how do i use json api in my kivy program becaue it didn't really help... The code doesn't work anymore because the API changed.
(If anyone finds this question and is looking for a working URL reader, here is my code. Don't forget to import requests)
def search_location(self):
#Get URL From Weather API + Input
search_template = "http://api.openweathermap.org/data/2.5/forecast/daily?APPID='enteryourweatherAPIKeyhere'&q=" + "{}"
search_url = search_template.format(self.search_input.text)
#Reads the Website and saves it in a string
urlresults = (requests.get(search_url)).text
#Converts Json to Python Dictionary
urlresults = json.loads(urlresults)
cities = ["{} ({})".format(urlresults["city"]["name"], urlresults["city"]["country"])]
Go to this page:
http://openweathermap.org/faq#error401
the API now requires a key. After registering on openweathermap, a key will be mailed to you. Replace the current URL with the one given in the mail.
This worked for me.

Configuring line charts with remote data in Kendo UI

I am looking to render a line chart using Kendo UI. http://demos.telerik.com/kendo-ui/line-charts/remote-data-binding
It expects the json data to be directly an array like in the format (from their example):
[
{
"date": "12/30/2011",
"close": 405,
"volume": 6414369,
"open": 403.51,
"high": 406.28,
"low": 403.49,
"symbol": "2. AAPL"
},
{
"date": "11/30/2011",
"close": 382.2,
"volume": 14464710,
"open": 381.29,
"high": 382.276,
"low": 378.3,
"symbol": "2. AAPL"
}
]
However, I have a URL that returns the data in the following format. Note the extra object 'ranks' at the beginning which has the array:
{
"ranks": [
{
"id": 2,
"rank": 3,
"rankdate": "2015-05-17T00:00:00+0000",
"student": {
"id": 203,
"name": "Student1",
"currentRank": 3,
"LastVerified": "2015-05-17T22:30:00+0000"
}
},
{
"id": 1,
"rank": 4,
"rankdate": "2015-05-16T00:00:00+0000",
"student": {
"id": 203,
"name": "Student1",
"currentRank": 3,
"LastVerified": "2015-05-17T22:30:00+0000"
}
}
]
}
I was wondering if there was a way to have the datasource look inside "ranks" for the array instead of expecting it directly.
Found it. One can customize the schema in Kendo for the datasource using:
schema: {
data: "ranks"
},

Resources