adding timer variable asp - time

Hi I'm looking for a way to add together and do a average of values in a time format.
if I only do a simple '+' it puts the time back to back :
totalconvavgtalkduration = ((CSQ1convavgtalkduration)+(CSQ2convavgtalkduration))
Instead of getting something like
3:02:00
I get
3:00:000:02:00

Related

Pentaho: How to rollup time

I have time for example I have in records time written in this way: 00:02:24 or 15:22:45, and now I want to make another column (hours), where can be values for example for time 02:43:22 is value 2, or for time 23:22:14, is value 23 and so on. But I don't know how can I do that, I tried number range, but unsuccessfully.
Here is a picture, how i want to be:
Thanks.
You can use the Modified JavaScript Value step.
I do not know which type is your Time.
If it is a String, a var Hour = Time.substr(0,2); will do.
If it is a Date, use var Hour = Time.getHour();.
If the type is something else, then convert in a String first.
To do this:
drag-and.drop the step Modified JavaScript Valueand link it to the data flow provider (in the example a Data grid).
edit this step and add your script. (Note that you can quickly add the input variable with a double click. Note also that clicking on the Transformation Function in the left menu gives you the list of available function additional to the Javascript built-in collection).
Click on the Get variable button, keep the variable you need (here Hour), and define/redefine its type (here String).
That's done: OK and preview.
If needed, adapt to the type of your input flow. For example Hour = Hour+'' to force a type conversion into a String.

Ruby - how to add phonecall's length? CSV file

I have class Call - it represents single phonecall with certain number of minutes/seconds, date of the call etc. I want to sum length of calls for given day.
Problem is my data is in string format, I'm formatting it with various Time.parse options and many different things.
But my main problem is, how to sum them? I need something like Ruby's inject/reduce but smart enough to know 60 seconds is one minute.
One additional problem is I'm reading from .CSV file, turning every row into Hash, and making Call objects out of it.
Any hints? :)
I suggest to store the duration of a call as a number of second in an integer. Because that would allow you to easily run calculation in the database.
But if you prefer to keep the string representation you might want to use something like this:
# assuming `calls` is an array of call instances and the
# duration of the call is stores an attribute `duration`
total = calls.sum do |call|
minutes, seconds = call.duration.split(':')
minutes * 60 + seconds
end
# format output
"#{total / 60}:#{total % 60}"
Please note that the sum method is part of ActiveSupport. When you are using pure Ruby without Rails you need to use this instead:
total = calls.inject(0) do |sum, call|
minutes, seconds = call.duration.split(':')
sum + minutes * 60 + seconds
end
You may could map them all to seconds represented by Float via Time.parse, then inject the mapped float array.

Yahoo Pipes: Extracting number from feed item for use in URL builder

Been looking all over the place for a solution to this issue. I have a Yahoo Pipe (http://pipes.yahoo.com/pipes/pipe.info?_id=e5420863cfa494ee40e4c9be43f0e812) that I've created to pull back image content from the Bing Search API. The URL builder includes a $skip attribute that takes an integer and uses it to select the starting (index) point for the result set that the query returns.
My initial plan had been to use the math engine in the Wolfram Alpha API to generate a random number (randomInteger[1000]) that I could use to seed the $skip value each time that the pipe is run. I have an earlier version of the pipe where I was able to get the query / result steps working using either "XPath Fetch" and "Fetch Data". However, regardless of how I Fetch the result, the response returns as an attribute / value pair in a list item.Even when I use "Emit items as string" in XPath Fetch, I still get a list with a single item, when what I really want is the integer that I can plug into my $skip attribute.
I've tried everything in Pipes I can think of, and spent a lot of time online looking for an answer. Is there anyway to extract text (in this case, a number) from a single list item and then use the output as input to "wire" a text parameter in another Pipes block? Any suggestions / ideas welcome. In the meantime, I'm generating a sorta-random number by manipulating a timecode hash, but it just feels tacky :-)
Thanks!
All the sources are for repeated items. You can't have a source that just makes a single number.
I'm not really clear what you're trying to do. You want to put a random number into part of the URL string that gets an RSS feed?

Convert dateTime.iso8601 value to human readable date in Ruby

I am playing around with the Red Hat Satellite API. One of the values being returned for an API call is dateTime.iso8601 "last_checkin" - Last time server successfully checked in. I'm not sure how to parse this, though.
This is the code that returns the data:
systems.each do |system|
print "#{system["name"]}" + " " + "#{system["last_checkin"]}" + "\n"
end
It gives a hash back: #<XMLRPC::DateTime:0x97102d8>. At least, I think that's a hash.
What do I need to do to look inside it and extract useful information?
That’s not a Hash, that’s an instance of class XMLRPC::DateTime. Use it’s methods to get printable values, e.g.:
systems.each do |system|
system = system["last_checkin"] # or whatever value you are interested in
puts "#{system.mon}-#{system.day}-#{system.year}"
end
Also please avoid using "a"+"b" string concatenation; there is inplace-evaluation ruby paradigm for that ("#{val}".)

Guess A Number - Ruby Online

I have been trying to create a Ruby program that will be running online where a user can guess a number, and it will say higher or lower. I know it will take a random number store in a variable, then run a loop? With conditionals to check?
Im not asking for full code, the basic structure for I can use this to get me going.
Any idea how i would do this? I found info to create a random number like this:
x = rand(20)
UPDATE: My code I am going to be working with is something like this: http://pastie.org/461976
I would say to do something like this:
x = rand(20)
loop {
# get the number from the user somehow, store it in num
if num == x
# they got it right
break
elsif num > x
# the guess was too high
else
# the guess was too low
end
}
If you're running it online, this structure may not be feasible. You may need to store the guess in the user's session and have a textbox for the guess, and submit it to a controller which would have the above code without the loop construct, and just redirect them to the same page with a message if they didn't get it right.

Resources