Audience Polling System

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

okk
Posts: 176
Joined: Wed Feb 04, 2015 11:37 am

Audience Polling System

Post by okk » Wed Sep 15, 2021 6:03 pm

Hi,
for a theatre performance I need to create a custom audience polling system. The idea is that the audience will download a mobile app to their phones before the show. During the performance I want to be able to pose questions to the audience, the question should appear roughly at the same time on their phones and then they should answer YES or NO (in the most simple scenario). After 30 seconds I want to project the results of the poll on a big screen for all to see. There are all kind of systems exisiting, but we have quite specific customisation needs, so I want to do it by myself. Has anyone done something similar? What would be a smart approach? I think at the moment to have a sort of control center on my laptop, from where I can launch the questions during the performance, the mobile apps will check maybe once per second if a new question is launched, then display it on the app and send the response back to a server to a table of the database. The control center then gets the responses from the server to create the poll result. Any pointers would be appreciated. Thanks.

Oliver

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Audience Polling System

Post by stam » Wed Sep 15, 2021 8:12 pm

I've not done anything like that but would imagine you'd need a network or internet database to collect the data from everyone's device. Should really be straightforward if you get that bit running, although sounds like a bit of work.

If you don't have a network/internet server/database, might i suggest trying out LiveCloud? You can just treat LiveCloud as a cloud based LiveCode array essentially. I imagine the setup for using this for your purposes would require very little RAM so you could probably just use their free 'Mist' tier.
Have a look at it here: https://livecloud.io.

I've used LiveCloud for desktop apps and it works fine - although if you're fluent in SQL there's a fair amount of re-learning required, kinda like driving an car with automatic gearbox, when all you've known is a stick shift. Guaranteed to give whiplash to everyone on the first day, but easier and simpler in the long run ;)

It does include count methods etc, so you should be able to derive the data you need, and just work on the integrating and presenting it.
Actually quite an interesting project!

-- EDIT --
Forgot to mention that LiveCloud requires TSnet, so will need Indy, Pro if using older LC, or the new subscription model (i presume this is now included by default)

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Audience Polling System

Post by SparkOut » Thu Sep 16, 2021 7:51 am

I once did a project for a TV production company making a pilot show which was essentially a prisoner's dilemma game. 4 players each chose a value from several figures listed, and voted (anonymously) to accept each others' anonymous choices or not. Each had a tablet to display the values and voting, with a PC showing the master screen for the TV studio to see and comment on. Each tablet updated its display according to the different choices made, which could be changed at any time.
This was done using sockets for direct communication with the master. I suspect it might be tricky to keep track of a whole audience with devices communicating by sockets, and probably "less than ideally robust".
But you could definitely have each device on a wireless network and polling every second or two to see if there's a new question, and then post the response to the server. It needn't be livecloud, although that would be a good fit, likely free on the mist tier, and work well. But you could keep it within the building using a server on the network without great trouble.

(The TV show never made it to air).

okk
Posts: 176
Joined: Wed Feb 04, 2015 11:37 am

Re: Audience Polling System

Post by okk » Thu Sep 16, 2021 8:52 am

Hi and thanks for the quick responses. I will for sure check out livecloud. I have followed them for a while but never tried it out. I have used MySQL databases earlier and it seemed to work okay and that would currently be my choice: to have a MySQL database with two simple tables, like one with the questions and response options, the other with the feedback from the devices. I have two main concerns:
1. how do I assign a unique ID to each device that is taking part to the performance, especially when in the beginning many devices are opened at the same time and trying to register.
2. Directly acessing / writing to a MySQL database on the internet: I have read many forum posts about this, but I am not still 100% sure why it is a such a bad idea to access a MySQL database directly from within my app. The credentials for the database access are baked into the code of my app, but if I understood right there is no way to access this credentials by analyzing the standalone builds of the android / ios apps. My app only writes responses that are pre-configured to the database, so there is no way that you can write some clever injections from the app itself. if the passwords are strong, what would be the secruity risk with this direct access?

@Sparkout Pity that the show didn't make it, it sounds quite interesting, at least I would watch everything related to prisoner dilemma https://ncase.me/trust/

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Audience Polling System

Post by stam » Thu Sep 16, 2021 9:50 am

okk wrote:
Thu Sep 16, 2021 8:52 am
1. how do I assign a unique ID to each device that is taking part to the performance, especially when in the beginning many devices are opened at the same time and trying to register.
Off the top of my head i would use UUID(). I would probably configure it so it creates a UUID on first run and stores it in a file in specialFolderPath("documents") if using mobile device, since that's sandboxed (on iOS at least; not sure about Android), and if desired also recording some specific user identifier, eg email. Then have the app just refer to that when creating a score in the database. By using UUID() as your primary key, you won't have to worry about creating a unique id in the database. It also means that that device will always have the same ID for subsequent performances, regardless of which database is used.


okk wrote:
Thu Sep 16, 2021 8:52 am
2. Directly accessing / writing to a MySQL database on the internet: I have read many forum posts about this, but I am not still 100% sure why it is a such a bad idea to access a MySQL database directly from within my app.
As far as i know and have read on many different sites, that is ill-advised. For example:
StackExchange.com wrote: Just opening the port isn't intrinsically any more dangerous that opening a SSH port.

The problem is that any application program that could USE the port could be hacked, and then be used to compromise your database. Anything running on the client side is inherently not to be trusted.
ServerFault.com wrote:To give an answer on your question: No it's not safe.
Just to name some security issues:

1: Login Your login data gets transferred plaintext over the internet you DO NOT want that obviously :)

2: SQL queries Your queries that you send (and their responses) are send in plain text again you DO NOT want that as one can easily tamper that data.

Furthermore having query results back in plain text which could contain sensitive information is a whole other issue. In case of personal files you could even get sued in some countries for neglecting/ignoring safety guidelines for personal data.

3: SQL port open on the internet is alway an extra attack vector for a potential malicious user. Think of remote mysql server exploits etc.
PS:
If you do decide to try liveCloud's free tier, i'd be happy to help - while the API is documented it can be difficult to digest on first read - not in the least because the mindset is very different and it took me a while to stop thinking in SQL terms (kind of like coming to LiveCode when all you've known is a different programming language).

Probably best to think of liveCloud as using an array and actually i pretty much use a single global array to process the data on local device and then selectively sync with cloud, but you can use a local liveCloud database and then sync that with cloud. Or you could just access the cloud directly, but that tends introduce a bit of lag and for my uses isn't the best. It does require TSnet, so there's that - but otherwise is secure out of the box and once you 'get' the API it's pretty straightforward.

However by basing your app on an array structure, the architecture becomes much more portable - you can switch the backend to MySQL, couchDB or any other database with little fuss as you'd only need to create a handlers to manage the communications between array and database, leaving the rest of your app intact.

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Audience Polling System

Post by stam » Thu Sep 16, 2021 10:27 am

okk wrote:
Thu Sep 16, 2021 8:52 am
https://ncase.me/trust/
Fascinating link!

okk
Posts: 176
Joined: Wed Feb 04, 2015 11:37 am

Re: Audience Polling System

Post by okk » Thu Sep 16, 2021 12:24 pm

Hi and thanks again for the quick replies and tips.

1. UUID
That sounds like an interesting option. It seems nearly impossible to generate an identical ID by coincidence. Do you have any thoughts on performance when I do a query with a 128 bit ID instead of a much shorter ID. I of course only have 100 - 200 entries in my table, so maybe it doesn' matter?

2. MySQL and security
According to my understanding the communication between the client app and the database uses SSL encryption, so it seems not trivial to intercept and manipulate those queries. The forum posts you quoted were mainly talking about plain text communication between client and DB, which indeed would be a big issue. Another risk I read about is injection attempts, but I dont have any free-form entry fields in my app that could be used for such attempts. How easy is it to hack a very simple standalone created with livecode?

3. Livecloud
Thanks for you offer. I have donwloaded the manager and will fiddle around to see if this would bring a big improvement to the more conventional approach (for me at least) with mysql.

simon.schvartzman
Posts: 641
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Audience Polling System

Post by simon.schvartzman » Thu Sep 16, 2021 2:21 pm

hi @okk, did you considered using notifications to send the polls to all users at the same time?

Using notifications you will avoid the need to have the App polling the DB to see if there are new questions asked. And of course the App doesn't even need to be open to receive the news.

As for the answers since they are going to be just Yes or No then it should be pretty easy to compute with mySQL.

Regarding showing the results on the big screen I have developed a solution using a Raspberry Pi hooked up to the screen and interacting with a LC application through ftp that works pretty well and I guess could be useful for your project.

If you want to please contact me in private to explore alternatives.

Best
Simon
________________________________________
To ";" or not to ";" that is the question

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Audience Polling System

Post by stam » Thu Sep 16, 2021 2:42 pm

okk wrote:
Thu Sep 16, 2021 12:24 pm
1. UUID
Can't imagine the length of the UUID vs a shorter integer will have a palpable impact. And yes you can pretty much consider the UUID unique.
okk wrote:
Thu Sep 16, 2021 12:24 pm
2. MySQL and security
I personally would have a degree of anxiety about setting up security correctly as that's a bit outside my comfort zone... If you're handy with MySQL and setting up server SSL and connecting securely then i imagine that would be OK but I'm sure there are more knowledgable people here that can comment.
okk wrote:
Thu Sep 16, 2021 12:24 pm
3. Livecloud
Mark Talluto and his team are very responsive on their own forum - but it tends to be more of a tech support type forum, users tend not to cross-comment, share tips, code etc. Keeping in mind there are many ways to skin that cat, may be worth checking with users here as well...

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Audience Polling System

Post by Bernard » Thu Sep 16, 2021 3:50 pm

Some webservers are programmable. Such webservers have shared variables (hashed arrays, like in Livecode). https://naviserver.sourceforge.io/n/man ... tures.html

The app connects to the server and is given a random UUID as a client ID. And the server only responds to requests that use some header (which was set by the server, or a specific User Agent built into the app).

The results of the survey are stored in the server's hashed array by UUID and question number (which ensures people can't submit multiple responses). The server has a URL that when called parses out the data from the shared variable.

Only 2 working parts: the app and the webserver. I've never used LC as a webserver. I don't know if it retains any state between http requests. If it does, then the above scenario should be doable in LC alone (behind Apache etc).

jiml
Posts: 336
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: Audience Polling System

Post by jiml » Thu Sep 16, 2021 5:09 pm

I suspect one of the more difficult parts of this project may be convincing the audience members to download an app.

I love LiveCode but doing it on a webpage pointing to that URL (with a QR code?) might get more participation.

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Audience Polling System

Post by stam » Thu Sep 16, 2021 8:52 pm

It probably does depend on what exactly the OP has in mind; if it's just a yes/no clicker with no possibility for the user to go back and change a response and so on, then a web page may well be better.

When i read the original question i subconsciously translated it in my head to something that would be more applicable for me (yeh, i know...), for teaching/conferences, but that's probably quite a different use-case and probably overkill for the OP's need.

With respect to the vehicle used for this: I know i personally wouldn't mind downloading a small app, and might prefer this if i could use this repeatedly at repeat attendances if that's a thing.

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Audience Polling System

Post by Bernard » Fri Sep 17, 2021 12:09 am

Maybe the simplest option of all would be to just have the app write each response to a new file to (e.g.) a Dropbox account where the file name was the userid + question number. The manager programme can just download the responses from Dropbox and process them, placing results back in another Dropbox folder where they are picked up by whatever mechanism is being used to display them.

Your app only needs to read the questions from a server in an event loop. The questions could also be taken from a Dropbox folder where questions are uploaded as the performance continues.

I think this is the least work. No need to setup a webserver and a database. No need to engage with Notifications on iOS and Android.

This same principle could also apply to a (S)FTP server under your control rather than Dropbox. That might be more work than with Dropbox. But someone was using this kind of setup before when the cloud service (which wasn't Dropbox) suddenly became unavailable on the very day that the app needed to be used in public and it failed in a fairly spectacularly disastrous way.

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Audience Polling System

Post by stam » Fri Sep 17, 2021 12:32 am

Perhaps because i'm already using LiveCloud for other things, i think using LiveCloud at least as simple (the free Mist tier would suffice for this).

The setup required is equivalent to setting up a stack for Dropbox; writing and retrieving results are 1-line jobs and is no different from working with arrays.

if the app is built around a central array structure, all of the above can be tested or even implemented simultaneously ;)

okk
Posts: 176
Joined: Wed Feb 04, 2015 11:37 am

Re: Audience Polling System

Post by okk » Fri Sep 17, 2021 2:24 pm

Hi and thanks for all the valuable input.

1. website or app
I am more familair of creating a mobile app than a website. In Finland it is quite common to download an app when visiting an exhibtion or a theatre etc. so that wont be a mayor issue, we will hand out devices with the app preinstalled if necessary.

2. Dropbox etc.
I feel more comfortable with using MySQL, so that would be my preferred choice. It is nevertheless an important remark, to be prepared for all eventualities, I was thinking of having a mirror server, so that we can switch seamlessly to the second server if the first one goes offline.

3. Notifications etc.
I havent used push notifications, I am also not totally sure how it would help in my case. What I have in mind is that the app is actually a stack with say 12 cards, each card is featuring a special question or quiz. Some are just text based, others have images, maybe even a video. Answer options might vary as well, maybe: YES or NO or A, B, C, or D. My idea was that from my "Control Centre" stack I just launch a question by sending an card ID to the server, and the app fetches that card ID and jumps to that card in the stack on all clients (hopefully at the same time, even though a synch error of a few seconds wouldnt be a problem.) When that specifc card is opened in the client app a 30 second timer starts and people have time to respond, the responses are then send to the server and written into the DB with their unique device specific ID. My control centre then fetches all responses from the server and creates an appropriate display of the results. Either in the same control stack or another "Display" stack.

4. livecloud
I will start messing around first with MySQL but will also look into mycloud, if it brings a massive benefit, for example in terms of security or robustness. Will keep you updated if I make any progress.

best
Oliver

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”