Skip to content

Instantly share code, notes, and snippets.

@nlubchenco
nlubchenco / rg charts
Created December 3, 2012 16:32
Embed Reporting: ReportGrid
ReportGrid.leaderBoard("#chart1",{
axes: ["product","sales"],
load: ReportGrid.query.precog(leaderBoardQuery).sortValue("sales").reverse()
});
ReportGrid.lineChart("#chart2",{
axes: ["month","quantity"],
load: ReportGrid.query.precog(lineChartQuery).sortValue("month"),
options: {displayrulemajor:true}
});
@nlubchenco
nlubchenco / query3
Created December 3, 2012 16:30
Embed Reporting: query 3
data := //tutorial/transactions
dataWithHour := data with
{hour: std::time::hourOfDay(data.timeStamp)}
aveSalesByHour :=solve 'source, 'hour
data' := dataWithHour where dataWithHour.source = 'source & dataWithHour.hour = 'hour
{source: 'source,
averageSales: sum(data'.total),
hour: 'hour}
@nlubchenco
nlubchenco / query2
Created December 3, 2012 16:30
Embed Reporting: query 2
import std::time::*
data := //tutorial/transactions
today := 233
dataWithMonthAndYearAndDay := data with
{month: monthOfYear(data.timeStamp),
year: year(data.timeStamp),
day: dayOfYear(data.timeStamp)}
@nlubchenco
nlubchenco / query1
Created December 3, 2012 16:29
Embed Reporting: query 1
data := //tutorial/transactions
salesByProduct := solve 'product
{product: 'product,
sales: sum(data.total where
data.ApocalypseProducts = 'product)}
rank := std::stats::rank(neg salesByProduct.sales)
salesByProduct where rank <= 5
@nlubchenco
nlubchenco / sql import
Created December 3, 2012 16:28
Embed Reporting: backimport sql using php
<?php
require_once("Precog.php");
$api = new PrecogAPI("yourAPI keyHere",
"your rootPath",
"http://beta.precog.com/");
$db = new PDO('sqlite:nimbleData.db');
$rows = $db->query('SELECT * FROM Users', PDO::FETCH_ASSOC);
$counter = 0;
foreach($rows as $row){
@nlubchenco
nlubchenco / upload.php
Created December 3, 2012 16:27
Embed Reporting: backimport php
<?php
require_once("Precog.php");
$api = new PrecogAPI("yourAPI key",
"your rootPath",
"http://beta.precog.com/");
$api->ingest("/path/to/store/data",
"dataToUpload.json",
"json");
}
@nlubchenco
nlubchenco / php store
Created December 3, 2012 16:26
Embed Reporting: BE instrumentation
require_once("Precog.php");
$api = new PrecogAPI("yourAPI key here",
"your rootPath here",
"http://beta.precog.com/");
date_default_timezone_set('UTC');
$datetime = new DateTime();
$datetime->format(DateTime::ISO8601);
@nlubchenco
nlubchenco / Precog.store options
Created December 3, 2012 16:25
Embed Reporting: FE instrumentation
var addedToShoppingCart = {
timeStamp: +new Date(),
durationOfPageView: 220.3,
productIDAdded: "EFXZ40-1248-9933",
otherProductsInCart: ["APLW40-1248-8821"],
country: "US",
state: "CO"
};
Precog.store("/path/to/store/data", addedToShoppingCart,
@nlubchenco
nlubchenco / instrument data
Created September 12, 2012 21:07
Example of Using the Precog JavaScript Client Library to Instrument your Data
<!DOCTYPE html>
<html>
<head>
<title>Instrument Your Data</title>
<script src="http://api.reportgrid.com/js/precog.js?apiKey=yourAPIKEY&analyticsService=beta2012v1.precog.com/v1">
<script>
function init() {
document.getElementById("button").onclick = function() {
var date = new Date();
@nlubchenco
nlubchenco / arrows.json.js
Created August 22, 2012 20:17
GeoChart Visualization
(function(){
var params = ReportGrid.parseQueryParameters(ReportGrid.findScript('arrows.json.js').src),
handler = params['callback'];
window[handler](
{"type": "FeatureCollection","features": [
{"type": "Feature", "geometry": {"type": "LineString", "coordinates": [[-105.390027, 40.063935], [-73.996328, 40.750422]]}},
{"type": "Feature", "geometry": {"type": "LineString", "coordinates": [[-105.390027, 40.063935], [-122.727802, 37.784827]]}},
{"type": "Feature", "geometry": {"type": "LineString", "coordinates": [[-105.390027, 40.063935], [ -90.196781,38.633232]]}}
]}