Can you limit the scope of the destination expression when using an SSRS LookupSet based on the category in a chart? - ssrs-2012

I have a bar chart which shows the total number of calls received in a contact centre over time. The report user chooses how to group the chart by selecting a parameter “rangeView” which has the options: “D” (Day), “W” (Week), “M” (Month). The user also chooses the date range “StartDate” and “EndDate” which gets passed to the stored proc to retrieve the data.
The dataset “BusyHourStats” contains a row for every hour of each day in the date range and has the following columns:
LABEL_YYYY_MM_DD_HH24 (the hour of the day eg: “2018-01-01 14”)
LABEL_YYYY_MM_DD (day eg: “2018-01-01”)
LABEL_YYYY_WE (week eg: “2018-W01)
LABEL_YYYY_MM (month eg: “2018-01”)
TOTAL_CALLS
The chart series is Sum(TOTAL_CALLS).
The chart Category Group expression uses the rangeView parameter:
=Switch(Parameters!rangeView.Value = "D", Fields!LABEL_YYYY_MM_DD.Value,
Parameters!rangeView.Value = "W", Fields!LABEL_YYYY_WE.Value,
Parameters!rangeView.Value = "M", Fields!LABEL_YYYY_MM
)
This works as expected, grouping the results by Day, Week or Month. No problems with displaying the data in the chart.
Problem:
As a Series tooltip when you hover over the category (which could be a day, week or month) I need to display Max(TOTAL_CALLS.Value) and the day and hour (or days and hours) when that the max total calls occurred. Eg: “Busy hour: 159 calls on 2018-01-03 14, 2018-01-05 16.”
I have been trying to use LookupSet but I’m not sure if this is the best way to go about it. Should a LookupSet be used when the source and destination dataset is the same dataset or is there a smarter/simpler way? My problem as best I understand is that the lookup finds the Max(TOTAL_CALLS.Value) in the source dataset and then matches it on and returns all TOTAL_CALLS.Values in the entire destination dataset (which includes all the data between the StartDate and EndDate). What I need is to have the lookup only match on the values that align with the category (day, week or month) which is being hovered over.
Is there are way to limit the scope of the destination expression in the lookup based on the current category being hovered over in the chart?
What I have got so far in the Series tooltip is (simplified for this example):
="Busy hour: " & Max(Fields!TOTAL_CALLS.Value) & "calls on " &
Join(LookupSet(Max(Fields!TOTAL_CALLS.Value),
Fields!TOTAL_CALLS.Value,
Fields!LABEL_YYYY_MM_DD_HH24.Value),
"BusyHourStats"), ", ")
which returns all the matching TOTAL_CALLS values in the dataset. What I need to work out is how to do something that equates to:
="Busy hour: " & Max(Fields!TOTAL_CALLS.Value) & "calls on " &
Join(LookupSet(Max(Fields!TOTAL_CALLS.Value),
Fields!TOTAL_CALLS.Value *<where scope equals the category being hovered over such as “2018 01” or “2018-W01”>*,
Fields!LABEL_YYYY_MM_DD_HH24.Value),
"BusyHourStats"), ", ")
I’m not sure if I am wasting my time trying to get the results I need by using LookupSet. Is there a more appropriate function/method I should be using or can it be done this way?
Edit: Attaching image. I have also provided the exact tooltip expression below which aligns with the tooltip shown in the image:
=Switch(
Parameters!rangeView.Value = "D", "Date: " & Fields!CAL_DAY_NUM_IN_MONTH.Value & Switch(
(Fields!CAL_DAY_NUM_IN_MONTH.Value = 1 or Fields!CAL_DAY_NUM_IN_MONTH.Value = 21 or Fields!CAL_DAY_NUM_IN_MONTH.Value = 31), "st ",
(Fields!CAL_DAY_NUM_IN_MONTH.Value = 2 or Fields!CAL_DAY_NUM_IN_MONTH.Value = 22), "nd ",
(Fields!CAL_DAY_NUM_IN_MONTH.Value = 3 or Fields!CAL_DAY_NUM_IN_MONTH.Value = 23), "rd ",
1=1, "th "
) & Fields!CAL_MONTH_NAME.Value & " " &Fields!LABEL_YYYY.Value,
Parameters!rangeView.Value = "W", "Week: " & Fields!LABEL_YYYY_WE.Value,
Parameters!rangeView.Value = "M", "Month: " & Fields!CAL_MONTH_NAME.Value & " " & Fields!LABEL_YYYY.Value
) &
vbcrlf &
"Total Volume: " & FormatNumber(Sum(Fields!TOTAL_CALLS.Value),0) & IIF(Max(Fields!TOTAL_CALLS.Value) = 1, " call", " calls") &
vbcrlf &
"Busy hour: " & FormatNumber(Max(Fields!TOTAL_CALLS.Value),0) & IIF(Max(Fields!TOTAL_CALLS.Value) = 1, " call at ", " calls at ") &
Join(LookupSet(Max(Fields!TOTAL_CALLS.Value),
Fields!TOTAL_CALLS.Value,
Fields!HourTime.Value & IIF(Parameters!rangeView.Value = "D", Nothing, " on " & Fields!LABEL_YYYY_MM_DD.Value),
"BusyHourStats"), Environment.NewLine & " and ") &
vbcrlf &
"Max Concurrent: " & FormatNumber(Max(Fields!MAX_CONCURRENT_CALLS.Value),0) & IIF(Max(Fields!MAX_CONCURRENT_CALLS.Value) = 1, " call at ", " calls at ") &
Join(LookupSet(Max(Fields!MAX_CONCURRENT_CALLS.Value),
Fields!MAX_CONCURRENT_CALLS.Value,
Fields!HourTime.Value & IIF(Parameters!rangeView.Value = "D", Nothing, " on " & Fields!LABEL_YYYY_MM_DD.Value),
"BusyHourStats"), Environment.NewLine & " and ")
As you can see when I hover the mouse over the category month "January 2018" it is returning the correct matching value for January "11am on 2018-01-12" but it is also returning the matching value for February "3pm on 2018-02-15". I'd like to only get the matches for the Month that is being hovered over (or Day or Week being hovered over depending on the category grouping chosen when the report was run).
Image:Report showing tooltip for January
Edit2: Added sample dataset below (csv). Note: removed many rows to comply to character limit in this post. The sample is exactly as used in the report (which is slightly different to the original post description).
BUSINESS_UNIT,CAL_MONTH_NAME,LABEL_WE,CAL_WEEK_START_DATE,CAL_WEEK_END_DATE,LABEL_YYYY_MM_DD,LABEL_YYYY_MM_DD_HH24,TOTAL_CALLS,MAX_CONCURRENT_CALLS
<All>,January,W02,2018-01-08 00:00:00.000,2018-01-14 00:00:00.000,2018-01-12,2018-01-12 11,85,3
<All>,January,W02,2018-01-08 00:00:00.000,2018-01-14 00:00:00.000,2018-01-12,2018-01-12 12,16,2
<All>,January,W02,2018-01-08 00:00:00.000,2018-01-14 00:00:00.000,2018-01-12,2018-01-12 13,3,1
<All>,January,W02,2018-01-08 00:00:00.000,2018-01-14 00:00:00.000,2018-01-12,2018-01-12 14,8,1
<All>,January,W02,2018-01-08 00:00:00.000,2018-01-14 00:00:00.000,2018-01-12,2018-01-12 15,9,2
<All>,January,W02,2018-01-08 00:00:00.000,2018-01-14 00:00:00.000,2018-01-12,2018-01-12 16,9,1
<All>,January,W02,2018-01-08 00:00:00.000,2018-01-14 00:00:00.000,2018-01-12,2018-01-12 19,1,1
<All>,January,W02,2018-01-08 00:00:00.000,2018-01-14 00:00:00.000,2018-01-13,2018-01-13 09,1,1
<All>,January,W02,2018-01-08 00:00:00.000,2018-01-14 00:00:00.000,2018-01-13,2018-01-13 11,2,1
<All>,January,W02,2018-01-08 00:00:00.000,2018-01-14 00:00:00.000,2018-01-13,2018-01-13 12,1,1
<All>,January,W02,2018-01-08 00:00:00.000,2018-01-14 00:00:00.000,2018-01-13,2018-01-13 13,2,1
<All>,January,W02,2018-01-08 00:00:00.000,2018-01-14 00:00:00.000,2018-01-13,2018-01-13 14,1,1
<All>,January,W02,2018-01-08 00:00:00.000,2018-01-14 00:00:00.000,2018-01-14,2018-01-14 10,5,1
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-15,2018-01-15 06,1,1
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-15,2018-01-15 07,12,2
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-15,2018-01-15 08,11,3
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-15,2018-01-15 09,24,2
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-15,2018-01-15 10,6,1
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-15,2018-01-15 11,19,2
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-15,2018-01-15 12,4,1
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-15,2018-01-15 13,38,3
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-15,2018-01-15 14,49,3
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-15,2018-01-15 15,28,3
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-15,2018-01-15 16,28,2
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-15,2018-01-15 21,1,1
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-16,2018-01-16 07,5,2
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-16,2018-01-16 08,23,1
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-16,2018-01-16 09,27,2
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-16,2018-01-16 10,77,4
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-16,2018-01-16 11,19,3
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-16,2018-01-16 12,14,3
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-16,2018-01-16 13,43,2
<All>,January,W03,2018-01-15 00:00:00.000,2018-01-21 00:00:00.000,2018-01-16,2018-01-16 14,37,2
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-13,2018-02-13 20,2,5
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-14,2018-02-14 07,165,50
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-14,2018-02-14 08,5,7
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-14,2018-02-14 09,365,51
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-14,2018-02-14 10,11,2
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-14,2018-02-14 11,58,3
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-14,2018-02-14 12,9,1
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-14,2018-02-14 13,425,53
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-14,2018-02-14 14,79,4
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-14,2018-02-14 15,57,4
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-14,2018-02-14 16,16,3
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-14,2018-02-14 17,13,2
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-14,2018-02-14 18,1,1
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-14,2018-02-14 21,1,1
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-15,2018-02-15 07,5,2
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-15,2018-02-15 08,17,2
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-15,2018-02-15 09,4,1
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-15,2018-02-15 10,30,3
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-15,2018-02-15 11,42,2
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-15,2018-02-15 12,17,2
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-15,2018-02-15 13,37,2
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-15,2018-02-15 14,62,3
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-15,2018-02-15 15,85,3
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-15,2018-02-15 16,33,2
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-15,2018-02-15 18,1,1
<All>,February,W07,2018-02-12 00:00:00.000,2018-02-18 00:00:00.000,2018-02-15,2018-02-15 22,6,1

Related

How to convert a ArrayList into a Map using Java8?

I have the below requirement and I want to use Java-8 to meet the desired solution:
Input ->
ArrayList<String> places = new ArrayList<String>(
Arrays.asList("Buenos Aires", "Córdoba", "La Plata", "Paris"));
Output-> HashMap<String,List<String>> detailsMap=new HashMap<>();
{"Buenos Aires"=[ "Córdoba", "La Plata", "Paris"], "Córdoba"=["Buenos Aires", "La Plata", "Paris"],
"La Plata"=["Buenos Aires", "Córdoba", "Paris"], "Paris"=["Buenos Aires", "Córdoba", "La Plata"]}
How I can achieve this using Java-8?
Here is the way to achieve that using streams.
List<String> places = Arrays.asList("Buenos Aires", "Córdoba", "La Plata", "Paris");
Map<String, List<String>> map = places.stream().collect(Collectors.toMap(Function.identity(), e-> places.stream().filter(k -> !e.equals(k)).collect(Collectors.toList())));

Retrieving label names with SPARQL query

I am having an issue with the Wikidata Query Service. https://query.wikidata.org/
What I want to do is retrieve a list of all persons who have a GTAA ID.
?q wdt:P1741 ?GTAA_ID.
For these persons, I want to retrieve the following optional information:
OPTIONAL{ ?q p:P166 ?award_received
OPTIONAL{ ?award_received pq:P585 ?point_in_time. }
OPTIONAL{ ?award_received pq:P1686 ?for_work. }
have received an award
at what point in time they received this award
for what work they received this award
As of now, my query mostly works. However, in the 'awards_received' column, for example, it is showing the following text:
wds:Q76343-ffa729dc-4d10-eb15-3a41-5fa6bf7ed80a
When clicking this it brings me to the Wikidata page concerning the person who received the award, NOT the title of the award itself.
What I would like to do is have the title of the received award retrieved, instead of a link to the receiver of the title.
The code I have is as follows:
SELECT ?GTAA_ID ?award_received ?point_in_time ?for_workLabel
WHERE
{
?q wdt:P1741 ?GTAA_ID.
OPTIONAL{ ?q p:P166 ?award_received
OPTIONAL{ ?award_received pq:P585 ?point_in_time. }
OPTIONAL{ ?award_received pq:P1686 ?for_work. }
. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "
[AUTO_LANGUAGE]". }
}
The actual award is given as the property ps:P166 of the statement:
SELECT ?GTAA_ID ?award ?awardLabel ?point_in_time ?for_workLabel {
?q wdt:P1741 ?GTAA_ID.
OPTIONAL {
?q p:P166 ?award_received .
?award_received ps:P166 ?award # Here
OPTIONAL { ?award_received pq:P585 ?point_in_time. }
OPTIONAL { ?award_received pq:P1686 ?for_work. }
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE]".
}
}
You can get a description of a resource with a DESCRIBE query, e.g.:
DESCRIBE wds:Q78217-3877ABD6-239F-47DA-A8BD-8035D3CBAA7A

I want to writing a queires in python script which is ultimately going to call these queries from django

Here is my mongodb database :
**{"Fruit" : "Pomegranate", "District" : "Nasik", "Taluka" : "Nasik", "Revenue circle" : "Nasik", "Sum Insured" : 28000, "Area" : 1200, "Farmer" : 183 }
{"Fruit" : "Pomegranate", "District" : "Jalna", "Taluka" : "Jalna", "Revenue circle" : "Jalna", "Sum Insured" : 28000, "Area" : 120, "Farmer" : 13 }
{"Fruit" : "Guava", "District" : "Pune", "Taluka" : "Haveli", "Revenue circle" : "Uralikanchan", "Sum Insured" : 50000, "Area" : 10, "Farmer" : 100 }
{"Fruit" : "Guava", "District" : "Nasik", "Taluka" : "Girnare", "Revenue circle" : "Girnare", "Sum Insured" : 50000, "Area" : 75, "Farmer" : 90 }
{"Fruit" : "Banana", "District" : "Nanded", "Taluka" : "Nandurbar", "Revenue circle" : "NandedBK", "Sum Insured" : 5000, "Area" : 2260, "Farmer" : 342 }
{"Fruit" : "Banana", "District" : "Jalgaon", "Taluka" : "Bhadgaon", "Revenue circle" : "Bhadgaon", "Sum Insured" : 5000, "Area" : 220, "Farmer" : 265 }**
Here is my models.py file :
from mongoengine import Document, fields
from django.db.models import Q
class Tool(Document):
Fruit = fields.StringField(required=True)
District = fields.StringField(required=True)
Taluka = fields.StringField(required=True)
Revenue_circle = fields.StringField(required=True)
Sum_Insured = fields.StringField(required=True)
Area = fields.StringField(required=True)
Farmer = fields.StringField(required=True)
Here is my serializers.py file :
from rest_framework import serializers
from rest_framework_mongoengine.serializers import DocumentSerializer
from models import Tool
class ToolSerializer(DocumentSerializer):
#id = serializers.CharField(read_only=False)
class Meta:
model = Tool
#fields=['Fruit']
Here is my views.py file
from __future__ import unicode_literals
from django.template.response import TemplateResponse
from rest_framework_mongoengine.viewsets import ModelViewSet as MongoModelViewSet
from app.serializers import *
def index_view(request):
context = {}
return TemplateResponse(request, 'index.html', context)
class ToolViewSet(MongoModelViewSet):
lookup_field = 'Fruit'
serializer_class = ToolSerializer
def get_queryset(self):
return Tool.objects.all()
Now, I want to writing queires,
But when I use lookup filed='Fruit' in views.py file then
http://127.0.0.1:8000/api/tool/Banana/
I get All information for fruit which is banana .
127.0.0.1:8000/api/tool/Guava/
then I get All information for fruit which is guava.
lookup filed is use for single fields,
But,I want to write all types of combination queires.
for example:
/api/tool/Guava/ (gives all data for fruit is guava)
/api/tool/Nasik/ (gives all data for district is Nasik)
/api/tool/Uralikanchan/ (gives all data for revenue_circle is uralikanchan)
/api/tool/265 (gives all data for farmer is 265)
/api/tool/2260/ (gives all data for Area is 2260 )
So,can you please tell me how to write all types of combination queries which call these queires to django?
you can use rest-framework-filter-backend ,create Filterset
see this doc http://www.django-rest-framework.org/api-guide/filtering/
You need to override the view's get_queryset to perform the request you want on the fields you want.

How to modify options of a specific Kendo Dropdownlist without affecting other dropdownlist which shares same datasource?

I have 3 kendo dropdownlist which shares same datasource. I have a requirement to remove a particular option say the first one (<--Select-->) from one of the dropdownlist, but retain the same for other two. I tried to remove the option using
$(dropDownListObject).data("kendoDropDownList")dataSource.remove(itemToRemove)
method, but this removed the option from all the dropdownlist. How can I attain this ?
Data Source :
-------------------
var data = [
{Code: "<--Select-->", value:"-1"},
{Code: "Option 1", value:"1"},
{Code: "Option 1", value:"2"},
{Code: "Option 1", value:"3"},
{Code: "Option 1", value:"4"},
];
Snippet where I am trying to remove the option :
-------------------------------------------------------
root.find('.dropdown').each(function (index, item) {
var dropdown = $(item).data("kendoDropDownList");
if (dropdown) {
if ((dropdown.element.attr('removeOption') == "true")) {
$('#'+dropdown.element.attr('id') + 'option[value="-1"]').each(function () {
var itemToRemove = $(item).data("kendoDropDownList").dataSource.at(0);
$(item).data("kendoDropDownList").dataSource.remove(itemToRemove);
});
}
}
});
Since cloning is an option, I would suggested to create 3 distinct dataSource. That way all the data behind will be independent and you won't have to worry about any other data manipulation that could occur in a shared data source (ex: filtering or sorting)
var data = [
{Code: "<--Select-->", value:"-1"},
{Code: "Option 1", value:"1"},
{Code: "Option 1", value:"2"},
{Code: "Option 1", value:"3"},
{Code: "Option 1", value:"4"},
];
var dataClone = jQuery.extend(true, {}, data);
//Create your dataSource with dataClone instead of data

how to filter according location in freebase?

i have been trying to filter the suggestions according to location but unsuccessful.
i want to show all locations, city , town, villages of country : India
what changes should i do to the below code for it ?
<script type="text/javascript">
$("#myinput")
.suggest({
"key": "my key",
filter: '(any type:/location/location )'
})
.bind("fb-select", function(e, data) {
alert(data.name + ", " + data.id + " (" + data['n:type'].name + ")");
});
</script>
The way to do this with a search filter is to use the part_of Metaschema predicate like this:
<script type="text/javascript">
$("#myinput")
.suggest({
"key": "my key",
filter: '(all type:/location/location part_of:/m/03rk0)'
})
.bind("fb-select", function(e, data) {
alert(data.name + ", " + data.id + " (" + data['n:type'].name + ")");
});
</script>
The part_of Metaschema predicate is transitive which means that it matches Freebase topics that are part_of India (/m/03rk0) or part_of a location which is part_of India, etc.
Shawn's approach will work for topics which have the containment properties set up correctly, but I'm not sure how good the coverage is there. I suspect simple geo data (lat/lon) coverage is better. If you want to just filter on distance from the centroid of India, you could do something like:
filter=(all type:/location/location (within radius:500km+lon:82.7948 lat:21.7866))
https://www.googleapis.com/freebase/v1/search?indent=true&filter=%28all+type%3A/location/location+%28within+radius%3A500km+lon%3A82.7948+lat%3A21.7866%29%29&output=%28geocode%29
Note that this is very sketchily documented and I'm not sure whether that means it's brand new and the documentation isn't finished or deprecated and about to go away.

Resources