Monday, October 9, 2017

Example of Loading New York City Payroll from Open Data

See https://taxhistory.brooklyncoop.org/nycpayroll.html

This link simply goes to the New York City Open Data website and uses the Application Programming Interface (API) to read the data and display it.

The advantage is you do not have to reload information in your database.  As the data is updated by New York City, your application will see the updates.

The code is very simple:

    <script>
            $(document).ready(function() {
                $.ajax({
                    url: "https://data.cityofnewyork.us/resource/4qxi-jgbe.json",
                    type: "GET",
                    data: {
                        $limit: 5000,
                        $$app_token: "GET-APPTOKEN-FROM-SOCRATA",  // see https://dev.socrata.com/docs/app-tokens.html
                        $select: "fiscal_year,title_description,work_location_borough,sum(regular_gross_paid),sum(regular_hours),sum(total_ot_paid),sum(total_other_pay)",
                        $group: "fiscal_year,title_description,work_location_borough",
                        $order: "sum(regular_gross_paid) desc"
                    }
                }).done(function(r) {
                    for (var o in r)
                        r[o].average_pay_per_period = "$" + (Number(r[o].sum_regular_gross_paid) / Number(r[o].sum_regular_hours)).toLocaleString(),
                        r[o].sum_regular_gross_paid = "$" + Number(r[o].sum_regular_gross_paid).toLocaleString(),
                        r[o].sum_total_ot_paid = "$" + Number(r[o].sum_total_ot_paid).toLocaleString(),
                        r[o].sum_total_other_pay = "$" + Number(r[o].sum_total_other_pay).toLocaleString(),
                        r[o].sum_regular_hours = Number(r[o].sum_regular_hours).toLocaleString();
                    $("#demo").columns({
                        data: r
                    })
                })
            });
    </script>

No comments:

Post a Comment