DIRKMJK / limepy

Download and summarise LimeSurvey data
MIT License
24 stars 8 forks source link

Is it possible to read a LSS file without having a dataframe of answers? #13

Closed jeanbaptisteb closed 3 years ago

jeanbaptisteb commented 3 years ago

Hi,

Nice library.

Here's my problem: I have a survey structure file (LSS format), without any answer yet.

I'd like to use this library to explore the survey structure. But from the example given on the main page and from the source code, my understanding is that it's necessary to have some dataframe containing the answers, in order to read the structure file.

Am I correct, or is there a way to read the LSS file on its own?

If it's not currently possible, it would be a pretty useful feature!

Thanks.

jeanbaptisteb commented 3 years ago

For those who are interested, here's a quick-and-dirty workaround, which involves creating a dataframe of fake answers:

from lxml import etree
import pandas
from limepy.wrangle import Survey, Question
lss =<path to the LSS file>
root = etree.parse(lss)
xpath = "/document/questions/rows/row/title"
titles = root.xpath(xpath)
fake_answers = [[""]*len(titles),
                [""]*len(titles)
                ]
df = pandas.DataFrame(fake_answers, columns=[title.text for title in titles])
with open(lss) as f:
    my_structure = f.read()
my_survey = Survey(df, my_structure)
DIRKMJK commented 3 years ago

Thanks for your feedback! I’ll take a look at it; it may take a couple days before I get round to this

jeanbaptisteb commented 3 years ago

Thanks for your quick reply! I've been able to explore the file's structure with the workaround I mentioned above, so this feature is not something urgent for me. But it sure would be great if the library could do this natively!

DIRKMJK commented 3 years ago

I considered making it possible to create an ‘empty’ Survey object by passing None instead of a dataframe. However, it turned out this wasn’t so easy to implement as I first thought. So thanks for offering the workaround for anyone who’s interested in this!