Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Data output

Reply
Thread Tools

Data output

 
 
Stuart Clarke
Guest
Posts: n/a
 
      11-06-2008
I am processing data from an array which basically involves me searching
for specific information and outputting the results that match eg.

.......
if data == 100
puts "#{data.time_written}"

I have just inserted a step which adds some additional criteria. This
states if you find data that equals 100 does it happens more than 10
times in one day.

This all works fine. What i want is some kind of nested if statement
thats does the following:

if data == 100
if data happens more than 5 times in one day
print out the results of all the data that equals 100 but highlight
(colour code, italics etc)the data within the results that happens more
than 5 times in a day.

An example of the results might be

100 monday - - - BOLD
100 monday - - - BOLD
100 monday - - - BOLD
100 monday - - - BOLD
100 monday - - - BOLD
100 monday - - - BOLD
100 tuesday - - - NORMAL

Hope this makes sense.

Regards
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Axel Etzold
Guest
Posts: n/a
 
      11-06-2008

-------- Original-Nachricht --------
> Datum: Fri, 7 Nov 2008 02:23:40 +0900
> Von: Stuart Clarke <(E-Mail Removed)>
> An: http://www.velocityreviews.com/forums/(E-Mail Removed)
> Betreff: Data output


> I am processing data from an array which basically involves me searching
> for specific information and outputting the results that match eg.
>
> .......
> if data == 100
> puts "#{data.time_written}"
>
> I have just inserted a step which adds some additional criteria. This
> states if you find data that equals 100 does it happens more than 10
> times in one day.
>
> This all works fine. What i want is some kind of nested if statement
> thats does the following:
>
> if data == 100
> if data happens more than 5 times in one day
> print out the results of all the data that equals 100 but highlight
> (colour code, italics etc)the data within the results that happens more
> than 5 times in a day.
>
> An example of the results might be
>
> 100 monday - - - BOLD
> 100 monday - - - BOLD
> 100 monday - - - BOLD
> 100 monday - - - BOLD
> 100 monday - - - BOLD
> 100 monday - - - BOLD
> 100 tuesday - - - NORMAL
>
> Hope this makes sense.
>
> Regards
> --
> Posted via http://www.ruby-forum.com/.


Dear Stuart,

you can output your report as a html document using textile:

http://whytheluckystiff.net/ruby/redcloth/

using very simple markup styles.

Best regards,

Axel


--
"Feel free" - 5 GB Mailbox, 50 FreeSMS/Monat ...
Jetzt GMX ProMail testen: http://www.gmx.net/de/go/promail

 
Reply With Quote
 
 
 
 
Jesús Gabriel y Galán
Guest
Posts: n/a
 
      11-07-2008
On Thu, Nov 6, 2008 at 6:23 PM, Stuart Clarke
<(E-Mail Removed)> wrote:
> I am processing data from an array which basically involves me searching
> for specific information and outputting the results that match eg.
>
> .......
> if data == 100
> puts "#{data.time_written}"
>
> I have just inserted a step which adds some additional criteria. This
> states if you find data that equals 100 does it happens more than 10
> times in one day.
>
> This all works fine. What i want is some kind of nested if statement
> thats does the following:
>
> if data == 100
> if data happens more than 5 times in one day
> print out the results of all the data that equals 100 but highlight
> (colour code, italics etc)the data within the results that happens more
> than 5 times in a day.
>
> An example of the results might be
>
> 100 monday - - - BOLD
> 100 monday - - - BOLD
> 100 monday - - - BOLD
> 100 monday - - - BOLD
> 100 monday - - - BOLD
> 100 monday - - - BOLD
> 100 tuesday - - - NORMAL


This is how I'd do it: first build an histogram of the data. In this case
you want to count how many there are of a combination of data and day.
Then print the array checking against the histogram for choosing style:

irb(main):001:0> TimeData = Struct.new :data, :day
=> TimeData
irb(main):002:0> a = []
=> []
irb(main):003:0> 6.times {a << TimeData.new(100, "monday")}
=> 6
irb(main):004:0> a << TimeData.new(100, "tuesday")
=> [#<struct TimeData data=100, day="monday">, #<struct TimeData
data=100, day="monday">, #<struct TimeData data=100, day="monday">,
#<struct TimeData data=100, day="monday">, #<struct TimeData data=100,
day="monday">, #<struct TimeData data=100, day="monday">, #<struct
TimeData data=100, day="tuesday">]
irb(main):005:0> h = Hash.new(0)
=> {}
irb(main):007:0> a.inject(h) {|histo,time| h[[time.data, time.day]] += 1}
=> 1
irb(main):008:0> h
=> {[100, "tuesday"]=>1, [100, "monday"]=>6}
irb(main):009:0> a.each do |time|
irb(main):010:1* if h[[time.data, time.day]] > 5
irb(main):011:2> puts "<bold>#{time.data} #{time.day}</bold>"
irb(main):012:2> else
irb(main):013:2* puts "<normal>#{time.data} #{time.day}</normal>"
irb(main):014:2> end
irb(main):015:1> end
<bold>100 monday</bold>
<bold>100 monday</bold>
<bold>100 monday</bold>
<bold>100 monday</bold>
<bold>100 monday</bold>
<bold>100 monday</bold>
<normal>100 tuesday</normal>

Hope this helps.

Jesus.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
eval of Data::Dumper output not same as original data structure himanshu.garg@gmail.com Perl Misc 4 08-01-2007 01:49 PM
Sony Precision Cinema Progressive Output vs Component 480p Output Otto Pylot DVD Video 1 04-18-2004 09:49 PM
reading output file data as input data Stephen Moon Perl Misc 5 02-29-2004 02:16 PM
Is Fuji S3000 3.2m/pixel output, or 6 m/pixel interpolated output? Peter H Digital Photography 43 12-04-2003 02:35 PM
Output / Debug window output bug? John Bentley ASP .Net 0 09-10-2003 07:38 AM



Advertisments