I'm scripting a web page that displays a HighStock chart of data from ThingSpeak. It limits data calls to 8000 points, so I need to make several calls to load the entire data set. I plan to show the chart when the latest data comes in, and then add earlier data. My first attempt using addPoint() expands the navigator back to 1970, but does not add the data. Is there a problem adding data with dates earlier than the current data? How should I script this?
Here's how I call the addPoint() method:
dynamicChart.series[fieldList[fieldIndex].series]
.addPoint(fieldList[fieldIndex].data,false);
and the Array[] that I send it:
fieldList: Array[3]
0: Object
data: Array[8000]
0: Array[2]
0: 1371821816000
1: 36.79
length: 2
__proto__: Array[0]
1: Array[2]
0: 1371821836000
1: 36.75
length: 2
__proto__: Array[0]
2: Array[2]
3: Array[2]
4: Array[2]
I tried increasing the turboThreshold to 10000, but it didn't help.
Then I replaced the add points() line with this:
dynamicChart.series[fieldList[fieldIndex].series].addPoint({},false);
...and got the same result. What's going on here? Whats wrong with my data object?
The addPoints() method only adds a single point.
My solution was to push the new points into the origional array, sort it, and then use setData() to update the series:
for (var h=0; h<data.feeds.length; h++) // iterate through each feed (data point)
{
// if a numerical value exists add it
if (!isNaN(parseInt(v))) { fieldList[fieldIndex].data.push(p); }
}
fieldList[fieldIndex].data.sort(function(a,b){return a[0]-b[0]});
dynamicChart.series[fieldList[fieldIndex].series].setData(fieldList[fieldIndex].data,false);
Sorting was important, if the order is not increasing, the new data will not be displayed.
Related
I'm creating a program in Q#.
Problem
You are given two qubits in state |00⟩. Your task is to create the following state on them:
1/3–√(|00⟩+|01⟩+|10⟩)
You have to implement an operation which takes an array of 2 qubits as an input and has no output. The "output" of your solution is the state in which it left the input qubits.
Code
namespace Solution {
open Microsoft.Quantum.Primitive;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Convert;
operation Solve (qs : Qubit[]) : Unit
{
body
{
Ry(ArcCos(Sqrt(2.0/3.0))*2.0,qs[0]);
(ControlledOnInt(0,H))([qs[0]],qs[1]);
}
}
}
But when I run it show me the following error.
Error
CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point
[C:\Users\Pawar\Desktop\HK\codeforces\Q#\Solution\Solution.csproj]
So I tried to put EntryPoint() before the method declaration . Which shows me different error as
error QS6231: Invalid entry point. Values of type Qubit may not be used as arguments or return values to entry points. [C:\Users\Pawar\Desktop\HK\codeforces\Q#\Solution\Solution.csproj]
Please help me how to run it properly ?
thanks ✌️
In order to run a Q# program as an executable, you need to have an #EntryPoint() operation defined. You can read more in this excellent blog post: https://qsharp.community/blog/qsharp-entrypoint/.
Specifically, in your case, the error message indicates that Qubit[] is not a valid parameter to the main entry point of your program. Which makes sense, because it doesn't make sense to pass an array of qubits when executing a program from the command line. And also, your operation doesn't print anything or return any results, so you won't be able to see what it's doing.
You should probably create an #EntryPoint() wrapper operation that invokes your existing operation with the appropriate parameters, maybe prints some diagnostics, and then returns some result. In your case, you could perhaps do something like this (note the additional namespaces you need to open):
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Measurement;
#EntryPoint()
operation SolveForTwoQubits() : Result[]
{
using (qubits = Qubit[2])
{
Solve(qubits); // invoke your existing Solve operation
DumpMachine(); // outputs the state of your qubits
let results = MultiM(qubits); // measure the qubits
ResetAll(qubits); // reset the qubits to the initial state
return results; // return the measured results
}
}
This will give some output that looks like:
# wave function for qubits with ids (least to most significant): 0;1
∣0❭: 0.577350 + 0.000000 i == ******* [ 0.333333 ] --- [ 0.00000 rad ]
∣1❭: 0.577350 + 0.000000 i == ******* [ 0.333333 ] --- [ 0.00000 rad ]
∣2❭: 0.577350 + 0.000000 i == ******* [ 0.333333 ] --- [ 0.00000 rad ]
∣3❭: 0.000000 + 0.000000 i == [ 0.000000 ]
[Zero,One]
I am creating an application that will help our employees manage tasks. Tasks are submited via form. OnBeforeCreate I'm taking a date of task subbmission:
record.Data_Zlozenia = new Date();
The task falls into view for region (table widget), from where employees can pick it up.
The task that is submmited has 48 hour deadline.
Problem: How to color the row of task that exceed the deadline?
I know that I can color the row via adding a class in style editor and then on the row "Display" styles the binding. But I don't know how to make it depend on time.
`.red {
background-color: red;
}
#widget.descendants.Field3.text === "Oczekujący - zwrot" ? ['red','app-ListTableRow','hoverAncestor'] : ['app-ListTableRow','hoverAncestor']`
EDIT 1: Here I give U screenshots how it looks and what I tried.
CSS
Bindings
EDIT 2: With #Markus help I found a solution. I should put a binding like this:
(#datasource.item.Data_Zlozenia)/3600000 < ((new Date())/3600000 - 48) ? ['red','app-ListTableRow','hoverAncestor'] : ['app-ListTableRow','hoverAncestor']
This is untested, but I would try the following in your row styles binding:
setInterval(function() {(new Date() - #widget.datasource.item.Data_Zlozenia)/3600000;}, 60000) > 48 ? ['red','app-ListTableRow','hoverAncestor'] : ['app-ListTableRow','hoverAncestor']
Hypothetically speaking this will take the current Date/Time minus your field Date/Time and convert it to hours by dividing it by 3.6 million (JS date minus a date will return milliseconds so you have to convert to hours) and it will repeat this function every minute (60000 milliseconds). As stated, this is untested so you might need to refine a little
Experienced programmer playing around with Gamemaker2 Studio.
Trying to draw some random squares on the screen using a 2D array to store the "map"
Step 1 : declare a 2D array MyMap[25,25] this works
Step 2 : Set 100 random locations in Map[]=1 this works
I get a crash when I try to look up the values I have stored in the array.
Its crashing with:
**Execution Error - Variable Index [3,14] out of range [26,14] **
So it looks like it is trying to read 26 element, when you can see from my code the for next loop only goes to 20 and the array bound is 25.
Oddly enough it does the first two loops just fine?
Looking like a bug, I've spent so much time trying to work it out, anyone got an idea what is going on?
var tx=0;
var ty=0;
var t=0;
MyMap[25,25]=99; **// Works**
for( t=1; t<100; t+=1 ) **// Works**
{
MyMap[random(20),random(15)]=1
}
for( tx=1; tx<20; tx+=1 )
{
for( ty=1; ty<15; ty+=1 )
{
show_debug_message(string(tx) + ":" + string(ty))
t = MyMap[tx,ty]; /// **<---- Crashes Here**
if t=1 then {draw_rectangle(tx*32,ty*32,tx*32+32,ty*32+32,false) }
}
}
The line MyMap[random(20),random(15)]=1 does not initialize values in the entire array, creating a sparse array(where some elements do not exist).
The line MyMap[25,25]=99;
Should read:
for( tx=1; tx<20; tx+=1 )
{
for( ty=1; ty<15; ty+=1 )
{
MyMap[tx,ty]=99;
}
}
This will pre-initialize the all of the array values to 99. Filling out the array.
Then you can randomly assign the ones. (You will probably get less than 100 ones the due to duplicates in the random function and the random returning zeros.)
You should have the above code in the Create Event, or in another single fire or controlled fire event, and move the loops for the draw into the Draw Event.
All draw calls should be in the Draw Event. If the entire block were in Draw, it would randomize the blocks each step.
I want to create a lottery skill that takes 6 numbers from the user.
I'm currently learning by going through the samples and developer guides, and I can go through the guides and get a working skill that will take one input and then end the session. But I believe I need to create a dialog somehow, which is where I get stuck.
Design-wise, I'd like the dialog to go like this:
Alexa: Please provide the first number
User: 1
Alexa: and now the second...
User: 2
etc etc
But I think it would be OK if it went like this:
Alexa: Please call out 6 numbers
User: 1, 2, 3, 4, 5, 6.
Is this even possible? Will I have to create a custom slot type called "Numbers" and then put in the numbers, eg 1-50 or whatever the limit is?
At best, I can currently get it to ask for one number, so its really the dialog interaction that I'm stuck on. Has anyone ever even done anything like this?
Thanks.
Yes to both questions. You could string together a response with 6 different custom slots. "User: My numbers are {num1}, {num2}, {num3}, {num4}, {num5}, {num6} " and make them all required using the skills beta developer. However, it will be a rather bad user experience if the user does not phrase their answer appropriately and Alexa has to ask follow up questions to obtain each number. The last problem you'll run into is that while a custom slot could be defined to contain the numbers 1-50 alexa will generally recognize similar values to those provided in a custom slot, such as numbers from 50-99. It would then be up to you to check that the values you receive are between 1 and 50. If not you'd want to ask the user to provide a different number in the appropriate range.
Conclusion: You'll want to have individual interactions where a user provides a single number at a time.
Alexa:"you will be prompted for 6 numbers between 1 and 50 please state them one at a time. Choose your first number."
User:"50"
Alexa:"Your First number is 50, Next number."...
You can implement this using a single intent. let's name that intent GetNumberIntent. GetNumberIntent will have sample uterances along the line of
{number}
pick {number}
choose {number}
where {number} is a custom slot type or simply AMAZON.NUMBER. It will then be up to you to check that the number is between 1 and 50.
I program in Node.js using the SDK. Your implementation may vary depending upon your language choice.
What I would do is define 6 different state handlers. Each handler should have the GetNumberIntent. When a GetNumberIntent is returned if the slot value is apropriate store the value to the session data and or dynamodb and move forward to the next state. If the slot value is invalid stay for example at state "NumberInputFiveStateHandlers" until a good value is received then change state to the next "NumberInputSixStateHandlers"
var NumberInputFiveStateHandlers = Alexa.CreateStateHandler(states.NUMFIVEMODE, {
'NewSession': function () {
this.emit('NewSession'); // Uses the handler in newSessionHandlers
},
//Primary Intents
'GetNumberIntent': function () {
let message = ` `;
let reprompt = ` `;
let slotValue = this.event.request.intent.slots.number.value;
if(parseInt(slotValue) >= 1 && parseInt(slotValue) <= 50){
this.handler.state = states.NUMSIXMODE;
this.attributes['NUMBERFIVE'] = this.event.request.intent.slots.number.value;
message = ` Your fifth number is `+slotValue+`. please select your sixth value. `;
reprompt = ` please select your sixth value. `;
}else{
message = ` The number `+slotValue)+` is not in the desired range between 1 and 50. please select a valid fifth number. `;
reprompt = ` please select your fifth value. `;
}
this.emit(':ask',message,reprompt);
},
//Help Intents
"InformationIntent": function() {
console.log("INFORMATION");
var message = ` You've been asked to choose a lottery number between 1 and 50. Please say your selection.`;
this.emit(':ask', message, message);
},
"AMAZON.StopIntent": function() {
console.log("STOPINTENT");
this.emit(':tell', "Goodbye!");
},
"AMAZON.CancelIntent": function() {
console.log("CANCELINTENT");
this.emit(':tell', "Goodbye!");
},
'AMAZON.HelpIntent': function() {
var message = `You're playing lottery. you'll be picking six numbers to play the game. For help with your current situation say Information. otherwise you may exit the game by saying quit.`;
this.emit(':ask', message, message);
},
//Unhandled
'Unhandled': function() {
console.log("UNHANDLED");
var reprompt = ' That was not an appropriate response. Please say a number between 1 and 50.';
this.emit(':ask', reprompt, reprompt);
}
});
This is an example of the fifth request. You'll have 6 identical states like this one that string back to back. Eventually you'll end up with 6 session values.
this.attributes['NUMBERONE']
this.attributes['NUMBERTWO']
this.attributes['NUMBERTHREE']
this.attributes['NUMBERFOUR']
this.attributes['NUMBERFIVE']
this.attributes['NUMBERSIX']
You can then use these values for your game.
If you have not used the alexa-sdk before you must remember to register your state handlers and add your modes to the states variable.
alexa.registerHandlers(newSessionHandlers, NumberInputOneStateHandlers, ... NumberInputSixStateHandlers);
var states = {
NUMONEMODE: '_NUMONEMODE',
...
...
NUMSIXMODE: '_NUMSIXMODE',
}
This answer is not intended to cover the basics of coding using Alexas-SDK. There are other resourced for more specific questions on that topic.
Alternatively, because your intent is identical [GetNumberIntent], you may be able to get by with a single StateHandler that pushes new valid numbers onto an array until the array is the desired length. That would simply require more logic inside the Intent Handler and a conditional to break out of the state once the array is of length 6.
Try the code above first because it's easier to see the different states.
In icCube reporting tool 6.1
is there a possibility to retrieve data like a cellValue(rowindex,columnindex) while i'm in a diffrent widget like chart box for example and wanna get a cell value from different table in the report? with Widget's JavaScript...? and also do other functions like column count or row count as i'm in the Widget's JavaScript of the actual table...?
UPDATED QUESTION
Example:
i wanna be able for example to get in the chart palette by Expression to
retrieve the number of the 1 row and column 2 (value 12)
and then for the example i wanna use this number and see if the number is greater then 10 then i will want the chart color to be Green and if less the blue... so i wanna know how to retrieve a specific cell from the table when the chart loads... and the chart will wait for a click on row from the table
so it will load after the table... so the rendering problem you've mentioned you have won't be a problem here.
You can share Table's data with global variable.
In On Data Received hook:
/**
* Return data object
*/
function(context, data, $box) {
window.ic3Data = {};
window.ic3Data.tableContext = context;
return data;
}
Then you can easily use PublicTableContext API from table widget in other charts. For example in a coloring expression for an AmChart:
return window.ic3Data.tableContext.cellValue(0,1) > 10 ? 'green' : 'red';