I'm using the TextFinder class in Google App Scripts to find cells that have a particular number in them. I believe that leaves me with a RangeList object, which seems to be a kind of Javascript Array, although I'm not sure.
I'd like to perform the getRow() operation on each Range in the list so that I can select the whole row in which that number occurs. Currently, this is the code I'm using to do this:
var idRowRanges = [];
for (cell of idCells) {
idRowRanges.push(cell.getRow());
var idRange = sheet.getRange(cell.getRow(), 1, 1, sheet.getLastColumn());
var rowValues = idRange.getValues();
}
Coming from a Python background this looks very slow to me, is there a faster way of performing an operation like this?
Ideally, you'd want to avoid touching the spreadsheet except twice for I/O(once for each). In this case, if you assume getRow() doesn't check the spreadsheet, the reason why it is slow, is because of your repeated calls to getValues(). Refactoring your code, you'd get:
const fullData = sheet.getDataRange().getValues();//I/O call
const idRowRanges = [];
for (cell of idCells) {
const thisIdRow = cell.getRow(),
thisIdRowValues = fullData[thisIdRow];//1D array; No call to ss
}
Using textfinder
function find(n=5) {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet0");
const rg = sh.getDataRange();
let ns = rg.createTextFinder(n).findAll();
let list = ns.map(n => n.getA1Notation());
Logger.log(JSON.stringify(list));
}
Execution log
2:41:09 PM Notice Execution started
2:41:10 PM Info ["E1","G4","G6","H7","J9","B10"]
2:41:11 PM Notice Execution completed
Sheet0:
COL1
COL2
COL3
COL4
COL5
COL6
COL7
COL8
COL9
COL10
9
10
9
4
14
14
8
12
6
17
9
16
2
19
12
10
4
1
10
2
10
14
17
11
7
0
5
19
10
17
14
14
2
7
8
19
12
17
2
0
7
7
10
4
4
19
15
16
14
18
13
11
13
6
3
9
10
15
3
12
17
1
2
13
11
8
18
19
10
9
4
0
12
12
0
10
8
3
19
15
0
5
6
13
7
19
4
2
10
19
I have a dictionary with 1000 keys and each key has 23 entries, each is an xarray.DataArray.
Each entry looks like this:
<xarray.DataArray 'time' (time: 23)>
array(['1861-01-16T12:00:00.000000000', '1861-02-15T00:00:00.000000000',
'1861-03-16T12:00:00.000000000', '1861-04-16T00:00:00.000000000',
'1861-05-16T12:00:00.000000000', '1861-06-16T00:00:00.000000000',
'1861-07-16T12:00:00.000000000', '1861-08-16T12:00:00.000000000',
'1861-09-16T00:00:00.000000000', '1861-10-16T12:00:00.000000000',
'1861-11-16T00:00:00.000000000', '1861-12-16T12:00:00.000000000',
'1862-01-16T12:00:00.000000000', '1862-02-15T00:00:00.000000000',
'1862-03-16T12:00:00.000000000', '1862-04-16T00:00:00.000000000',
'1862-05-16T12:00:00.000000000', '1862-06-16T00:00:00.000000000',
'1862-07-16T12:00:00.000000000', '1862-08-16T12:00:00.000000000',
'1862-09-16T00:00:00.000000000', '1862-10-16T12:00:00.000000000',
'1862-11-16T00:00:00.000000000'], dtype='datetime64[ns]')
Coordinates:
* time (time) datetime64[ns] 1861-02-15 ... 1862-12-16T12:00:00
month (time) int64 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11
I am trying to concatenate all these entries and get a new variable with dimensions ( 1000,23)
which would look like
<xarray.DataArray 'entries','time' (entries:1000,time: 23)>
and then I want to be able to write this into a Netcdf file so to use .to_netcdf.
If I do
tt=xr.concat(entry[0],entry[1])
I get the following:
<xarray.DataArray 'time' (time: 23)>
array(['1861-01-16T12:00:00.000000000', '1861-02-15T00:00:00.000000000',
'1861-03-16T12:00:00.000000000', '1861-04-16T00:00:00.000000000',
'1861-05-16T12:00:00.000000000', '1861-06-16T00:00:00.000000000',
'1861-07-16T12:00:00.000000000', '1861-08-16T12:00:00.000000000',
'1861-09-16T00:00:00.000000000', '1861-10-16T12:00:00.000000000',
'1861-11-16T00:00:00.000000000', '1861-12-16T12:00:00.000000000',
'1862-01-16T12:00:00.000000000', '1862-02-15T00:00:00.000000000',
'1862-03-16T12:00:00.000000000', '1862-04-16T00:00:00.000000000',
'1862-05-16T12:00:00.000000000', '1862-06-16T00:00:00.000000000',
'1862-07-16T12:00:00.000000000', '1862-08-16T12:00:00.000000000',
'1862-09-16T00:00:00.000000000', '1862-10-16T12:00:00.000000000',
'1862-11-16T00:00:00.000000000'], dtype='datetime64[ns]')
Coordinates:
* time (time) datetime64[ns] 1861-01-16T12:00:00 1861-02-15 ... 1862-11-16
month (time) int64 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11
<xarray.DataArray 'time' (time: 23)>
array(['1861-01-16T12:00:00.000000000', '1861-02-15T00:00:00.000000000',
'1861-03-16T12:00:00.000000000', '1861-04-16T00:00:00.000000000',
'1861-05-16T12:00:00.000000000', '1861-06-16T00:00:00.000000000',
'1861-07-16T12:00:00.000000000', '1861-08-16T12:00:00.000000000',
'1861-09-16T00:00:00.000000000', '1861-10-16T12:00:00.000000000',
'1861-11-16T00:00:00.000000000', '1861-12-16T12:00:00.000000000',
'1862-01-16T12:00:00.000000000', '1862-02-15T00:00:00.000000000',
'1862-03-16T12:00:00.000000000', '1862-04-16T00:00:00.000000000',
'1862-05-16T12:00:00.000000000', '1862-06-16T00:00:00.000000000',
'1862-07-16T12:00:00.000000000', '1862-08-16T12:00:00.000000000',
'1862-09-16T00:00:00.000000000', '1862-10-16T12:00:00.000000000',
'1862-11-16T00:00:00.000000000'], dtype='datetime64[ns]')
Coordinates:
* time (time) datetime64[ns] 1861-02-15 ... 1862-12-16T12:00:00
month (time) int64 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11
So how I loop over this and transform the entries of the dictionary into a new dimension for the xarran.DataArray and get the (1000,23) xarray.DataArray ?
Thanks !
Some ideas:
ds = xr.Dataset({'Entry_0': entry[0],
'Entry_1': entry[1],
'Entry_2': entry[2]
#... and so on
})
Or another way to do the same thing is:
# create empty xarray dataset
ds = xr.Dataset({})
# add data arrays to xarray dataset
ds['Entry_0'] = entry[0]
ds['Entry_1'] = entry[1]
ds['Entry_2'] = entry[2]
# add so on
Or use a for loop for more concise code:
# create empty list to store xarray data arrays
data_arrays = []
# for loop to add data arrays to list
for idx in range(len(entry)):
da = entry[idx]
data_arrays.append(da)
# concatenate list of data arrays along new dimension into xarray dataset
ds = xarray.concat(data_arrays, dim='new_dim')
when I create links in Cake Paginator with:
$this->Paginator->numbers(array('separator' => '', 'modulus' => 2))
I get the result:
1 2 3 4 5 [6] 7 8 9 10
6 - current page
I want result:
1 .. 4 5 [6] 7 8 .. 10
Why option modulus dont working? I think that with modulus =2 result should be that what I want to achieve.
Try to read the documentation first. Modules is the amount of records shown around the page you're on. The documentation explains this pretty clearly:
Uses a modulus to decide how many numbers to show on each side of the
current page By default 8
There is even an example for what you want:
echo $this->Paginator->numbers(array(
'first' => 2,
'last' => 2,
'modulus' => 2
)
);
Output:
1 | 2...5 | 6 | 7...56480 | 56481
Yea I've got a ton of records in that table. ;)
Are you overriding the 'first' and 'last' parameters?
This code should give you what you're after:
echo $this->Paginator->numbers(array(
'separator' => ' ',
'modulus' => 4,
'first' => 1,
'last' => 1
));
On my system it gives the following output:
1...5 6 7 8 9...13
I have 6 txt files with words in them, each on a new line, which gets read and processed into their respective arrays. The code below worked for the first 5 arrays but not the last which is slightly different.
var loadFavourites: URLLoader = new URLLoader();;
var arFavourites = new Array();
loadFavourites.load(new URLRequest("Lists/Favourites.txt"));
loadFavourites.addEventListener(Event.COMPLETE, onLoadedFavourites);
function onLoadedFavourites(e6:Event):void {
arFavourites = e6.target.data.split("\r\n");}
I load it in the exact same way but no luck. If I trace arFavourites.length it gives me 0. I just need it to load every 5 values into a datagrid.
var iC:int=0;
var iX:int=0;
while (!iX==arFavourites.length-1)
{
trace(iX);
if (iC == 5) {
dg.addItem({Place: arFavourites[iX-4],Subject:arFavourites[iX-3],Object:arFavourites[iX-2],Feeling:arFavourites[iX-1],Action:arFavourites[iX]});
iC=0;
} else {
iC++;
trace(iC);
}
iX++;
}
Thank you so much in advance for the help!
try doing something like this instead:
Favourites.txt:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Code:
var loadFavourites: URLLoader = new URLLoader();;
var favouritesArray = new Array();
loadFavourites.addEventListener(Event.COMPLETE, onLoadedFavourites);
loadFavourites.load(new URLRequest("Favourites.txt"));
function onLoadedFavourites(event:Event):void
{
favouritesArray = event.target.data.split("\r\n");
for (var i:int = 0; i <= favouritesArray.length; i++)
{
if (i != 0 && i % 5 == 0)
{
trace(i - 4, i - 3, i - 2, i - 1, i);
}
}
}
Output:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
I want to get the count of records from database.
In my table this is the values:
id emp_id number created_emp_id status timestamp
29 7 1 2 0 2012-09-24 15:18:28
30 16 1 2 0 2012-09-24 15:18:28
31 7 2 2 0 2012-09-24 15:18:54
32 19 2 2 0 2012-09-24 15:18:54
i have created_emp_id as 2.
So the result i needed her is 2.
That means the number is a repeated column.
This is the code i wrote for getting result:
$result = $this->TravancoDSRGroup->find('all', array('conditions' => array('created_emp_id= '.$emp_id),'fields' => array('DISTINCT TravancoDSRGroup.number')));
The $result return the two rows only.
But i need to get the count of this query....
Like...
$dsrPageCnt = $this->TravancoDSRGroup->find('count',................
How can i do this?
You can try this:
$dsrPageCnt = $this->TravancoDSRGroup->find('count', array('conditions' => array('created_emp_id= '.$emp_id),'fields' => array('DISTINCT TravancoDSRGroup.number')));
http://book.cakephp.org/1.3/view/1020/find-count