[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: better way to accumulate totals

Robert Klemme

10/31/2007 9:16:00 AM

2007/10/30, Robert Keller <rlkeller@yahoo.com>:
>
>
> I am just learning RUBY and am very impressed, I one week I've built tree routines that will save my group 6 to 7 hours each week, and they run in 2 minutes. Pretty cool. I would appreciate a suggest on how to do some. I have a script that correctly parses a directory full of text file and extracts key data. The data lines look like this:
>
> " category value"
>
> I have 15 categories and the code below works. But is crude. I create 15 global arrays and match each line "category" to the text trying in the case statement. Would hash or an object work better. Just looking for pointer of which way to direct my research. Thanks!

Here is a different approach. I start by creating a statistics object:

Statistics = Struct.new :count, :sum

stats = Hash.new {|h,k| h[k] = Statistics.new(0, 0)}

File.foreach "foo.dat" do |line|
if /^\s+\b(.+?)\b\s+(\d+\.\d+)/ =~ line
s = stats[$1]
s.count += 1
s.sum += Float($2)
end
end

Note, you might have to tweak the regexp.

Kind regards

robert

--
use.inject do |as, often| as.you_can - without end

11 Answers

Anim8rFSK

7/30/2013 7:33:00 PM

0

In article <1l6tdu1.lc7ytc297hskN%csampson@inetworld.net>,
csampson@inetworld.net (Charles H. Sampson) wrote:

> One last comment, since I have decided that Monday's episode is the
> last one for me.
>
> In the opening sequence, a small plane crashes into the outside of
> the dome.

No, it doesn't. It's hitting the inside wall.

> You know it's the outside because the dome is sloping away
> from the plane, which you can see from the shape of the fireball.

The sfx people on this show are lazy and incompetent and likely
Canadian. It's still hitting the inside.

(Of
> course, there has to be a fireball. No crash is complete without one.)
> Yet I'm pretty sure that the plane falls inside the dome.

Yes, because it hit the inside.

Exactly who is
> diving away from the falling debris is not to clear but one of them
> looks like Barbie.

Yes

In any case, if memory serves, there was a shot
> earlier in the series inside the dome that had the plane's debris
> incidentally in the scene. Also, the debris from a plane crashing into
> the outside of the dome would tend to slide down the side of the dome,
> not fall.

It hit the inside. There was no point at which it remotely looked like
it hit the outside. They said who the pilot was, they said he was
leaving Chesters Mill, the guys on the ground inside the dome saw and
heard the plane headed for the dome from inside, the plane hit the
inside of the dome, the plane came almost straight down almost hitting
them at the edge of the dome (which would mean it wasn't very high).
>
> The above analysis doesn't stand if pertinent laws of physics have
> been suspended.

They clearly have, but that doesn't have anything to do with the fact
that the plane was inside.

--
Wait - are you saying that ClodReamer was wrong, or lying?

Michael Black

7/30/2013 9:41:00 PM

0

Stan Brown

7/30/2013 11:17:00 PM

0

On Tue, 30 Jul 2013 09:29:04 -0700, Charles H. Sampson wrote:
>
> In the opening sequence, a small plane crashes into the outside of
> the dome. You know it's the outside because the dome is sloping away
> from the plane, which you can see from the shape of the fireball.
>

I don't know what you mean by "sloping away from", but I remember
that sequence clearly, and the plane was inside the dome.

You don't need sophisticated arguments here: the debris of the crash
fell inside the dome, so the plane must have been inside the dome.

--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadS...
Shikata ga nai...

Jim G.

7/31/2013 6:32:00 PM

0

anim8rFSK sent the following on 7/30/2013 2:33 PM:
> In article <1l6tdu1.lc7ytc297hskN%csampson@inetworld.net>,
> csampson@inetworld.net (Charles H. Sampson) wrote:
>
>> One last comment, since I have decided that Monday's episode is the
>> last one for me.
>>
>> In the opening sequence, a small plane crashes into the outside of
>> the dome.
>
> No, it doesn't. It's hitting the inside wall.

Yep. But it does raise the question of how large the dome is, given that
it apparently encompasses an airfield of some sort along with the town
and whatnot. I suspect that, especially given a second season already,
this dome's footprint is going to get larger and larger over time...

>> You know it's the outside because the dome is sloping away
>> from the plane, which you can see from the shape of the fireball.
>
> The sfx people on this show are lazy and incompetent and likely
> Canadian. It's still hitting the inside.

Heh. I noticed something similar when the butterflies were all
collecting on the *outside* of the dome while the image of them
certainly appeared to have them collecting on the *inside*. But I spent
so much time ripping on major flaws with that particular outing that it
felt like piling on to bring this up, as well, at that time.

--
Jim G. | A fan of the good and the bad, but not the mediocre
"Dang it. That was my best Dirty Harry. He might just be an idiot." --
Jason Stackhouse, TRUE BLOOD

BTR1701

7/31/2013 7:22:00 PM

0

On Jul 31 2013 11:32 AM, Jim G. wrote:

> anim8rFSK sent the following on 7/30/2013 2:33 PM:
> > In article <1l6tdu1.lc7ytc297hskN%csampson@inetworld.net>,
> > csampson@inetworld.net (Charles H. Sampson) wrote:
> >
> >> One last comment, since I have decided that Monday's episode is the
> >> last one for me.
> >>
> >> In the opening sequence, a small plane crashes into the outside of
> >> the dome.
> >
> > No, it doesn't. It's hitting the inside wall.
>
> Yep. But it does raise the question of how large the dome is, given that
> it apparently encompasses an airfield of some sort along with the town
> and whatnot.

In the book, the airfield was elsewhere. The plane was being flown by a
flight student and her instructor. The student was the wife of one of the
Chester's Mill town selectmen and they were flying over the town when the
dome came down because she wanted to see her home from the air. But the
actual airport from which they took off wasn't inside the dome's confines.

Anim8rFSK

7/31/2013 9:37:00 PM

0

In article <ktbkru$mbf$10@dont-email.me>,
"Jim G." <jimgysin@geemail.com.invalid> wrote:

> anim8rFSK sent the following on 7/30/2013 2:33 PM:
> > In article <1l6tdu1.lc7ytc297hskN%csampson@inetworld.net>,
> > csampson@inetworld.net (Charles H. Sampson) wrote:
> >
> >> One last comment, since I have decided that Monday's episode is the
> >> last one for me.
> >>
> >> In the opening sequence, a small plane crashes into the outside of
> >> the dome.
> >
> > No, it doesn't. It's hitting the inside wall.
>
> Yep. But it does raise the question of how large the dome is, given that
> it apparently encompasses an airfield of some sort along with the town
> and whatnot. I suspect that, especially given a second season already,
> this dome's footprint is going to get larger and larger over time...

Well, it's possible that the airfield is outside THE DUMB and the guy's
flight path took him through THE DUMB as it appeared.
>
> >> You know it's the outside because the dome is sloping away
> >> from the plane, which you can see from the shape of the fireball.
> >
> > The sfx people on this show are lazy and incompetent and likely
> > Canadian. It's still hitting the inside.
>
> Heh. I noticed something similar when the butterflies were all
> collecting on the *outside* of the dome while the image of them
> certainly appeared to have them collecting on the *inside*. But I spent
> so much time ripping on major flaws with that particular outing that it
> felt like piling on to bring this up, as well, at that time.

Yeah I remember noting that one of the butterfly shots was odd.

I was annoyed that they claimed there shouldn't have been butterflies at
all, and yet there they were on the *outside*

--
Wait - are you saying that ClodReamer was wrong, or lying?

Michael Black

7/31/2013 10:57:00 PM

0

Stan Brown

7/31/2013 11:43:00 PM

0

On Wed, 31 Jul 2013 18:57:24 -0400, Michael Black wrote:
>
> On Wed, 31 Jul 2013, Jim G. wrote:

> > Yep. But it does raise the question of how large the dome is, given that it
> > apparently encompasses an airfield of some sort along with the town and
> > whatnot. I suspect that, especially given a second season already, this
> > dome's footprint is going to get larger and larger over time...
> >
> Couldn't it have been in the air already (like it took off from the local
> airfield) and was over the twon when the dome went up? Just like the car,
> truck, it was already in motion and unaware that the dome now existed.

Indeed, that seemed to me far and away the most likely explanation
when I saw the crash.



--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadS...
Shikata ga nai...

csampson

8/1/2013 4:30:00 PM

0

Jim G. <jimgysin@geemail.com.invalid> wrote:

> anim8rFSK sent the following on 7/30/2013 2:33 PM:
> > In article <1l6tdu1.lc7ytc297hskN%csampson@inetworld.net>,
> > csampson@inetworld.net (Charles H. Sampson) wrote:
> >
> >> One last comment, since I have decided that Monday's episode is the
> >> last one for me.
> >>
> >> In the opening sequence, a small plane crashes into the outside of
> >> the dome.
> >
> > No, it doesn't. It's hitting the inside wall.
>
> Yep. But it does raise the question of how large the dome is, given that
> it apparently encompasses an airfield of some sort along with the town
> and whatnot. I suspect that, especially given a second season already,
> this dome's footprint is going to get larger and larger over time...

For heaven's sake, I know that from the storyline the plane is
inside the dome. The title of this thread is "More Dome Dumbness". Just
take a look at the opening sequence, Use your eyes. If you can't see it
in real time, record it and look at it in slow motion. The plane flies
into the outside of the dome. The CGI guys made a mistake.

> >> You know it's the outside because the dome is sloping away
> >> from the plane, which you can see from the shape of the fireball.
> ...

Charlie
--
Nobody in this country got rich on his own. You built a factory--good.
But you moved your goods on roads we all paid for. You hired workers we
all paid to educate. So keep a big hunk of the money from your factory.
But take a hunk and pay it forward. Elizabeth Warren (paraphrased)

Jim G.

8/1/2013 5:50:00 PM

0

BTR1701 sent the following on 7/31/2013 2:21 PM:
> On Jul 31 2013 11:32 AM, Jim G. wrote:
>
>> anim8rFSK sent the following on 7/30/2013 2:33 PM:
>>> In article <1l6tdu1.lc7ytc297hskN%csampson@inetworld.net>,
>>> csampson@inetworld.net (Charles H. Sampson) wrote:
>>>
>>>> One last comment, since I have decided that Monday's episode is the
>>>> last one for me.
>>>>
>>>> In the opening sequence, a small plane crashes into the outside of
>>>> the dome.
>>>
>>> No, it doesn't. It's hitting the inside wall.
>>
>> Yep. But it does raise the question of how large the dome is, given that
>> it apparently encompasses an airfield of some sort along with the town
>> and whatnot.
>
> In the book, the airfield was elsewhere. The plane was being flown by a
> flight student and her instructor. The student was the wife of one of the
> Chester's Mill town selectmen and they were flying over the town when the
> dome came down because she wanted to see her home from the air. But the
> actual airport from which they took off wasn't inside the dome's confines.

Yeah, I didn't consider the possibility of it just being rotten timing
for the poor pilot, so this is clearly not a legitimate complaint point.

--
Jim G. | A fan of the good and the bad, but not the mediocre
"Dang it. That was my best Dirty Harry. He might just be an idiot." --
Jason Stackhouse, TRUE BLOOD