Cannot call 'operator-' with 'expr2'=input string. The argument should be of type: const integer; - operators

My code:
// © Crystal_Catalyst
//#version=4
strategy("My Script")
period = input("1", title="Period")
fees = input(".0025", title="Fees")
var price=close
if close>price/(1-fees)
strategy.order("Tab Beta", false, qty=20, when = close>price/(1-fees))
price := close
if close<price*(1-fees)
strategy.order("Tab Beta", true, qty=20, when = close<price*(1-fees))
price := close
So why does it say for lines 9, 10, 12, and 13:
Cannot call 'operator-' with 'expr2'=input string. The argument should be of type: const integer;
It worked fine when I did something similar to this in a more complex code. What am I doing wrong?

Wait, I forgot to set the values in the input to "defval". That is why it was not recognizing it. I wish the backtester would have mentioned THAT instead. It works now, but I have other problems. I will make another post about it soon.

Related

I am trying to get data over an OpenWeather API in Rust but I am facing some iusse regarding parsing I guess

extern crate openweather;
use openweather::LocationSpecifier;
static API_KEY: &str = "e85e0a3142231dab28a2611888e48f22";
fn main() {
let loc = LocationSpecifier::Coordinates {
lat: 24.87,
lon: 67.03,
};
let weather = openweather::get_current_weather(loc, API_KEY).unwrap();
print!(
"Right now in Minneapolis, MN it is {}K",
weather.main.humidity
);
}
error : thread 'main' panicked at 'called Result::unwrap() on an
Err value: ErrorReport { cod: 0, message: "Got unexpected response:
\"{\\"coord\\":{\\"lon\\":67.03,\\"lat\\":24.87},\\"weather\\":[{\\"id\\":803,\\"main\\":\\"Clouds\\",\\"description\\":\\"broken
clouds\\",\\"icon\\":\\"04n\\"}],\\"base\\":\\"stations\\",\\"main\\":{\\"temp\\":294.15,\\"pressure\\":1018,\\"humidity\\":60,\\"temp_min\\":294.15,\\"temp_max\\":294.15},\\"visibility\\":6000,\\"wind\\":{\\"speed\\":5.1,\\"deg\\":30},\\"clouds\\":{\\"all\\":70},\\"dt\\":1574012543,\\"sys\\":{\\"type\\":1,\\"id\\":7576,\\"country\\":\\"PK\\",\\"sunrise\\":1573955364,\\"sunset\\":1573994659},\\"timezone\\":18000,\\"id\\":1174872,\\"name\\":\\"Karachi\\",\\"cod\\":200}\""
}
The issue is a JSON parsing error due to the deserialized struct not matching OpenWeather's JSON, perhaps the API recently added this? With your example, the OpenWeatherCurrent struct is missing timezone.
But it looks like there is an open PR that will fix this, you can test it by doing the following:
Change your Cargo.toml dependency to openweather = { git = "https://github.com/caemor/openweather" }.
The PR author has also updated the get_current_weather signature so you'll need to change lines 2, 10 to the following:
use openweather::{LocationSpecifier, Settings};
let weather = openweather::get_current_weather(&loc, API_KEY, &Settings::default()).unwrap();

Generate dynamic tests based on a parameter in Nightwatch

I'm using NightwatchJS to automate the test on our reporting website.
This is my actual code:
module.exports = {
'#tags': ['Report 1','base','full'],
'Report 1' : function (browser) {
checkAnalisi(browser, 'report1', 1, 2015, '767.507')
}
};
function checkAnalisi(browser, nomeAnalisi, scheda, year, risultatoAtteso){
return browser
.url('https://example.com/Wizard?analisi=' + nomeAnalisi)
.waitForElementVisible('body', 5000)
.selectScheda(scheda-1) //Seleziona la scheda (0-based)
.selectPromptValue('Year', year)
.selectRappresentazione('Table')
.waitForElementVisible('table', 5000, true)
.assert.containsText('table tr:last-child td:last-child', risultatoAtteso)
.end();
}
I made some helper commands to select different things in the page:
.selectScheda(scheda-1)
.selectPromptValue('Year', year)
.selectRappresentazione('Table')
selectPromptValue wants a prompt name and the value to set it in the page.
For now the function only sets the year parameter but in my reports I also have different parameters.
What I want to do is to pass an object to the checkAnalisi function to dynamically generate test. For example if I want to set different prompt values I want to pass something like [['Year', 2015],['Another prompt','another value']] and the checkAnalisi function should add 2 .selectPromptValue steps with the respective values.
Is it possible to cycle an input array in my function to add more steps?
Actually I was able to solve this easily directly in my selectPromptValue custom command.
I simply added the new parameter to the checkAnalisi function like this (promptValues is the new parameter):
function checkAnalisi(browser, nomeAnalisi, scheda, promptValues, risultatoAtteso){
return browser
.url('https://example.com/Wizard?analisi=' + nomeAnalisi)
.waitForElementVisible('body', 5000)
.selectScheda(scheda-1) //Seleziona la scheda (0-based)
.selectPromptValue(promptValues)
.selectRappresentazione('Table')
.waitForElementVisible('table', 5000, true)
.assert.containsText('table tr:last-child td:last-child', risultatoAtteso)
.end();
}
I then modified the selectPromptValue.js custom command like this:
exports.command = function(v) {
for(var i=0; i<v.length; i++){
this.execute('$("#"+$("label:visible:contains(\'' + v[i][0] + '\')").attr("for")).val("' + v[i][1] + '")');
}
return this;
};

Linqpad extension to plot graphs

I tried to plot some graphs in Linqpad with with "Util.RawHtml()" and "Dump()" but it is not working with this example from amcharts.com. I created a string variable including all the HTML source code but the result is not working.
string html = "";
using (System.Net.WebClient client = new System.Net.WebClient ())
{
html = client.DownloadString(#"http://pastebin.com/raw/pmMMwXhm");
}
Util.RawHtml(html).Dump();
Later versions of LinqPad 5 now support charting out of the box with Util.Chart. You can see the samples in the Samples Tab (next to My Queries) under
LINQPad Tutorial&Reference
Scratchpad Features
Charting with Chart
The following script is the Chart() - dual scale sample:
// Each y-series can have a different series type, and can be assigned to the secondary y-axis scale on the right.
var customers = new[]
{
new { Name = "John", TotalOrders = 1000, PendingOrders = 50, CanceledOrders = 20 },
new { Name = "Mary", TotalOrders = 1300, PendingOrders = 70, CanceledOrders = 25 },
new { Name = "Sara", TotalOrders = 1400, PendingOrders = 60, CanceledOrders = 17 },
};
customers.Chart (c => c.Name)
.AddYSeries (c => c.TotalOrders, Util.SeriesType.Spline, "Total")
.AddYSeries (c => c.PendingOrders, Util.SeriesType.Column, "Pending", useSecondaryYAxis:true)
.AddYSeries (c => c.CanceledOrders, Util.SeriesType.Column, "Cancelled", useSecondaryYAxis:true)
.Dump();
As I understand it, this will not work because the html contains scripts that will not be executed.
As an alternative, you can still use the old (and deprecated) google charts api, eg
var link = #"http://chart.apis.google.com/chart?chxt=y&chbh=a&chs=300x225&cht=bvg&chco=A2C180,3D7930&chd=t:10,20,30,40,50,60|30,35,40,45,55,60&chtt=Sample";
Util.Image (link).Dump();
or see
http://blog.divebomb.org/2012/11/dumping-charts-in-linqpad/
Not sure if it's the answer you're after but there may be value in looking at the DisplayWebPage method on the Util class in Linqpad. This correctly rendered your chart in the result window, (although there was a script error). Obviously, this may not solve your underlying issue.
I used version 5.10.00 to test this.

How to create Fields

I am trying to create a script to add Fields on MarkLogic Database with Admin API. I have created following functions to perform this task:
declare function local:createField($config as element(configuration), $server-config as element(http-server))
{
let $dbid := xdmp:database(fn:data($server-config/database))
let $addField :=
let $fieldspec := admin:database-field("VideoTitle1", fn:false())
return admin:save-configuration(admin:database-add-field($config, $dbid, $fieldspec))
return "SUCCESS"
};
declare function local:createFieldPath($config as element(configuration), $server-config as element(http-server))
{
let $dbid := xdmp:database(fn:data($server-config/database))
let $addPath :=
let $fieldpath := admin:database-field-path("/Video/BasicInfo/Title", 1.0)
return admin:save-configuration(admin:database-add-field-paths($config, $dbid, "VideoTitle1", $fieldpath))
return "SUCCESS"
};
declare function local:createFieldRangeIndex($config as element(configuration), $server-config as element(http-server))
{
let $dbid := xdmp:database(fn:data($server-config/database))
let $addRange :=
let $rangespec := admin:database-range-field-index("string","VideoTitle1", "http://marklogic.com/collation/",fn:false() )
return admin:save-configuration(admin:database-add-range-field-index($config, $dbid, $rangespec))
return "SUCCESS"
};
But I am getting error:
[1.0-ml] ADMIN-BADPATHFIELDTYPE: (err:FOER0000) Incorrect field:
the field VideoTitle1 already has include-root.
In /MarkLogic/admin.xqy on line 5255
In database-check-path-field(<configuration/>, xs:unsignedLong("12095791717198876597"), "VideoTitle1")
$config := <configuration/>
$database-id := xs:unsignedLong("12095791717198876597")
$field-name := "VideoTitle1"
$field := <field xmlns="http://marklogic.com/xdmp/database" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><field-name>VideoTitle1</field-name><include-root>false</include...</field>
$field-path := ()
I am running complete script through QC and my MarkLogic version is "7.0-1". I have created Element Range Index, Attribute Range Index successfully by the script. But for this I am getting error.
Error description says that field has include-root. But, I am keeping it false()
admin:database-field("VideoTitle1", fn:false())
Is I am using wrong function or missed something?
Please help.
If you're trying to set up an entire database you're usually better off using the packaging API and services: https://developer.marklogic.com/learn/packaging-tutorial gives a tour of the configuration manager web UI, and then there is a guide, an XQuery API, and a REST API.
That said let's try to debug. It's difficult to debug your error message because the variable names and line numbers in the error message don't match up with your sample code. For example the stack trace has $database-id but your code has $dbid. A test case needs to be reproducible.
However I notice that you aren't calling the right function to construct your field configuration. If you want to use paths, say so up front using https://docs.marklogic.com/admin:database-path-field — not admin:database-path. The error message could use some work: it should be something more like "Incorrect field: the field VideoTitle1 is not a path field".
If you really want to stick with the admin API for this, I recommend changing your code so that you only call admin:save-configuration once. That's more efficient, and more robust in the face of any need to restart. One way to arrange this would be for each of your function calls to take a $config as element(configuration) param and return a new element(configuration) with the changes. Another method is to have a module variable $CONFIG as element(configuration) and mutate it with xdmp:set. Take a look at https://stackoverflow.com/a/12252515/908390 for examples of both techniques.
Here's a working version of your code:
import module namespace admin="http://marklogic.com/xdmp/admin"
at "/MarkLogic/admin.xqy";
declare function local:createField(
$config as element(configuration),
$server-config as element(http-server))
as element(configuration)
{
let $dbid := xdmp:database(fn:data($server-config/database))
let $fieldspec :=
admin:database-path-field(
"VideoTitle1",
admin:database-field-path("/Video/BasicInfo/Title", 1.0))
return admin:database-add-field($config, $dbid, $fieldspec)
};
declare function local:createFieldRangeIndex(
$config as element(configuration),
$server-config as element(http-server))
as element(configuration)
{
let $dbid := xdmp:database(fn:data($server-config/database))
let $rangespec :=
admin:database-range-field-index(
"string",
"VideoTitle1",
"http://marklogic.com/collation/",
fn:false())
return
admin:database-add-range-field-index(
$config, $dbid, $rangespec)
};
let $cfg := admin:get-configuration()
let $fubar := <http-server><database>test</database></http-server>
let $_ := xdmp:set($cfg, local:createField($cfg, $fubar))
let $_ := xdmp:set($cfg, local:createFieldRangeIndex($cfg, $fubar))
return admin:save-configuration($cfg)
Not a direct answer, but why reinvent a wheel that other have already invented. There are several solutions that can help deploy database settings and more. One of them is Roxy:
https://github.com/marklogic/roxy
Roxy provides a full framework for managing a MarkLogic project. You can find docs and tutorials on the wiki of the github project.
Another, less intrusive solution could be to configure your databases once, and then use the built-in Configuration Manager (http://host:8002/nav/) to export your database settings, and use the export to import the settings elsewhere.
HTH!

Corona SDK error on lines 172 and 218, no filename, only question marks

Corona SDK simulator, version 2013.1137 (2013.6.7) is displaying the following error:
Corona Simulator Runtime error
File: ?
Attempt to perform arithmetic on field '?' (a function value)
stack traceback:
[C]: ?
?: in function <?:172>
?: in function <?:218>
The error is caused by the following code (main.lua):
local d1 = display.newCircle(0, 40, 10)
local gNonEmpty1 = display.newGroup()
gNonEmpty1:insert(display.newCircle(0, 70, 10))
local gEmpty1 = display.newGroup()
transition.to(d1, { time = 1000, x = 100 })
transition.to(gNonEmpty1, { time = 1000, x = 100 })
transition.to(gEmpty1, { time = 1000, x = 100 })
local d2 = display.newCircle(0, 150, 10)
local gNonEmpty2 = display.newGroup()
gNonEmpty2:insert(display.newCircle(0, 180, 10))
local gEmpty2 = display.newGroup()
transition.to(d2, { time = 1000, x = 100, transition = easing.outExpo })
transition.to(gNonEmpty2, { time = 1000, x = 100, transition = easing.outExpo })
transition.to(gEmpty2, { time = 1000, x = 100, transition = easing.outExpo })
local d3 = display.newCircle(0, 260, 10)
local gNonEmpty3 = display.newGroup()
gNonEmpty3:insert(display.newCircle(0, 290, 10))
local gEmpty3 = display.newGroup()
transition.to(d3, { time = 1000, x = 100, easing.outExpo })
transition.to(gNonEmpty3, { time = 1000, x = 100, easing.outExpo })
transition.to(gEmpty3, { time = 1000, x = 100, easing.outExpo })
The actual line causing the error is the second to last one:
transition.to(gNonEmpty3, { time = 1000, x = 100, easing.outExpo })
You can check it out by commenting it.
Corona documentation states that:
You should have at least one DisplayObject inserted into a
Display Group before you change or read any of the properties
of the group (e.g., x, y, setReferencePoint(), etc.).
Hence, it would be legit to expect some weird behavior when using transition.to
on gEmpty1, gEmpty2 or gEmpty3. As expected, the first two blocks of transition.to, for a total of six calls, behave the same, except for the easing
which is the default, easing.linear, for the first three calls, and easing.outExpo for the other three calls.
If you make a mistake in writing the transition.to calls, and you write something similar to the last three transition.to calls, where the transition = part is missing in the specification of the easing function, the surprising thing is that only the one that targets the non-empty group, gNonEmpty3 is responsible for the incomprehensible error message.
Questions
What should you do in Corona SDK when you get an error with no line numbers and no file names, but only question marks?
Why Corona SDK is not able to provide meaningful reporting beside two line numbers, 172 and 218?
Why this error is occurring? My theory is that the transition.to doesn't perform much error checking; if you target an empty group the error in specifying the easing function will go unnoticed; probably this is related with the fact empty groups properties should not be used, so maybe transition.to or its internal update callback finds out that the group is empty and simply returns without doing anything. Instead, for the non-empty group, the missing transition = causes some code to be triggered not necessarily the easing code, and in that code the actual error occurs.
config.lua
application = {
content = {
width = 320,
height = 480,
scale = "letterBox",
fps = 30
}
}
Original Post (obsolete)
I'm having a hard time at tracking down an error in Corona SDK.
The error causes the simulator to show the following message:
Corona Simulator Runtime error
File: ?
Attempt to perform arithmetic on field '?' (a function value)
stack traceback:
[C]: ?
?: in function <?:172>
?: in function <?:218>
How shall I interpret such message? I have no source files with
that many lines, by the way.
I have a file named Button.lua and line 41 seems to be involved
in raising an exception, although it is not raised from that
line. The line is:
button:insert(b1)
I wrapped that line between two prints:
print("Before", button, b1)
button:insert(b1)
print("After")
The following messages are printed in the simulator console:
Corona Simulator[9801:f03] Before table: 0x11daf4aa0 table: 0x1152363a0
Corona Simulator[9801:f03] After
Instead of your line:
transition.to(gNonEmpty3, { time = 1000, x = 100, easing.outExpo })
use :
transition.to(gNonEmpty3, { time = 1000, x = 100, transition = easing.outExpo })
In corona, such error message will occur when you have some wrong syntax or wrong logic. So, check for those issues first. Inserting print between the lines (that you used) is the best solution to find such error lines.
Keep Coding............. :)