What is Causing this Behavior in an IIf in a MS Project Custom Field Formula? - ms-project

I don't understand the behavior I'm seeing from a custom field formula--actually from two formulas trying to do the same thing.
I'm trying to create a custom formula to flag whether a task is associated with any baseline at all. I figure that if there is a Baseline Start or Baseline# Start associated with the task, then that means, yes, there is a baseline associated with the task. So, I created this formula and used it for a flag field at the task level:
IIf([Baseline Start] <> "" Or [Baseline1 Start] <> "" Or [Baseline2 Start] <> "" Or [Baseline3 Start] <> "" Or [Baseline4 Start] <> "" Or [Baseline5 Start] <> "" Or [Baseline6 Start] <> "" Or [Baseline7 Start] <> "" Or [Baseline8 Start] <> "" Or [Baseline9 Start] <> "" Or [Baseline10 Start] <> "", True, False)
Simple enough to me. It "says" if Baseline Start is not blank or Baseline1 Start is not blank or any of the other Baseline# Start values are not blank, then return True, else return False. But what is happening is it is only acting upon the first condition--[Baseline Start] <> "". The tasks that meet that condition are receiving True. Tasks that meet the other conditions are all receiving False even though they should have True. I cannot figure out why.
If I swap the order of the conditions so that another Baseline# Start is tested first, then that condition is met and the rest are ignored like before. Only tasks meeting that newly swapped first condition receive the True and the rest receive False even if they should have True.
I also tried this nested inline if approach and received the exact same outcome:
IIf([Baseline1 Start] <> "", True, IIf([Baseline Start] <> "", True, IIf([Baseline2 Start] <> "", True, IIf([Baseline3 Start] <> "", True, IIf([Baseline4 Start] <> "", True, IIf([Baseline5 Start] <> "", True, IIf([Baseline6 Start] <> "", True, IIf([Baseline7 Start] <> "", True, IIf([Baseline8 Start] <> "", True, IIf([Baseline9 Start] <> "", True, IIf([Baseline10 Start] <> "", True, False)))))))))))
Any ideas?

This is due to an oddity of MS Project whereby it uses 4294967296 (2 to the 32nd power - 1) if the field is "NA" (blank). So instead, test to see if the date is less than that huge number, for instance 4/8/2064 which conveniently is stored as 60000.
[Baseline Start] < 60000 Or [Baseline1 Start] < 60000 Or [Baseline2 Start] < 60000 Or [Baseline3 Start] < 60000 Or [Baseline4 Start] < 60000 Or [Baseline5 Start] < 60000 Or [Baseline6 Start] < 60000 Or [Baseline7 Start] < 60000 Or [Baseline8 Start] < 60000 Or [Baseline9 Start] < 60000 Or [Baseline10 Start] < 60000
Note that the IIf formula is unnecessary as the above will directly return True or False.
Reference: Working with Custom Field Formulas

Related

Faster method for creating key value pairs

I want to create a mapping from key (string) to value (string[]). I read a file:
gloveEmbeddings := make(map[string][]string)
f, _ := ioutil.ReadFile("./glove.840B.300d.txt")
The file is in the following format:
key0 val0_index0 val0_index1 val0_index2 val0_index3
key1 val1_index0 val1_index1 val1_index2 val1_index3
...
There are two separations, the new line and the space.
First I create a split of the new line:
newlineSplit := strings.Split(string(f), "\n")
Then I split each row with the space and put the first value in the resulting array as the key and the slice of the rest as the value:
for i := 0; i < len(newlineSplit); i++ {
spaceSplit := strings.Split(newlineSplit[i], " ")
gloveEmbeddings[spaceSplit[0]] = spaceSplit[1:]
}
fmt.Println(gloveEmbeddings)
The file is 5.5GB and this loop is taking more than 20 minutes. The goal is to be able to access the value fast given the key. Is there a better way to do this?
EDIT
I reading the file line by line.
gloveEmbeddings := make(map[string][]string)
f, _ := os.Open("./glove.840B.300d.txt")
scanner := bufio.NewScanner(f)
count := 0
for scanner.Scan() {
spaceSplit := strings.Split(scanner.Text(), " ")
gloveEmbeddings[spaceSplit[0]] = spaceSplit[1:]
if count % 10000 == 0 {
fmt.Println(count)
}
count++
}
But the counts stop printing at 2.19 million.
The loop actually runs fast, even the original version that uses ioutil.ReadFile. What was taking long was the fmt.Println(gloveEmbeddings) which was there only for debugging. Reading the file all at once and one line at a time take the same time, about 42-44 s on my machine.

Adding 120 minutes if date diff is negative in Amazon Redshift

I am grouping times how much it takes for a person to purchase an item, from the session time to purchase time. There are some cases when due to the timezones the purchase time is 120 minutes than it should be, in that case, I want to add 120 minutes and then group it like so:
CASE
WHEN date_diff('minute'::character varying::text, sessions.event_time, sales.event_time) < 0 AND sales.event_time IS NOT NULL THEN '0. 0'::character varying
WHEN date_diff('minute'::character varying::text, sessions.event_time, sales.event_time) <= 5 AND sales.event_time IS NOT NULL THEN '1. 0-5min'::character varying
ELSE 'no sale'::character varying
END AS grouped_session_to_sale,
And because of the timezone difference of 2 hours I get a lot of 0.0 groups, I need to add 120 minutes to the sales.event_time, I tried this:
CASE
WHEN date_diff('minute'::character varying::text, sessions.event_time, sales.event_time) < 0
THEN sales.event_time::numeric+120::text
ELSE sales.event_time
END as sales.event_time,
CASE
WHEN date_diff('minute'::character varying::text, sessions.event_time, sales.event_time) < 0 AND sales.event_time IS NOT NULL THEN '0. 0'::character varying
WHEN date_diff('minute'::character varying::text, sessions.event_time, sales.event_time) <= 5 AND sales.event_time IS NOT NULL THEN '1. 0-5min'::character varying
ELSE 'no sale'::character varying
END AS grouped_session_to_sale
But I get an error which is very uninformative:
SQL Error [500310] [42601]: Amazon Invalid operation: syntax error at or near "."
Position: 3346;
How can I achieve such a result?
You cannot assign the output of the first CASE statement to sales.event_time - "END as sales.event_time,". This implies that you are changing the source data from inside the select. You could call this output "new_event_time" with no ".".

How to get r to read 'date taken' of a JPG file

I could use some help performing a database correction, in regards to date and time of pictures were taken.
Essentially, the research we perform entails taking many pictures and entering the picture information into a database (we automated this with Microsoft Access). However, I performed a random check of our database and found that several dates and times of the photos were incorrect, and I am attempting to correct this via R as I was unable to correct it via Access.
What I need to do is to is write a script that reads these data, and compiles a list of the date taken information for all photos (there are several thousand). So far the best thing that I've found is
file.info(list.files(
"E:/Whatcom Creek Project/Data/Seal photos/Discovery/Catalog/Phoca vitulina",
recursive = T))
However this returns a list of NA NA for all information. Also, if I manually select one image to run file.info on, it doesn't return date taken (see the picture for the data I am attempting to retrieve)
If anyone has any suggestions I am all ears. Thanks in advance!!
-Ian
enter image description here
maybe still of any use?
i saw this message. I solved this a long time ago (2011) with a very basic VB6 code. The job is still working, but it is not applicable to all '.jpg files'. It depends with what camera the picture has been taken, but mostly pictures taken from a smartphone and classic camera's are returning the date the picture has been taken (not usable for whatsapp images or edited images).
The code is here below, and it is very basic code (but i hope it still can help or give idea's, and ... any new idea's are welcome too) :
'Reading of "Date Picture Taken" from .jpg file
'-----------------------------------------------
Debug.Print ">>>>>==== Start Read of .jpg-file ===== "; Date; " ===== "; Time; " ====<<<<<"
X = 0
DatePictureTaken = ""
TimePictureTaken = ""
FOUNDdatum = False
SWdatum = False
TELdatum = 0
Foto = FOLDER & "\" & tabFileName(FotoNr)
Open Foto For Binary Access Read As #1
'get startposition of the field "date picture taken"
Do
X = X + 1
Get #1, X, MyByte ': Debug.Print Chr(MyByte);
DoEvents
If Chr(MyByte) = ":" Then
'Debug.Print
SWdatum = True
Get #1, X + 3, MyByte
'Debug.Print "x+03="; Chr(MyByte)
If Chr(MyByte) <> ":" Then SWdatum = False 'Debug.Print "x+03="; Chr(MyByte)
Get #1, X + 9, MyByte
'Debug.Print "x+09="; Chr(MyByte)
If Chr(MyByte) <> ":" Then SWdatum = False 'Debug.Print "x+09="; Chr(MyByte)
Get #1, X + 12, MyByte
'Debug.Print "x+12="; Chr(MyByte)
If Chr(MyByte) <> ":" Then SWdatum = False 'Debug.Print "x+12="; Chr(MyByte)
'if a ':' is on the 3 locations (found above) then it is a date!
If SWdatum _
Then
TELdatum = TELdatum + 1
End If
'the 3e date is the date the picture has been taken
If TELdatum = 3 _
Then
FOUNDdatum = True
X = X - 4
Exit Do
End If
X = X + 12
End If
Loop Until EOF(1) 'Or X = 32765
If FOUNDdatum = False Then Close 1: End
BPdatum = X
EPdatum = X + 9
BPuur = X + 11
EPuur = X + 15
For X = BPdatum To EPdatum
Get #1, X, MyByte
'Debug.Print Chr(MyByte)
If Chr(MyByte) <> ":" _
Then
' DatePictureTaken = DatePictureTaken & "/"
'Else
DatePictureTaken = DatePictureTaken & Chr(MyByte)
End If
Next X
For X = BPuur To EPuur
Get #1, X, MyByte
'Debug.Print Chr(MyByte)
If Chr(MyByte) <> ":" _
Then
' DatePictureTaken = DatePictureTaken & "/"
'Else
TimePictureTaken = TimePictureTaken & Chr(MyByte)
End If
Next X
'Debug.Print "Date Picture Taken = "; DATUM
tbxDatum.Text = DatePictureTaken
tbxUur.Text = TimePictureTaken
Close 1
End Sub

How to know end of PDF File on Auto IT

I have an AutoIT script to open and scroll to end of PDF file by mouse action. By the number of times for scrolling is depended on the zoom percent and the number of pages. How do I determine the end of PDF file for configure the number of times for scrolling?
Below is the sample script. I fixed the number of times for scrolling is 15
Func OpenAllPDFFile($vardirectory)
If #error = 1 Then
MsgBox($MB_SYSTEMMODAL, "", "Path is invalid.", 2)
ElseIf #error = 4 Then
MsgBox($MB_SYSTEMMODAL, "", "No report(s) found.", 2)
ElseIf #error Then
MsgBox($MB_SYSTEMMODAL, "", "Fail to open report", 2)
Else
$FileArray = _FileListToArray($vardirectory, "*.pdf",1)
$NewFileArray = SortPDFFile($FileArray)
For $i = 0 To UBound($NewFileArray)-1
ShellExecute($vardirectory & "\" & $NewFileArray[$i])
ConsoleWrite("Opening pdf file: " & $NewFileArray[$i] & #CRLF)
if WinWaitActive($NewFileArray[$i]) Then
ConsoleWrite("Pdf file " & $NewFileArray[$i] & " is opened" & #CRLF)
WinSetState($NewFileArray[$i], "", #SW_MAXIMIZE)
Sleep($varSleep)
ControlClick($NewFileArray[$i], "", $varZoomPercent)
ControlSend($NewFileArray[$i], "", $varZoomPercent, $vPercent)
Send("{ENTER}")
Sleep($varSleep)
For $y = 0 To 15
If WinExists("[CLASS:AcrobatSDIWindow]") Then
MouseWheel($MOUSE_WHEEL_DOWN, 12)
Sleep($varSleepRead)
Else
ExitLoop
EndIf
Next
Else
ConsoleWrite("Could not find pdf file: " & #CRLF)
EndIf
WinClose("[CLASS:AcrobatSDIWindow]")
Next
EndIf
WinClose($varDUTPlot,"")
EndFunc
If you really just need to go to the end of the PDF I would use Page Down like this:
Send("{PGDN down}") # hold key down
Sleep(10000) # hold it for 10 sec
Send("{PGDN up}") # stop holding it
You can increase or lower the time just by editing the sleep time(in ms).
I don't know how to scale it with the PDF size.
If you know the pagecount it would be easy. ;)
$c = PAGES_IN_PDF
$t = $c * 200 # plan enough time for slow PCs
Sleep($t)

VBScript - Date and Time Constraints for Running a File

Ok I am new with writing VBScript and I want to write a string of code that plays a file (WAV format) only on a certain day and only between specific times. After piecing together multiple fragments of code I found on the internet I was left with the following:
Dim myDateString
Dim thing1
thing1 = 0
myDateString = Date()
If myDateString < "13/08/13" Then
thing1 = 1
end if
if thing1 = 1 then
If myDateString > "15/08/13" Then
thing1 = 2
end if
end if
if thing1 = 2 then
hournow = hour(Time())
If hour(Time()) >= 9 And Hour(Now()) < 22 Then
set WshShell = CreateObject("WScript.Shell")
music = "C:\Users\MYUSERNAME\Desktop\MYSOUND.wav"
WshShell.Run "wmplayer """ & music & """",0,True
Else
wscript.quit 1
End If
Else
wscript.quit 1
End If
Ok so I had set this for the date I ran this on, within the hour I was in. But
it didn't work. I expected the VBS to start playing MYSOUND.wav but it didn't. When running the file
there were no errors though, so I was wondering what I did wrong!
I running Windows 7
If anyone could tell me what I did wrong, and how to fix it that would be great.
Double points if anyone could post a corrected version of the code!
Thanks to any answers!
First, indent your code and give your variables meaningful names!
Then, your date comparison doesn't work because you're trying to compare strings as if they were dates. This usually won't work (depending on your "system locale"): you need to use date type variables and an actual date comparison function (DateDiff in VBScript).
(EDIT: as Ansgar Wiechers pointed out, you don't need to use DateDiff to compare dates in VBScript, "DateStart <= Now And Now <= DateEnd" will do just fine)
Try this:
Dim DateStart, DateEnd, WshShell, music
DateStart = DateSerial(2013, 8, 13)
DateEnd = DateSerial(2013, 8, 15)
If DateDiff("D", DateStart, Now) >= 0 And DateDiff("D", Now, DateEnd) >= 0 Then
If Hour(Now) >= 9 And Hour(Now) < 22 Then
'*** delete after debugging ***
MsgBox "play sound"
Set WshShell = CreateObject("WScript.Shell")
music = "C:\Users\MYUSERNAME\Desktop\MYSOUND.wav"
'*** 2nd parameter : 0 hides wmplayer, 1 shows it ***
WshShell.Run "wmplayer """ & music & """", 1, True
Else
'*** delete after debugging ***
MsgBox "Not the right time"
End If
Else
'*** delete after debugging ***
MsgBox "Not the right day"
End If
Also, if you want to debug a small script like this, you can call MsgBox to do a simple tracking of what's actually executed (in your example, replacing your "WScript.Quit 1" by MsgBox would show you that the date is not properly compared.

Resources