Skip to content

Commit

Permalink
Add data for rate centers and cities (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie authored Oct 5, 2024
1 parent 1d3a90c commit 16ad42f
Show file tree
Hide file tree
Showing 138 changed files with 1,136,267 additions and 534,971 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: 'bundler'
directory: '/'
schedule:
interval: 'daily'
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
17 changes: 17 additions & 0 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Dependabot auto-merge
on: pull_request

permissions:
contents: write
pull-requests: write

jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
16 changes: 3 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
name: Ruby
name: Build

on:
push:
branches:
- main

pull_request:
on: push

jobs:
build:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}
strategy:
matrix:
ruby:
- '3.3.3'

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Run the default task
run: bundle exec rake
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: release

on:
push:
branches:
- main

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
id: release

- uses: actions/checkout@v4
if: ${{ steps.release.outputs.release_created }}

- uses: ruby/setup-ruby@v1
if: ${{ steps.release.outputs.release_created }}

- run: bundle install
if: ${{ steps.release.outputs.release_created }}

- name: publish gem
if: ${{ steps.release.outputs.release_created }}
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push *.gem
env:
GEM_HOST_API_KEY: "${{secrets.GEM_HOST_API_KEY}}"
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.1.0"
}
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ GEM
connection_pool (2.4.1)
countries (7.0.0)
unaccent (~> 0.3)
csv (3.3.0)
diff-lcs (1.5.1)
drb (2.2.1)
faraday (2.12.0)
Expand All @@ -33,6 +34,10 @@ GEM
logger
faraday-net_http (3.3.0)
net-http
fiddle (1.1.2)
geocoder (1.8.3)
base64 (>= 0.1.0)
csv (>= 3.0.0)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.7.2)
Expand Down Expand Up @@ -116,7 +121,11 @@ PLATFORMS

DEPENDENCIES
countries
csv
faraday
fiddle
geocoder
logger
multi_xml
ostruct
ox
Expand Down
79 changes: 70 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,99 @@
# RateCenter

TODO: Delete this and the text below, and describe your gem
A collection of useful data about [NANPA Rate Centers](https://en.wikipedia.org/wiki/Rate_center).

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rate_center`. To experiment with that code, run `bin/console` for an interactive prompt.
Data is currently sourced from [Simple Maps](https://simplemaps.com/data/us-cities) and [Local Calling Guide](https://localcallingguide.com/).

## Installation

TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.

Install the gem and add to the application's Gemfile by executing:

```bash
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
bundle add rate_centers
```

If bundler is not being used to manage dependencies, install the gem by executing:

```bash
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
gem install rate_centers
```

## Usage

TODO: Write usage instructions here
### Working with Rate Centers

```rb
# Load rate centers
RateCenter.load(:rate_centers, only: { us: [:ny, :ca] }) # Loads rate centers in New York and California
# RateCenter.load(:rate_centers, only: { us: { ny: [ "NWYRCYZN01" ], ca: [ "LSAN DA 01"] } }) # Loads only specific rate centers
# RateCenter.load(:rate_centers, only: { [ :us ] }) # Load all rate centers in US
# RateCenter.load(:rate_centers, :all) # Load all rate centers

# RateCenter::RateCenter.all # returns all rate centers loaded

rate_center = RateCenter::RateCenter.find_by!(country: "US", region: "NY", name: "NWYRCYZN01")
rate_center.full_name # "New York City Zone 01"
rate_center.lata # 132
rate_center.ilec_name # "VERIZON NEW YORK, INC."
rate_center.lat # "40.739362"
rate_center.long # "-73.991043"
rate_center.closest_city.name # "Manhattan"
rate_center.closest_city.distance.value # 5.33
rate_center.closest_city.distance.units # km
```

### Working with Cities

```rb
# Load cities
RateCenter.load(:cities, only: { us: [:ny, :ca] }) # Loads cities in New York and California
# RateCenter.load(:cities, only: { us: { ny: [ "New York" ], ca: [ "Los Angeles"] } }) # Loads only specific cities
# RateCenter.load(:cities, only: { [ :us ] }) # Load all cities in US
# RateCenter.load(:cities, :all) # Load all cities

# RateCenter::City.all # returns all cities loaded

city = RateCenter::City.find_by!(country: "US", region: "NY", name: "New York")
city.lat # "40.6943"
city.log # "-73.9249"
city.nearby_rate_centers.each do |rate_center|
puts "Rate Center: #{rate_center.name}, Distance: #{rate_center.distance.value} #{rate_center.distance.units}"
end
# Rate Center: NWYRCYZN14, Distance: 7.5 km
# Rate Center: NWYRCYZN15, Distance: 7.5 km
# Rate Center: NWYRCYZN11, Distance: 7.5 km
# Rate Center: NWYRCYZN10, Distance: 7.5 km
# Rate Center: NWYRCYZN13, Distance: 7.5 km
# Rate Center: NWYRCYZN09, Distance: 7.5 km
# Rate Center: NWYRCYZN08, Distance: 7.5 km
# Rate Center: NWYRCYZN07, Distance: 7.5 km
# Rate Center: NWYRCYZN06, Distance: 7.5 km
# Rate Center: NWYRCYZN05, Distance: 7.5 km
# Rate Center: NWYRCYZN12, Distance: 7.5 km
# Rate Center: NWYRCYZN04, Distance: 7.5 km
# Rate Center: NWYRCYZN03, Distance: 7.5 km
# Rate Center: NWYRCYZN01, Distance: 7.5 km
# Rate Center: NASSAUZN02, Distance: 18.96 km
# Rate Center: NASSAUZN03, Distance: 20.16 km
```

## Updating Data

In order to pull data from the sources, run the following script

```bash
bin/update_data
```

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
To install this gem onto your local machine, run `bundle exec rake install`.

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rate_center.
Bug reports and pull requests are welcome on GitHub at https://github.com/somleng/rate_center.

## License

Expand Down
13 changes: 0 additions & 13 deletions bin/fetch_data

This file was deleted.

22 changes: 22 additions & 0 deletions bin/update_data
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env ruby

# Usage:

# $ update_data

require "bundler/setup"
require "rate_center"
require "rate_center/data_source/local_calling_guide"
require "rate_center/data_source/simple_maps"
require "rate_center/data_prep"

data_directory = Pathname(File.expand_path("../data/", __dir__))

logger = Logger.new(STDOUT)

logger.info("Fetching city data from SimpleMaps")
RateCenter::DataSource::SimpleMaps.new.load_data!(data_directory: data_directory.join("cities/us"))
logger.info("Fetching rate center data from LocalCallingGuide")
RateCenter::DataSource::LocalCallingGuide.new.load_data!(data_directory: data_directory.join("rate_centers/us"))
logger.info("Prepping data")
RateCenter::DataPrep.new(data_directory:).call
Loading

0 comments on commit 16ad42f

Please sign in to comment.