clear channel feeds more efficiently; add spline type to charts

This commit is contained in:
Lee Lawlor 2014-04-03 23:08:00 -04:00
parent 99fe498041
commit a59507718d
9 changed files with 38 additions and 11 deletions

View File

@ -30,11 +30,11 @@ function updateChart(index,
} }
src = iframe.split('?')[0]; src = iframe.split('?')[0];
// if not a line chart, a timeslice should be present or set timescale=30 // if bar or column chart, a timeslice should be present or set timescale=30
if ($('#type_' + index).val() != 'line') { if ($('#type_' + index).val() === 'bar' || $('#type_' + index).val() === 'column') {
if ($('#timescale_' + index).val().length == 0 && $('#average_' + index).val().length == 0 && $('#median_' + index).val().length == 0 && $('#sum_' + index).val().length == 0) { if ($('#timescale_' + index).val().length == 0 && $('#average_' + index).val().length == 0 && $('#median_' + index).val().length == 0 && $('#sum_' + index).val().length == 0) {
$('#timescale_' + index).val(30); $('#timescale_' + index).val(30);
} }
} }
// add inputs to array // add inputs to array

View File

@ -2,7 +2,7 @@ class ClearChannelJob
@queue = :clear_channel @queue = :clear_channel
def self.perform(channel_id) def self.perform(channel_id)
Feed.delete_all(["channel_id = ?", channel_id]) Feed.delete_in_batches(channel_id)
DailyFeed.delete_all(["channel_id = ?", channel_id]) DailyFeed.delete_all(["channel_id = ?", channel_id])
if channel = Channel.find(channel_id) if channel = Channel.find(channel_id)
channel.last_entry_id = nil channel.last_entry_id = nil

View File

@ -33,6 +33,22 @@ class Feed < ActiveRecord::Base
attr_readonly :created_at attr_readonly :created_at
# delete feeds in batches
def self.delete_in_batches(channel_id)
channel = Channel.find(channel_id)
connection = ActiveRecord::Base.connection
# while there are still feeds left
while channel.feeds.count > 0
# create the sql query to delete 1000 feeds from the channel
sql = "DELETE FROM feeds WHERE channel_id=#{channel_id} LIMIT 1000"
# execute the sql query
connection.execute(sql)
# wait a bit before the next delete
sleep 0.1
end
end
# for to_xml, return only the public attributes # for to_xml, return only the public attributes
def self.public_options def self.public_options
{ {

View File

@ -28,6 +28,7 @@
<option>line</option> <option>line</option>
<option>bar</option> <option>bar</option>
<option>column</option> <option>column</option>
<option>spline</option>
</select> </select>
</td> </td>
</tr> </tr>
@ -171,7 +172,7 @@
// draw initial chart with saved options // draw initial chart with saved options
var width = <%= (@width) ? @width : 450 %>; var width = <%= (@width) ? @width : 450 %>;
var height = <%= @height ? @height : 260 %>; var height = <%= @height ? @height : 260 %>;
updateChart(<%= index %>, false, width, height, <%= @channel.id %>); updateChart(<%= index %>, false, width, height, <%= @channel.id %>);
}); });
@ -179,7 +180,7 @@
$('#button<%= index %>').click(function() { $('#button<%= index %>').click(function() {
var width = <%= (@width) ? @width : 450 %>; var width = <%= (@width) ? @width : 450 %>;
var height = <%= @height ? @height : 260 %>; var height = <%= @height ? @height : 260 %>;
updateChart(<%= index %>, true, width, height, <%= @channel.id %>); updateChart(<%= index %>, true, width, height, <%= @channel.id %>);
}); });
@ -192,5 +193,6 @@
$(this).val(selectedValue); $(this).val(selectedValue);
}); });
</script> </script>

View File

@ -121,6 +121,9 @@
column: { column: {
color: '<%= params[:color] || "#d62020" %>' color: '<%= params[:color] || "#d62020" %>'
}, },
spline: {
color: '<%= params[:color] || "#d62020" %>'
},
series: { series: {
marker: { marker: {
radius: 3 radius: 3

View File

@ -9,7 +9,7 @@
<h1 id="charts">Charts</h1> <h1 id="charts">Charts</h1>
The Charts API allows you to create an instant visualization of your data. The chart displays properly in all modern browsers and mobile devices. The chart can also show dynamic data by loading new data automatically. The Charts API allows you to create an instant visualization of your data. The chart displays properly in all modern browsers and mobile devices. The chart can also show dynamic data by loading new data automatically.
<br><br> <br><br>
Use the Charts API to present numerical data stored in ThingSpeak Channels on charts. Supported chart types are line, bar, column, and step. Options include size, color, and labels. Use the Charts API to present numerical data stored in ThingSpeak Channels on charts. Supported chart types are line, bar, column, spline, and step. Options include size, color, and labels.
<br><br> <br><br>
<hr /> <hr />

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long