Saturday, 15 August 2015

Map a Ruby array of timeseries values to a weighted interval -



Map a Ruby array of timeseries values to a weighted interval -

i have ruby array of arrays represents series of observations of metric that's recorded on time. each inner array has 2 elements:

a time instance in utc describing when observation recorded the integer value of observation

for example, might have like:

[ [<time: 2014-01-15 @ 18:00>, 100], [<time: 2014-01-16 @ 06:00>, 200], [<time: 2014-01-16 @ 12:00>, 300], [<time: 2014-01-16 @ 23:00>, 400], [<time: 2014-01-17 @ 12:00>, 500], [<time: 2014-01-18 @ 03:00>, 600], [<time: 2014-01-18 @ 06:00>, 700], ]

the problem @ hand turn array of weighted values each date:

[ [<date: 2014-01-15>, 100], [<date: 2014-01-16>, 229], ... ]

the value each day in above array obtained next procedure:

break day series of intervals delimited each observation , boundaries of day.

for example, since jan 16th has observations @ 06:00, 12:00, , 23:00, broken intervals of 00:00-06:00, 06:00-12:00, 12:00-23:00, , 23:00-00:00.

the value of each interval equal value of observation @ origin of interval, or lastly observation made if it's start of day.

for example, value of 06:00-12:00 interval on jan 16th 200, since value of 200 recorded @ 06:00.

the value of 00:00-06:00 interval on jan 15th 100, since value of 100 lastly observation recorded @ point day started.

the weighted value of each interval equal value multiplied fraction of lengths of intervals in day occupied.

for example, weighted value of 06:00-12:00 interval on jan 16th 50 (200 * 0.25).

the final weighted value of each day sum of weighted values of intervals, coerced integer.

for example, weighted value jan 16th 229, because:

(100*(6/24) + 200*(6/24) + 300*(11/24) + 400*(1/24)).to_i = 229

the first point in array special case: day starts there, rather @ 00:00, jan 15th has 1 interval: 18:00-00:00 value of 100, weighted value 100.

any suggestions on how started tackling this?

i've assumed there no days no entries.

i found convenient first transform array of time objects. rules used transformation follows (arb refers arbitrary value, may equal val):

for first day, replace single element [dt, val] 3 elements: [dt1, val], dt1 same date @ time 00:00:00 [dt2, arb], dt2 same date @ time 23:59:59 [dt3, val], dt3 1 day later @ time 00:00:00 for lastly day, if [dt, val] lastly element day, add together element [dt1, arb], dt same date @ time 23:59:59. for every day other first , last, if [dt, val] lastly element day, add together 2 elements: [dt1, arb], dt1 same date @ time 23:59:59 [dt2, val], dt2 1 day later @ time 00:00:00

suppose next initial array. clarity, i've used strings (allowing me replace "23:59:59" "24:00"):

arr = [ ["2014-01-15 18:00", 100], ["2014-01-16 06:00", 200], ["2014-01-16 12:00", 300], ["2014-01-16 23:00", 400], ["2014-01-17 12:00", 500], ["2014-01-18 03:00", 600], ["2014-01-18 06:00", 700] ]

after applying above rules, obtain:

arr1 = [ ["2014-01-15 00:00", 100], ["2014-01-15 24:00", 100], ["2014-01-16 00:00", 100], ["2014-01-16 06:00", 200], ["2014-01-16 12:00", 300], ["2014-01-16 23:00", 400], ["2014-01-16 24:00", 400], ["2014-01-17 00:00", 400], ["2014-01-17 12:00", 500], ["2014-01-17 24:00", 500], ["2014-01-18 00:00", 500], ["2014-01-18 03:00", 600], ["2014-01-18 06:00", 700], ["2014-01-18 24:00", 700] ]

or elements grouped date,

arr1 = [ ["2014-01-15 00:00", 100], ["2014-01-15 24:00", 100], ["2014-01-16 00:00", 100], ["2014-01-16 06:00", 200], ["2014-01-16 12:00", 300], ["2014-01-16 23:00", 400], ["2014-01-16 24:00", 400], ["2014-01-17 00:00", 400], ["2014-01-17 12:00", 500], ["2014-01-17 24:00", 500], ["2014-01-18 00:00", 500], ["2014-01-18 03:00", 600], ["2014-01-18 06:00", 700], ["2014-01-18 24:00", 700] ]

code implement these rules should straightforward. 1 time have arr1, create enumerator enumerable#chunk:

enum = arr1.chunk { |a| a.first[0,10] } #=> #<enumerator: #<enumerator::generator:0x000001010e30d8>:each>

let's see elements of enum:

enum.to_a #=> [["2014-01-15", [["2014-01-15 00:00", 100], ["2014-01-15 24:00", 100]]], # ["2014-01-16", [["2014-01-16 00:00", 100], ["2014-01-16 06:00", 200], # ["2014-01-16 12:00", 300], ["2014-01-16 23:00", 400], # ["2014-01-16 24:00", 400]]], # ["2014-01-17", [["2014-01-17 00:00", 400], ["2014-01-17 12:00", 500], # ["2014-01-17 24:00", 500]]], # ["2014-01-18", [["2014-01-18 00:00", 500], ["2014-01-18 03:00", 600], # ["2014-01-18 06:00", 700], ["2014-01-18 24:00", 700]]]]

now need map each element (one per date) weighted average of vals (noting don't utilize first element of each element of enum):

enum.map { |_,arr| (arr.each_cons(2) .reduce(0.0) { |t,((d1,v1),(d2,_))| t + min_diff(d2,d1)*v1 }/1440.0).round(2) } #=> [100.0, 229.17, 450.0, 662.5]

using helper:

def min_diff(str1, str2) 60*(str1[-5,2].to_i - str2[-5,2].to_i) + str1[-2,2].to_i - str2[-2,2].to_i end

putting together:

arr1.chunk { |a| a.first[0,10] } .map { |_,arr| (arr.each_cons(2) .reduce(0.0) { |t,((d1,v1),(d2,_))| t + min_diff(d2,d1)*v1 }/1440.0).round(2) } #=> [100.0, 229.17, 450.0, 662.5]

along helper min_diff.

ruby arrays time

windows - CMD how to pass parameters to script and save to file name of one of the parameters -



windows - CMD how to pass parameters to script and save to file name of one of the parameters -

i want pass next parameters script:

myscript.cmd "foo" "bar" "file"

where 3rd parameter should added extension .log

in illustration should file.log

set logfile = "%~3" + .log echo logfilename "%logfile%" echo %date% %time% got parameters "%~1" "%~2" >> "%logfile%"

should script above, not beingness able create work

three problems, quotes (included in value of variable), spaces (you have included spaces in name of variable) , concatenation (there no concatenation operator in batch files)

you have defined variable named logfile_, aditional space (represented underscore) in name, , assigned value literal _"file"_+_.log (as before, underscores represent spaces)

the line

set logfile = "%~3" + .log ^ ^^ ^^^^ unneeded/problematic characters

should

set "logfile=%~3.log"

no aditional spaces , quotes not included in value, delimit assignment prevent problems special characters or aditional spaces @ end of line

windows command-line cmd dos

Running Spatial Queries in PostGIS 2.1.3 and Postgresql 9.3 in Windows 7 -



Running Spatial Queries in PostGIS 2.1.3 and Postgresql 9.3 in Windows 7 -

i installed postgresql 9.3 ( pgadmin 3 gui) , postgis 2.1.3 (http://www.enterprisedb.com/products-services-training/pgdownload#windows) windows 7 64 bit. after installing it, downloaded sql files country database (http://www.spatial.cs.umn.edu/book/labs/vania/spatialqueries.html) , tried execute commands in country.sql

in sql builder , stuck @ next error:

notice: srid value -1 converted officially unknown srid value 0 context: sql statement "select addgeometrycolumn('',$1,$2,$3,$4,$5,$6,$7)" pl/pgsql function addgeometrycolumn(character varying,character varying,character varying,integer,character varying,integer,boolean) line 5 @ sql statement error: function geometryfromtext(unknown, integer) not exist line 4: ...3000.0000','dollar','usd','n','5','united states',geometryfr... ^ hint: no function matches given name , argument types. might need add together explicit type casts. ********** error **********

error: function geometryfromtext(unknown, integer) not exist sql state: 42883 hint: no function matches given name , argument types. might need add together explicit type casts. character: 769

i can't error resolved. please help me out.

postgresql postgis windows-7-x64

override - Java abstract class and overriding variables -



override - Java abstract class and overriding variables -

i have encountered problem cannot solve. let's have superclass a:

public enum enumeration { a, b, c; } public abstract class { private enumeration e; public void somemethod { // here 'e'. } }

now let's assume have class b.

public class b extends { private final enumeration = e.a; }

here compiler warning value never used.

i want define method in class a, have define variable. want give variable new fixed value in subclass.

is not possible?

field can't overridden. if want assign specific enum instance class, utilize constructor:

public abstract class { private final enumeration e; protected (enumeration e) { this.e = e; } public void somemethod { // 'e'. } } public class b extends { public b() { super(enumeration.a); } }

java override abstract-class

html/javascript how to display user input with a method on button click? -



html/javascript how to display user input with a method on button click? -

i'm trying alert window display first , lastly name user inputs after click "submit". i'm trying using methods in javascript, can't display after user clicks button.

here code:

<html> <head> <meta charset = 'utf-8'> <title>form</title> <script type = 'text/javascript'> var firstname; //first name var lastname; //last name function getfirstname() { //get first name homecoming document.getelementbyid("first_name").value; } function getsecondname() { //get lastly name homecoming document.getelementbyid("last_name").value; } function display() { //get names , display them firstname = getfirstname(); lastname = getlastname(); window.alert(firstname + lastname); } document.getelementbyid("submit").onclick = display(); </script> </head> <body> <form id='form' method = 'post'> <p> first name: <input type='text' id = "first_name"/></p> <p> lastly name: <input type='text' id = "last_name"/> </p> <p><input id ="submit" type = "button" value = 'clickme' /></p> </form> </body> </html>

http://jsfiddle.net/wqymjl32/

<form id='form' method = 'post'> <p> first name: <input type='text' id = "first_name"/></p> <p> lastly name: <input type='text' id = "last_name"/> </p> <p><input id ="submit" type = "button" onclick="display()" value='clickme'/></p> </form>

slight alter html, onclick attribute / event added submit button.

var firstname; //first name var lastname; //last name function getfirstname() { homecoming document.getelementbyid("first_name").value; } function getsecondname() { homecoming document.getelementbyid("last_name").value; } function display() { firstname = getfirstname(); lastname = getsecondname(); window.alert(firstname + lastname); document.getelementbyid("form").submit(); }

slight alter javascript phone call getsecondname instead of getlastname

javascript html

Set Timeout for MAX_AGI_CONNECT in Asterisk -



Set Timeout for MAX_AGI_CONNECT in Asterisk -

i have asterisk installed , zoiper softphone. whenever create call, there error displayed on asterisk :

warning[28761]: res_agi.c:1498 launch_netscript: fastagi connection 'agi://0.0.0.0/incoming.agi' timed out after max_agi_connect (2000) milliseconds. -- auto fallthrough, channel 'sip/123-0000003d' status 'unknown'

it takes approx 10 seconds connect call, time-out 2 sec, phone call never connected.

my question : how can alter default time-out 2000ms 15000ms ?

problem in point of dialplan there agi can't executed. it's this:

exten => ????,n,agi(agi://0.0.0.0/incoming.agi)

if need have prepare script receive connection in proper way or alter dialplan.

in case realy need this, can change timeout in sources

asterisk

npm install q --save only saves in devDependencies -



npm install q --save only saves in devDependencies -

i getting strangest behavior npm install q --save installing q in devdependencies, never in dependencies. true module, not q. no matter install flags use, modules ever saved in devdependencies.

i switched between multiple versions of npm including latest stable version , behavior same every time.

eventually tracked downwards ~/.npmrc file contained following:

save = true save-dev =

i changed this:

save = false save-dev = false

and npm install q --save correctly saves dependencies!

npm