Reminds And Send me Email - reminders

I'm trying to develop a reminds app. This code is a framework that I need. I have 3 spreadsheets, and I intend, in each spreadsheets, monitor deadlines. When the deadline is less than five days, it should send an e-mail. It has worked well in the following manner:
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('2016.2');
var clientesInfo = sheet.getRange(2, 7, sheet.getLastRow() - 1, 2).getValues();
//Data de hoje na coluna G2;
for (var i = 0; i < clientesInfo.length; i++) {
if (clientesInfo[i][1] < 5 && clientesInfo[i][1] >= 0 ) {
MailApp.sendEmail("roger#tr.br", "Atenção! Prazo se esgotando(Isso é apenas um teste)", "Verifique tarefas que estão próximas de vencer, em: https://g.gl/plgTRU7");
} `enter code here`
}
}
But I want now that that same code, I can monitor multiple spreadsheets, spreadsheet 2016.2. How should I do? Create multiple ifs? What if I have 100 sheets? Will be 100 ifs?

Related

how cloud masking is done on Landsat 8 surface reflectance data in Google earth engine?

I want to download cloud-masked Landsat 8 surface reflectance collection from google earth engine. I don't have any idea how to perform a cloud masking algorithm. here's my code:
Map.centerObject(table);
Map.addLayer(table);
var sur = ee.ImageCollection.load('LANDSAT/LC08/C01/T1_SR')
.filterBounds(table)
.filterDate('2013-01-01','2019-11-01')
.filter(ee.Filter.equals('WRS_PATH',15))
.filter(ee.Filter.equals('WRS_ROW',33))
.filter(ee.Filter.lt('CLOUD_COVER', 5))
//.filter(ee.Filter.equals('IMAGE_QUALITY',4))
//.filter(ee.Filter.rangeContains('CLOUD_COVER',15,45));
.filter(ee.Filter.lt('CLOUD_COVER_LAND', 5));
print(sur);
// list of images (client side)
var imColl_sur = sur.getInfo().features;
print('features: ', imColl_sur);
print('length: ', imColl_sur.length);
// loop on client side
for (var i = 0; i < imColl_sur.length; i++) {
var id = imColl_sur[i]["id"];
var im = ee.Image(id);
var clip = im.clip(table);
var b1 = clip.select('B1');
var D_T = imColl_sur[i]["properties"]["SENSING_TIME"];
var sza = (imColl_sur[i]["properties"]["SOLAR_ZENITH_ANGLE"]).toString();
Export.image.toDrive({
image: b1,
description: id.slice(8, 12)+"_surReflectance_B1_"+ id.slice(28, 34) +"_"+ D_T.slice(0,4)+D_T.slice(5,7)+D_T.slice(8,10) + "_" + D_T.slice(11,13)+D_T.slice(14,16) + "_" + sza.slice(0,2)+sza.slice(3,8),
scale: 30,
region : table,
maxPixels : 1e9
});
}
thanks
You should check out this example provided by the Earth Engine team: https://code.earthengine.google.com/?scriptPath=Examples:Cloud%20Masking/Landsat8%20Surface%20Reflectance
This script uses the pre-computed Landsat 8 QA band from CFMask to remove clouds and cloud shadows.

Is there a way to use a script to pull a date from a Google Form submission from sheets into Gmail?

I have no experience with script writing, but I was able to find a script and edit it (with lots of trial and error) to fit my need.
I have a Google Form where the first question allows users to select a date, but it is not necessarily the date users are completing the form. The results export to a Google Sheet, and I have a script that sends an email with the form responses.
It worked beautifully until Daylight Savings Time. Now, the dates in the spreadsheet are correct, but in the emails they are one day off.
Example email message:
Your child, NAME, received a dress code violation on Wed Mar 27 2019
23:00:00 GMT-0600 (CST), for No ID.
Before Daylight Savings Time, the time was showing as 00:00:00.
In the code, row[2] is the date pulled from the spreadsheet.
var EMAIL_SENT = "EMAIL_SENT";
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Script");
var startRow = 2;
var numRows = 5000;
var dataRange = sheet.getRange(startRow, 1, numRows, 5000)
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[12];
var message = "Your child, " + row[10] + ", received a dress code violation on " + row[2] + ", for " + row[11] + ".\nIf you have any questions, please email NAME at name.name#name.org\n\nThank you,\n\nNAME\nAssistant Principal";
var emailSent = row[13];
if (emailSent != EMAIL_SENT) {
var subject = "Uniform Violation - Do Not Reply";
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 14).setValue(EMAIL_SENT);
SpreadsheetApp.flush();
}
}
}
Ideally, the email would provide the date exactly from the spreadsheet in MM/DD/YYYY format.
Instead, the emails show the previous day with the time of 11 pm.
Try this:
var EMAIL_SENT = "EMAIL_SENT";
function sendEmails2() {
var ss=SpreadsheetApp.getActive();//added this
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Script");
var startRow = 2;
var numRows = 5000;
var dataRange = sheet.getRange(startRow, 1, numRows, 5000)
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[12];
var message = "Your child, " + row[10] + ", received a dress code violation on " + Utilities.formatDate(new Date(row[2]),ss.getSpreadsheetTimeZone(), "MM dd, yyyy HH:mm:ss" ) + ", for " + row[11] + ".\nIf you have any questions, please email NAME at name.name#name.org\n\nThank you,\n\nNAME\nAssistant Principal";//modified this
var emailSent = row[13];
if (emailSent != EMAIL_SENT) {
var subject = "Uniform Violation - Do Not Reply";
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 14).setValue(EMAIL_SENT);
SpreadsheetApp.flush();
}
}
}
You will probably have to change the dates format.
Date Format

How can I plot a graph at the end of the function

I need to implement a script where the user enters information for multiple samples. I need to draw a graph with that information, but I need to plot it with all information at the end of the execution. My actual script plots one graph every time the user enters information for one of the samples.
op=input('Digite a quantidade de compostos:');
i=1;
j=1;
k=1;
temp =0:5:100
while(i<=op)
produto=input('Digite o nome do produto:','s');
quant(i)=input('Digite a quantidade de amostras:')
lista{i}=produto;
for j =1:quant(i)
amostras(j,k)=input('Digite o valor da solubilidade:')
k++;
amostras(j,k)=input('Digite o valor da temperatura:')
k=1;
end
hold all;
gplot(amostras,amostras);
i++
end
hold off;
You can use the 'Visible' property of the figure to hide it during the execution of your loops and show it later.
So insert this before your while loop:
figure();
set(gcf, 'Visible', 'off');
and now at the end of your code, make it visible again with:
set(gcf, 'Visible', 'on');
[...] I need to plot it with all information at the end of the execution. My actual script plots one graph every time the user enters information for one of the samples.
Don't plot it each time. Store the values and plot everything at the end instead. Like so:
op = input ('Digite a quantidade de compostos: ');
lista = cell (op, 1);
amostras = cell (op, 1);
for i = 1:op
lista = input ('Digite o nome do produto: ','s');
quant = input ('Digite a quantidade de amostras: ');
amostras{i} = zeros (quant, 1);
for j = 1:quant
amostras{i}(j,1) = input ('Digite o valor da solubilidade: ');
amostras{i}(j,2) = input ('Digite o valor da temperatura: ');
endfor
endfor
## plot now

.pluck returning undefined in Meteor

Trying to pull a list of ratings from a collection of Reviews and then average them to come up with an aggregated average rating for a Plate. When I look at the data output from the ratings variable I get nothing but "undefined undefined undefined".
averageRating: function() {
var reviews = Reviews.findOne({plateId: this._id});
var ratings = _.pluck(reviews, 'rating');
var sum = ratings.reduce(function(pv, cv){return pv + cv;}, 0);
var avg = sum / ratings.length;
//Testing output
var test = "";
var x;
for (x in reviews) {
text += reviews[x] + ',';
}
return test;
}
Sorry if this is a super newbie question, but I've been at this for hours and cannot figure it out.
I figured out the issue. As listed above var reviews gets set to a cursor which apparently .pluck does not work on. By first converting the cursor to an array of objects I was then able to use .pluck. So updated code looks like this:
averageRating: function() {
var reviewsCursor = Reviews.find({plateId: this._id});
//Converts cursor to an array of objects
var reviews = reviewsCursor.fetch();
var ratings = _.pluck(reviews, 'rating');
var sum = ratings.reduce(function(pv, cv){return pv + cv;}, 0);
var avg = (sum / ratings.length).toPrecision(2);
return avg;
}

After encoding UTF-16, the string is broken if I want to use in iTextSharp

Firstly I am getting some informations from a text file, later these informations are added to pdf files' meta data. In the "Producer" section an error was occured about Turkish characters as ğ, ş. And I solved the problem via using UTF-16 like this:
write.Info.Put(new PdfName("Producer"), new PdfString("Ankara Üniversitesi Hukuk Fakültesi Dergisi (AÜHFD), C.59, S.2, y.2010, s.309-334.", "UTF-16"));
Here is the screenshot:
Then, I am getting all pdf files with foreach loop and reading meta data and insert into SQLite database file. The problem occurs right here. Because when I want to get from pdf file and set to database file UTF-16 encoded string (Producer data), it arises strange characters like this:
I don't understand, why it occurs error.
EDIT: Here is my all codes. The following codes get meta data from text file and insert pdf files' meta meta section:
var articles = Directory.GetFiles(FILE_PATH, "*.pdf");
foreach (var article in articles)
{
var file_name = Path.GetFileName(article);
var read = new PdfReader(article);
var size = read.GetPageSizeWithRotation(1);
var doc = new Document(size);
var write = PdfWriter.GetInstance(doc, new FileStream(TEMP_PATH + file_name, FileMode.Create, FileAccess.Write));
// Article file names like, 1.pdf, 2.pdf, 3.pdf....
// article_meta_data.txt file content like this:
//1#Article 1 Tag Number#Article 1 first - last page number#Article 1 Title#Article 1 Author#Article 1 Subject#Article 1 Keywords
//2#Article 2 Tag Number#Article 2 first - last page number#Article 2 Title#Article 2 Author#Article 2 Subject#Article 2 Keywords
//3#Article 3 Tag Number#Article 3 first - last page number#Article 3 Title#Article 3 Author#Article 3 Subject#Article 3 Keywords
var pdf_file_name = Convert.ToInt32(Path.GetFileNameWithoutExtension(article)) - 1;
var line = File.ReadAllLines(FILE_PATH + #"article_meta_data.txt");
var info = line[pdf_file_name].Split('#');
var producer = Kunye(info); // It returns like: Ankara Üniversitesi Hukuk Fakültesi Dergisi (AÜHFD), C.59, S.2, y.2010, s.309-334.
var keywords = string.IsNullOrEmpty(info[6]) ? "" : info[6];
doc.AddTitle(info[3]);
doc.AddSubject(info[5]);
doc.AddCreator("UzPDF");
doc.AddAuthor(info[4]);
write.Info.Put(new PdfName("Producer"), new PdfString(producer, "UTF-16"));
doc.AddKeywords(keywords);
doc.Open();
var cb = write.DirectContent;
for (var page_number = 1; page_number <= read.NumberOfPages; page_number++)
{
doc.NewPage();
var page = write.GetImportedPage(read, page_number);
cb.AddTemplate(page, 0, 0);
}
doc.Close();
read.Close();
File.Delete(article);
File.Move(TEMP_PATH + file_name, FILE_PATH + file_name);
}
And the following codes get data from files and insert SQLite database file. For database operation, I am using Devart - dotConnect for SQLite.
var files = Directory.GetFiles(FILE_PATH, "*.pdf");
var connection = new Linq2SQLiteDataContext();
TruncateTable(connection);
var i = 1;
foreach (var file in files)
{
var read = new PdfReader(file);
var title = read.Info["Title"].Trim();
var author = read.Info["Author"].Trim();
var producer = read.Info["Producer"].Trim();
var file_name = Path.GetFileName(file)?.Trim();
var subject = read.Info["Subject"].Trim();
var keywords = read.Info["Keywords"].Trim();
var art = new article
{
id = i,
title = (title.Length > 255) ? title.Substring(0, 255) : title,
author = (author.Length > 100) ? author.Substring(0, 100) : author,
producer = (producer.Length > 255) ? producer.Substring(0, 255) : producer,
filename = file_name != null && (file_name.Length > 50) ? file_name.Substring(0, 50) : file_name,
subject = (subject.Length > 50) ? subject.Substring(0, 50) : subject,
keywords = (keywords.Length > 500) ? keywords.Substring(0, 500) : keywords,
createdate = File.GetCreationTime(file),
update = File.GetLastWriteTime(file)
};
connection.articles.InsertOnSubmit(art);
i++;
}
connection.SubmitChanges();
Instead of:
new PdfString(producer, "UTF-16")
Use:
new PdfString(producer, PdfString.TEXT_UNICODE)
UTF-16 is a specific way to store Unicode values but you don't need to worry about that, iText will take care of everything for you.

Resources