J
Jeff Carlson
I am very new to ruby and thought I would start with my simplest python
script and port it over and along the way, learn the "ruby way" of doing
things. My solution so far is unsatisfactory and long. If you have any
suggestions, most especially about the "ruby way" to write the file2Map
method, I would appreciate it and all of my future ruby programs would
also appreciate it.
Cheers,
Jeff Carlson
-------------------------------------------------------------
#!/usr/bin/python
# print statistics for seti@home jobs
from mx.DateTime import TimeDelta
import sys
# this method takes a file with key/value pairs, seperated by "="
# and makes a map of the file, keys and values, the length of the
# map is the length of the file
def getMapFromFile(fname):
lines = open(fname).readlines()
return dict([line.split("=") for line in lines])
# make maps of the two files
sMap = getMapFromFile(sys.argv[1])
uMap = getMapFromFile(sys.argv[2])
prog = float(sMap["prog"].strip())*100
et = TimeDelta(seconds=float(sMap["cpu"].strip()))
#print results
print '%.2f%c completed in %d:%02d:%02d' % (prog, '%', et.hour, /
et.minute, et.second)
print 'units of work so far %s' % (uMap["nresults"].strip())
script and port it over and along the way, learn the "ruby way" of doing
things. My solution so far is unsatisfactory and long. If you have any
suggestions, most especially about the "ruby way" to write the file2Map
method, I would appreciate it and all of my future ruby programs would
also appreciate it.
Cheers,
Jeff Carlson
-------------------------------------------------------------
#!/usr/bin/python
# print statistics for seti@home jobs
from mx.DateTime import TimeDelta
import sys
# this method takes a file with key/value pairs, seperated by "="
# and makes a map of the file, keys and values, the length of the
# map is the length of the file
def getMapFromFile(fname):
lines = open(fname).readlines()
return dict([line.split("=") for line in lines])
# make maps of the two files
sMap = getMapFromFile(sys.argv[1])
uMap = getMapFromFile(sys.argv[2])
prog = float(sMap["prog"].strip())*100
et = TimeDelta(seconds=float(sMap["cpu"].strip()))
#print results
print '%.2f%c completed in %d:%02d:%02d' % (prog, '%', et.hour, /
et.minute, et.second)
print 'units of work so far %s' % (uMap["nresults"].strip())