Use Google APIs to calculate the timezones of each location object and then return output as this same array of objects - json

1) a) You have a list of addresses. Use Google APIs to calculate the timezones of each location object and then return output as this same array of objects, with each object comprising of following values -
[{
"id":"1",
"address":"Plot 5, CDCL Building, Chandigarh"m
"latitude":"30.123123",
"longitude":"76.123213"
"timezone":"-330", //in minutes
"UTC_time":"2016-10-18 5:30:00 AM"
}]
b) Now write an algorithm, to divide this array into least no. of sub-arrays, such that difference between the minimum UTC_time and maximum UTC_time in that array is less than or equal to 4 hrs.
2) Parse the attached html file and generate a JSON file as output, which contains all the key
FORMAT
Test Duration- 5 Hours
Test Date -27 October,2016
Format to be send in : "Student name- college name -roll number- 2016"||
Email Id - kunal#tookanapp.com ( All the students need to send their test on the mentioned email ID in the mentioned format )
Start Time - 11.00 AM
End Time - 4.00 PM

Just go through this link.You will get the answer.
https://developers.google.com/maps/documentation/timezone/intro

This is an algorithm not a program::--
initialise i, ar [100],d ;
MAX UTC_time= +14:00(150°);
Min UTC_time=-12:00 (180°);
for min UTC_time initialise to -12:00;
min UTC_time <=+14:00
If min UTC_time > +10:00
Then d=max UTC _time - min UTC_time;
And then print d;
Else
Min UTC_time++;
Link is :--
https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331766000&key=YOUR_API_KEY

{
"dstOffset" : 0,
"rawOffset" : -28800,
"status" : "OK",
"timeZoneId" : "America/Los_Angeles",
"timeZoneName" : "Pacific Standard Time"
}

In html language......
OK
-28800.0000000
0.0000000
America/Los_Angeles
Pacific Standard Time
time_zone_name>

Related

How can I convert a hour range to a total number of hours using SQL?

I'm currently working with Yelp's dataset and my objective is to find the total hours a business is open a week. From the data, I am able to extract a time range for each day that looks like "9:0-0:0" or "17:30-21:30" for a certain day. How can I use SQL to get a single value for these hourly ranges?
This is some code I used to simply show the hours for a business in the dataset.
df_busSelected = df_business.select("business_id", "name"
, "hours.Sunday", "hours.Monday", "hours.Tuesday"
,"hours.Wednesday", "hours.Thursday", "hours.Friday"
, "hours.Saturday")
df_busSelected.show()
I hope to make a new column with the total hours a business is open a week with the given ranges.
Using pyspark, you can do something like the following:
from pyspark.sql.functions import expr
df.withColumn('h', expr('split(hours, "[-:]")').astype('array<int>')) \
.withColumn('h1', expr('''
h[2] - h[0] + IF(h[2]<h[0],24,0) + round((h[3]-h[1])/60,0)
''').astype('int')) \
.show()
+----------+-----------+----------------+---+
| bdate| hours| h| h1|
+----------+-----------+----------------+---+
|2019-10-17| 9:0-0:0| [9, 0, 0, 0]| 15|
|2019-10-18|17:30-21:30|[17, 30, 21, 30]| 4|
+----------+-----------+----------------+---+
First use the charset [-:] to split the column hours into an array of 4 items (named h) and cast it into array of int (originally array of StringType)
Then do the simple math and at the end cast the result type to int again.
Next, use date_format('bdate', 'EEEE') to get week name and then use groupby and pivot and probably agg + sum functions to get the final result

Combine individual messages to 1 output every 15 seconds

Is it possible to combine separate device messages received every 15 seconds into 1 summarized device message?
For example I want to collect "Temperature","RPM" and "Gauge" messages:
Message 1
{
DeviceId: 1
Key: "Temperature"
Value: 15
}
Message 2
{
DeviceId: 1,
Key: "RPM"
Value: 2000
}
Into:
{
DeviceId: 1,
Readings:
{
"Temperature": 15,
"RPM": 2000
"Gauge": "Unknown" (no value in the 15 seconds window, so unknown)
}
}
EDIT:
Forgot to add, it is expected that if 1 of 3 messages for a device ("Temperature","RPM" and "Gauge") arrives in SA. The other 2 will be likely received within the next 15 seconds. So the SA job should start "collecting" when it sees 1 of the messages. Is a SA job suitable for this or should I look for another solution?
You can do this using the LAG function. Would look something like this:
SELECT
DeviceId, [Key], [Value]
LAG(reading) OVER (PARTITION BY DeviceId LIMIT DURATION(hour, 1) WHEN reading IS NOT NULL)
FROM input
LAG allows you to look a specified number of events and then also for a given partition key (in this case I used the DeviceId).
Thanks for the replies. I have solved this using the SessionWindow.

How to send Json with different values?

I have a JSON, for example:
{
"name":"John",
"age":30,
"car":"Ford"
}
I would like to send this same JSON many times, but every time the age value is different, for example
"age":31, then "age":32 and so on...
How can I do that?
You need to use variable as age,
For example for incremented value: add Config Element -> Counter with Reference Name age Start 30, Increment 1.
You JSON will be with ${age}:
{ "name":"John", "age":${age}, "car":"Ford" }
And then just execute Thread Group with Loop Count as 5 and the request will submitted with increasing age value.

N1QL query add hours and minutes

I want to add 5 hours and 30 minute in a time in N1QL. How can I do it ?
I have time like 2016-04-03T18:30:00.000Z I need to add 5:30.
You can use the DATE_ADD_STR(expression, n, part) Date Function. Your query would look similar to the following:
SELECT
DATE_ADD_STR(DATE_ADD_STR(old_time, 5, "hour"), 30, "minute") AS new_time, ...
FROM some_bucket
Documentation:
Performs date arithmetic. n and part are used to define an interval or
duration, which is then added (or subtracted) to the date string in a
supported format, returning the result. Parts:
"millennium"
"century"
"decade"
"year"
"quarter"
"month"
"week"
"day"
"hour"
"minute"
"second"
"millisecond"
Source: http://developer.couchbase.com/documentation/server/4.5/n1ql/n1ql-language-reference/datefun.html

Read unique Char format in R

I have a data.frame DT_A, with several rows and two columns address and date_time (of class character). Example of rows:
address date_time
Canada 1 '"verfied"=>"2013-07-28 09:47:20 +0000", "verified_oleh"=>"nur#web.com", "verfification req"=>"2013-04-21 05:22:00 +0000"'
Canada 1 '"verfied"=>"2013-07-28 09:47:20 +0000", "verfied_oleh"=>"nur#web.com"
Germany '"verfied"=>"2013-07-28 09:47:20 +0000", "verified_oleh"=>"nur#web.com", "verfification req"=>"2013-04-21 05:22:00 +0000"'
Germany '"verfied"=>"2013-07-28 09:47:20 +0000", "verfied_oleh"=>"nur#web.com"'
The column date_time can take other status.
I need to filter each row of column date_time has "verified" string, I think it need to convert to JSON, I have tried to jsonlite package, but it still doesn't work.
It is not clear what you mean by "has "verified string". But if I assume that you mean that there is the string "verified" in your date_time column this should do the trick:
DT_A[grepl('^"verfied"', DT_A$date_time, ] # please note the typo in verfied
This grepl looks for the regular expression where the string starts with "verfied".