Skip to content

Commit

Permalink
feat: build data dict static + content updates
Browse files Browse the repository at this point in the history
  • Loading branch information
allejo committed Feb 12, 2024
1 parent ddf54d4 commit 3f29957
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 39 deletions.
14 changes: 14 additions & 0 deletions src/_plugins/csv_to_json.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
module Jekyll
class CsvData < Generator
def generate(site)
site.data['csv'] = {}

Dir.glob(File.join(site.source, "metadata", "providers", "*.csv")).each do |path|
filename = File.basename(path, '.*')
puts "Injecting site.data['csv']['#{filename}']"
site.data['csv'][filename] = CSV.parse(File.read(path), headers: :first_row).map(&:to_h)
end
end
end
end

Jekyll::Hooks.register :site, :post_write do |_site|
Dir.glob(File.join("_site", "metadata", "providers", "*.csv")).each do |path|
puts "Formatting CSV to JSON for #{path}"
Expand Down
8 changes: 4 additions & 4 deletions src/metadata/providers/dictionary.csv
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
column,label,type,definition
agency_name,Agency Name,string,The name of the TA as specified in NTD.
ntd_id,NTD Id,string,"The organization's ID in the National Transit Database / FTA agency ID number. Data entry processes / sources of truth for this field have changed over time. As of May 2023, the source is the `raw_ntd_id` field in the Airtable `organizations` table; for records before May 2023, sources were some combination of the `NTD agency info` table in Airtable and the `ntd_agency_to_organizations` CSV seed file in this dbt project (now renamed to `_deprecated__ntd_agency_to_organizations`)."
ntd_id,NTD ID,string,"The organization's ID in the National Transit Database / FTA agency ID number. Data entry processes / sources of truth for this field have changed over time. As of May 2023, the source is the `raw_ntd_id` field in the Airtable `organizations` table; for records before May 2023, sources were some combination of the `NTD agency info` table in Airtable and the `ntd_agency_to_organizations` CSV seed file in this dbt project (now renamed to `_deprecated__ntd_agency_to_organizations`)."
hq_city,HQ City,string,The city where this TA's headquarters is located.
hq_county,HQ County,string,The county where this TA's headquarters is located.
counties_served,Counties Served,string,A semi-colon delimited list of counties that are serviced by the parent organization this TA belongs to; this TA may not service all counties listed.
agency_website,Agency Website,string,The website for this TA.
caltrans_district_id,CalTrans District Id,int64,null
caltrans_district_id,CalTrans District ID,int64,null
caltrans_district_name,CalTrans District Name,string,null
is_public_entity,Is Public Entity,bool,"Formula in source system returns true if the `organization_type` column has been set to one of the following: City/Town, Independent Agency, MPO/RTPA, County, Tribe, Federal Government, Joint Powers Agency, or Council of Governments"
is_publicly_operating,Is Publicly Operating,bool,"Formula in source system returns true value if the following criteria are met: 1. Service has “Operating” value in `operational_status` column (for organizations, only at least one managed service must meet this criterion) 2. Service is rideable by the general public (for organizations, only at least one managed service must meet this criterion) 3. Provider is either an NTD reporter (indicated by non-empty `raw_ntd_id`) or is a public entity."
funding_sources,Founding Sources,string,"A semi-colon delimted list of numerical funding program names that this TA's parent organization receives; all non-numerical (e.g. `Public`, `Caltrans`) funding programs are excluded in this column."
funding_sources,Funding Sources,string,"A semi-colon delimted list of numerical funding program names that this TA's parent organization receives; all non-numerical (e.g. `Public`, `Caltrans`) funding programs are excluded in this column."
vehicles_at_max_service,VOMS,float64,"(abbreviated as ""voms"") The number of revenue vehicles operated to meet the annual maximum service requirement. This is the revenue vehicle count during the peak season of the year on the week and day that maximum service is provided."
on_demand_vehicles_at_max_service,VOMS DR,float64,"(abbreviated as ""voms_dr"") The number of revenue vehicles operated to meet the annual maximum service requirement for NTD categories: Demand Response (DR) and Demand Response Taxi (DT)."
on_demand_vehicles_at_max_service,VOMS (Demand Response),float64,"(abbreviated as ""voms_dr"") The number of revenue vehicles operated to meet the annual maximum service requirement for NTD categories: Demand Response (DR) and Demand Response Taxi (DT)."
gtfs_schedule_uris,GTFS Schedule URIs,string,A semi-colon delimited list of URLs for GTFS schedules this TA's parent organization has under its umbrella of services; there may be feeds that do not belong to this TA but instead from a sibling service provider within the same parent organization.
49 changes: 29 additions & 20 deletions src/provider-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@
};
</script>
<script defer src="/scripts/providers/map.js"></script>
<script>
const data_tabulator = "tabulator";
</script>
<script defer src="https://unpkg.com/[email protected]/dist/js/tabulator.min.js"></script>
<script>
const data_table = {
src: "/scripts/providers/table.js",
data_id: "table-data",
dict_id: "table-dict",
data_file: "/metadata/providers/providers.json",
dict_file: "/metadata/providers/dictionary.json",
};
Expand All @@ -45,22 +41,14 @@ <h1 class="page-header">California transit providers</h1>
</header>

<div class="mb-3">
<p>
From buses, shuttles, and on-demand paratransit to commuter and intercity rail, passengers want transportation that’s easy
to find and easy to pay for.
</p>
<p>From buses, shuttles, and on-demand paratransit to commuter and intercity rail, passengers want transportation that’s easy to find and easy to pay for.</p>

<p>To better understand the size and scale of opportunities for integration in transportation, the Cal-ITP team compiled a list of California’s transit providers.</p>

<p>
To better understand the size and scale of opportunities for integration in transportation, the Cal-ITP team compiled a list
of California’s transit providers.
</p>
<p>Explore the data below, which links to each operator’s website and offers just a taste of our full dataset—a CSV download that includes funding information, fleet size, GTFS information, and more.</p>

<p>
Explore the more than 300 providers on this map and table, which links to each operator’s website and offers just a taste of
our full dataset—a CSV download that includes fare revenues, fleet size, vehicle type, and more.
</p>
<h2>Download the data package</h2>

<h3>Download the data package</h3>
<p>The data package includes the full dataset, data dictionary, and glossary as CSV files.</p>

<div class="mt-4 text-center">
Expand Down Expand Up @@ -112,9 +100,30 @@ <h2 class="mt-0">About the data</h2>
<header>
<h2 class="mt-0">Data dictionary</h2>
</header>
<div>
<div class="provider-data-dictionary" id="table-dict"></div>
</div>
<ul class="list-unstyled">
{% for term in site.data.csv.dictionary %}
{% capture description %}
{%- assign arr = term.definition | markdownify | strip | split: "<p>" -%}
{%- if arr.size > 2 -%}
{{ arr | join: "<p>" | prepend: "<p>" }}
{%- else -%}
{{ arr[1] | remove: "</p>" }}
{%- endif -%}
{% endcapture %}
<li>
<p><strong>{{ term.label }}</strong>: {{ description }}</p>
<dl class="ps-4">
<dt>Data Type</dt>
<dd>{{ term.type }}</dd>

<dt>Column</dt>
<dd>
<code>{{ term.column }}</code>
</dd>
</dl>
</li>
{% endfor %}
</ul>
</article>

<article class="mt-5 mb-5">
Expand Down
15 changes: 0 additions & 15 deletions src/scripts/providers/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,6 @@ $(function () {
return [data, dictionary];
};

const buildDictTable = (dictionary) => {
// create the dict table (don't keep a reference)
new Tabulator(`#${data_table.dict_id}`, {
layout: "fitColumns",
data: dictionary,
autoColumns: true,
headerSort: false,
pagination: false,
selectable: false,
});

return dictionary;
};

const refresh = (county) => {
if (county && county !== "") {
// filter where service_county column contains county
Expand Down Expand Up @@ -152,6 +138,5 @@ $(function () {

Promise.all(jobs)
.then(([data, dictionary]) => buildDataTable(data, dictionary))
.then(([_, dictionary]) => buildDictTable(dictionary))
.then(() => refresh());
});

0 comments on commit 3f29957

Please sign in to comment.