Skip to content

Instantly share code, notes, and snippets.

@henri
Last active November 3, 2024 05:32
Show Gist options
  • Save henri/62696ae97d109f2c2adcbb9aba32443b to your computer and use it in GitHub Desktop.
Save henri/62696ae97d109f2c2adcbb9aba32443b to your computer and use it in GitHub Desktop.
hue tempature data adverage script
#!/usr/bin/env ruby
# copyright henri shustak 2024
# released under GNU GPL v3 or later
# this script is designed to provide adverages from the hue tempature sensors
# you can increase or decrease the line count to change the adverage ammount
# reccursivly run the script using the scripts output
lines_array = []
total_value = 0
line_count = 0
loop do
line = $stdin.gets
break if line.nil?
begin
columns = line.chomp.split
rescue ArgumentError
next
end
next if columns[0].chomp != "tempature"
lines_array << columns[2].chomp
total_value += columns[2].chomp.to_i
line_count += 1
if line_count == 100
#puts lines_array
average = total_value / lines_array.size
date = columns[3..8].to_a
puts "#{columns[0]}\t#{columns[1]}\t#{average}\t#{date.join(' ')}"
lines_array.clear
line_count = 0
total_value = 0
end
end
# note that this file has limited data...
# you would need to add more data or decrease the line count in the porcessing script
temp Station1 1139 Tue 15 Sep 2020 16:19:58 NZST
temp Station1 1139 Tue 15 Sep 2020 16:24:58 NZST
temp Station1 1167 Tue 15 Sep 2020 16:29:57 NZST
temp Station1 1167 Tue 15 Sep 2020 16:34:57 NZST
temp Station1 1139 Tue 15 Sep 2020 16:39:56 NZST
temp Station1 1139 Tue 15 Sep 2020 16:44:56 NZST
temp Station1 1139 Tue 15 Sep 2020 16:49:55 NZST
temp Station1 1125 Tue 15 Sep 2020 16:54:55 NZST
temp Station1 1125 Tue 15 Sep 2020 16:59:54 NZST
temp Station1 1111 Tue 15 Sep 2020 17:04:54 NZST
temp Station1 1111 Tue 15 Sep 2020 17:09:53 NZST
temp Station1 1139 Tue 15 Sep 2020 17:14:53 NZST
temp Station1 1139 Tue 15 Sep 2020 17:19:52 NZST
temp Station1 1111 Tue 15 Sep 2020 17:24:51 NZST
temp Station1 1097 Tue 15 Sep 2020 17:29:51 NZST
temp Station1 1111 Tue 15 Sep 2020 17:34:50 NZST
temp Station1 1111 Tue 15 Sep 2020 17:39:49 NZST
temp Station1 1097 Tue 15 Sep 2020 17:44:49 NZST
temp Station1 1097 Tue 15 Sep 2020 17:49:48 NZST
temp Station1 1097 Tue 15 Sep 2020 17:54:48 NZST
temp Station1 1097 Tue 15 Sep 2020 17:59:47 NZST
temp Station1 1097 Tue 15 Sep 2020 18:04:47 NZST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment