Giter VIP home page Giter VIP logo

goblt's Introduction

goblt

A BLT file format parser in Go. Used for election data.

Background

6 3
-2 -6
28 1=2 3 0
26 2 1 3 0
3 3 0
2 4 0
1 5 0
0
"Alice"
"Bob"
"Chris"
"Don"
"Eric"
"Frank"
"My Election"
  • The first line 6 3 indicates the number of candidates 6 and seats 3.

  • The second line -2 -6 is optional and may be omitted. It contains negative candidate numbers indicating candidates 2 and 6 are withdrawn.

  • The next lines contain vote data. 28 1=2 3 0 indicates there are 28 votes each containing candidate preferences 1=2 3. The end of a vote line is indicated by a 0. The preference 1=2 3 indicates 1 and 2 are tied for first preference, and 3 is second preference.

  • A line with a single 0 indicates the end of all vote data.

  • Next are quoted candidate names listed in a specific order matching the numbers for vote preferences.

  • The last line is the title of the election.

Use

NewParser accepts an io.Reader and initializes a new parser.

parser := blt.NewParser(reader)

election, err := parser.Parse()

The resulting parsed election struct will look like this:

{
    "NumCandidates":6,
    "NumSeats":3,
    "Withdrawn":[2,6],
    "Ballots":[
        {
            "Count":28,
            "Preferences":[[1,2],[3]]
        },
        {
            "Count":26,
            "Preferences":[[2],[1],[3]]
        },
        {
            "Count":3,
            "Preferences":[[3]]
        },
        {
            "Count":2,
            "Preferences":[[4]]
        },
        {
            "Count":1,
            "Preferences":[[5]]
        }
    ],
    "Candidates": [
        "Alice",
        "Bob",
        "Chris",
        "Don",
        "Eric",
        "Frank"
    ],
    "Title":"Test"
}

goblt's People

Contributors

shawntoffel avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.