JSON to R Analysis: Using the JSON file below, call it Home.JSON, how can we gen
ID: 3696044 • Letter: J
Question
JSON to R Analysis: Using the JSON file below, call it Home.JSON, how can we generate various visualizations in R depicting the historical overall spend and the same by project.
What I have so far in R was to mash the data in a data frame but it didn't run
[ {
"accountId" : "00BAB0-FBE045-2A9ECF",
"lineItemId" : "com.google.cloud/services/support/Gold",
"startTime" : "2015-06-26T00:00:00-07:00",
"endTime" : "2015-06-27T00:00:00-07:00",
"measurements" : [ {
"measurementId" : "com.google.cloud/services/support/Gold",
"sum" : "253",
"unit" : "USD"
} ],
"cost" : {
"amount" : "253",
"currency" : "USD"
}
}, {
"accountId" : "00BAB0-FBE045-2A9ECF",
"lineItemId" : "com.google.cloud/services/app-engine/DatastoreReadOps",
"startTime" : "2015-06-29T00:00:00-07:00",
"endTime" : "2015-06-30T00:00:00-07:00",
"projectNumber" : "20221773448",
"measurements" : [ {
"measurementId" : "com.google.cloud/services/app-engine/DatastoreReadOps",
"sum" : "0",
"unit" : "requests"
} ],
"cost" : {
"amount" : "0",
"currency" : "USD"
}
Explanation / Answer
import numpy as np
from accelerate.mkl import ufuncs as mkl_ufuncs
def spherical_to_cartesian_numpy(r, theta, phi):
cos_theta = np.cos(theta)
sin_theta = np.sin(theta)
cos_phi = np.cos(phi)
sin_phi = np.sin(phi)
x = r * sin_theta * cos_phi
y = r * sin_theta * sin_phi
z = r * cos_theta
def spherical_to_cartesian_mkl(r, theta, phi):
cos_theta = mkl_ufuncs.cos(theta)
sin_theta = mkl_ufuncs.sin(theta)
cos_phi = mkl_ufuncs.cos(phi)
sin_phi = mkl_ufuncs.sin(phi)
x = r * sin_theta * cos_phi
y = r * sin_theta * sin_phi
z = r, cos_theta
return x, y, z
n = 100000
r, theta, phi = np.random.uniform(1, 10, n), np.random.uniform(0, np.pi, n), np.random.uniform(-np.pi, np.pi, n)
%timeit spherical_to_cartesian_numpy(r, theta, phi)
%timeit spherical_to_cartesian_mkl(r, theta, phi)
100 loops, best of 3: 7.01 ms per loop
1000 loops, best of 3: 978 µs per loop
A speedup of 7x is not bad for a 2.3 GHz quad core laptop CPU from 2012. In future releases, we are looking to expand and integrate this functionality further into the Anaconda Platform, so stay tuned