agri-controller 0.0.0 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. checksums.yaml +7 -0
  2. data/ChangeLog.txt +36 -0
  3. data/LICENSE.txt +15 -0
  4. data/agri-controller.gemspec +36 -0
  5. data/gpl-2.0.txt +339 -0
  6. data/lib/agri-controller.rb +11 -33
  7. data/lib/agri-controller/bcc.rb +86 -53
  8. data/lib/agri-controller/bit.rb +158 -143
  9. data/lib/agri-controller/device.rb +7 -0
  10. data/lib/agri-controller/device/dacs.rb +148 -0
  11. data/lib/agri-controller/device/kr.rb +23 -0
  12. data/lib/agri-controller/device/ma.rb +92 -0
  13. data/lib/agri-controller/device/mch383.rb +178 -0
  14. data/lib/agri-controller/device/tr.rb +230 -0
  15. data/lib/agri-controller/device/wr1010.rb +314 -0
  16. data/lib/agri-controller/dt.rb +17 -0
  17. data/lib/agri-controller/error_caption.rb +67 -46
  18. data/lib/agri-controller/gruff.rb +7 -0
  19. data/lib/agri-controller/gruff/base.rb +88 -0
  20. data/lib/agri-controller/gruff/chdata.rb +64 -0
  21. data/lib/agri-controller/gruff/join_csv.rb +62 -0
  22. data/lib/agri-controller/gruff/rename_csv.rb +50 -0
  23. data/lib/agri-controller/{thermo_data_each_day.rb → gruff/thermo_data_each_day.rb} +67 -67
  24. data/lib/agri-controller/{thermo_gruff.rb → gruff/thermo_gruff.rb} +112 -109
  25. data/lib/agri-controller/gruff/thermo_gruff2.rb +161 -0
  26. data/lib/agri-controller/{thermo_gruff_generate.rb → gruff/thermo_gruff_generate.rb} +28 -28
  27. data/lib/agri-controller/gruff/thermo_gruff_loop.rb +42 -0
  28. data/lib/agri-controller/loger.rb +91 -51
  29. data/lib/agri-controller/main.rb +0 -0
  30. data/lib/agri-controller/main_linux.rb +282 -0
  31. data/lib/agri-controller/main_new.rb +401 -401
  32. data/lib/agri-controller/multiple_pulse_timer.rb +190 -169
  33. data/lib/agri-controller/n_dan_thermo.rb +156 -154
  34. data/lib/agri-controller/save_threads.rb +181 -172
  35. data/lib/agri-controller/setting_io.rb +53 -53
  36. data/lib/agri-controller/ttyUSB_watchdog.rb +43 -0
  37. data/lib/agri-controller/value_controller.rb +209 -167
  38. data/lib/agri-controller/version.rb +7 -5
  39. data/lib/agri-controller/web.rb +39 -39
  40. data/lib/agri-controller/webrick_test.rb +51 -46
  41. data/lib/agri-controller/wet_sensor.rb +92 -0
  42. data/test/tc_bit.rb +14 -3
  43. data/test/tc_trigger.rb +27 -0
  44. data/test/ts_agri-controller.rb +10 -10
  45. metadata +62 -202
  46. data/bin/main.bat +0 -2
  47. data/bin/main.bat /202/326/202/314/203V/203/207/201[/203g/203J/203b/203g.lnk +0 -0
  48. data/bin/main.rb +0 -23
  49. data/bin/memo.txt +0 -4
  50. data/bin/server.bat +0 -1
  51. data/bin/server.bat /202/326/202/314/203V/203/207/201[/203g/203J/203b/203g.lnk +0 -0
  52. data/bin/server.rb +0 -4
  53. data/bin/set_config.rb +0 -47
  54. data/bin/usual.rb +0 -3
  55. data/bin//203R/203}/203/223/203h /203v/203/215/203/223/203v/203g.lnk +0 -0
  56. data/lib/agri-controller/dacs.rb +0 -114
  57. data/lib/agri-controller/dircopy.rb +0 -30
  58. data/lib/agri-controller/kr.rb +0 -34
  59. data/lib/agri-controller/kr_2.rb +0 -78
  60. data/lib/agri-controller/serial.rb +0 -114
  61. data/lib/agri-controller/thermo_gruff_loop.rb +0 -35
  62. data/lib/agri-controller/wetsensor.rb +0 -119
  63. data/lib/agri-controller/wr1010.rb +0 -316
  64. data/lib/agri-controller/wr1010_2.rb +0 -0
  65. data/lib/cgi-bin/auto01.cgi +0 -0
  66. data/lib/cgi-bin/auto02.cgi +0 -0
  67. data/lib/cgi-bin/change_step.cgi +0 -42
  68. data/lib/cgi-bin/config/change_step +0 -4
  69. data/lib/cgi-bin/config/house1 +0 -20
  70. data/lib/cgi-bin/config/house2 +0 -8
  71. data/lib/cgi-bin/config/kr01_readable.txt +0 -2
  72. data/lib/cgi-bin/config/kr02_readable.txt +0 -2
  73. data/lib/cgi-bin/config/kr1_bit.txt +0 -2
  74. data/lib/cgi-bin/config/kr2_bit.txt +0 -2
  75. data/lib/cgi-bin/config/last_bit.txt +0 -1
  76. data/lib/cgi-bin/config/last_thermo_data +0 -22
  77. data/lib/cgi-bin/config/last_thermo_time +0 -2
  78. data/lib/cgi-bin/config/manual_bool01.txt +0 -2
  79. data/lib/cgi-bin/config/manual_bool02.txt +0 -2
  80. data/lib/cgi-bin/config/reload_flag +0 -2
  81. data/lib/cgi-bin/config/run_check +0 -2
  82. data/lib/cgi-bin/config/thermo_define.yml +0 -4
  83. data/lib/cgi-bin/config/time_array +0 -10
  84. data/lib/cgi-bin/config/wait_time +0 -2
  85. data/lib/cgi-bin/config/wet0 +0 -3
  86. data/lib/cgi-bin/config/wet0_drain +0 -2
  87. data/lib/cgi-bin/config/wet1 +0 -3
  88. data/lib/cgi-bin/config/wet1_drain +0 -2
  89. data/lib/cgi-bin/config/wet_input.txt +0 -1
  90. data/lib/cgi-bin/curtain_h1.cgi +0 -43
  91. data/lib/cgi-bin/curtain_h1_setting.cgi +0 -43
  92. data/lib/cgi-bin/curtain_h2.cgi +0 -43
  93. data/lib/cgi-bin/curtain_h2_setting.cgi +0 -43
  94. data/lib/cgi-bin/dacs_port.cgi +0 -43
  95. data/lib/cgi-bin/delay_time_0.cgi +0 -43
  96. data/lib/cgi-bin/delay_time_1.cgi +0 -43
  97. data/lib/cgi-bin/error_clear.cgi +0 -0
  98. data/lib/cgi-bin/house1.cgi +0 -42
  99. data/lib/cgi-bin/house1a.cgi +0 -43
  100. data/lib/cgi-bin/house2.cgi +0 -42
  101. data/lib/cgi-bin/house2b.cgi +0 -43
  102. data/lib/cgi-bin/house_n_dan_thermo1.cgi +0 -43
  103. data/lib/cgi-bin/house_n_dan_thermo2.cgi +0 -0
  104. data/lib/cgi-bin/keitai.cgi +0 -25
  105. data/lib/cgi-bin/kr01.cgi +0 -0
  106. data/lib/cgi-bin/kr01_readable.txt.cgi +0 -42
  107. data/lib/cgi-bin/kr02.cgi +0 -0
  108. data/lib/cgi-bin/kr02_readable.txt.cgi +0 -42
  109. data/lib/cgi-bin/kr1_bit.txt.cgi +0 -42
  110. data/lib/cgi-bin/kr2_bit.txt.cgi +0 -42
  111. data/lib/cgi-bin/kr_log.cgi +0 -18
  112. data/lib/cgi-bin/last_bit.txt.cgi +0 -42
  113. data/lib/cgi-bin/last_thermo_data.cgi +0 -42
  114. data/lib/cgi-bin/last_thermo_time.cgi +0 -42
  115. data/lib/cgi-bin/log.cgi +0 -19
  116. data/lib/cgi-bin/log/errors.txt +0 -1
  117. data/lib/cgi-bin/log/errors_.txt +0 -93
  118. data/lib/cgi-bin/log/kr_command_log.txt +0 -240
  119. data/lib/cgi-bin/log/log.txt +0 -441
  120. data/lib/cgi-bin/log/old_log/log_.txt +0 -15
  121. data/lib/cgi-bin/log/thermo/2010-05-22_thermo.csv +0 -1438
  122. data/lib/cgi-bin/log/thermo/2010-06-12_thermo.csv +0 -3
  123. data/lib/cgi-bin/log/thermo/2010-06-13_thermo.csv +0 -2
  124. data/lib/cgi-bin/log/thermo/2010-06-16_thermo.csv +0 -85
  125. data/lib/cgi-bin/log/thermo/2010-06-17_thermo.csv +0 -285
  126. data/lib/cgi-bin/log/thermo_data.csv +0 -643
  127. data/lib/cgi-bin/log/thermo_graph_loop.txt +0 -1
  128. data/lib/cgi-bin/main.cgi +0 -98
  129. data/lib/cgi-bin/manual_bool01.txt.cgi +0 -42
  130. data/lib/cgi-bin/manual_bool02.txt.cgi +0 -42
  131. data/lib/cgi-bin/post_change_step.cgi +0 -44
  132. data/lib/cgi-bin/post_house1.cgi +0 -44
  133. data/lib/cgi-bin/post_house2.cgi +0 -44
  134. data/lib/cgi-bin/post_kr01.cgi +0 -0
  135. data/lib/cgi-bin/post_kr01_readable.txt.cgi +0 -44
  136. data/lib/cgi-bin/post_kr02.cgi +0 -0
  137. data/lib/cgi-bin/post_kr02_readable.txt.cgi +0 -44
  138. data/lib/cgi-bin/post_kr1_bit.txt.cgi +0 -44
  139. data/lib/cgi-bin/post_kr2_bit.txt.cgi +0 -44
  140. data/lib/cgi-bin/post_last_bit.txt.cgi +0 -44
  141. data/lib/cgi-bin/post_last_thermo_data.cgi +0 -44
  142. data/lib/cgi-bin/post_last_thermo_time.cgi +0 -44
  143. data/lib/cgi-bin/post_manual_bool01.txt.cgi +0 -44
  144. data/lib/cgi-bin/post_manual_bool02.txt.cgi +0 -44
  145. data/lib/cgi-bin/post_reload_flag.cgi +0 -44
  146. data/lib/cgi-bin/post_run_check.cgi +0 -44
  147. data/lib/cgi-bin/post_thermo_define.yml.cgi +0 -44
  148. data/lib/cgi-bin/post_time_array.cgi +0 -44
  149. data/lib/cgi-bin/post_wait_time.cgi +0 -44
  150. data/lib/cgi-bin/post_wet0.cgi +0 -44
  151. data/lib/cgi-bin/post_wet0_drain.cgi +0 -44
  152. data/lib/cgi-bin/post_wet1.cgi +0 -44
  153. data/lib/cgi-bin/post_wet1_drain.cgi +0 -44
  154. data/lib/cgi-bin/post_wet_input.txt.cgi +0 -44
  155. data/lib/cgi-bin/reload_flag.cgi +0 -42
  156. data/lib/cgi-bin/reset_.cgi +0 -0
  157. data/lib/cgi-bin/run_check.cgi +0 -42
  158. data/lib/cgi-bin/set.cgi +0 -33
  159. data/lib/cgi-bin/set_post_yml_each.rb +0 -72
  160. data/lib/cgi-bin/set_yml_cgi_each.rb +0 -0
  161. data/lib/cgi-bin/setting.cgi +0 -0
  162. data/lib/cgi-bin/setting.cgi.1 +0 -0
  163. data/lib/cgi-bin/setting_io.rb +0 -53
  164. data/lib/cgi-bin/thermo_data_graphs.cgi +0 -0
  165. data/lib/cgi-bin/thermo_data_list.cgi +0 -0
  166. data/lib/cgi-bin/thermo_define.yml.cgi +0 -42
  167. data/lib/cgi-bin/thermo_graph.cgi +0 -0
  168. data/lib/cgi-bin/time_array.cgi +0 -42
  169. data/lib/cgi-bin/wait_time.cgi +0 -42
  170. data/lib/cgi-bin/web.rb +0 -39
  171. data/lib/cgi-bin/wet0.cgi +0 -42
  172. data/lib/cgi-bin/wet0_drain.cgi +0 -42
  173. data/lib/cgi-bin/wet1.cgi +0 -42
  174. data/lib/cgi-bin/wet1_drain.cgi +0 -42
  175. data/lib/cgi-bin/wet_input.txt.cgi +0 -42
  176. data/lib/htdocs/css/str.css +0 -89
  177. data/lib/htdocs/favicon.ico +0 -0
  178. data/lib/htdocs/thermo/thermo_data.jpg +0 -0
  179. data/lib/htdocs/thermo/thumb/thermo_data.jpg +0 -0
  180. data/test/tc_bit.rb.1 +0 -15
  181. data/test/tc_bit.rb.2 +0 -21
  182. data/test/ts_agri-controller.rb.1 +0 -8
@@ -0,0 +1,88 @@
1
+ #fixed by Takayasu_Hayashi for cristal background
2
+
3
+ #require 'rubygems'
4
+ #require 'RMagick'
5
+
6
+ #require File.dirname(__FILE__) + '/deprecated'
7
+
8
+ ##
9
+ # = Gruff. Graphs.
10
+ #
11
+ # Author:: Geoffrey Grosenbach boss@topfunky.com
12
+ #
13
+ # Originally Created:: October 23, 2005
14
+ #
15
+ # Extra thanks to Tim Hunter for writing RMagick, and also contributions by
16
+ # Jarkko Laine, Mike Perham, Andreas Schwarz, Alun Eyre, Guillaume Theoret,
17
+ # David Stokar, Paul Rogers, Dave Woodward, Frank Oxener, Kevin Clark, Cies
18
+ # Breijs, Richard Cowin, and a cast of thousands.
19
+ #
20
+ # See Gruff::Base#theme= for setting themes.
21
+
22
+ module Gruff
23
+
24
+
25
+ class Base
26
+
27
+ # You can set a theme manually. Assign a hash to this method before you
28
+ # send your data.
29
+ #
30
+ # graph.theme = {
31
+ # :colors => %w(orange purple green white red),
32
+ # :marker_color => 'blue',
33
+ # :background_colors => %w(black grey)
34
+ # }
35
+ #
36
+ # :background_image => 'squirrel.png' is also possible.
37
+ #
38
+ # (Or hopefully something better looking than that.)
39
+ #
40
+
41
+ # A color scheme plucked from the colors on the popular usability blog.
42
+ def theme_37signals
43
+ # Colors
44
+ @green = '#339933'
45
+ @purple = '#cc99cc'
46
+ @blue = '#336699'
47
+ @yellow = '#FFF804'
48
+ @red = '#ff0000'
49
+ @orange = '#cf5910'
50
+ @black = 'black'
51
+ @colors = [@black, @blue, @green, @red, @purple, @orange, '#202020']
52
+
53
+ self.theme = {
54
+ :colors => @colors,
55
+ :marker_color => 'black',
56
+ :font_color => 'black',
57
+ :background_colors => ['white', 'white']
58
+ }
59
+ =begin
60
+ # Colors
61
+ @dark_pink = '#FF3333'
62
+ @dark_blue = '#3a5b87'
63
+ @some_blue= '#3333ee'
64
+ @peach = '#daaea9'
65
+ '#a9a9da' # dk purple
66
+ @green = '#009933'
67
+ @purple = '#cc99cc'
68
+ @light_purple = '#a9a9da'
69
+ @light_blue='#333399'
70
+ @blue = '#0000ff'
71
+ @yellow = '#FFF804'
72
+ @red = '#ff0000'
73
+ @orange = '#cf5910'
74
+ @black = 'black'
75
+
76
+ @colors = [@black, @some_blue,@green, @red,@dark_pink ,@blue, @orange,@dark_blue ]
77
+
78
+ self.theme = {
79
+ :colors => @colors,
80
+ :marker_color => 'black',
81
+ :font_color => 'black',
82
+ :background_colors => ['white', 'white']
83
+ }
84
+ =end
85
+ end
86
+ end # Gruff::Base
87
+ end # Gruff
88
+
@@ -0,0 +1,64 @@
1
+ require "date"
2
+ #require "pp"
3
+
4
+ module AgriController
5
+ module_function
6
+ #配列をcsvにする
7
+ #ary2dat([["2012-12-03 07:02:00", 9.0, 27.9, 436.0, "9.0", 0.0, 0.0]]) # =>
8
+ # "2012-12-03 07:02:00,9.0,27.9,436.0,9.0,0.0,0.0\n"
9
+ def ary2dat(res)
10
+ str=""
11
+ res.each do |ary|
12
+ ary.each do |dat|
13
+ str=str+dat.to_s+","
14
+ end
15
+ str=str.chop+"\n"
16
+ end
17
+ str
18
+ end
19
+
20
+ #csv文字列を第2リストによって整える
21
+ # ("time"であれば、時間としてパースし、Rなどで使いやすい時間文字列に変換)
22
+ # (同時表示しやすいように、変換。 falseなどは0になる)
23
+ #chdat("2012/12/03 07:02:00,9.0,83.7,436,9.0,83.7,436\n",["time",1.0,1.0/3,1.0,false])
24
+ #[["2012-12-03 07:02:00", 9.0, 27.9, 436.0, "9.0", 0.0, 0.0]]
25
+ def chdat(str,list)
26
+ str
27
+
28
+ res=[]
29
+ str.each_line do |line|
30
+ dat=line.chomp.split(",")
31
+ i=0
32
+ kekka=[]
33
+ dat.each do |datum|
34
+ list[i]
35
+ datum
36
+ if (list[i]!=false) and (list[i]!="time")
37
+ list[i].to_f
38
+ datum.to_f
39
+ kekka << list[i].to_f*datum.to_f
40
+ elsif (list[i]=="time")
41
+ kekka << DateTime.parse(datum).strftime("%Y-%m-%d %H:%M:%S")
42
+ else
43
+ kekka << datum
44
+ end
45
+ i+=1
46
+
47
+ end
48
+ res << kekka
49
+ end
50
+ res
51
+ end
52
+
53
+ end
54
+
55
+ if $0==__FILE__
56
+ include AgriController
57
+ list=["time",1.0,1.0/3,1.0,false]
58
+ file= ARGV[0] || "2012/12/03 07:02:00,9.0,83.7,436,9.0,83.7,436\n"
59
+ ls=eval(ARGV[1].to_s) || list
60
+
61
+ p str=chdat(file,list)
62
+ print ary2dat(str)
63
+
64
+ end
@@ -0,0 +1,62 @@
1
+ require "csv"
2
+ require "time"
3
+
4
+ module AgriController
5
+
6
+ def delete_comment(ary,comment_count)
7
+ comment_count.times{ary.shift}
8
+
9
+ ary
10
+ end
11
+
12
+ def to_h(ary,time_line=0)
13
+ hash={}
14
+ ary.each do |list|
15
+ t=list.delete_at(time_line=0)
16
+ t=Time.parse(t)
17
+ hash[t]=list
18
+ end
19
+ hash
20
+ end
21
+
22
+ module_function
23
+ def join_csv(f1,f2,comment_f1=0,comment_f2=0)
24
+ a=CSV.read(f1)
25
+ a=delete_comment(a,comment_f1)
26
+ size=a[0].size
27
+ hash1=to_h(a,0)
28
+ #hash1
29
+
30
+ b=CSV.read(f2)
31
+ b=delete_comment(b,comment_f1)
32
+ hash2=to_h(b,0)
33
+
34
+ new_hash={}
35
+ hash2.each do |i,j|
36
+ if hash1.has_key?(i)
37
+ else
38
+ hash1[i]=Array.new(size-1){"false"}
39
+ end
40
+ new_hash[i]=hash1[i].concat(j)
41
+ end
42
+ ary=new_hash.sort_by{|i,j| i}
43
+ ary.map{|i| i.flatten}
44
+ end
45
+
46
+ end
47
+ if $0==__FILE__
48
+ f1=ARGV[0] || "../mch383/thermo_data.csv"
49
+ f2=ARGV[1] || "../mch383_2/thermo_data.csv"
50
+ to_file=ARGV[2]
51
+ comment_f1=1
52
+ comment_f2=1
53
+ list=join_csv(f1,f2,comment_f1,comment_f2)
54
+ if to_file
55
+ CSV.open(to_file,"w") do |csv|
56
+ list.each do |i|
57
+ i[0]=i[0].strftime("%Y/%m/%d %H:%M:%S")
58
+ csv << i
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,50 @@
1
+ require "fileutils"
2
+ module AgriController
3
+ module_function
4
+ def rename_csv(dist,dist_dir,deli=".csv.")
5
+ if ARGV[0]=="-h"
6
+ raise
7
+ end
8
+ unless File.exist?(dist_dir)
9
+ Dir.mkdir(dist_dir)
10
+ end
11
+
12
+ list=Dir.glob(dist+"/*#{deli}*")
13
+ #p list
14
+ list.each do |file|
15
+ basename=File.basename(file)
16
+ dir=File.dirname(file)
17
+ name=basename.split(".")
18
+ if name.last.to_i!=0
19
+ new_name=name[0]+"."+name[2]+"."+name[1]
20
+ #p file
21
+ new_full_name=dist_dir+"/"+new_name
22
+ FileUtils.cp(file,new_full_name)
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ if $0==__FILE__
29
+ include AgriController
30
+ #FileUtils.cp("from","to")
31
+ #FileUtils.cp(["list",],"dir")
32
+ #Dir.mkdir("dir")
33
+ dist=ARGV[0]
34
+ dist_dir=ARGV[1]
35
+ begin
36
+ rename_csv(dist,dist_dir)
37
+ rescue
38
+ puts 'Usage::
39
+
40
+ sample $> ruby rename_csv.rb "." "csv_dir"
41
+
42
+ ruby rename_csv.rb "from_dir" "to_dir"
43
+
44
+ Rename and copy
45
+ "from_dir/*.csv.{logger_day_number}" to
46
+ "to_dir/*.{logger_day_number}.csv"
47
+
48
+ Ruby Dir::mkdir("to_dir") if not exist.'
49
+ end
50
+ end
@@ -1,67 +1,67 @@
1
- require "time"
2
- module AgriController
3
- def thermo_data_each_day(file)
4
- if File.exist?(file)
5
- dat=File.read(file)
6
- else
7
- dat=file
8
- end
9
- x=[]
10
- y=[]
11
- line=0
12
- file_num=0
13
- last_day_data=0
14
- change=nil
15
- date=Time.now
16
- begin
17
- dat.each_line do |str|
18
- line+=1
19
- #split day data
20
- #p str
21
- if str!=""
22
- data=str.chomp.split(",")
23
- date=Time.parse(data[0])
24
- last_day_data=date.day
25
- change=date if change==nil
26
- end
27
- #not change
28
- if change.day==last_day_data
29
- #day change
30
- elsif change.day!=last_day_data
31
- y[file_num] = change
32
- change=date
33
- file_num+=1
34
- else
35
- p "??"
36
- end
37
- x[file_num]="" if x[file_num]==nil
38
- x[file_num]+=str
39
-
40
- #normal end
41
-
42
- end
43
- y[file_num]=date
44
- end
45
- #return split array
46
- ret=[x,y]
47
- return ret
48
- end
49
- def save_each_day(file="_thermo_data.csv")
50
- p result=thermo_data_each_day(file)
51
- x=0
52
- result[1].each do |date|
53
- i=date.year.to_s
54
- j=date.month.to_s
55
- k=date.day.to_s
56
- #save_each_day
57
- filename="./thermo_data/"+i+"-"+j+"-"+k+"_thermo.csv"
58
- open(filename,"w"){|io| io.print result[0][x]}
59
-
60
- x+=1
61
- end
62
- end
63
- end
64
-
65
- if $0==__FILE__
66
- save_each_day(file="_thermo_data.csv")
67
- end
1
+ require "time"
2
+ module AgriController
3
+ def thermo_data_each_day(file)
4
+ if File.exist?(file)
5
+ dat=File.read(file)
6
+ else
7
+ dat=file
8
+ end
9
+ x=[]
10
+ y=[]
11
+ line=0
12
+ file_num=0
13
+ last_day_data=0
14
+ change=nil
15
+ date=Time.now
16
+ begin
17
+ dat.each_line do |str|
18
+ line+=1
19
+ #split day data
20
+ #p str
21
+ if str!=""
22
+ data=str.chomp.split(",")
23
+ date=Time.parse(data[0])
24
+ last_day_data=date.day
25
+ change=date if change==nil
26
+ end
27
+ #not change
28
+ if change.day==last_day_data
29
+ #day change
30
+ elsif change.day!=last_day_data
31
+ y[file_num] = change
32
+ change=date
33
+ file_num+=1
34
+ else
35
+ p "??"
36
+ end
37
+ x[file_num]="" if x[file_num]==nil
38
+ x[file_num]+=str
39
+
40
+ #normal end
41
+
42
+ end
43
+ y[file_num]=date
44
+ end
45
+ #return split array
46
+ ret=[x,y]
47
+ return ret
48
+ end
49
+ def save_each_day(file="_thermo_data.csv")
50
+ p result=thermo_data_each_day(file)
51
+ x=0
52
+ result[1].each do |date|
53
+ i=date.year.to_s
54
+ j=date.month.to_s
55
+ k=date.day.to_s
56
+ #save_each_day
57
+ filename="./thermo_data/"+i+"-"+j+"-"+k+"_thermo.csv"
58
+ open(filename,"w"){|io| io.print result[0][x]}
59
+
60
+ x+=1
61
+ end
62
+ end
63
+ end
64
+
65
+ if $0==__FILE__
66
+ save_each_day(file="_thermo_data.csv")
67
+ end
@@ -1,109 +1,112 @@
1
- require 'rubygems'
2
- require 'gruff'
3
- require "date"
4
-
5
- module AgriController
6
- #thrmo datas to jpg graph
7
- def thermo_gruff(output_filename="thermo_data.jpg",input_csv_data="thermo_data.csv",thermo_num=3,view="500x420")
8
- #data ini
9
- data=File.read(input_csv_data)
10
- thermo_data_hash={}
11
-
12
- result=[]
13
- #arrays generate
14
- (2*thermo_num).times do
15
- result << []
16
- end
17
- result
18
- title_day=""
19
- line=0
20
- label={}
21
- hour=0
22
- day=0
23
- data.each_line do |str|
24
- line+=1#line+=
25
- dat=str.chomp.split(",")
26
- #p dat[0]
27
- begin
28
- time=DateTime.parse(dat[0])
29
- rescue
30
- line=line-1
31
- next
32
- end
33
- #title_day
34
- if line==1
35
- title_day=time.year.to_s+"/"+time.month.to_s+"/"+time.day.to_s
36
- end
37
- #line if day change
38
- if time.day!=day #(day change)
39
- day=time.day
40
- label[line]=":"#time.month.to_s+"/"+day.to_s
41
- elsif time.hour!=hour
42
- hour=time.hour
43
- label[line]="|"+hour.to_s
44
- if time.hour==12
45
- label[line]="|12"
46
- end
47
- else
48
- end
49
-
50
- #set thermo datas
51
- thermo_num.times do |n|
52
- begin
53
- x=dat[n*2+1].to_f
54
- if x>-100
55
- result[n*2] << x
56
- else
57
- result[n*2] << nil
58
- end
59
- rescue
60
- result[n*2] << nil
61
- end
62
- #Judge nil data
63
- if dat[n*2+2]!="false"
64
- result[n*2+1] << dat[n*2+2].to_f/3
65
- else
66
- result[n*2+1] << nil
67
- end
68
- end
69
- end
70
- #p result
71
- #p label
72
- #gruff main
73
- g = Gruff::Line.new(view)
74
- g.title="Thermo data since "+title_day
75
- #g.title_font_size =24
76
- g.theme_37signals
77
- g.maximum_value = 35
78
- g.minimum_value = 5
79
- g.y_axis_increment = 1
80
- #g.baseline_value=9
81
- #g.increment=5
82
- #dataset
83
- datasets=[]
84
- thermo_num.times do |i|
85
- x=i+1
86
- datasets[i*2 ]=[("'C:"+x.to_s).intern,result[i*2]]
87
- datasets[i*2+1]=[("%/3:"+x.to_s).intern,result[i*2+1]]
88
- end
89
- #% humidity data delete
90
- [7,5,3].each{|i| datasets.delete_at(i)}
91
-
92
- #dataset
93
- datasets.each do |data|
94
- g.data(*data)
95
- end
96
- g.labels =label
97
- # Default theme
98
- g.write(output_filename)
99
- end
100
- end
101
-
102
- if $0==__FILE__
103
- p Dir.pwd
104
- input_csv_data="./thermo_data/2009-11-21_thermo.csv"
105
- if File.readable?(input_csv_data)
106
- thermo_gruff(output_filename="../htdocs/thermo/2009-11-21.jpg",input_csv_data,thermo_num=2,"480x420")
107
- p Time.now
108
- end
109
- end
1
+ require 'rubygems'
2
+ require 'gruff'
3
+ require "date"
4
+ require "time"
5
+ module AgriController
6
+ #thrmo datas to jpg graph
7
+ def thermo_gruff(output_filename="thermo_data.jpg",input_csv_data="thermo_data.csv",thermo_num=3,view="500x420")
8
+ #data ini
9
+ data=File.read(input_csv_data)
10
+ thermo_data_hash={}
11
+
12
+ result=[]
13
+ #arrays generate
14
+ (2*thermo_num).times do
15
+ result << []
16
+ end
17
+ result
18
+ title_day=""
19
+ line=0
20
+ label={}
21
+ hour=0
22
+ day=0
23
+ data.each_line do |str|
24
+ line+=1#line+=
25
+ dat=str.chomp.split(",")
26
+ #p dat[0]
27
+ begin
28
+ time=Time.iso8601(dat[0]).localtime#DateTime
29
+ #dat[0].inspect+","+time.to_s
30
+ rescue
31
+ line=line-1
32
+ next
33
+ end
34
+ #title_day
35
+ if line==1
36
+ title_day=time.year.to_s+"/"+time.month.to_s+"/"+time.day.to_s
37
+ end
38
+ #line if day change
39
+ time.hour
40
+ if time.day!=day #(day change)
41
+ day=time.day
42
+ label[line]=":"#time.month.to_s+"/"+day.to_s
43
+ elsif time.hour!=hour
44
+ hour=time.hour
45
+ label[line]="|"+hour.to_s
46
+ if time.hour==12
47
+ label[line]="|12"
48
+ end
49
+ else
50
+ end
51
+
52
+ #set thermo datas
53
+ thermo_num.times do |n|
54
+ begin
55
+ x=dat[n*2+1].to_f
56
+ if x>-100
57
+ result[n*2] << x
58
+ else
59
+ result[n*2] << nil
60
+ end
61
+ rescue
62
+ result[n*2] << nil
63
+ end
64
+ #Judge nil data
65
+ if dat[n*2+2]!="false"
66
+ result[n*2+1] << dat[n*2+2].to_f/3
67
+ else
68
+ result[n*2+1] << nil
69
+ end
70
+ end
71
+ end
72
+ #p result
73
+ #p label
74
+ #gruff main
75
+ g = Gruff::Line.new(view)
76
+ g.title="Thermo data since "+title_day
77
+ #g.title_font_size =24
78
+ g.theme_37signals
79
+ g.maximum_value = 35
80
+ g.minimum_value = 5
81
+ g.y_axis_increment = 1
82
+ #g.baseline_value=9
83
+ #g.increment=5
84
+ #dataset
85
+ datasets=[]
86
+ thermo_num.times do |i|
87
+ x=i+1
88
+ datasets[i*2 ]=[("'C:"+x.to_s).intern,result[i*2]]
89
+ datasets[i*2+1]=[("%/3:"+x.to_s).intern,result[i*2+1]]
90
+ end
91
+ #% humidity data delete
92
+ [9,7,5,3].each{|i| datasets.delete_at(i)}
93
+
94
+ #dataset
95
+ datasets.each do |data|
96
+ g.data(*data)
97
+ end
98
+ g.labels =label
99
+ # Default theme
100
+ #p g
101
+ g.write(output_filename)
102
+ end
103
+ end
104
+
105
+ if $0==__FILE__
106
+ p Dir.pwd
107
+ input_csv_data="./thermo_data/2009-11-21_thermo.csv"
108
+ if File.readable?(input_csv_data)
109
+ thermo_gruff(output_filename="../htdocs/thermo/2009-11-21.jpg",input_csv_data,thermo_num=2,"480x420")
110
+ p Time.now
111
+ end
112
+ end