During the cleaning of my stock market data, I realize that it has change to character after executive the following lines of codes - character

During the cleaning of my stock market data, I realize that it has change to character after executive the following lines of codes
nse<-xts(nse[, -1], order.by=as.Date(nse$Date))
nse <- xts(nse)
nse <- nse[,-1]
head(nse)
output
High Low Close Vol. Change..
2012-06-11 " 3.45" " 3.35" " 3.40" "3.24M" "0.00%"
2012-06-12 " 3.50" " 3.40" " 3.45" "6.09M" "1.47%"
2012-06-13 " 3.45" " 3.35" " 3.40" "7.29M" "-1.45%"
2012-06-14 " 3.45" " 3.35" " 3.40" "31.81M" "0.00%"
2012-06-15 " 3.50" " 3.40" " 3.40" "7.57M" "0.00%"
2012-06-18 " 3.45" " 3.40" " 3.45" "1.82M" "1.47%"
The columns have been change to characters, what could I have done wrong and how should I rectify?

Related

Convert between diacritic variants of a character

I'm passing a string as a parameter to command line tool written in swift.
I have a problem with some characters containing diacritics.
If I pass à á ả ã ạ й ё as a line argument, inside the app I got à á ả ã ạ й ё. It looks the same, but it's not:
func printUnicodeScalars(_ string: String) {
print(string, "->", string.unicodeScalars.map { $0 })
}
printUnicodeScalars("à á ả ã ạ й ё")
// à á ả ã ạ й ё -> ["\u{00E0}", " ", "\u{00E1}", " ", "\u{1EA3}", " ", "\u{00E3}", " ", "\u{1EA1}", " ", "\u{0439}", " ", "\u{0451}"]
printUnicodeScalars("à á ả ã ạ й ё")
// à á ả ã ạ й ё -> ["a", "\u{0300}", " ", "a", "\u{0301}", " ", "a", "\u{0309}", " ", "a", "\u{0303}", " ", "a", "\u{0323}", " ", "\u{0438}", "\u{0306}", " ", "\u{0435}", "\u{0308}"]
I know that a diacritics character can in ASCII can be represented in different ways: like a single character, or like a combination of two: a letter and a diacritics.
For some reason command line tool converts first variant into the second one. Probably that's because it's limited to UTF-8.
How can I convert it back? Like to join many unicode-scalars character into a single one.
I think you need to use precomposedStringWithCanonicalMapping. This converts the string to Normalization Form C, which is:
Canonical Decomposition, followed by Canonical Composition
Example:
let string = "à á ả ã ạ й ё"
print(string.unicodeScalars.count) // 20
print(string.precomposedStringWithCanonicalMapping.unicodeScalars.count) // 13

sporfire: calculate the avg per 15 minutes

I am a beginner for Spotfire. I have a problem about the average calculation per each 15 mins by calculated column. A sample table could be like this:
id time-stamp value
1 7/1/2016 12:01:01 AM 1.1
2 7/1/2016 12:05:03 AM 0.9
3 7/1/2016 12:08:04 AM 1.2
4 7/1/2016 12:09:06 AM 0.8
5 7/1/2016 12:12:09 AM 0.4
6 7/1/2016 12:14:10 AM 0.6
7 7/1/2016 12:15:12 AM 1.3
8 7/1/2016 12:18:04 AM 1.4
9 7/1/2016 12:21:06 AM 0.7
10 7/1/2016 12:24:09 AM 1.7
11 7/1/2016 12:31:10 AM 0.5
12 7/1/2016 12:39:12 AM 1.3
I want to calculate the avg value for each 15 mins, the table is already ordered by time.
the final table I want to have is:
time-stamp Avg
7/1/2016 12:00:00 AM 0.83333
7/1/2016 12:15:00 AM 1.275
7/1/2016 12:30:00 AM 0.9
for example, for the first number 0.83333 =(1.1+0.9+1.2+0.8+0.4+0.6)/6
it seems that I should identify an expression of the calculation for a new table, but how to calculate the avg. for each 15 mins. somebody could help me ?
thanks for your help :)
note: thanks for code #ksp585, but after this, i still have a small problem for it, the cross table just shows the times-stamp until 9:45 PM
# ZAWD - I have created a calculated column which groups the timestamp into 4 quarters for an hour. Used this column in the cross table below to calculate average time.
timestamp grouping expression (time_interval):
case
when (DatePart("minute",[time-stamp])>0) and (DatePart("minute",[time-stamp])<15) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":00" & ":00"
when (DatePart("minute",[time-stamp])=15) and (DatePart("second",[time-stamp])>0) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":15" & ":00"
when (DatePart("minute",[time-stamp])>15) and (DatePart("minute",[time-stamp])<30) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":15" & ":00"
when (DatePart("minute",[time-stamp])=30) and (DatePart("second",[time-stamp])>0) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":30" & ":00"
when (DatePart("minute",[time-stamp])>30) and (DatePart("minute",[time-stamp])<45) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":30" & ":00"
when (DatePart("minute",[time-stamp])=45) and (DatePart("second",[time-stamp])>0) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":45" & ":00"
when (DatePart("minute",[time-stamp])>45) and (DatePart("minute",[time-stamp])<=60) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":45" & ":00"
when (DatePart("minute",[time-stamp])=0) and (DatePart("second",[time-stamp])>0) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":00" & ":00"
else null end
Final Table:
Tested with a different datetime format:

ImageJ macro for deinterleaving and merging colors

I'm trying to write a macro in Fiji that would deinterleave my original tif file, and then merge the two channels.
name=getTitle();
subname = substring(name, 0,14);
selectWindow(name);
dir = getDirectory("image");
fullname2 = name + " #2";
fullname1 = name + " #1";
run("Deinterleave", "how=2 keep");
selectWindow(name + " #2");
run("8-bit");
selectWindow(name + " #1");
run("8-bit");
run("Merge Channels...", "c1=["fullname2"] c2=["fullname1"] create");
saveAs("Tiff", dir + subname + "_composite.tif");
But there seems to be an error in the 12. line with Merge channels.
I don't get why.
I also tried writing that line like this:
run("Merge Channels...", "c1=[fullname2] c2=[fullname1] create");
But it also doesn't work.
Any ideas on what I'm doing wrong?
Thanks a lot!!
Ok! I figured it out! This is the solution, in case anyone has the same problem.
run("Merge Channels...", "c1=["+fullname2+"] c2=["+fullname1+"] create");

Progress 4gl Secure Socket Authentication

Currently attempting to perform a socket connection to a host that has authentication setup using the username:password#domain syntax. The following curl request works fine when run via command line:
/opt/pware/bin/curl -s -v -S -k -X POST -d #/test/worldpay.xml https://username:password#secure-test.worldpay.com/jsp/merchant/xml/paymentService.jsp
The problem lies when attempting to post the same worldpay.xml payload file using progress secure socket. My socket connects using the following:
DEFINE VARIABLE vhSocket AS HANDLE NO-UNDO.
CREATE SOCKET vhSocket.
vhSocket:CONNECT('-H test.worldpay.com -S 443 -ssl -nohostverify') NO-ERROR.
IF vhSocket:CONNECTED() EQ FALSE THEN
DO:
Message "COULD NOT CONNECT".
vhSocket:DISCONNECT().
DELETE OBJECT vhSocket NO-ERROR.
RETURN.
END.
ELSE
Message "CONNECTED!".
I am setting up my header as follows once the socket connection is opened:
ASSIGN
vRequest = 'POST ' +
username + ":" + password + "#" + "/jsp/merchant/xml/paymentService.jsp" +
' HTTPS/1.1' + chr(13) + chr(10) +
'Connect: close' + chr(13) + chr(10) +
'Host: ' + "secure-test.worldpay.com" + chr(13) + chr(10) +
'Content-Length: ' + string(LENGTH(postdata,"raw")) + chr(13) + chr(10) +
'Content-Type: text/xml' + chr(13) + chr(10) +
chr(13) + chr(10) +
postData +
chr(13) + chr(10).
set-byte-order(vData) = BIG-ENDIAN.
set-size(vData) = LENGTH(vRequest,"raw").
put-string(vData,1,LENGTH(vRequest,"raw")) = vRequest.
vReturnCode = vhSocket:WRITE(vData, 1, LENGTH(vRequest,"raw")).
Any help on figuring out how the header should be structured or how to perform basic authentication over Secure Sockets in Progress would be greatly appreciated. Thanks guys!
For http(s) basic authentication, you don't POST the username as part of the URL.
See https://en.wikipedia.org/wiki/Basic_access_authentication#Client_side
This is what we use in our http client, you'll have to change the call to AddHttpHeader to code that send that header line to the server socket.
/*------------------------------------------------------------------------------
Purpose: Adds a basic authorization header to the request
Notes:
#param pcUserName The UserName to use for basic authorization
#param pcPassword The password to use for basic authorization
------------------------------------------------------------------------------*/
METHOD PUBLIC VOID SetBasicAuthorization (pcUserName AS CHARACTER,
pcPassword AS CHARACTER):
DEFINE VARIABLE cBase64 AS LONGCHAR NO-UNDO.
DEFINE VARIABLE mAuthorization AS MEMPTR NO-UNDO .
ASSIGN cBase64 = SUBSTITUTE ("&1:&2":U, pcUserName, pcPassword) .
SET-SIZE (mAuthorization) = LENGTH (cBase64) .
PUT-STRING (mAuthorization, 1, LENGTH (cBase64)) = cBase64 .
ASSIGN cBase64 = BASE64-ENCODE (mAuthorization) .
AddHttpHeader (SUBSTITUTE ("Authorization Basic &1":U, cBase64)) .
FINALLY:
SET-SIZE (mAuthorization) = 0 .
END FINALLY.
END METHOD .
So in your case, try this:
ASSIGN
vRequest = 'POST ' + "/jsp/merchant/xml/paymentService.jsp" +
' HTTPS/1.1' + chr(13) + chr(10) +
'Connect: close' + chr(13) + chr(10) +
'Host: ' + "secure-test.worldpay.com" + chr(13) + chr(10) +
'Content-Length: ' + string(LENGTH(postdata,"raw")) + chr(13) + chr(10) +
'Content-Type: text/xml' + chr(13) + chr(10) +
'Authorization: Basic ' + cBase64 + chr(13) + chr(10) +
chr(13) + chr(10) +
postData +
chr(13) + chr(10).

Status check of service is failing

I am working on Windows 2008 Server R2. I found this VBScript that should be checking the whether a service is either started or stopped.
Here is the script:
'Declare Variables
Dim objWMIService, objProcess, colProcess, Status, strComputer, strService
'Assign Arguments
strComputer = WScript.Arguments(0)
strService = WScript.Arguments(1)
Status = False
'Check For Arguments - Quit If None Found
If Len(strService) < 1 Then
Wscript.echo "No Arguments Entered - Exiting Script"
WScript.Quit
End If
'Setup WMI Objects
Set objWMIService = GetObject("winmgmts:"& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("SELECT DisplayName, Status, State FROM Win32_Service WHERE DisplayName = '" & strService & "'")
'Check For Running Service
For Each objProcess In colProcess
If InStr(objProcess.DisplayName, strService) > 0 And objProcess.State = "Running" Then
Status = True
End If
Next
If Status = True Then
WScript.Echo "Service: " & UCase(strComputer) & " " & strService & " Running"
Else
WScript.Echo "Service: " & UCase(strComputer) & " " & strService & " Not Running"
End If
Via the command line I call the script like this
CSCRIPT ServiceCheckScript.vbs LOCALHOST "Print Spooler"
Response from the command line is
...\ServiceCheckScript.vbs(20, 1) (null): 0x80041017
I see that the 0x80041017 error refers to result of a query returning a null value, but I am not sure as to why that may be.
A few issues with the above code:
Verify you got results from your WMI query so you don't attempt to use a null. Wrap the use of the results in if colProcess.count > 0 then.
Remove the extra .quit by enclosing your code in the parameters verification. Its cheaper/cleaner to do this with an argument count than a string function wscript.arguments.count = 2 since you were only checking to ensure they were not empty. If you need a more sophisticated validation, then more logic would be required.
There isn't any reason to use instr(objProcess.Displayname, strService) because your WMI query already specified that the results are equal to the service display name in this, where DisplayName = strService.
It's simpler/clearer to perform the conditional inspection of service status all inside the loop.
Here is my example.
'Declare Variables
Dim objWMIService, objProcess, colProcess, Status, strComputer, strService
'Verify arguments were passed
if WScript.Arguments.Count = 2 then
'Assign Arguments
strComputer = WScript.Arguments(0)
strService = WScript.Arguments(1)
'Setup WMI Objects
Set objWMIService = GetObject("winmgmts:"& "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("SELECT DisplayName, Status, State FROM " & _
"Win32_Service WHERE DisplayName = '" & strService & "'")
'Ensure there were results returned
if colProcess.count > 0 then
'Check For Running Service
For Each objProcess In colProcess
If objProcess.State = "Running" Then
WScript.Echo "Service: " & UCase(strComputer) & " " & strService & " Running"
else
WScript.Echo "Service: " & UCase(strComputer) & " " & strService & " Not Running"
End If
Next
else
WScript.Echo "Service: " & UCase(strComputer) & " " & strService & " Does not exist"
end if
end if
edit: Just adding that I validated the above code in both Win 8.1 and Server 2012R2, using both valid and invalid service names. However, I would add more error checking, like verifying the computer parameter is valid to ensure your WMI query doesn't fail unnecessarily/inexplicably.