ExperimentHandler CSV output value separator environment dependant - python

(I'm not a pyschologist nor pysychopy export but helping one)
We're developing an expirement using the Coder (not Builder).
The output of an experiment is written out using the data.ExperimentHandler.addData().
When I run the application on my machine I get output like this:
,,1,1,z,f,o,o,1.254349554568762,0.8527608618387603,0.0,1.0,FSAS,,,,,,,,,,,,,,,52,male,52,
When the other person runs the application she gets:
;;0;1;z;z;j;j;105.498.479.999.369;0.501072800019756;1.0;1.0;FNES;;;;;;;;;;;;;;;23;male;0
(the difference I want to show is about format, not the values)
There are 2 differences:
RT values > 1 are printed wrong: the value 105.498.479.999.369 (RT less then 1.5s) should be 1.05498479999369
value separator is ; in my output and , in hers. I don't know what is the best value separator comma or semilcolon for later processing in R ?
I think it has to do something with regional settings.
Question: Is it possible to force the format so the application always generates the same output format independant from local settings ?

You don't specify whether you are using the graphical Builder interface to PsychoPy to generate your Python script, or writing a custom script directly in Python.
If using the Builder interface, click the "Experiment settings" toolbar icon select the "Data" tab, and specify that the datafile delimiter should be "comma" rather than "auto".
If running your own script, then in the saveAsWideText() method of the ExperimentHandler class, similarly specify ',' as the delim parameter. The API is here:
https://psychopy.org/api/data.html
In future, you will likely get better support at the dedicated PsychoPy forum at https://discourse.psychopy.org
The actual PsychoPy developers and other experienced users are much more likely to see your queries there compared to here at StackOverflow.

Related

set the current date within the cmd scope only

I'm doing tests for a system on which the output depends on the current date, the system compares the output with an expected output I prepared previously.
For the test to pass, I shall invoke the system with the same date so I can obtain the same results and the test can succeed. otherwise, the test will fail.
I want to set the current date within the cmd scope ONLY without affecting the current date of the system.
This date is accessed either using the latex (\the\year) variable and from python using the datetime library (datetime.now()).
I tried using the date command but this changes the date in the system which triggers many operations and errors (Antivirus updates, etc ...) because its a corporate server so I should not change the date of the server while running the tests.
I can write code to neglect the comparison of the dates, but this operation is too complicated as the date is written in generated PDFs and many other files are in different formats.
So, is it possible to change the current date within the windows 10 command line ONLY (Not system scope)?
you might find your answer here Stackoverflow Discussion about Datetime from CMD and here Getting Datetime independently from Windows locale
Furthermore, you can set a locale in python this way:
import locale
locale.setlocale(locale.LC_TIME, "your/locale/here")
making something that works across both Python and LaTeX is awkward and very OS specific. google suggests that tools like RunAsDate exists for Windows but they hook some pretty nasty internal calls to do things
as #ndclt suggested, in Python the standard approach would be to "mock" the relevant functions out such that they return a known value. under LaTeX you could write a "test harness" that does \year=2000 \input{orig.tex}

Changing VBA code in hundreds of Excel files without opening every one of them

I have a data base of hundreds of submitted forms, every submitted form contains various modules with VBA code in them to process the data.
Each form file name starts with same unique prefix.
All of the forms are saved in our main global directory of documents.
Data from every form is logged into a log file.
VBA code within each forms allow me to change information in the form and send the updated information into the log.
Now because of the office 2019 being introduced, vb scripts in every form made in 2016 version is not working and I have to force change the code in every single form to make it compatible with 2019.
This mass change is not only required due to office version change but also required because I need to update log file with additional information contained within the forms cells which old VBA code does not process.
There are 4 VBA modules in every form file and scripts in every modules needs to be replaced with the new code.
Really don't know where to start, any ideas are much appreciated.
I have no idea what to try.
Expected result is that I have updated/new code for 4 macro modules currently exist in 100's of files which needs to be replaced over the old codes.. of excel files starting with a common unique prefix.
You can use VBA to modify VBA projects. For this, the "Trust access to the VBA project object model" checkbox must be ticked in the Trust Center/Macro Settings.
After that, open the VBA editor. Set a reference to "Microsoft Visual Basic for Applications Extensibility 5.3" (possibly the version is different for you, I don't know).
Now a couple of additional classes become available under the VBIDE library and those can be used to manipulate VBA projects programmatically. (I'm using this feature to export VBA modules for source control.)
There is no easy way to modify the text of the module, but you can try exporting, deleting and re-importing them to see if that already is enough:
Sub Test()
Dim vbcs As VBIDE.VBComponents
Dim vbc As VBIDE.VBComponent
Dim filename As String
Set vbcs = ActiveWorkbook.VBProject.VBComponents
For Each vbc In vbcs
Debug.Print vbc.name
If vbc.name = "The ones you want" Then
filename = GetFilenameFromModule(vbc)
vbc.Export filename
' you could modify the file contents now if needed
vbcs.Remove vbc
vbcs.Import filename
End If
Next vbc
End Sub
Private Function GetFilenameFromModule(vbc As VBIDE.VBComponent) As String
Select Case vbc.Type
Case vbext_ct_ClassModule, vbext_ct_Document:
GetFilenameFromModule = vbc.name & ".cls"
Case vbext_ct_MSForm:
GetFilenameFromModule = vbc.name & ".frm"
Case vbext_ct_StdModule:
GetFilenameFromModule = vbc.name & ".bas"
End Select
End Function
Be sure to check out the properties of the various objects in the debugger or object browser (F2), just to see what's available. I'm not sure how well documented all of that is, but it's versatile and stable.
To work with files in VBA easily, you can set a reference to the "Microsoft Scripting Runtime" library and use the FileSystemObject.

Execute GameFbxExporter Maya with Python

I need to export thousand of files with the GameFbXExporter Plugin from Maya, and I was wondering if there was any way to script those exports, knowing that the parameters are fine in every files. All I need to do is fill the path section and the name of the exported file in FBX, then launching the export itself with the plugin.
I'm kind of lost and doesn't know how to do this. Could someone help me understand how to reach that please?
Thank you
The game exporter is written in MEL, so you can interact with it from Python using the maya.mel module. This will open the dialog, for example:
import maya.mel as mel
mel.eval("gameFbxExporter();")
Unfortunately a quick look at the actual game exporter scripts (which are in your maya install directory in the scripts/others directory -- they all start with the prefix "gameFBX") make it look like the UI is hopelessly entangled with the actual act of exporting; it doesn't seem to expose anything which actually just exports the current file in a batch friendly way.
The operative procedure is called gameExp_FBXExport, defined in "gameFbxExporter.mel." It appears like the actual business of exporting is actually delegated to the regular FBX plugin -- all the other stuff in the game exporter is just managing fbx presets, selecting parts of the scene to export (if you have the scenes set that way) and then calling the fbx plugin. So, you may be able to batch the process using Python by looping over your files and calling FBXExport() from Python. This will export file to FBX:
import maya.cmds as cmds
cmds.FBXExport('-file', 'path/to/file.fbx')
It will just use whatever FBX settings are currently active, so you will need to be confident that the files are correctly set up. You'll be tempted to write it as cmds.FBXExport(f='path/to/file') but that won't work -- the FBX plugin commands don't use regular python syntax.
If your current settings rely on the export-selected functionality you'll need to figure out how to cache the correct selections -- if you're using the "export selections set" functionality you should be able to have your exporter find the set by name and the select it before exporting.
cmds.select("name_of_selection_set")
cmds.FBXExport('-file', 'path/to/file.fbx')
You can use the other FBX plugin commands -- documented here to inspect and manipulate the settings in your files as you go along.
Most professional users don't use the GameExport pipeline precisely because it's very opaque and not batch friendly. In the long run you'll probably want to write a simple system that provides standard settings for different file types and exports the FBXes directly without the GameExporter - while it's a not-trivial project it's going to be easier to maintain and expand than hacking your way around the edges of Autodesk's version which is, frankly, pretty lame.
If you're not already familiar with it http://tech-artists.org/ is a great place to look for pipeline help and advice.

How to save program settings to computer?

I'm looking to store some individual settings to each user's computer. Things like preferences and a license key. From what I know, saving to the registry could be one possibility. However, that won't work on Mac.
One of the easy but not so proper techniques are just saving it to a settings.txt file and reading that on load.
Is there a proper way to save this kind of data? I'm hoping to use my wx app on Windows and Mac.
There is no proper way. Use whatever works best for your particular scenario. Some common ways for storing user data include:
Text files (e.g. Windows INI, cfg files)
binary files (sometimes compressed)
Windows registry
system environment variables
online profiles
There's nothing wrong with using text files. A lot of proper applications uses them exactly for the reason that they are easy to implement, and additionally human readable. The only thing you need to worry about is to make sure you have some form of error handling in place, in case the user decides to replace you config file content with some rubbish.
Take a look at Data Persistence on python docs. One option a you said could be persist them to a simple text file. Or you can save your data using some serialization format as pickle (see previous link) or json but it will be pretty ineficient if you have several keys and values or it will be too complex.
Also, you could save user preferences in an .ini file using python's ConfigParser module as show in this SO answer.
Finally, you can use a database like sqlite3 which is simpler to handle from your code in order to save and retrieve preferences.

What is the best, efficient way to index/store code (scripts, queries) for search/retrieval?

We have a whole lot of code, queries in a whole bunch of folders on a Linux box. Whenever I have to find a script, I do a fgrep -ircl --include=*.{sql, py, sh} "Keyword" * .
I am planning on creating a simple search interface (web) which lets you search for a keyword, file type and displays the location of the file and an excerpt from the resulting file. Lucene can be a good candidate I guess but I don't want to create a copy of all my files just for this purpose.
I am planning on indexing the files using a Python script every day at off hours. More like Google desktop I guess but for web (cross-platform availability).
What do you guys suggest is the best way of accomplishing this task?
I wrote a perl script waaaaay back when to provide a web interface result, still works on my deprecated blackbeltvb.com website if you want to look. It did a live search though, not indexed, and without excerpts.
I also wrote the search for wugnet.com that did ranked results and excerpts, and architected the search that's now in QB Desktop. In your case, I would take that approach - just have a cron job that adds new or updated scripts/files into a database, one big text field, with other fields containing metadata like filenames and types. Then have a web interface into that DB, searching with:
select * from data where keyword like '%word%' and keyword (or keyword) etc...
There's a FAQ on blackbeltvb.com that shows how to construct a SQL search for ranked keyword results, e.g. "all keywords found", "some found" etc...
Using Python, Xapian is the only solution you should consider. It is more "bare metal" than Lucene, but it has first class support for the Python bindings to the native C++ implemenation, and is way smaller and faster than Lucene is with real world data sets, by that I mean LARGE data sets.

Categories