Skip to content

Instantly share code, notes, and snippets.

@mikeymckay
Created December 20, 2018 13:09
Show Gist options
  • Save mikeymckay/a5fe527c245be0767f917a4b4f6574c6 to your computer and use it in GitHub Desktop.
Save mikeymckay/a5fe527c245be0767f917a4b4f6574c6 to your computer and use it in GitHub Desktop.
FuzzyMatch = require 'fuzzy-matching'
PouchDB = require 'pouchdb'
_ = require 'underscore'
database = new PouchDB("http://****:*******@gooseberry.tangerinecentral.org:5984/gooseberry")
database.get "tusome teacher zones"
.then (doc) =>
zones = _(doc.data).chain().map (row) =>
row.Zone.replace(/\(.*\)/, "").trim()
.uniq().sort().value()
fuzzyMatch = new FuzzyMatch(zones)
database.query "results_by_question_set_and_date",
startkey: ["TUSOMETEACHER", "2018-12-17"]
endkey: ["TUSOMETEACHER", "2018-12-20"]
reduce: false
.then (result) =>
for row in result.rows
#console.log row
original = row.value?.Zone
cleaned = fuzzyMatch.get(row.value?.Zone).value
if original?.toLowerCase() isnt cleaned?.toLowerCase() and original?
console.log "#{row.id}, #{row.value?.Zone}, #{fuzzyMatch.get(row.value?.Zone).value}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment