What
Where
photosmarinavlad  

 

Didenko Family

© 2003-2023 Vlad Didenko, Marina Didenko

ALL RIGHTS RESERVED

The content rights are not available for sale or licensing. Any use of the content except by the website owners is prohibited, unless specified per-page otherwise, or agreed in writing otherwise.

This website is for personal photos and posts, for the benefit of family and friends. As such it has a minimal needed set of features. No backward compatibility with old browsers is considered.

Most photos are processed to match a personal perception at the time of capture, and some photos are processed creatively. No guarantees presented about photos resemblibling a reality in any sense. No guarantees presented that a technology, or a personal advice, or/and any information posted on the website is usefull or harmless for your environment.

Distribution aggregation

I needed to plot distribution of timed events today and ended up with the following Ruby script to prepare the csv data:

#!/usr/bin/env ruby
#
# (c) 2009 Vlad Didenko
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    See the GNU General Public License at
#    http://www.gnu.org/licenses/gpl-3.0.txt
#    for the detailed text of the license.
#

data = {}

while gets() do
  $_.split().each do |item|
    inum = item.to_i
    if data[inum]; then data[inum] += 1; else data[inum] = 1 end
  end
end

data.keys().sort().each do |key|
  puts "#{key}, #{data[key]}"
end

Here is the usage example when this script saved as distr executable:

$ echo "1 4 235 3 2 3 1 4 2 3 4 1 2 45 6 3 2" | distr
1, 3
2, 4
3, 4
4, 3
6, 1
45, 1
235, 1
$

As with any gets-based script, it takes filenames as parameters as well.

2009-10-27

 ∽   ⦾   ∽