CouchDB-Why my rerduce is always coming as false ? I am not able to reduce anything properly - mapreduce

I am new to CouchDB. I have a 9 gb dataset loaded into my couchdb. I am able to map everything correctly. But I cannot reduce any of the results using the code written in the reduce column. When i tried log, log shows that rereduce values as false. Do i need to do anything special while doing the Map() or how to set the rereduce value is TRUE??
A sample of my data is as follows:
{
"_id": "33d4d945613344f13a3ee92933b160bf",
"_rev": "1-0425ca93e3aa939dff46dd51c3ab86f2",
"release": {
"genres": {
"genre": "Electronic"
},
"status": "Accepted",
"videos": {
"video": [
{
"title": "[1995] bola - krak jakomo",
"duration": 349,
"description": "[1995] bola - krak jakomo",
"src": "http://www.youtube.com/watch?v=KrELXoYThpI",
"embed": true
},
{
"title": "Bola - Forcasa 3",
"duration": 325,
"description": "Bola - Forcasa 3",
"src": "http://www.youtube.com/watch?v=Lz9itUo5xtc",
"embed": true
},
{
"title": "Bola (Darrell Fitton) - Metalurg (MV)",
"duration": 439,
"description": "Bola (Darrell Fitton) - Metalurg (MV)",
"src": "http://www.youtube.com/watch?v=_MYpOOMRAeQ",
"embed": true
}
]
},
"labels": {
"label": {
"catno": "SKA005",
"name": "Skam"
}
},
"companies": "",
"styles": {
"style": [
"Downtempo",
"Experimental",
"Ambient"
]
},
"formats": {
"format": {
"text": "",
"name": "Vinyl",
"qty": 1,
"descriptions": {
"description": [
"12\"",
"Limited Edition",
"33 ⅓ RPM"
]
}
}
},
"country": "UK",
"id": 1928,
"released": "1995-00-00",
"artists": {
"artist": {
"id": 390,
"anv": "",
"name": "Bola",
"role": "",
"tracks": "",
"join": ""
}
},
"title": 1,
"master_id": 13562,
"tracklist": {
"track": [
{
"position": "A1",
"duration": "4:33",
"title": "Forcasa 3"
},
{
"position": "A2",
"duration": "5:48",
"title": "Krak Jakomo"
},
{
"position": "B1",
"duration": "7:50",
"title": "Metalurg 2"
},
{
"position": "B2",
"duration": "6:40",
"title": "Balloom"
}
]
},
"data_quality": "Correct",
"extraartists": {
"artist": {
"id": 388200,
"anv": "",
"name": "Paul Solomons",
"role": "Mastered By",
"tracks": "",
"join": ""
}
},
"notes": "Limited to 480 copies.\nA1 is a shorter version than that found on the 'Soup' LP.\nA2 ends in a lock groove."
}
}
My intention is to count the mapped values. My mapping function is as follows:
function(doc){
if(doc.release)
emit(doc.release.title,1)
}
Map results shows around 5800 results
I want to use the following functions in the reduce tab to count:
Reduce:
_count or _sum
It does not give single rounded value. Even i cannot get the simple _count operations right !!! :(
for screenshot,
Please help me !!!

What you got was the sum of values per title. What you wanted, was the sum of values in general.
Change the grouping drop-down list to none.
Check CouchdDB's wiki for more details on grouping.

Related

Can I partially color a bar based on percentage complete on a temporal axis?

I am trying to create a Gantt chart and I want to color a single task with two colors, based on a percentage complete. Say, make the complete part green and the remaining part orange.
How can I achieve this?
Below is a sample code, also available in the editor here.
{
"data": {
"values": [
{"Description": "Task 1", "Start": "2023-01-05", "End": "2023-01-10", "Percentage complete": 0},
{"Description": "Task 2", "Start": "2023-01-01", "End": "2023-01-15", "Percentage complete": 75},
{"Description": "Task 3", "Start": "2023-01-01", "End": "2023-01-03", "Percentage complete": 100}
]
},
"layer": [
{
"mark": "bar",
"encoding": {
"y": {
"field": "Description",
"type": "ordinal",
"stack": null
},
"x": {
"field": "Start",
"type": "temporal"
},
"x2": {
"field": "End",
"type": "temporal"
}
}
}
]
}
The expected result should look like this.
I tried looking at folding, transforming, and scale. But as I am new to Vega-lite, to no avail.
You have two options.
Reshape your data upstream. Your partially coloured bars should be rendered as two bars stacked - one for incomplete and one for complete.
Use Reactive Geometry as described here. This may need Vega rather than VL.
Here it is using reactive geometry.
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"background": "white",
"padding": 5,
"width": 200,
"style": "cell",
"data": [
{
"name": "source_0",
"values": [
{
"Description": "Task 1",
"Start": "2023-01-05",
"End": "2023-01-10",
"Percentatecomplete": 0
},
{
"Description": "Task 2",
"Start": "2023-01-01",
"End": "2023-01-15",
"Percentatecomplete": 0.75
},
{
"Description": "Task 3",
"Start": "2023-01-01",
"End": "2023-01-03",
"Percentatecomplete": 1
}
]
},
{
"name": "data_0",
"source": "source_0",
"transform": [
{"type": "formula", "expr": "toDate(datum[\"Start\"])", "as": "Start"},
{"type": "formula", "expr": "toDate(datum[\"End\"])", "as": "End"},
{
"type": "filter",
"expr": "(isDate(datum[\"Start\"]) || (isValid(datum[\"Start\"]) && isFinite(+datum[\"Start\"])))"
}
]
}
],
"signals": [
{"name": "y_step", "value": 20},
{
"name": "height",
"update": "bandspace(domain('y').length, 0.1, 0.05) * y_step"
}
],
"marks": [
{
"name": "layer_0_marks",
"type": "rect",
"style": ["bar"],
"from": {"data": "data_0"},
"encode": {
"update": {
"fill": {"value": "#4c78a8"},
"x": {"scale": "x", "field": "Start"},
"x2": {"scale": "x", "field": "End"},
"y": {"scale": "y", "field": "Description"},
"height": {"signal": "max(0.25, bandwidth('y'))"}
}
}
},
{
"type": "rect",
"from": {"data": "layer_0_marks"},
"encode": {
"update": {
"x": {"field": "x"},
"y": {"field": "y"},
"fill": {"value": "red"},
"width": {"signal": "(datum.x2 - datum.x) * datum.datum.Percentatecomplete"},
"height": {"signal": "max(0.25, bandwidth('y'))"}
}
}
}
],
"scales": [
{
"name": "x",
"type": "time",
"domain": {"data": "data_0", "fields": ["Start", "End"]},
"range": [0, {"signal": "width"}]
},
{
"name": "y",
"type": "band",
"domain": {"data": "data_0", "field": "Description", "sort": true},
"range": {"step": {"signal": "y_step"}},
"paddingInner": 0.1,
"paddingOuter": 0.05
}
],
"axes": [
{
"scale": "x",
"orient": "bottom",
"gridScale": "y",
"grid": true,
"tickCount": {"signal": "ceil(width/40)"},
"domain": false,
"labels": false,
"aria": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
},
{
"scale": "x",
"orient": "bottom",
"grid": false,
"title": "Start, End",
"labelFlush": true,
"labelOverlap": true,
"tickCount": {"signal": "ceil(width/40)"},
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"grid": false,
"title": "Description",
"zindex": 0
}
]
}

Power BI - Deneb chart showing tooltips in reverse

I've created a simple stacked bar chart in Deneb where the user can highlight in place: x-axis is group, highlight is tiers. I've also created a tooltip that should show the name for each bar and should match the label on the bar. What's strange is that the tooltip shows in reverse order: pointing to A shows D, F shows E, etc. (See this pbix file.) I've attempted to insert sorting to the bars; that didn't work. My preference is to have the bars remain as they are and the tooltips show to match; however, it would be ok (less desirable) to reverse the order of the bars. How can I get the tooltip to match the label?
This cleaned up spec works.
Don't forget to accept the answer if this solves your problem.
{
"data": {"name": "dataset"},
"transform": [
{
"stack": "test2",
"as": ["a", "b"],
"groupby": ["group"]
}
],
"layer": [
{
"mark": {
"type": "bar",
"stroke": "black",
"strokeWidth": 1,
"opacity": 0.3
},
"encoding": {
"color": {
"field": "group",
"type": "nominal",
"scale": {
"domain": [
"Low",
"Med",
"High"
],
"range": [
"#e15759",
"#ffff00",
"#59a14f"
]
},
"legend": null
}
}
},
{
"mark": {
"type": "bar",
"stroke": "black",
"strokeWidth": 1,
"tooltip": true
},
"encoding": {
"color": {
"field": "group",
"type": "nominal",
"scale": {
"domain": [
"Low",
"Med",
"High"
],
"range": [
"#e15759",
"#ffff00",
"#59a14f"
]
},
"legend": null
},
"opacity": {
"condition": {
"test": "datum['test2__highlight']!=null",
"value": 1
},
"value": 0
}
}
},
{
"mark": {
"type": "text",
"color": "black",
"dy": -90
},
"encoding": {
"text": {"field": "name"}
}
}
],
"encoding": {
"y": {
"field": "a",
"type": "quantitative",
"axis": {
"title": "Number of Projects",
"tickMinStep": 1
}
},
"y2": {"field": "b"},
"x": {
"field": "group",
"type": "nominal",
"axis": {
"title": null,
"labelAngle": 0
}
}
}
}

"Buffalo" query fails to return "Buffalo Exchange" from /discover endpoint

NOTE: this question is specifically for support staff of the HERE Developer API because they ask freemium users to post support questions on Stack Overflow rather than trying to contact them directly. If you're not a member of their staff and you're unable to help or if the question is unclear to you, don't worry about it. :)
For some reason the /discover endpoint doesn't return the "Buffalo Exchange" place that's at my specified coordinates, but only returns 2 localities that are much further away. This is the query that I'm using: https://discover.search.hereapi.com/v1/discover?at=34.003975%2C-118.484823&q=Buffalo&limit=20&apiKey=<insert API KEY>. These are the results I currently receive:
{
"items": [
{
"title": "Buffalo, NY, United States",
"id": "here:cm:namedplace:21018816",
"resultType": "locality",
"localityType": "city",
"address": {
"label": "Buffalo, NY, United States",
"countryCode": "USA",
"countryName": "United States",
"stateCode": "NY",
"state": "New York",
"county": "Erie",
"city": "Buffalo",
"postalCode": "14202"
},
"position": {
"lat": 42.88544,
"lng": -78.87846
},
"distance": 3551940,
"mapView": {
"west": -78.9168,
"south": 42.82603,
"east": -78.79492,
"north": 42.96651
}
},
{
"title": "Buffalo City, Eastern Cape, South Africa",
"id": "here:cm:namedplace:23402337",
"resultType": "locality",
"localityType": "city",
"address": {
"label": "Buffalo City, Eastern Cape, South Africa",
"countryCode": "ZAF",
"countryName": "South Africa",
"state": "Eastern Cape",
"county": "Buffalo City",
"city": "Buffalo City",
"postalCode": "5201"
},
"position": {
"lat": -33.0148,
"lng": 27.9038
},
"distance": 16910944,
"mapView": {
"west": 27.15745,
"south": -33.28749,
"east": 28.08053,
"north": -32.674
}
}
]
}
You can see that for both places the resultType is "locality".
Now compare that to the first result of a similar query that searches for the term "Exchange" instead of "Buffalo". All other query params are the same. This is the URL: https://discover.search.hereapi.com/v1/discover?at=34.003975%2C-118.484823&q=Exchange&limit=20&apiKey=<insert API KEY>, and this is how the results begin (not shown fully because there are many results):
{
"items": [
{
"title": "Buffalo Exchange",
"id": "here:pds:place:8403fv6k-b15f290ec4f409deea99318f7388bbd6",
"resultType": "place",
"address": {
"label": "Buffalo Exchange, 2449 Main St, Santa Monica, CA 90405, United States",
"countryCode": "USA",
"countryName": "United States",
"stateCode": "CA",
"state": "California",
"county": "Los Angeles",
"city": "Santa Monica",
"district": "City of Santa Monica",
"street": "Main St",
"postalCode": "90405",
"houseNumber": "2449"
},
"position": {
"lat": 34.00342,
"lng": -118.48483
},
"access": [
{
"lat": 34.00331,
"lng": -118.48493
}
],
"distance": 61,
"categories": [
{
"id": "600-6800-0090",
"name": "Women's Apparel",
"primary": true
},
{
"id": "600-6800-0000",
"name": "Clothing & Accessories"
},
{
"id": "600-6800-0089",
"name": "Men's Apparel"
},
{
"id": "600-6900-0251",
"name": "Used/Second-hand Merchandise Stores"
}
],
"references": [
{
"supplier": {
"id": "core"
},
"id": "1211447153"
},
{
"supplier": {
"id": "yelp"
},
"id": "5PzeN6hGLBPmJpCJ2ZmfCQ"
}
],
"contacts": [
{
"phone": [
{
"value": "+13103147300"
},
{
"value": "+13103924301",
"categories": [
{
"id": "600-6800-0000"
}
]
}
],
"fax": [
{
"value": "(520) 622-7015",
"categories": [
{
"id": "600-6800-0000"
}
]
}
],
"www": [
{
"value": "http://www.buffaloexchange.com",
"categories": [
{
"id": "600-6800-0000"
},
{
"id": "600-6900-0251"
}
]
}
],
"email": [
{
"value": "contact#bufex.com",
"categories": [
{
"id": "600-6800-0000"
}
]
}
]
}
],
"openingHours": [
{
"categories": [
{
"id": "600-6800-0000"
}
],
"text": [
"Mon-Sun: 11:00 - 20:00"
],
"isOpen": false,
"structured": [
{
"start": "T110000",
"duration": "PT09H00M",
"recurrence": "FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR,SA,SU"
}
]
},
{
"categories": [
{
"id": "600-6800-0090"
},
{
"id": "600-6900-0251"
}
],
"text": [
"Mon-Sat: 11:00 - 20:00",
"Sun: 11:00 - 19:00"
],
"isOpen": false,
"structured": [
{
"start": "T110000",
"duration": "PT09H00M",
"recurrence": "FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR,SA"
},
{
"start": "T110000",
"duration": "PT08H00M",
"recurrence": "FREQ:DAILY;BYDAY:SU"
}
]
}
]
},
...
}
You can see that the first result has the name "Buffalo Exchange" and the "resultType" is "place". This is the result I want. The question is why does this result fail to show up when the search query is "Buffalo"? Of course with the /discover endpoint I can't specify the category IDs I want to search, that's only available via the /browse endpoint. But with the /browse endpoint I can't specify a specific search term like "Buffalo" or "Exchange".
Update: this problem also happens with the "Bison" query in Alberta, Canada. The query for this is https://discover.search.hereapi.com/v1/discover?at=56.745531%2C-111.351341&q=Exchange&limit=20&apiKey=<insert API KEY>. This query yields only 10 results, and only 4 of them have resultType of "place".
We recommend application developers to use both Autosuggest and Discover, you get the nearby Buffalo Exchange because Autosuggest considers that the query is incomplete. Note that Discover considers the query to be complete.
As HERE Geocoding and Search is meant to provide relevant responses to user queries.
Geocoding Search Api (Autosuggest): https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics/endpoint-autosuggest-brief.html
Geocoding Search Api (Discover): https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics/endpoint-discover-brief.html
The above-mentioned user guide can help modify the query for accurate results.

Elastic Search Sort

I have a table for some activities like
[
{
"id": 123,
"name": "Ram",
"status": 1,
"activity": "Poster Design"
},
{
"id": 123,
"name": "Ram",
"status": 1,
"activity": "Poster Design"
},
{
"id": 124,
"name": "Leo",
"categories": [
"A",
"B",
"C"
],
"status": 1,
"activity": "Brochure"
},
{
"id": 134,
"name": "Levin",
"categories": [
"A",
"B",
"C"
],
"status": 1,
"activity": "3D Printing"
}
]
I want to get this data from elastic search 5.5 by sorting on field activity, but I need all the data corresponding to name = "Ram" first and then remaining in a single query.
You can use function score query to boost the result based on match for the filter(this case ram in name).
Following query should work for you
POST sort_index/_search
{
"query": {
"function_score": {
"query": {
"match_all": {}
},
"boost": "5",
"functions": [{
"filter": {
"match": {
"name": "ram"
}
},
"random_score": {},
"weight": 1000
}],
"score_mode": "max"
}
},
"sort": [{
"activity.keyword": {
"order": "desc"
}
}]
}
I would suggest using a bool query combined with the should clause.
U will also need to use the sort clause on your field.

Hypen in response data is throwing error when setting as global variable for nested response

I have a post man request. Which returns a response data as:
[
{
"id": "7ca27c09-2b67-417e-b367-f97d49824a2f",
"tags": [],
"type": "ApplicationProfile",
"userId": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"profile": {
"User-Profile": {
"PHI": {
"gender": "Male",
"surgeryDate": {
"value": "2017-06-06"
},
"surgeryType": {
"value": "gastricBand"
},
"heightInches": "72",
"approvalPhase": "2",
"profileImageUrl": "",
"motivationalImageUrl": ""
},
"PII": {
"mail": "c11#c111.com",
"lastName": "",
"firstName": "name1",
"shouldReceiveNotifications": true
}
},
"motivationalGoals": [
{
"goal": "Improving health",
"goalId": "2957"
},
{
"goal": "Relieving pain",
"goalId": "2958"
},
{
"goal": "Feeling better",
"goalId": "2960"
}
]
},
"version": 35,
"createdBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"lastModifiedBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"applicationName": "Health Partner",
"createdDateTime": "2017-06-08T16:08:32.497Z",
"lastModifiedDateTime": "2017-06-09T13:23:03.503Z"
},
{
"id": "091b5ebd-b096-436e-a703-f97f0ae77baf",
"tags": [
"Application-Profile"
],
"type": "ApplicationProfile",
"userId": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"profile": {
"User-Profile": {
"PHI": {
"gender": "",
"surgeryDate": {
"value": "2017-06-01"
},
"surgeryType": {
"value": ""
},
"heightInches": "72",
"approvalPhase": "2",
"profileImageUrl": "",
"motivationalImageUrl": ""
},
"PII": {
"mail": "c11#c111.com",
"lastName": "Dev",
"firstName": "Kat",
"shouldReceiveNotifications": true
}
},
"motivationalGoals": [
{
"goal": "Improving health",
"goalId": "2957"
},
{
"goal": "Relieving pain",
"goalId": "2958"
},
{
"goal": "Feeling better",
"goalId": "2960"
}
]
},
"version": 41,
"createdBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"lastModifiedBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"applicationName": "Health Partner Weightloss",
"createdDateTime": "2017-06-03T16:19:57.811Z",
"lastModifiedDateTime": "2017-06-08T16:07:49.555Z"
}
]
I need to extract the value of the emailid and set as global variable.
here is my code:
var jsonData1 = JSON.parse(responseBody);
postman.setGlobalVariable("jsonData1",jsonData1.profile.User-Profile.PII.mail);
But I am getting error. "User is undefined".
The problem here is that the hyphen / minus sign is interpreted as the subtraction operator.
Consider changing your API and using "userProfile" instead of "User-Profile".