Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
145 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,4 +1,3 @@ | |||
require 'comm' | |||
require 'mongo' | require 'mongo' | ||
|
|
||
module EventChopper | module EventChopper | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
module EventChopper | |||
|
|||
class Scb < Base | |||
def event_types | |||
['search', 'click', 'booking'] | |||
end | |||
|
|||
def map topic, record, stamp | |||
if topic == 'booking' | |||
dt = DateTime.strptime record['booked_at'], '%Y-%m-%dT%H:%M:%SZ' | |||
stamp = DateTime.strptime(record['occured_at'], '%Y-%m-%dT%H:%M:%S+04:00').to_time.to_i | |||
tk = TimeKey.from_date dt | |||
emit({topic => {record['order_number'] => {'state' => record['state'], 'stamp' => stamp}}}, tk) | |||
else | |||
emit({topic => 1}) | |||
end | |||
end | |||
|
|||
def reduce data | |||
t = data.inject({}) do |acc, entry| | |||
acc.merge(entry) do |k, v1, v2| | |||
if k.start_with? 'booking' | |||
v1.merge(v2) do |k, b1, b2| | |||
b1['stamp'] >= b2['stamp'] ? b1 : b2 | |||
end | |||
else | |||
v1 + v2 | |||
end | |||
end | |||
end | |||
puts "REDUCE" + t.to_s | |||
t | |||
end | |||
|
|||
def finalize record | |||
if ! record.nil? and record.has_key? 'booking' | |||
record['paid_booking'] = record['booking'].inject(0) do |acc, k| | |||
acc + (k[1]['state'] == 'paid' ? 1 : 0) | |||
end | |||
record['booking'] = record['booking'].length | |||
end | |||
record | |||
end | |||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,80 @@ | |||
<html> | |||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> | |||
<script src="/js/highcharts.js" type="text/javascript"></script> | |||
<script src="http://datejs.googlecode.com/files/date.js" type="text/javascript"></script> | |||
<form method='get' onsubmit='onsub(); return false;'> | |||
Start date: <input type='text' name='start' id='start' value=''><br> | |||
Stop date: <input type='text' name='stop' id='stop' value=''><br> | |||
Group by: <select name='group' id='group'> | |||
<option value='minute'>10 Minutes</option> | |||
<option value='hour' selected="selected">Hour</option> | |||
<option value='day'>Day</option> | |||
<option value='month'>Month</option> | |||
<option value='year'>Year</option> | |||
</select><br> | |||
<input type='submit'/> | |||
</form> | |||
<div id="container" style="width: 100%; height: 100%"></div> | |||
<script> | |||
$(document).ready(function() { | |||
var cur = Date.today().add(1).days(); | |||
var last = Date.today().add(-1).days(); | |||
$('#start').val(last.toString('yyyy-MM-dd hh:00')); | |||
$('#stop').val(cur.toString('yyyy-MM-dd hh:00')); | |||
}); | |||
|
|||
function onsub() { | |||
draw_graph($('#start').val(), $('#stop').val(), $('#group').val()); | |||
} | |||
|
|||
var chart; | |||
var d = []; | |||
var xticks = []; | |||
var all_gates = {}; | |||
var dd; | |||
function draw_graph(from, to, period) { | |||
$.getJSON('/json?from=' + from + '&to=' + to + '&period=' + period + '&reporter=Scb', function(data) { | |||
var stamps = []; | |||
var searches = []; | |||
var clicks = []; | |||
var bookings = []; | |||
var pbookings = []; | |||
for(var stamp in data) { | |||
stamps.push(stamp); | |||
clicks.push(data[stamp] && data[stamp]['click'] ? data[stamp]['click'] : null); | |||
searches.push(data[stamp] && data[stamp]['search'] ? data[stamp]['search'] : null); | |||
bookings.push(data[stamp] && data[stamp]['booking'] ? data[stamp]['booking'] : null); | |||
pbookings.push(data[stamp] && data[stamp]['paid_booking'] ? data[stamp]['paid_booking'] : null); | |||
} | |||
chart1 = new Highcharts.Chart({ | |||
chart: { | |||
renderTo: 'container', | |||
type: 'line', | |||
spacingRight: 20, | |||
zoomType : 'x' | |||
}, | |||
title: { | |||
text: 'clicks & searches & bookings' | |||
}, | |||
yAxis: { | |||
title: { | |||
text: 'Count' | |||
} | |||
}, | |||
xAxis: { | |||
categories: stamps, | |||
labels: { | |||
rotation: -90, | |||
y: 50 | |||
} | |||
}, | |||
series: [ | |||
{name : 'clicks' , data : clicks}, | |||
{name : 'searches', data : searches}, | |||
{name : 'bookings', data : bookings}, | |||
{name : 'paid_bookings', data : pbookings} | |||
] | |||
}); | |||
}); | |||
}</script> | |||
</html> |