I have the following spreadsheet I am looking to solve a somewhat simple problem for:
Spreadsheet
Data tab contains the irregular data (as seen by the dates)
Chart 1 tab contains a working chart as I wish it to be presented
Chart 2 tab contains the new array structure I wish to populate
I cannot for the life of me figure out how to populate cell x,y on the Chart 2 array when matching x & y from the Data tab. ie - replicating 322 from cell Data - F3 to cell Chart 2 - H75 etc
INDEX - MATCH doesn't work as it references the cell location, not the cell contents - and as the array, I am graphing from is dynamic, this doesn't work.
The intended outcome is to be able to then QUERY the resultant data and plot an Age vs Weight chart instead of current Date vs Weight chart.
paste this into H4 cell and drag to the right:
=ARRAYFORMULA(IFERROR(VLOOKUP($G$4:$G, Data!$A$2:$U,
IFS(H2="Bear", 2,
H2="Bwuce", 3,
H2="Calcifer", 4,
H2="Capt. Kwazy Sox", 5,
H2="Chooie", 6,
H2="Lil Fibbs", 7,
H2="Howl", 8,
H2="JC", 9,
H2="Jim Rat", 10,
H2="Milo Jr", 11,
H2="Sgt. Simba Sox", 12,
H2="Angel", 14,
H2="Fern", 15,
H2="Fuzznut", 16,
H2="Houdini", 17,
H2="Kami", 18,
H2="Mumma Bear", 19,
H2="Rosie J", 20,
H2="Sophie", 21), 0), ))
Related
I am using Laravel + Backpack for admin panel and I am trying to display a chart with 12 labels (for each month) and integer data corresponding for each month. My problem is that all datasets go under the first label and I cannot figure out how to put each dataset under the correct label.
Code (keep it short):
$array; // array of eloquent models
$array2; // array of eloquent models
$this->chart->labels([
'January',
'February',
]);
$this->chart->dataset('January Exp', 'bar', count($array))
->color('rgba(205, 32, 31, 1)')
->backgroundColor('rgba(205, 32, 31, 0.4)');
$this->chart->dataset('February Exp', 'bar', count($array2))
->color('rgba(205, 32, 31, 1)')
->backgroundColor('rgba(205, 32, 31, 0.4)');
I have tried looking up on Google of a way I can bind each dataset to a particular label, but I was not able to find a solution. Perhaps I am going at it from the wrong direction.
Following Backpack's docs and Laravel Charts' docs I should be able to declare the labels and the datasets and those should show up as expected.
I have also tried declaring the datasets in the setup() function as well as the data() function. Both ways lead to the same result.
Found a solution that seems to work for my use case.
Declare the labels then one dataset with an array for the values.
Code:
$array; // array of eloquent models
$array2; // array of eloquent models
$this->chart->labels([
'January',
'February',
]);
$this->chart->dataset('Exp', 'bar', [count($array), count($array2)])
->color('rgba(205, 32, 31, 1)')
->backgroundColor('rgba(205, 32, 31, 0.4)');
I hope someone finds this useful in the future.
Task is to show only last 5 records in google chart. As you move slider, on end, data is adding.
Records are from some "slider", later will be replaced with some live senzor data.
hAxis is timestamp so i don't know how to use:
viewWindowMode: 'explicit',
// viewWindow: {
// min: 0,
// max: 4
// },
Sow question is how to remove rows from data cache?
JSFiddle: https://jsfiddle.net/ejovrh2/k59u6be3/17/
when using timestamp on the x-axis,
you can use a date object directly, no need to convert to a string.
var data = google.visualization.arrayToDataTable([
["Date", "level"],
[new Date(), level],
]);
and to control the range displayed on the x-axis,
viewWindow min & max should be the same data type.
in this case, a date.
viewWindow: {
min: new Date(2020, 10, 1),
max: new Date(2020, 10, 30)
},
As #WhiteHat said you can use data.getColumnRange and then extract min&max.
In my case I need to show just last few records no matter dates.
So I needed this part of code:
data.removeRow(0);
Answer
// when data is populated with 4 rows, remove first one [0]
if (data.cache.length>4){
data.removeRow(0);
// just to see range and how is removing first element
var dateRange = data.getColumnRange(0);
console.log(dateRange);
}
Finnish fiddle
I'm using IndexSet and I'm trying to access some indexes which at times are consecutive and at other times are not.
For example, my set may contain [1, 2, 3, 5, 6, 7, 13, 31]
I want to pull out of the set a range of 3...13, but am having difficulty with the syntax. I've learned how to use the function commands from Apple documentation, by using myIndexSet.sorted(). However, the Apple Documentation does not give an example of how to access a range of elements in the set. The Apple Documentation for accessing elements in the index set are the following:
subscript(Range<IndexSet.Index>)
I've tried a number of ways to write this but can't figure out how to do it right. Can someone show me how to access a range of elements in the set to create a new set? I've tried things such as:
let subset = subscript(Range: myLargerSet.3...13)
but it doesn't seem to work.
Thanks
What you're looking for is the intersection of your IndexSet ([1, 2, 3, 5, 6, 7, 13, 31]) with another IndexSet ([3, 4, ..., 12, 13]):
let yourIndexSet: IndexSet = [1, 2, 3, 5, 6, 7, 13, 31]
let desiredIndexRange = IndexSet(3...13)
let indicesOfInterest = yourIndexSet.intersection(desiredIndexRange)
print(indicesOfInterest.sorted()) // => [3, 5, 6, 7, 13]
One possible solution is to use a filter to create a new IndexSet.
let set = IndexSet(arrayLiteral: 1,2,3,5,6,7,13,31)
let subset = set.filteredIndexSet { (index) -> Bool in
index >= 3 && index <= 13
}
You can access a slice of your original set as follows:
let slice = indexSet[indexSet.indexRange(in: 3...13)]
slice accesses the existing elements in place, so creation of the slice is O(1)
How to generate different random number by scala? and the number should be as short as possible.I want to generate unique id to label data, in the same time the id should be short enough to save the cost?
Since your requirement is
random number
unique
as short as possible
Then I think you should consider to use scala.util.Random.shuffle, eg,
scala.util.Random.shuffle(1 to 30)
Above code will generate a Vector that contains unique random number (in terms of position) from 1 to 30, eg, Vector(26, 10, 7, 29, 11, 14, 16, 1, 12, 9, 28, 6, 19, 4, 27, 8, 13, 18, 30, 20, 23, 5, 21, 24, 17, 25, 2, 15, 22, 3).
Basically it just fulfill everything you need.
If you prefer to get the result in Set or List, simply call toSet or toList method will do.
nextInt can achieve the same thing but you might need a lot of logic and retry mechanism for it.
Try this:
import util.Random.nextInt
Stream.continually(nextInt(100)).take(10)
or you can check in console the numbers generated:
import util.Random.nextInt
val res = Stream.continually(nextInt(100)).take(10)
res.foreach(println)
So basically you can use "Set" to generate unique random numbers.
val r = scala.util.Random
var temp:Int = 0
var s:Set[Int] = Set()
var i:Int = 0
while(i<n){
temp = r.nextInt(range) //random number will be checked whether it is already in the set or not
if(!s.contains(temp)){ //if the random number is not in the set
s=s+temp; //random number is added in the set
i+=1
}
}
s.toArray //converts the set into array
I have a spatially enabled database (DB2, in this case). I need to store a large number of squares in a table. Which standard spatial SQL datatype is most suitable?
I guess I could use an ST_polygon, but maybe there is a more specialized type which would give
better performance
better data guarantees (I want to catch it as an error if someone where to store a non-square value in the particular column)
I've tried to find an ST_rectangle or ST_square type, but they don't seem to exist(?)
While I'm working with DB2, I'm also interested in solutions which don't work on DB2, as long as they are standards-compliant.
Even if your data represents a rectangle or square, you will still need to use the ST_POLYGON type. However, when you perform a query against the data, you can use a first-order filters such as ST_EnvIntersects.
Normally, a spatial database will compare the envelopes (i.e. a rectangle that contains the polygon) for an intersection. Then it performs the more expensive polygon-to-polygon intersection calculation. In this case, since your polygons are equal to the envelope, you can skip the second more expensive step.
As far as data validation, you can add a database trigger that checks ST_EQUALS(ST_ENVELOPE(geom),geom) = 1.
In DB2 it is also a Polygon. It looks like you are storing grids, so a quick check could be that if ST_ENVELOPE(geometry) == geometry then you have a square
This code is from
DB2's documentation
SET CURRENT PATH = CURRENT PATH, db2gse;
CREATE TABLE sample_geoms (id INTEGER, geometry ST_Geometry);
INSERT INTO sample_geoms VALUES
(1, ST_Geometry(ST_Point('point EMPTY',0)));
INSERT INTO sample_geoms VALUES
(2, ST_Geometry(ST_Point('point zm (10 10 16 30)' ,0)));
INSERT INTO sample_geoms VALUES
(3, ST_Geometry(ST_Multipoint('multipoint m (10 10 5, 50 10 6,
10 30 8)' ,0)));
INSERT INTO sample_geoms VALUES
(4, ST_Geometry(ST_Linestring('linestring (10 10, 20 10)',0)));
INSERT INTO sample_geoms VALUES
(5, ST_Geometry(ST_Polygon('polygon((40 120, 90 120, 90 150,
40 150, 40 120))',0)));
SELECT id, CAST(ST_AsText(ST_Envelope(geometry)) as VARCHAR(160)) Envelope
FROM sample_geoms;
Results:
ID ENVELOPE
----------- ---------------------------------------------------------------
1 -
2 POLYGON (( 9 9, 11 9, 11 11, 9 11, 9 9))
3 POLYGON (( 10 10, 50 10, 50 30, 10 30, 10 10))
4 POLYGON (( 10 9, 20 9, 20 11, 10 11, 10 9))
5 POLYGON (( 40 120, 90 120, 90 150, 40 150, 40 120))
See ID = 5? the last POLYGON == ST_ENVELOPE(geometry)
You may be looking for ST_Envelope -- I don't know for sure about DB2 but it is part of the OGC standard. Any non-vertical or non-horizontal line, or polygon, will generate a rectangle via this function, storing the coordinates typically as floats.