Skip to content

Commit

Permalink
FIX: Rename Definition column > Tags (#178)
Browse files Browse the repository at this point in the history
partially addresses #178
  • Loading branch information
dwhieb committed Jul 25, 2024
1 parent 53b49e7 commit 9f58608
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ data/credentials.json
node_modules/
sprites.hbs
temp.js
temp.json
working.js
25 changes: 2 additions & 23 deletions data/DataManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { outputFile } from 'fs-extra/esm'
import path from 'node:path'
import ProgressBar from 'progress'
import { readFile } from 'node:fs/promises'
import { setTimeout } from 'node:timers/promises'
import retryRequest from './utilities/retryRequest.js'
import stringifyCSV from './utilities/stringifyCSV.js'

export default class DataManager {
Expand Down Expand Up @@ -99,29 +99,8 @@ export default class DataManager {
})

for (const key of this.languages.keys()) {

let waitTime = 1

const makeRequest = async () => {
try {
await this.fetchLanguageComponents(key)
} catch (e) {
if (e?.response?.status === 429) {

waitTime *= 2
console.warn(`\nHit rate limit. Retrying after ${ waitTime }ms.`)
await setTimeout(waitTime)
await makeRequest()

} else {
throw e
}
}
}

await makeRequest() // Kick off request sequence
await retryRequest(this.fetchLanguageComponents.bind(this), key)
progressBar.tick()

}

}
Expand Down
2 changes: 1 addition & 1 deletion data/csv/Abenaki/components.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ID,Author Surname,Source Code,Page #,ISO code,Dialect,Glottocode,Form (original orthography),Orthography Key Code,Form (project orthography),UR (if given; if different),UR (project orthography),PA form (original orthography),PA form (project orthography),Translation,Project Definition,Component Type,Subcategory,Initial: Reduplicated,Final: concrete / abstract,Final: secondary (y/n/b),Base Category (if secondary)-A,Match AI,Match II,Match TA,Match TI,Allomorph-A,Condition-A,Component occurs in stem (orig. orth)-A,Component occurs in stem (proj. orth)-A,Stem UR-A,Stem category-A,Stem subcategory-A,Stem translation-A,Secondary stem-A,Stem Source-A,Formative/component occurs in what component(s)-A,Contains component (enter)-A,Contains formative (enter)-A,Deverbal (y/n),Deverbal from,Comments,Speaker,1st check done,2nd check done
ID,Author Surname,Source Code,Page #,ISO code,Dialect,Glottocode,Form (original orthography),Orthography Key Code,Form (project orthography),UR (if given; if different),UR (project orthography),PA form (original orthography),PA form (project orthography),Translation,Tags,Component Type,Subcategory,Initial: Reduplicated,Final: concrete / abstract,Final: secondary (y/n/b),Base Category (if secondary)-A,Match AI,Match II,Match TA,Match TI,Allomorph-A,Condition-A,Component occurs in stem (orig. orth)-A,Component occurs in stem (proj. orth)-A,Stem UR-A,Stem category-A,Stem subcategory-A,Stem translation-A,Secondary stem-A,Stem Source-A,Formative/component occurs in what component(s)-A,Contains component (enter)-A,Contains formative (enter)-A,Deverbal (y/n),Deverbal from,Comments,Speaker,1st check done,2nd check done
1,Goddard,IG1965,0213,,,aben1250,ôben-,AB:2,,,,*a·p-,,untie,untie,initial,,,,,,,,,,,,,,,,,,,,,,,,,"GVM: Looks like an initial, but is listed as ""(TA, TI)""",,MAM
2,Goddard,IG1965,0214,,,aben1250,ôjemi-,AB:2,,,,*a·t-,,"relate, declare","relate, declare",initial,,,,,,,,,,,,,,,,,,,,,,,,,,,MAM
3,Goddard,IG1965,0214,,,aben1250,ôtl-,AB:2,,,,*a·nt-,,"move, change, afresh, anew","move, change, afresh, anew",initial,,,,,,,,,,,,,,,,,,,,,,,,,"GVM: Looks like an initial, but is listed as ""(TA, TI)"". MAM: this is a PA initial, so I don't know why it would say that.",,MAM
Expand Down
1 change: 1 addition & 0 deletions data/models/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default class Components extends Map {
stemSubcategory: `Stem subcategory`,
stemUR: `Stem UR`,
subcategory: `Subcategory`,
tags: `Tags`,
type: `Component Type`,
UR: `UR (if given; if different)`,
}
Expand Down
50 changes: 19 additions & 31 deletions data/tags/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { parse as parseCSV } from 'csv-parse/sync'
import path from 'node:path'
import ProgressBar from 'progress'
import { readFile } from 'node:fs/promises'
import { setTimeout } from 'node:timers/promises'
import retryRequest from '../utilities/retryRequest.js'

const csvPath = path.resolve(import.meta.dirname, `tags.csv`)

Expand Down Expand Up @@ -70,12 +70,23 @@ async function updateSpreadsheet(lang) {
const headings = originalRows.shift()
const { range } = data

// Replace "Definition" heading with "Tags"
const definitionIndex = headings.indexOf(`Project Definition`)
const tagsHeader = `Tags`

if (definitionIndex !== -1) headings.splice(definitionIndex, 1, tagsHeader)

const records = originalRows.map(row => {

const record = {}

row.forEach((cell, i) => {
record[headings[i]] = cell
const heading = headings[i]
if (heading) record[heading] = cell
})

return record

})

const cols = Components.columns
Expand All @@ -84,15 +95,17 @@ async function updateSpreadsheet(lang) {

for (const record of records) {

const gloss = record[cols.gloss].trim()
const gloss = record[cols.gloss]?.trim()
const type = record[cols.type]
const tags = tagsMap.get(gloss)

if (gloss && tags && type === `initial`) {
record[cols.definition] = tags.join(`, `)
record[cols.tags] = tags.join(`, `)
}

updatedRows.push(Object.values(record))
const row = Object.values(record)

updatedRows.push(row)

}

Expand Down Expand Up @@ -129,33 +142,8 @@ async function updateAllSpreadsheets() {
const progressBar = new ProgressBar(`:bar`, { total: languages.size })

for (const key of languages.keys()) {

let waitTime = 1

const makeRequest = async () => {
try {

await updateSpreadsheet(key)

} catch (e) {

if (e?.response?.status === 429) {

waitTime *= 2
console.warn(`\nHit rate limit. Retrying after ${ waitTime }ms.`)
await setTimeout(waitTime)
await makeRequest()

} else {
throw e
}

}
}

await makeRequest() // Kick off request sequence
await retryRequest(updateSpreadsheet, key)
progressBar.tick()

}

}
Expand Down
28 changes: 28 additions & 0 deletions data/utilities/retryRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { setTimeout } from 'node:timers/promises'

export default function retryRequest(requestFunction, ...args) {

let waitTime = 1

const request = async () => {
try {

return requestFunction(...args)

} catch (e) {

if (e.response?.status == 429) {
waitTime *= 2
console.warn(`\nHit rate limit. Retrying after ${ waitTime }ms.`)
await setTimeout(waitTime)
return request()
}

throw e

}
}

return request()

}

0 comments on commit 9f58608

Please sign in to comment.