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];
// if not a line chart, a timeslice should be present or set timescale=30
if ($('#type_' + index).val() != 'line') {
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);
}
// if bar or column chart, a timeslice should be present or set timescale=30
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) {
$('#timescale_' + index).val(30);
}
}
// add inputs to array

View File

@ -2,7 +2,7 @@ class ClearChannelJob
@queue = :clear_channel
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])
if channel = Channel.find(channel_id)
channel.last_entry_id = nil

View File

@ -33,6 +33,22 @@ class Feed < ActiveRecord::Base
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
def self.public_options
{

View File

@ -28,6 +28,7 @@
<option>line</option>
<option>bar</option>
<option>column</option>
<option>spline</option>
</select>
</td>
</tr>
@ -194,3 +195,4 @@
</script>

View File

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

View File

@ -9,7 +9,7 @@
<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.
<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>
<hr />

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long