I'm coding in React-Native.
Glympse docs says that location data should be sent in a delta-compressed array. I don't really know what that means. I think I get the idea of each element being the amount of change (delta) from the previous element, but I still don't have a clear picture of how the body should look when I make the POST request.
Can anyone show an example of this process?
Examples of location arrays that are compressed can be found here https://developer.glympse.com/docs/core/api/reference/objects/location-points#examples
The idea behind this format is that the first item in the array contains specific values for each parameter, but each item that comes after that only contains the change (or delta) from the previous point.
[
[1339989715000, 37123450, -112123450, 18000, 55, null, 2, 4],
[1000, 1000000, 1000000, 0, null, 1000, 1, -1],
[1000, 0, 0, 0, 1, 0, 0, 0],
[1000, 0, 0, 0, 0, 0, 0, 0],
[1000, 0, 0, 0, 0, 0, 0, 0]
]
The first parameter is the timestamp, so if we look at the second item it shows 1000 which means it's the first timestamp + 1000ms.
The second parameter is latitude * 10^6. The first item shows latitude 37.123450, and the second item in the array has the value 1000000 which represents 37123450 + 1000000 or the latitude 38.123450. Not likely to have something moving that fast in real data, but that's the idea of how this format works.
Timestamp, latitude, and longitude are the only required fields. A POST body with only the required fields would look like this.
[
[1339989715000, 37123450, -112123450],
[1000, 1000000, 1000000],
[1000, 0, 0],
[1000, 0, 0],
]
So i opened a dataset and in short it looked something like this:
list1= ['Adrian,20,5,2000,green', 'Steve,15,6,1997,blue', ...]
trial = np.array(list1)
when i tried to print(trial[0][0]) to get Adrian, i only got the A.
So i figured i should make everything that has a comma after it an independent element, please help me get the output to be:
(['Adrian', 20, 5, 2000, 'green'], ['steve', 15, 6, 1997, 'blue'], ...)
where print(trial[0]) will give: ['Adrian', 20, 5, 2000, 'green']
and print(trial[0][0]) will give: Adrian
Just use the split function with a comma as the parameter like this:-
list2= ['Adrian,20,5,2000,green', 'Steve,15,6,1997,blue']
list1= []
for i in list2:
a = i.split(',')
list1 += [a]
trial = numpy.array(list1)
print(trial[0][0])
This will return Adrian.
You will still have to typecast the numbers to integer though, but that's easy to work around.
Say I have data: 0 (or near 0), 0, 0, ..., 1, 10, 52, 80, 100, 100, 100, 100 (for a while), 90, 45, 5, 0, 0, 0...
I want to find the index (not necessarily an int, I want more precision) of the 'center' of my plateau of data.
My first thought was to do a gaussian fit, but the data is rather flat for a while in the center. So maybe some kind of square (?) fit. I've been looking at minimization with gsl also, but I don't know what the simplest way to do this would be.
A simple way would be to find the index corresponding to the median value, but that gives me only a precision of 1. With a curve fitting I can do better.
Note: I'm in C and can use GSL, but a general math solution would work too!
Suggested algorithm:
Optionally filter data: median of 3, low pass, etc.
Find average value: Avg
Find average index of values above Avg: Center_index.
Average a few of the "values above" near Center_index.
Weighted Mean Center of a line, with an array similar to your data:
int w[] = {0, 0, 0, 1, 10, 52, 80, 100, 100, 100, 100, 90, 45, 5, 0, 0}
...is calculated by multiplying the x and y coordinate by the weight
for that feature and summing all for both x and y individually, and
then dividing this by the sum of all the weights.
Because this is a 1D array, position is expressed using the position within the array, i.e. the index, and looks like this:
weighted mean center = sum(w[i]*i)/sum(w[i]) //for all i
in pseudo code:
double sum_w=0;//sum of all values (weights)
double prod_wx=0;//product of all corresponding weights and positions
double wmc=0; //weighted mean center
for(int i=0;i<sizeof(w)/sizeof(w[0]);i++)
{
prod_wx += w[i]*i;
sum_w += w[i];
}
wmc = prod_wx/sum_w;
LogicApps Azure:
I have this array, and i need a function for get the value max for each property.
[
{
"limMec": 18,
"limMed": 6,
"maxCons": 1,
"maxImp": 188.23,
"maxVeh": 7
},
{
"limMec": 12,
"limMed": 6,
"maxCons": 10,
"maxImp": 200.66,
"maxVeh": 1
},
{
"limMec": 4,
"limMed": 9,
"maxCons": 1,
"maxImp": 1,
"maxVeh": 2
}
]
I need a function, not variables !!!
I have not found multiples functions for have a subarray with the differentes results.
Someone know?
With this i can get the value of an element, but not max of the collection:
max(body('Seleccionar')[1]['limMec'])
For this requirement, I provide a sample below for your reference:
1. I initialize a variable named data and store the same data with yours to simulate your situation.
2. Then add a "Select" action and click "Switch Map to key value mode", choose the variable data into "From" box and write expression item()?['limMec'] into "Map" box.
3. Now, initialize a variable result and use the expression max(body('Select')).
4. After running the logic app, we can get the max value of limMec.
I have a (somewhat) large truth table / state machine that I need to implement in my code (embedded C). I anticipate the behavior specification of this state machine to change in the future, and so I'd like to keep this easily modifiable in the future.
My truth table has 4 inputs and 4 outputs. I have it all in an Excel spreadsheet, and if I could just paste that into my code with a little formatting, that would be ideal.
I was thinking I would like to access my truth table like so:
u8 newState[] = decisionTable[input1][input2][input3][input4];
And then I could access the output values with:
setOutputPin( LINE_0, newState[0] );
setOutputPin( LINE_1, newState[1] );
setOutputPin( LINE_2, newState[2] );
setOutputPin( LINE_3, newState[3] );
But in order to get that, it looks like I would have to do a fairly confusing table like so:
static u8 decisionTable[][][][][] =
{{{{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }},
{{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }}},
{{{ 0, 0, 1, 1 },
{ 0, 1, 1, 1 }},
{{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 }}}},
{{{{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 }},
{{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 }}},
{{{ 0, 1, 1, 1 },
{ 0, 1, 1, 1 }},
{{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 }}}};
Those nested brackets can be somewhat confusing -- does anyone have a better idea for how I can keep a pretty looking table in my code?
Thanks!
Edit based on HUAGHAGUAH's answer:
Using an amalgamation of everyone's input (thanks -- I wish I could "accept" 3 or 4 of these answers), I think I'm going to try it as a two dimensional array. I'll index into my array using a small bit-shifting macro:
#define SM_INPUTS( in0, in1, in2, in3 ) ((in0 << 0) | (in1 << 1) | (in2 << 2) | (in3 << 3))
And that will let my truth table array look like this:
static u8 decisionTable[][] = {
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 1, 1 },
{ 0, 1, 1, 1 },
{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 },
{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 },
{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 },
{ 0, 1, 1, 1 },
{ 0, 1, 1, 1 },
{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 }};
And I can then access my truth table like so:
decisionTable[ SM_INPUTS( line1, line2, line3, line4 ) ]
I'll give that a shot and see how it works out. I'll also be replacing the 0's and 1's with more helpful #defines that express what each state means, along with /**/ comments that explain the inputs for each line of outputs. Thanks for the help, everyone!
I'd suggest either (preferred approaches first):
Use a macro to intialize each "row" - this will hide the braces within the macro call.
Use comments to break up the rows.
Use an init function to initialize the context explicitly - perhaps use functions to initialize each section. This is similar to the first option above but has a disadvantage that the init function must be invoked before the state machine can be used.
No need for a multidimensional table. With a 4 bit => 4 bit mapping, you can have a single u8[16] array mapping inputs to outputs. State lookups will be much cheaper, and you can extract individual bits with some shift-and-mask ops.
If the algorithm to populate rows is easy to codify, you could #define a macro to populate each row by index number.
Personally, I'd read it from a configuration file. CSV, perhaps, which is easy to export to from Excel. Or you could just copy and paste from Excel into plain text, which gives you space-separated values, which is equally easy to import.
This also means, given that you are working with C, that you won't have to recompile your code each time the decision table changes.
if your truth-table is all booleans, you could just collapse it to a list of pairs, e.g.
1111,0000
1110,0110
...
for data compression, represent the values as bytes (two nybbles)...
where/how to store it for soft-coding in your particular embedded-system configuration, only you can say ;-)
If the truth table is really only 4x4x4x4 then I'd use macros. If it's ever going to grow past that, I'd use Ragel. Chances are it will make smaller, faster C code than you will.
I don't see any reference to the current state in order to get your output state. This means it is not a state machine, but only a truth table. There are four inputs, so there are only 16 possible input combinations. So, a table with 16 positions ought to do it.
Usually when you have a problem like this, one tries to reduce it to a simple boolean formula. I don't see why that wouldn't be the best approach here. It would be much more compact and more readable, plus it has the potential to be faster (I imagine a handful of ANDs and ORs would execute more quickly than the collection of multiplies/shifts + memory access needed for the lookup table approach). The easiest way to reduce this table to a boolean formula is with a K-Map.