Need to increase Timeout for URLFetch.Fetch(url) - google-apps-script

I have a Keynote API that I use to provide metrics for Week to Date, Month to Date, and Year to Date performance Metrics. The Week to date responds quickly, Month to Date sometimes Times out, and Year to Date always times out due to server side calculations.
Is there any way to increase the Timeout for my Google Script?
var prods = Utilities.jsonParse(UrlFetchApp.fetch(json_api_url).getContentText());

There are ways to get Google Apps Script to handle time-outs when performing repeated operations, but they don't apply in this case. You've got a single operation that just takes a long time.
You have no way to increase the timeout values for your google scripts.

Related

importXML is making too many Mapquest transactions

I am trying to use the following formula and a key I obtained from mapquest (for the free service) to initiate their location services and calculate the distances between one variable location and 20 of my plant locations.
=importXML("http://mapquestapi.com/directions/v2/route?key=*****************&outFormat=xml&from=" & $B$3 & "&to=" & 56244,"//response/route/distance")
This is working flawlessly expect after using it for a short period of time I have received an email stating I have used 80% of my allotment (15000 transactions) for the month.
The variable location has only been changed around 20-25 times this month so I don't see how I could have used that many transactions. Can someone explain what exactly this formula is doing and how I could make it more efficient if possible? I feel like it has to be using transaction that are unnecessary. Keep in mind I do not need the actual directions all I need is the driving mileage required.
Thanks in advance.

storing time in database for users in different time zones [duplicate]

This question already has answers here:
Daylight saving time and time zone best practices [closed]
(30 answers)
Closed 8 years ago.
I have a question about storing time for users in different time zones. My wording may get a little coiled up, but please bear with me. If I just store the time a user accesses my web app in UTC into MySql, then is it okay for me to disregard different time zones?
For example, say there are two users living across the world. One says for both to chat in the web app at 4:00 his time. So then the other person has to access maybe at 1:00 her time so that both can successfully meet up. If I call UTC_Time() in Mysql when each of them logs onto the web app in their respective time, will I get one universal 4:00 for both of them? Thank you very much.
You've landed in one of the more complicated areas of programming.
If the time you store into you database is derived from 'now()' in MySQL,
then you will store the event at a correct moment in time, and you use
the UTC scale to measure it. Which, for international apps is probably the
right thing to do.
If one person just says '4:00' this number will not change, unless you provide
a form on your page to enter the time, and which can then be used for calculations.
In that case, you can ask each user for its time zone (eg. once, on registration),
and calculate UTC to save '4:00' in, say '11:00 UTC'. If the other user
logs in, you can calculate his local time from the UTC stored.
By the way, if you use Linux, you can run your system on UTC instead of localtime (it will still show local time, but the internal clock runs on UTC). DO NOT do this if your system is Windows or dual-boot. Windows does not like systems running on different timezones.
From the MySQL manual:
CONVERT_TZ() converts a datetime value dt from time zone given by
from_tz to the time zone given by to_tz and returns the resulting
value
I.e. something like:
SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
-> '2004-01-01 13:00:00'
In case you stored times/dates as GMT, and your friend registered and selected 'MET'

MySQL Timezone for different rows

I'm stuck in this logic. I'm working on a message scheduling project and I have clients from different countries. Let's consider Asia (does not observe daylight saving) and America/New York (observes daylight saving).
Now, i'm writing following query to get schedules within 10 min gap from current time:
select message,subject,person_or_group,customer_id from common_schedule where reminder_type_1 in('beforedays','beforehours') and now() between cast(reminder_time1 as datetime) and addtime(cast(reminder_time1 as datetime),'00:10:00')
Now, if we have two records, one for New York (under daylight saving) and one for New Delhi: India that is not under daylight saving, I'll get wrong data for New York as 1 hour should be subtracted from it.
Also assume that there is an extra column in the table DY (daylight saving) which has values 'y' or 'n'.
A few things:
When you use MYSQL's now() function (docs here), the value is returned in the current time zone.
The time zone can be set either global for the system, or per-connection to the database (docs here).
You can use MYSQL's CONVERT_TZ function (docs here) to convert from one time zone to another, or between a local time zone and UTC.
A boolean flag for DST is never a good idea because countries around the world observe DST at different points in time. Additionally, countries often change their rules about when to observe DST. All of the different rules are included in the time zone data, which you are referencing when you use a time zone like America/New_York.
For future scheduling of events, you should probably store both the local time of the event and the time zone that it pertains to.
Depending on the volume of data you're working with, you might consider a strategy that pre-calculates a UTC time to run from the local time it was scheduled at. Then you can much easier locate the next tasks to run, by comparing the UTC "now" against the pre-calculated column. However, you should be prepared to reassess the UTC equivalents periodically, or at least as often as you receive updates to time zone data.
Scheduling of future events is inherently difficult. See also previous posts I've written on this subject: here, here, here and here.

Average calculation procedure

i'm implementing a mysql database for saving logged energy consumption data out of a smart home applications. The data then should be plotted within a javascript framework. Unfortunately the usage get's logged every 8 seconds and there's too much information to plot a year consumption graph.
The data gets saved in a simple table by it's time, device id and consumption at this specific time.
I'm hoping to be able to automatically aggregate the given data by minutes, hours and finally day average values.
After some research I came across some queries/procedures to calculate average values of specific intervals. Unfortunately this isn't much help to me as I have data over a period of three years and I don't want to create the given intervals by hand.
Ideally the procedure in mysql should be able to aggregate the given device values by it's time and calculate an average value and save it in a separate table.
Does anyone have a idea how I could implement it?
select avg(consumption) minute_average, date_format(log_date,'%m/%d/%y %H:%i') minute from data
group by date_format(log_date,'%m/%d/%y %H:%i');
select avg(consumption) hour_average, date_format(log_date,'%m/%d/%y %H') hour from data
group by date_format(log_date,'%m/%d/%y %H');
select avg(consumption) day_average, date_format(log_date,'%m/%d/%y') day from data
group by date_format(log_date,'%m/%d/%y');
note: you could just as easily calculate any aggregate like sum or standard deviation as well.

SQL, querying by date intervals

I've got a dataset that I want to be able to slice up by date interval. It's a bunch of scraped web data and each item has a unix-style milisecond timestamp as well as a standard UTC datetime.
I'd like to be able to query the dataset, picking out the rows that are closest to various time intervals:
e.g.: Every hour, once a day, once a week, etc.
There is no guarantee that the timestamps are going to fall evenly on the interval times, otherwise I'd just do a mod query on the timestamp.
Is there a way to do this with SQL commands that doesn't involve stored procs or some sort of pre-computed support tables?
I use the latest MariaDB.
EDIT:
The marked answer doesn't quite answer my specific question but it is a decent answer to the more generalized problem so I went ahead and marked it.
I was specifically looking for a way to query a set of data where the timestamp is highly variable and to grab out rows that are reasonably close to periodic time intervals. E.g.: get all the rows that are the closest to being on 24 hour intervals from right now.
I ended up using a modulus query to solve the problem: timestamp % interval < average spacing between data points. This occasionally grabs extra points and misses a few but was good enough for my graphing application.
And them I got sick of the node-mysql library crashing all the time so I moved to MongoDB.
You say you want 'closest to various time intervals' but then say 'every hour/day/week', so the actual implementation will depend on what you really want, but you can use a host of standard date/time functions to group records, for example count by day:
SELECT DATE(your_DateTime) AS Dt, COUNT(something) AS CT
FROM yourTable
GROUP BY DATE(your_DateTime)
Count by Hour:
SELECT DATE(your_DateTime) AS Dt,HOUR(your_DateTime) AS Hr, COUNT(something) AS CT
FROM yourTable
GROUP BY DATE(your_DateTime), HOUR(your_DateTime)
See the full list of supported date and time functions here:
https://mariadb.com/kb/en/date-and-time-functions/