I'm struggling with my project. I can't get cell values, please if somebody help me with that.
In my project I have Roster tab and Holiday request tab, I want to find in roster tab cells that are in between dates from the Holiday request tab for that particular name and setValue("Holiday").
I tried with for loop, and didn't have any success, and map and get the indexOf column and find and no success to get it.
Here's the code I have
function Holidays() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
//Holiday request from
var master = ss.getSheetByName("Holiday Request");
//Roster tab
var target = ss.getSheetByName("Roster");
//
var values = target.getRange("A3:NI20").getValues();
var lc = target.getRange(3, 1, 1,target.getLastColumn()-1).getValues();
//
var appdis = master.getRange("G2:G250").getValues();
var name = master.getRange(2,3, master.getLastRow()-1, 1).getValues();
var sdate = master.getRange(2,4, master.getLastRow()-1, 1).getValues();
var edate = master.getRange(2,5, master.getLastRow()-1, 1).getValues();
sdate.map(d =>{
d[0]
var shd = sdate.find(n => n[0] == d[0])
name.map(n =>{
n[0]
var sname = values.find(r => r[0] == n[0])
for(i=0, j=0; i<values.lenght, j<values[i].lenght; i++, j++){
if(i == sname && j == shd)
var cells = values.getRange(i, j).getValues();
cells.setValues("Holiday");
}
})
})
}
Here is the file
https://docs.google.com/spreadsheets/d/1i3qMZgls3_WRPY5QSlQJo802D7xYDO80dih8E2-Vrd4/edit#gid=399093041
Any help will be really appreciated!
UPDATE!!!
I did research as I was advised. Now I am able to extract value for just one date from the list, as well I transformed the sname 2d array into Object. The difficult part is I still don't get it how to loop though the multiple dates that I have. With get.DisplayValue() it get one date, with get.DisplayValues() I can get all of them but can't get the indexOf all of them. Here's what I have
function Holidays() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
//Holiday request from
var hsheet = ss.getSheetByName("Holiday Request");
//Roster tab
var target = ss.getSheetByName("Roster");
// Roster values
//var dates = target.getDataRange().getDisplayValues();
var rosvalues = target.getRange(1, 1, target.getLastRow()-1,target.getLastColumn()-1).getValues();
var [, , dates, , ...rvalues] = target.getDataRange().getDisplayValues();
var sdate = hsheet.getRange(3, 4, hsheet.getLastRow()-1, 1).getDisplayValue();
//for(i=0; i<sdate.length; i++){
var col = dates.indexOf(sdate);
Logger.log(col)
//}
var sname = hsheet.getRange(2, 3, hsheet.getLastRow()-1, 1).getValues();
Logger.log(sdate)
Logger.log(sname)
var fcol = rvalues.reduce((o, r) => {
if(r[0]) o[r[0]] = r[col];
return o;
}, {});
Logger.log(fcol)
var nameObj = sname.reduce((a, [val1, val2]) => {
a[val1] = val2;
return a;
},{});
Logger.log(nameObj)
var textObj = { "08 - 17": "Holiday", "17 - 02": "Holiday", "11 - 20": "Holiday"};
var key1 = Object.keys(textObj);
var key2 = Object.keys(nameObj);
var cell = rosvalues.map((r, i) => r.map((c, j) => fcol[c] && key1.includes(fcol[c]) && key2.includes(fcol[c]) ? textObj[fcol[c]] : null));
cell.setValue("Holiday");
Logger.log(cell)
}
Please if you can tell me what I'm doing wrong. Thank you!
This function will calculate the total number of work days during the period of the holiday request and place that number in column 6 of the request sheet for each person on the list. I presumed that works days are days that do not contain the string "OFF"
function Holidays() {
const mA = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"];
const ss = SpreadsheetApp.getActive();
const req = ss.getSheetByName("Sheet0");//request sheet
const reqvs = req.getRange(2, 1, req.getLastRow() - 1, req.getLastColumn()).getValues();
const ros = ss.getSheetByName("Sheet1");//roster sheet
const rosdates = ros.getRange(3, 8, 1, ros.getLastColumn() - 7).getDisplayValues().flat();
const rosnames = ros.getRange(5, 1, ros.getLastRow() - 4).getDisplayValues().flat();
let vs;//I put vs up here so that I could see it in the debugger
reqvs.forEach(([, , n, s, e, d, ,], i) => {
let name = n;
let idx = rosnames.indexOf(name);
if (~idx) {
wds = 0;
let row = idx + 5;
let sd = new Date(s);//start date
let ed = new Date(e);//end date
const ds = dateStrings(sd, ed);
vs = rosdates.map((d, j) => { if (~ds.indexOf(d)) { return j + 8; } else { return ''; } }).filter(e => e);//returns column numbers and they are always consecutive
ros.getRange(row, vs[0], 1, vs.length).getValues().flat().forEach(v => { if (v != "OFF") { wds += 1; } });
req.getRange(i + 2, 6).setValue(wds)
}
});
}
function dateStrings(Day1,Day2) {
const mA = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"];
if(Day1 && Day2 && (Object.prototype.toString.call(Day1) === '[object Date]') && (Object.prototype.toString.call(Day2) === '[object Date]')) {
var day=86400000;
var t1=new Date(Day1).valueOf();
var t2=new Date(Day2).valueOf();
var d=Math.abs(t2-t1);
var days=Math.floor(d/day);
let dA = Array.from(new Array(days + 1).keys(),x => {
let dt = new Date(Day1.getFullYear(),Day1.getMonth(),Day1.getDate() + x);
return `${dt.getDate()} ${mA[dt.getMonth()]}`;
});
//Logger.log(dA);
return dA;
}
}
The Roster Sample Sheet:
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
21
23
25
27
29
31
33
35
37
39
2
Sun
Mon
Tue
Wed
Thu
Fri
Sat
Sun
Mon
Tue
Wed
Thu
Fri
Sat
Sun
Mon
Tue
Wed
Thu
Sat
Mon
Wed
Fri
Sun
Tue
Thu
Sat
Mon
Wed
3
1 Jan
2 Jan
3 Jan
4 Jan
5 Jan
6 Jan
7 Jan
8 Jan
9 Jan
10 Jan
11 Jan
12 Jan
13 Jan
14 Jan
15 Jan
16 Jan
17 Jan
18 Jan
19 Jan
21 Jan
23 Jan
25 Jan
27 Jan
29 Jan
31 Jan
2 Feb
4 Feb
6 Feb
8 Feb
4
Name
TL
Lang
EID
LI ID
Leaver
5
Name 1
Name 1
17 - 02
OFF
17 - 02
17 - 02
17 - 02
OFF
OFF
17 - 02
OFF
17 - 02
17 - 02
17 - 02
OFF
OFF
17 - 02
OFF
17 - 02
17 - 02
17 - 02
OFF
OFF
17 - 02
OFF
17 - 02
17 - 02
17 - 02
OFF
OFF
17 - 02
6
Name 2
Name 2
OFF
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
OFF
08 - 17
08 - 17
7
Name 3
Name 3
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
OFF
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
8
Name 4
Name 4
08 - 17
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
08 - 17
9
Name 5
Name 5
08 - 17
OFF
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
OFF
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
OFF
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
OFF
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
10
Name 6
Name 6
17 - 02
17 - 02
OFF
17 - 02
17 - 02
17 - 02
OFF
17 - 02
17 - 02
OFF
17 - 02
17 - 02
17 - 02
OFF
17 - 02
17 - 02
OFF
17 - 02
17 - 02
OFF
17 - 02
17 - 02
17 - 02
17 - 02
OFF
17 - 02
OFF
17 - 02
17 - 02
11
Name 7
Name 7
17 - 02
17 - 02
17 - 02
OFF
17 - 02
17 - 02
17 - 02
17 - 02
17 - 02
17 - 02
OFF
17 - 02
17 - 02
17 - 02
17 - 02
17 - 02
17 - 02
OFF
17 - 02
17 - 02
17 - 02
OFF
17 - 02
17 - 02
17 - 02
17 - 02
17 - 02
17 - 02
OFF
12
Name 9
Name 9
17 - 02
17 - 02
OFF
17 - 02
17 - 02
OFF
OFF
17 - 02
17 - 02
OFF
17 - 02
17 - 02
OFF
OFF
17 - 02
17 - 02
OFF
17 - 02
17 - 02
OFF
17 - 02
17 - 02
OFF
17 - 02
OFF
17 - 02
OFF
17 - 02
17 - 02
13
Name 10
Name 10
OFF
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
OFF
08 - 17
08 - 17
14
Name 11
Name 11
08 - 17
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
08 - 17
15
Name 12
Name 12
08 - 17
OFF
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
OFF
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
OFF
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
OFF
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
16
Name 13
Name 13
17 - 02
17 - 02
17 - 02
OFF
17 - 02
17 - 02
17 - 02
17 - 02
17 - 02
17 - 02
OFF
17 - 02
17 - 02
17 - 02
17 - 02
17 - 02
17 - 02
OFF
17 - 02
17 - 02
17 - 02
OFF
17 - 02
17 - 02
17 - 02
17 - 02
17 - 02
17 - 02
OFF
17
Name 14
Name 14
17 - 02
17 - 02
OFF
17 - 02
17 - 02
OFF
OFF
17 - 02
17 - 02
OFF
17 - 02
17 - 02
OFF
OFF
17 - 02
17 - 02
OFF
17 - 02
17 - 02
OFF
17 - 02
17 - 02
OFF
17 - 02
OFF
17 - 02
OFF
17 - 02
17 - 02
18
Name 15
Name 15
OFF
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
08 - 17
08 - 17
08 - 17
08 - 17
OFF
OFF
08 - 17
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
08 - 17
OFF
08 - 17
08 - 17
OFF
08 - 17
08 - 17
The Request Sample Sheet:
A
B
C
D
E
F
G
H
1
Request Date
Username
Name
Start Date
End Date
WorkDays
Approved
Reason
2
30 Mar
ag1
Name 1
1 Jan
6 Jan
4
3
31 Mar
ag2
Name 2
16 Jan
27 Jan
10
4
31 Mar
ag3
Name 3
10 Jan
20 Jan
8
creating markdown tables
google-apps-script reference
javascript reference
Learn More
i have 2 tables : dt_user and dt_invoice.
**dt_members :**
id firstname
3 Salim
5 Sara
8 Julie
**dt_invoice**
user_id amount_ht period month year
3 4950 04 2018 04 2018
3 7200 10 2018 10 2018
8 11000 10 2018 10 2018
8 5500 11 2018 11 2018
3 6750 11 2018 11 2018
3 8700 12 2018 12 2018
3 8800 01 2019 01 2019
8 7500 01 2019 01 2019
3 4950 02 2019 02 2019
3 7550 03 2019 03 2019
I want to create a query joining the two table, but i want to show each user_id for PERIOD that there is in table dt_invoice.
**Expected results :**
user_id amount_ht period month year
3 4950 04 2018 04 2018
5 0 04 2018 04 2018 //non-existent record in dt_invoice
8 0 04 2018 04 2018 //non-existent record in dt_invoice
3 7200 10 2018 10 2018
5 0 10 2018 10 2018 //non-existent record in dt_invoice
8 11000 10 2018 10 2018
8 5500 11 2018 11 2018
5 0 11 2018 11 2018 //etc ...
3 6750 11 2018 11 2018
3 8700 12 2018 12 2018
5 0 12 2018 12 2018
8 0 12 2018 12 2018
3 8800 01 2019 01 2019
5 0 01 2019 01 2019
8 7500 01 2019 01 2019
3 4950 02 2019 02 2019
5 0 02 2019 02 2018
8 0 02 2019 02 2018
3 7550 03 2019 03 2019
5 0 03 2019 03 2018
8 0 03 2019 03 2018
Thanks in advance for your help, i'm totally stuck ..
SQL datas available here : https://rextester.com/live/LBSEY76360
also in sqlfiddle : http://sqlfiddle.com/#!9/728af3/1
Use a cross join to generate the rows and left join to bring in the values:
select m.user_id, p.period, p.month, p.year,
coalesce(t.amount_ht, 0) as amount_ht
from dt_members m cross join
(select distinct period, month, year from dt_invoice) p left join
dt_invoice t
on t.user_id = m.id and t.period = p.period;
Maybe this would help.
SELECT user_id, amount_ht, period, month, year
FROM dt_invoice
LEFT JOIN dt_members ON user_id = id
I have query about following question:
Suppose, we have a 9*7 picture (7 pixels in the x direction and 9 pixels in the y direction), how many warps will have control divergence assuming block of 4*4 threads and 8 threads per warp?
How will the blocks and warps be organized here?
for x or horizontal direction, i can assume 2 blocks per row.Similarly,
for vertical direction, 3 blocks per column.
But, How will the warps are organized? Can someone point out the thread ids of the warps , and the cases where control divergence happens(Thread ids etc for those).
thanks
Suppose, we have a 9*7 picture (7 pixels in the x direction and 9 pixels in the y direction), how many warps will have control divergence assuming block of 4*4 threads and 8 threads per warp?
Divergence is a property of the program (the code), not of the block/warp layout itself. If your algorithm operates identically across all pixels in the image then there will be no divergence whatsoever, irrespective of the number of threads and their organization. If your algorithm branches on warp boundaries, there will be no divergence either. Therefore, without seeing your code, your question is technically unanswerable.
If you're running with a block of 16 threads and 8 threads per warp (which is not physically possible on CUDA hardware: warps are made of 32 threads and their size is not configurable) then you might as well run without a GPU at all. These numbers are way too small to benefit from any hardware acceleration.
How will the blocks and warps be organized here? for x or horizontal direction, i can assume 2 blocks per row.Similarly, for vertical direction, 3 blocks per column. But, How will the warps are organized?
I'll stick to your example and try to provide a schema of the thread IDs, block IDs, warp IDs. Keep in mind that this layout is, in practice, impossible on CUDA hardware.
Image Global Thread IDs Block IDs Local Thread IDs
□□□□□□□ | 00 01 02 03 04 05 06 | 00 00 00 00 00 00 00 | 00 01 02 03 04 05 06
□□□□□□□ | 07 08 09 10 11 12 13 | 00 00 00 00 00 00 00 | 07 08 09 10 11 12 13
□□□□□□□ | 14 15 16 17 18 19 20 | 00 00 01 01 01 01 01 | 14 15 00 01 02 03 04
□□□□□□□ | 21 22 23 24 25 26 27 | 01 01 01 01 01 01 01 | 05 06 07 08 09 10 11
□□□□□□□ | 28 29 30 31 32 33 34 | 01 01 01 01 02 02 02 | 12 13 14 15 00 01 02
□□□□□□□ | 35 36 37 38 39 40 41 | 02 02 02 02 02 02 02 | 03 04 05 06 07 08 09
□□□□□□□ | 42 43 44 45 46 47 48 | 02 02 02 02 02 02 03 | 10 11 12 13 14 15 00
□□□□□□□ | 49 50 51 52 53 54 55 | 03 03 03 03 03 03 03 | 01 02 03 04 05 06 07
□□□□□□□ | 56 57 58 59 60 61 62 | 03 03 03 03 03 03 03 | 08 09 10 11 12 13 14
----------------------------------------------------------------------------
Image Global Warp IDs Block IDs Local Warp IDs
□□□□□□□ | 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00
□□□□□□□ | 00 01 01 01 01 01 01 | 00 00 00 00 00 00 00 | 00 01 01 01 01 01 01
□□□□□□□ | 01 01 02 02 02 02 02 | 00 00 01 01 01 01 01 | 01 01 00 00 00 00 00
□□□□□□□ | 02 02 02 03 03 03 03 | 01 01 01 01 01 01 01 | 00 00 00 01 01 01 01
□□□□□□□ | 03 03 03 03 04 04 04 | 01 01 01 01 02 02 02 | 01 01 01 01 00 00 00
□□□□□□□ | 04 04 04 04 04 05 05 | 02 02 02 02 02 02 02 | 00 00 00 00 00 01 01
□□□□□□□ | 05 05 05 05 05 05 06 | 02 02 02 02 02 02 03 | 01 01 01 01 01 01 00
□□□□□□□ | 06 06 06 06 06 06 06 | 03 03 03 03 03 03 03 | 00 00 00 00 00 00 00
□□□□□□□ | 07 07 07 07 07 07 07 | 03 03 03 03 03 03 03 | 01 01 01 01 01 01 01
----------------------------------------------------------------------------
and the cases where control divergence happens(Thread ids etc for those)
As mentioned above, divergence being a property of the code and not the thread layout, this question cannot be answered without code.
I have two mysql tables
suppose table one name 'marks'
no A B C D
1 10 05 01 04
2 08 07 10 05
3 09 05 07 10
4 07 05 04 10
5 04 07 06 09
6 05 09 07 07
7 09 05 10 06
8 09 06 06 08
9 08 06 10 07
10 08 07 04 06
suppose table two name 'results'
in second table I want to put total marks and average marks based on above table.(import data from 'marks' table,process it and save it in 'results' table)
So once it filled it must be like this.
I want add column A,B,C,D in 'marks' table and put total value in column 'Total' in table 'results' and average by dividing 'Total' column by 4.
no Total Average
1 20 5.00
2 30 7.50
3 31 7.75
4 26 6.50
5 26 6.50
6 28 7.00
7 30 7.50
8 29 7.25
9 31 7.75
10 25 6.25
So how can I fill the 'result' table using mysql query?
Is it possible to do in mysql?
Thank you
Try something like:
INSERT INTO result (no, total, average)
SELECT no, A+B+C+D, (A+B+C+D)/4
FROM marks
How would I get a sum of sales totals for the current week against the same week last year?
There are two possible scenarios related to how the dates are stored, as below:
Scenario 1
**Sales**
Date Sales
-----------------------
2012-08-10 11040.00
2012-08-09 11500.00
2012-08-08 14060.00
2012-08-07 93000.00
2012-08-06 11200.00
...
2011-08-10 11040.00
2011-08-09 11500.00
2011-08-08 14060.00
2011-08-07 93000.00
2011-08-06 11200.00
Scenario 2
**Sales**
year month day Sales
---------------------------------------------
2012 08 10 11040.00
2012 08 09 11500.00
2012 08 08 14060.00
2012 08 07 23000.00
2012 08 06 11200.00
...
2011 08 10 13040.00
2011 08 09 11500.00
2011 08 08 12060.00
2011 08 07 33000.00
2011 08 06 11250.00
For your first scenario, join against the same table on the WEEKOFYEAR() and one added to last year's YEAR():
SELECT
YEARWEEK(thisyear.Date) AS `YearWeek`
SUM(lastyear.Sales) AS LastYearSales
SUM(thisyear.Sales) AS ThisYearSales
FROM
Sales thisyear
LEFT JOIN Sales lastyear ON
WEEKOFYEAR(thisyear.Date) = WEEKOFYEAR(lastyear.Date)
AND YEAR(thisyear.Date) = (YEAR(lastyear.Date) + 1)
GROUP BY `YearWeek`
The second scenario requires building a date out of the 3 separate values. I think this will work:
SELECT
YEARWEEK(CONCAT_WS('-', thisyear.year, thisyear.month, thisyear.day)) AS `YearWeek`,
SUM(lastyear.Sales) AS LastYearSales,
SUM(thisyear.Sales) AS ThisYearSales
FROM
Sales thisyear
LEFT JOIN Sales lastyear ON
WEEKOFYEAR(CONCAT_WS('-', thisyear.year, thisyear.month, thisyear.day)) = WEEKOFYEAR(CONCAT_WS('-', lastyear.year + 1, lastyear.month, lastyear.day))
GROUP BY `YearWeek`