From 0fbfec77830b4e51aec88f5ef6d290d8a0c4daca Mon Sep 17 00:00:00 2001 From: hellekin Date: Tue, 6 Oct 2020 17:27:01 +0200 Subject: Document importation of resources Renamed `readme.txt` to `README.md` to stick to standard README case and take advantage of Markdown formatting supported by code hosting services. Also fixed names in the content. And added import method to the database. --- doc/import/README.md | 32 ++++++++++++++++++++++++++++++++ doc/import/readme.txt | 10 ---------- 2 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 doc/import/README.md delete mode 100644 doc/import/readme.txt diff --git a/doc/import/README.md b/doc/import/README.md new file mode 100644 index 0000000..b65225e --- /dev/null +++ b/doc/import/README.md @@ -0,0 +1,32 @@ +## Parsing Resources + +The script `parser.rb` creates a file named `Locations.geojson`, which contains +all the points from the ConcertES and Dewey Maps databases. It parses the .csv +files from the Concertes folder and the .json files from the Dewey folder. To +run it: `ruby parser.rb` + +The main files it uses are: + +- `Concertes/20200312_EntreprisesSignaletique.csv` which contains the name of + the points from the Concertes data +- `Concertes/20200312_EntreprisesCoordonnees.csv` which contains the coordinates + of the points from the Concertes data and +- `Dewey/dewey-maps-markers.json` which contains the data of the points from the + Dewey data + +## Importing to Database + +Once you have `Locations.geojson`, connect to the Rails console: + +```ruby +# Load the GeoJSON into an Array +locs = JSON.parse(IO.read('doc/import/Locations.geojson')) +# Get related Agent records. You must have run `rails db:seed` beforehand. +dewey = Agent.find_by(name: 'Dewey') +concertes = Agent.find_by(name: 'ConcertES') +# Create Resource records +locs['features'].each do |f| + agent = f['properties']['source'] == dewey['name'] ? dewey : concertes + Resource.create(agent_id: agent.id, feature: f) +end +``` diff --git a/doc/import/readme.txt b/doc/import/readme.txt deleted file mode 100644 index b534433..0000000 --- a/doc/import/readme.txt +++ /dev/null @@ -1,10 +0,0 @@ -The script LocationsParser.rb creates a file named "Locations.json", which contains all the points from the Concertes and Dewey database. -It parses the .csv files from the Concertes folder and the .json files from the Dewey folder. -To run it: - ruby parser.rb - -The main files it uses are: - Concertes/20200312_EntreprisesSignaletique.csv which contains the name of the points from the Concertes data - Concertes/20200312_EntreprisesCoordonnees.csv which contains the coordinates of the points from the Concertes data -and - Dewey/dewey-maps-markers.json which contains the data of the points from the Dewey data -- cgit v1.2.3