How to use list parameters in Fulfillment - dialogflow-es

I have a composite entity named #flavorQuantity.
This entity collects the "flavors" present in the order and their "quantities", in phrases like "I want 2 cocoa and 1 pumpkin", like this:
want #sys.number:quantity #flavor:flavor and #sys.number:quantity #flavor:flavor
Dialogflow identifies these parameters ($quantity and $flavor) separately, as in the image:
PT-BR = saborQuantidade = #flavorQuantity || Cacau = Cocoa || Punpkin = Abóbora
How can I use each of these parameters in Fulfillmment to set up a function that provides the total value of each item, to add up the total value of the order. Using the function below it does not recognize the name of the values ​​contained within the parameter #flavorQuantity.
**
function order (agent){
const quantity = agent.parameters.quantity;
const flavor = agent.parameters.flavor;
var total;
if (flavor == 'Cacau & Castanhas'){
total = 3*quantity;
**

have you tried agent.queryResult.parameters.quantity?

Related

Filter leading to different results when typed manually and via defined as a variable

I'm trying to create a calculated column indicating if a team has a prize or not from the table below:
To do that I need to count within the group if there's a player whose "Prize" field is not empty. Here's the 1st attempt:
Dax Formula:
=
Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = len(Table4[Prize])>0
Return
calculate(countrows(filter(Table4,len(Table4[Prize])>0)),Player_Same_Team)>0
Looks like it's going what I intend it to do. However, when I swap the filter content to a pre-defined variable, it gave me results that don't make sense:
Dax Formula:
=
Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = len(Table4[Prize])>0
Return
calculate(countrows(filter(Table4,Has_Prize)),Player_Same_Team)>0
The typed content len(Table4[Prize])>0 is the same as that in the variable, so what may be causing the difference? Thanks for your help.
As soon as you assign it to a variable, the value of the variable remains constant. Therefore the Len is evaluated to a value, that you are then passing as a filter.
The first example works because the CALCULATE accepts a table as a parameter, and player_same_team is evaluated to a table, by using the FILTER expression.
In order for what you are trying to do to work it would have to be something like this:
= Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = filter(Table4,len(Table4[Prize])>0)
Return calculate(countrows(Has_Prize),Player_Same_Team)>0
You can also write the measure in a slightly different way:
= CALCULATE ( COUNT(Table4[Team]),
ALLEXCEPT(Table4[Team]),
LEN(Table4[Prize])>0) > 0

Displaying the total sum of values from strings

My project is a simple shopping game where the user types in the quantity amount, and the value of the individual prices appears and then a total sum can appear below.
I have managed to create the part of displaying the individual product price but i am confused on how to add the total sum and display correctly at the instance that i defined.
Some info
Actionscript will check for keypress event
sample of code snippet:
if(e.keyCode == 49){ //1
trace("Key Code Pressed: " + e.keyCode);
amount1.text = "1.00"
}
...
var total:Number = amount1+ amount2+amount3+amount4+amount5;
output1.text = String(total);
From the code above, when the user types 1, the price will change to "1.00" on the price instance field (dynamic text type).
Picture below:
A sample of my game running:
Total price should be $13.00 dollars..
Is there any way to make this happen? I believe is it something to do with parseint.
You should be able to string together multiple parseint statements like this:
var total:number = parseint(amount1.text) + parseint(amount2.text) + parseint(amount3.text) + parseint(amount4.text) + parseint(amount5.text);
output1.text = total;
If you go this route, you will need to handle stituations that involve NaN
Here is the documentation on parseint if you haven't already, you should look at it. http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000590.html

mutivalue date field search not working

I have a multivalue field called freeDaysPool which has multiple dates as strings. With the following code, the search does not return anything. If I leave that field out, the search works just fine with the two other fields. I read that I should use CONTAINS with multivalue fields but then I got query not understandable.
I've tried the back-end field as a date field and as a text field and tested all kinds of query combinations and date formats but no luck. Any help is really appreciated.
This is the search button code:
var query = new Array("");
var cTerms = 0;
// Field 1
var search01 = getComponent("searchcustomReservationField01").getValue();
if (#Contains(#Text(search01),"any city")){"";}
else {query[cTerms++] = '[customReservationField01]="' + search01 +'"'};
// Field 2
var search02 = getComponent("searchcustomReservationField02").getValue();
if (#Contains(#Text(search02),"any city")){"";}
else {query[cTerms++] = '[customReservationField02]="' + search02 + '"'};
// Date 1
var formatter = new java.text.SimpleDateFormat("d.M.yyyy");
query[cTerms++] = 'FIELD freeDaysPool = ' + formatter.format(getComponent("searchcustomDateField01").getValue());
// if query is still empty, we fill it with asterisk
if(query == "" || query == null){
query[cTerms++] = "*";
}
// make all as string
qstring = query.join(" AND ").trim();
sessionScope.searchString = qstring;
It will return query as:
[customReservationField01]="Oslo" AND [customReservationField02]="Oslo" AND FIELD freeDaysPool = 6.2.2015
AFAIK date values in formulas (and a query is a formula) have to be noted like
[06.02.2015]
to compare them. Just try to use your formular in the Notes Client to do a fulltext search. If you get results and no errors you found the correct format. That's at least the way I test queries as I'm not able to remind the syntax for years :-D
Thank you for all the help! Seems that Domino keeps the field type as date field even if you change it back to text field (noticed that from the notes FTsearch). I created completely new text field and added the days as strings in dd.MM.yyyy format. I also search them as strings and it works fine.
The changed code bit now looks like this:
// Date 1
var formatter = new java.text.SimpleDateFormat("dd.MM.yyyy");
query[cTerms++] = '[freeDays] CONTAINS "' + formatter.format(getComponent("searchcustomDateField01").getValue())+'"';

create a filter not a group filter

I am creating a custom module in Orchard , I would like to create a query programmatically.
string queryName= "Product";
var item = _orchardServices.ContentManager.New("Query");
item.As<TitlePart>().Title =queryName;
_orchardServices.ContentManager.Create(item, VersionOptions.Draft);
if (!item.Has<IPublishingControlAspect>() && !item.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable)
_orchardServices.ContentManager.Publish(item);
var queryPart = item.As<QueryPart>();
queryPart.ContentItem.ContentType = queryName;
string desc =" filter for the query";
string contentType = "CommonPart.ChannelID.";
var filterGroupRecord = new FilterGroupRecord();
var filterRecord = new FilterRecord()
{
Category = "CommonPartContentFields",
Type = contentType,
Position = 0,
};
filterRecord.State = "<Form><Description>" + desc + "</Description><Operator>Equals</Operator><Value>ChannelId</Value></Form>";
filterGroupRecord.Filters.Add(filterRecord);
queryPart.FilterGroups.Insert(0, filterGroupRecord);
the problem is that:I want set a filters of the query,not a filters group.
could you tell me how to improve my code?
Database structure and class declarations make it impossible. Why do you need it?
Update:
I means that you must use FilterGroupRecord at least one.
But when Query published that Filter Group will be created automatically if query have not yet Filter Group (see at QueryPartHandler). You should add your filters to this group. And not needed to create new group.
var existingFilterGroup = queryPart.FilterGroups[0];
existingFilterGroup.Filters.Add(filterRecord);
Update 2:
To avoid problems with draftable query (and several other potential problems Orchard CMS: Adding default data to fields and then querying them) it is better to move the calling Publish method to the end of your code and other part of your code should be left unchanged. And in your case would be better if you will always publish your query without checking IPublishingControlAspect and Draftable.

How do I search Google Spreadsheets?

I am doing a few exhaustive searches and need to determine if a new domain (URL) is already in a Spreadsheet. However, none of the Spreadsheet objects have search functions, namely findText() found in most Document objects. I feel like I am missing something significant.
What am I missing?
findText function: https://developers.google.com/apps-script/class_table#findText
SearchResult object: https://developers.google.com/apps-script/class_searchresult
Spreadsheet object: https://developers.google.com/apps-script/class_sheet
My best guess is to try and convert specific Spreadsheet ranges in Document tables, then perform the search. Mendokusai
Unfortunately there is no searching functionality in the Spreadsheet services. You can get the data for the range you are searching on, and then iterate over it looking for a match. Here's a simple function that does that:
/**
* Finds a value within a given range.
* #param value The value to find.
* #param range The range to search in.
* #return A range pointing to the first cell containing the value,
* or null if not found.
*/
function find(value, range) {
var data = range.getValues();
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < data[i].length; j++) {
if (data[i][j] == value) {
return range.getCell(i + 1, j + 1);
}
}
}
return null;
}
I wrote a search tool with a graphical user interface that performs a global search in 3 columns of a single sheet. It could be easily modified to suit your needs. I guess it would be a good idea to add an anchor in the UI to let you open the url you just found.
Here is the code, hoping it will help you to design your own version.
EDIT : I added the anchor widget in the code below (getting its ref in column E)
// G. Variables
var sh = SpreadsheetApp.getActiveSheet();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var lastrow = ss.getLastRow();
//
function onOpen() {
var menuEntries = [ {name: "Search GUI", functionName: "searchUI"},
];
ss.addMenu("Search Utilities",menuEntries);// custom menu
}
// Build a simple UI to enter search item and show results + activate result's row
function searchUI() {
var app = UiApp.createApplication().setHeight(130).setWidth(400);
app.setTitle("Search by name / lastname / adress");
var panel = app.createVerticalPanel();
var txtBox = app.createTextBox().setFocus(true);
var label=app.createLabel(" Item to search for :")
panel.add(label);
txtBox.setId("item").setName("item");
var label0=app.createLabel("Row").setWidth("40");
var label1=app.createLabel("Name").setWidth("120");
var label2=app.createLabel("Lastname").setWidth("120");
var label3=app.createLabel("Street").setWidth("120");
var hpanel = app.createHorizontalPanel();
hpanel.add(label0).add(label1).add(label2).add(label3)
//
var txt0=app.createTextBox().setId("lab0").setName("0").setWidth("40");
var txt1=app.createTextBox().setId("lab1").setName("txt1").setWidth("120");
var txt2=app.createTextBox().setId("lab2").setName("txt2").setWidth("120");
var txt3=app.createTextBox().setId("lab3").setName("txt3").setWidth("120");
var hpanel2 = app.createHorizontalPanel();
hpanel2.add(txt0).add(txt1).add(txt2).add(txt3)
var hidden = app.createHidden().setName("hidden").setId("hidden");
var subbtn = app.createButton("next ?").setId("next").setWidth("250");
var link = app.createAnchor('', '').setId('link');
panel.add(txtBox);
panel.add(subbtn);
panel.add(hidden);
panel.add(hpanel);
panel.add(hpanel2);
panel.add(link);
var keyHandler = app.createServerHandler("click");
txtBox.addKeyUpHandler(keyHandler)
keyHandler.addCallbackElement(panel);
//
var submitHandler = app.createServerHandler("next");
subbtn.addClickHandler(submitHandler);
submitHandler.addCallbackElement(panel);
//
app.add(panel);
ss.show(app);
}
//
function click(e){
var row=ss.getActiveRange().getRowIndex();
var app = UiApp.getActiveApplication();
var txtBox = app.getElementById("item");
var subbtn = app.getElementById("next").setText("next ?")
var txt0=app.getElementById("lab0").setText('--');
var txt1=app.getElementById("lab1").setText('no match').setStyleAttribute("background", "white");// default value to start with
var txt2=app.getElementById("lab2").setText('');
var txt3=app.getElementById("lab3").setText('');
var link=app.getElementById('link').setText('').setHref('')
var item=e.parameter.item.toLowerCase(); // item to search for
var hidden=app.getElementById("hidden")
var data = sh.getRange(2,2,lastrow,4).getValues();// get the 4 columns of data
for(nn=0;nn<data.length;++nn){ ;// iterate trough
if(data[nn].toString().toLowerCase().match(item.toString())==item.toString()&&item!=''){;// if a match is found in one of the 4 fields, break the loop and show results
txt0.setText(nn+2);
txt1.setText(data[nn][0]).setStyleAttribute("background", "cyan");
txt2.setText(data[nn][1]);
txt3.setText(data[nn][2]);
link.setText(data[nn][3]).setHref(data[nn][3]);
sh.getRange(nn+2,2).activate();
subbtn.setText("found '"+item+"' in row "+Number(nn+2)+", next ?");
hidden.setValue(nn.toString())
break
}
}
return app ;// update UI
}
function next(e){
var row=ss.getActiveRange().getRowIndex();
var app = UiApp.getActiveApplication();
var txtBox = app.getElementById("item");
var subbtn = app.getElementById("next").setText("no other match")
var hidden=app.getElementById("hidden");
var start=Number(e.parameter.hidden)+1;//returns the last search index stored in the UI
var item=e.parameter.item.toLowerCase(); // item to search for
var txt0=app.getElementById("lab0");
var txt1=app.getElementById("lab1").setStyleAttribute("background", "yellow");
var txt2=app.getElementById("lab2");
var txt3=app.getElementById("lab3");
var link=app.getElementById('link').setText('').setHref('')
var data = sh.getRange(2,2,lastrow,4).getValues();// get the 4 columns of data
for(nn=start;nn<data.length;++nn){ ;// iterate trough
if(data[nn].toString().toLowerCase().match(item.toString())==item.toString()&&item!=''){;// if a match is found in one of the 4 fields, break the loop and show results
txt0.setText(nn+2);
txt1.setText(data[nn][0]).setStyleAttribute("background", "cyan");
txt2.setText(data[nn][1]);
txt3.setText(data[nn][2]);
link.setText(data[nn][3]).setHref(data[nn][3])
sh.getRange(nn+2,2).activate();
subbtn.setText("found '"+item+"' in row "+Number(nn+2)+", next ?");
hidden.setValue(nn.toString())
break
}
}
return app ;// update UI
}// eof 05-12 Serge insas
I ended up using spreadsheet formulas to solve my problem instead. Specifically, I used the MATCH() function, which can look up a string in an array (in this case a column in another sheet in the same document).
This is significantly simpler than looping through an array, though less efficient and does not allow for full automation. In fact, when the column reached 2,000 entries, Google Drive froze so often, I had to start using Excel instead. Nevertheless, the Match() solution was more appropriate for what I was looking for.
Appreciate all the other responses though.
You can "search" using the SpreadsheetAPI List Feed query parameter. This will return any row that matches using full word matching. Throw some asterisks around your parameter (URL encoded of course) and it becomes wildcard.
I have not tried it, but it appears that the Google Visualization API Query Language will allow you to execute SQL queries against Google sheets.

Resources