Graphics

 View Only
Expand all | Collapse all

Datalinq and elections

Corina Blank

Corina Blank06-06-2012 10:09

  • 1.  Datalinq and elections

    Posted 06-01-2012 15:49
    I'm setting up election night graphics and am running into a few hurdles. To preface, I have little to no scripting knowledge which is probably what is making this more difficult than it should be. We are trying to use Datalinq to grab election results from the ND Secretary of State's website. They offer RSS feeds and the ability to export results to Excel. The issue I seem to be having is in the formatting of these options. For example, using RSS, a particular cell for a race may come through as [Candidate Name - Votes - Percentage, Candidate Name - Votes - Percentage, etc]. Is there a way to break this up into individual parts or even just take the number of votes? The exported Excel documents are similarly formatted. Additionally, if this is possible, how can I then script my text fields to order themselves based on vote counts?


  • 2.  RE: Datalinq and elections

    Posted 06-02-2012 22:28
    What is the address for the RSS feed? Maybe by looking at it we might be able to suggest or provide some scripting.. Splitting the data into parts should be easy by using the visual basic Split() function (depending on how they separate the different components).. Doing the sorting gets quite a bit more complicated though but is still possible.

    #XPression


  • 3.  RE: Datalinq and elections

    Posted 06-04-2012 16:06
    Here is a link to one of the RSS feeds from the election results in 2010. This years feeds are not currently up on the site yet but I've been told they will be early this week.

    http://results.sos.nd.gov/resultsRSS.aspx?text=All&type=SW&map=CTY

    #XPression


  • 4.  RE: Datalinq and elections

    Posted 06-04-2012 17:42
    Here is a sample I just created to split the datalinq into multiple text objects.. It seems like the RSS feed already orders them in order of most votes to least votes; so I didn't add any sorting.. There are two hidden text objects in the scene which are datalinq'd to the RSS feed. Those two text objects have the scripts on them which breaks the single string up into multiple parts and sets it onto the other text objects in the scene.

    https://rossvideo.centraldesktop.com/p/eAAAAAAAANqhAAAAAGmop3k

    #XPression


  • 5.  RE: Datalinq and elections

    Posted 06-04-2012 17:43
    Oh, and you'll only see the script execute if you put it online from the sequencer; because they OnSetText script doesn't run when a scene is put on air from Layout mode.

    #XPression


  • 6.  RE: Datalinq and elections

    Posted 06-05-2012 15:28
    Thank you! This worked great as I was testing this morning. I had started getting all my pages in order and then they updated to this years feeds. If you take a look at the RSS link now, it appears they are separating each race into their respective parties instead of doing the full race as a single item. I imagine this makes things more complicated?

    #XPression


  • 7.  RE: Datalinq and elections

    Posted 06-05-2012 15:32
    Well, being a Canadian and not understanding how your elections work at all; I'm not sure how you want the results displayed.. Will you create a separate full page graphic for each Party? i.e. one graphic for Republican senator with the 3 candidates; then another graphic for Democratic Senator? or does the graphic need to merge the results of all the different parties into one graphic?

    #XPression


  • 8.  RE: Datalinq and elections

    Posted 06-05-2012 16:00
    I just realized that the formatting they are using is indeed correct. I spaced out as this is not the general election, but just a primary election. Each party chooses a candidate for the general election in November. It's been a long week! The script you gave me should work. Thanks again.

    Oh, one other thing. Is there a simple script to drop the decimal from the percentage?

    #XPression


  • 9.  RE: Datalinq and elections

    Posted 06-05-2012 18:30
    oh I just saw your updated response now.. Well I just finished a version that would merge all the results together but I guess you don't need it now..

    Here's a link if you wanted to see how it works.. I had to add hidden text objects for each party and each one would be datalinq'd to the results for that party. Then I created an OnOnline script that would parse all the candidates out of each text object and put them into one combined list that then gets sorted. The top 4 candidates would be written out to the graphic:

    https://rossvideo.centraldesktop.com/p/eAAAAAAAAN7sAAAAABW0bq8

    #XPression


  • 10.  RE: Datalinq and elections

    Posted 06-05-2012 18:39
    Here is an updated version of the original that includes a new script that will strip the decimal point from the percentage..

    https://rossvideo.centraldesktop.com/p/eAAAAAAAAN7wAAAAAABwPzo

    The changed line is as follows:



    textobj.text = Split(segments(2),".")(0) + "%"



    #XPression


  • 11.  RE: Datalinq and elections

    Posted 06-05-2012 18:40
    Also, for testing you might find it best to save the XML from the RSS feed to a local file which you can then use the standard XML Datalinq to point this. This allows you to change the data in the XML file (using XML Notepad) so that you can test everything correctly. The script I provided as an example may have bug/issues I didn't catch, so please test this as thoroughly as you can before taking it on air.

    #XPression


  • 12.  RE: Datalinq and elections

    Posted 06-06-2012 10:09
    Thanx Brian, you right.

    #XPression


  • 13.  RE: Datalinq and elections

    Posted 06-06-2012 20:38
    Thanks so much for all your help, Brian.

    #XPression


  • 14.  RE: Datalinq and elections

    Posted 10-04-2012 16:39

    For the upcoming general election, in addition to scripting pages for North Dakota election results via RSS, I will be getting downloadable text results from the Minnesota Secretary of State election website. You can see examples of past results and a link to how results are formatted here: http://electionresults.sos.state.mn.us/ENR/Select/Download/2.

    I need a script to loop through each candidate row, find the top 4 candidates with the highest vote count and then to write those to my results page. My question is, what would be the best (and most efficient) way to go about scripting this?

    Below is an example of how I'm currently scripting my North Dakota result pages. The difference between MN and ND is that the ND RSS places all candidates in a single line of data separated by a break tag, which is why I use a single "MasterList" text object to loop through all candidates. I'd like to do something similar for MN results, but just don't know how to go about it.

    I admit my scripting skills are severely lacking so any help would be appreciated. Thanks.

    ND RSS feed @ http://results.sos.nd.gov/resultsRSS.aspx?text=All&type=SW&map=CTY


    ' These 5 arrays hold a master combined list of all candidates for all parties

    ' They will then be sorted

    dim names(20) as string

    dim votes(20) as integer

    dim percentage(20) as string

    dim used(20) as boolean ' used for sorting to mark a candidate as already being used

    ' Index/Loop variables

    dim idx as integer

    dim i as integer

    dim j as integer

    dim allcands(0) as string

    dim cand as string

    dim textobj as xpTextObject

    dim group as xpBaseObject

    ' This text object will be datalinq'd to the appropriate datalinq field

    allcands(0) = "MasterList"

    ' Reset the index

    idx = 0

    ' Clear the used flags

    for i = 0 to 20

    used(i) = false

    next

    ' Loop over each cand

    for each cand in allcands

    dim line as string

    dim lines(20) as string

    if self.GetObjectByName(cand, textobj) then

    ' Get the candidates and split them by


    line = Replace(textobj.text, "
    ", vbCr)

    lines = Split(line, vbCr)

    ' Loop over all of the candidates and add them to the master list

    for i = 0 to UBound(lines)-1

    dim segments(3) as string

    ' Remove the spaces around the dashes and replace with a carriage return

    line = Replace(lines(i), " - ", vbCr)

    if len(line) > 0 then

    ' Split the line into it's individual components

    segments = split(line, vbCr, 3)

    names(idx) = segments(0)

    votes(idx) = CInt(segments(1))

    percentage(idx) = segments(2)

    idx = idx + 1

    end if

    next

    end if

    next

    ' NOW BEGIN THE PROCESS OF FINDING THE HIGHEST VOTE COUNTS

    dim numPeople as integer

    numPeople = idx

    dim maxVotes as Integer

    dim currentHighest as Integer

    ' Now we need to loop over the master combined list and find the highest votes

    ' We try to find the top 4 candidates

    for i = 1 to 4

    currentHighest = -1

    maxVotes = -1

    ' Loop over the master candidate list to find the highest unused candidate

    for j = 0 to numPeople-1

    if used(j) = false then ' make sure we don't pick a used entry

    ' If this person has more votes than our maximum, use this person

    if votes(j) > maxVotes then

    currentHighest = j

    maxVotes = votes(j)

    end if

    end if

    next

    if currentHighest >= 0 then

    used(currentHighest) = true

    if self.GetObjectByName("Candidate" + i.toString, textobj) then

    if Trim(names(currentHighest)) = "write-in" then

    textobj.text = "Write In"

    else

    textobj.text = Trim(names(currentHighest))

    end if

    end if

    if self.GetObjectByName("Votes" + i.toString, textobj) then

    textobj.text = votes(currentHighest).toString

    end if

    if self.GetObjectByName("Percentage" + i.toString, textobj) then

    textobj.text = percentage(currentHighest)

    end if

    ' Show the line

    if self.GetObjectByName("Person" + i.toString, group) then

    group.Visible = true

    end if

    else

    ' Hide the line

    if self.GetObjectByName("Person" + i.toString, group) then

    group.Visible = false

    end if

    end if

    next

    #XPression


  • 15.  RE: Datalinq and elections

    Posted 10-04-2012 18:57
    Since each row in the data source represents a different candidate; you will need hidden text objects to represent every candidate (row). You'll need to datalinq each of those text objects to the appropriate rows in the text file.

    Then the script would then need to loop over all of those hidden text objects to figure out which four have the highest vote count and copy those particular rows into visible text objects in the scene.

    #XPression


  • 16.  RE: Datalinq and elections

    Posted 10-05-2012 16:23
    Yup, I figured that was going to be the best way to do it. I created 10 hidden text objects (should be enough) in my scene and datalinq'd them with my text file, but I'm really lost as to how to re-write the script to make this work for me.

    #XPression


  • 17.  RE: Datalinq and elections

    Posted 10-11-2012 12:58
    Hi, I'm trying to set up our election graphics for the first time in Xpression. We have only been on the system since July. We are using the AP ENPS news system and "STATS" election to manually input results. Can anyone tell me how to set this up in Xpression?

    #XPression